Subversion Repositories f9daq

Compare Revisions

No changes between revisions

Ignore whitespace Rev 218 → Rev 219

/cvi/RedPitaya/Perušek_Primož_-_Razvoj_LabVIEW_gonilnikov_za_inštrument_Red_Pitaya.pdf
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
Property changes:
Added: svn:mime-type
+application/octet-stream
\ No newline at end of property
/cvi/RedPitaya/RedPitaya.c
0,0 → 1,226
//==============================================================================
//
// Title: RedPitaya.c
// Purpose: A short description of the implementation.
//
// Created on: 27. 01. 2017 at 13:29:33 by Samo Korpar.
// Copyright: . All Rights Reserved.
//
//==============================================================================
 
//==============================================================================
// Include files
 
//#include "RedPitaya.h"
#include "RedPitaya_ui.h"
#include <userint.h>
#include <ansi_c.h>
#include <utility.h>
#include <visa.h>
#include <cvirte.h>
 
//==============================================================================
// Constants
 
#define MAX_THREADS 10
#define NSAMPLES 2048
#define NBEFORE 80
#define NGROUP 32
#define MAXSAMPLES 16384
#define MINTRGDELAY -8192
#define MAXTDCCH 0x80
 
//==============================================================================
// Types
 
//==============================================================================
// Static global variables
 
static int daq_on = 0;
static int ntics;
static int poolHandle = 0;
static int p1h, pID, rID, tfID;
static int ph_tdc, ph_wf;
static int dtdc[MAXTDCCH];
static int debugOut = 0;
 
static ViStatus istat;
static ViSession RedPHandle,RMHandle;
 
//==============================================================================
// Static functions
 
static int update_plots (void)
{
if (ph_tdc>0) DeleteGraphPlot (p1h, P1_TDC_G, ph_tdc, VAL_DELAYED_DRAW);
ph_tdc = PlotY (p1h, P1_TDC_G, &dtdc[0], MAXTDCCH, VAL_INTEGER,
VAL_VERTICAL_BAR, VAL_EMPTY_SQUARE, VAL_SOLID, 1, VAL_RED);
return (0);
}
 
static int CVICALLBACK daq_run(void *functionData)
{
int i,trgdly,neve,ieve,ndata;
float data[10000];
char datac[100000];
char *ctoken_p;
char response[80];
 
istat = viPrintf (RedPHandle, "ACQ:RST\r\n");
istat = viPrintf (RedPHandle, "ACQ:AVG OFF\r\n");
istat = viPrintf (RedPHandle, "ACQ:DEC 1\r\n");
istat = viPrintf (RedPHandle, "ACQ:TRIG:LEV -0.03\r\n");
trgdly = MINTRGDELAY + NSAMPLES - NBEFORE + 1;
istat = viPrintf (RedPHandle, "ACQ:TRIG:DLY %0d\r\n", trgdly);
istat = viPrintf (RedPHandle, "ACQ:START\r\n");
Delay(0.01);
istat = viPrintf (RedPHandle, "ACQ:TRIG CH1_NE\r\n");
// istat = viPrintf (RedPHandle, "ACQ:TRIG NOW\r\n");
 
GetCtrlVal (p1h, P1_NEVE_N, &neve);
ieve=0;
do {
while (VI_TRUE) {
istat = viQueryf (RedPHandle, "ACQ:TRIG:STAT?\r\n", "%s",response);
if (response[0]=='T') break;
if (!daq_on) break;
}
if (!daq_on) break;
istat = viQueryf (RedPHandle, "ACQ:SOUR1:DATA:LAT:N? %0d\r\n", "%s", NSAMPLES, datac);
istat = viPrintf (RedPHandle, "ACQ:START\r\n");
Delay(0.001);
istat = viPrintf (RedPHandle, "ACQ:TRIG CH1_NE\r\n");
// istat = viPrintf (RedPHandle, "ACQ:TRIG NOW\r\n");
// Delay(0.01);
ndata=0;
ctoken_p = strtok (datac, "{,}\r");
while (ctoken_p) {
sscanf(ctoken_p,"%f",&data[ndata]);
if ((ndata)&&(data[ndata]<-0.015)&&(data[ndata-1]>=-0.015)) dtdc[ndata/NGROUP]++;
ctoken_p = strtok (NULL, "{,}\r");
ndata++;
}
ph_wf = PlotY (p1h, P1_WF_G, data, ndata, VAL_FLOAT, VAL_THIN_LINE, VAL_NO_POINT, VAL_SOLID, 1, VAL_BLUE);
SetCtrlVal (p1h, P1_CEVE_N, ++ieve);
if (debugOut) {
sprintf(response,"%d, %d",ieve,ndata);
istat = InsertTextBoxLine (p1h, P1_IO_TB, -1, response);
debugOut=0;
}
} while (ieve<neve);
daq_on=0;
SetCtrlVal (p1h, P1_DAQ_S, daq_on);
SetCtrlVal (p1h, P1_CEVE_N, ieve);
return 0;
}
//==============================================================================
// Global variables
 
//==============================================================================
// Global functions
 
/// HIFN What does your function do?
/// HIPAR x/What inputs does your function expect?
/// HIRET What does your function return?
 
int CVICALLBACK cb_timer (int panel, int control, int event, void *callbackData,
int eventData1, int eventData2)
{
QueueUserEvent (9000, p1h, P1_TIMER_T);
return (0);
}
 
int CVICALLBACK debug_pressed (int panel, int control, int event,
void *callbackData, int eventData1, int eventData2) {
switch (event) {
case EVENT_COMMIT:
debugOut=1;
break;
}
return 0;
}
 
int __stdcall WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
LPSTR lpszCmdLine, int nCmdShow) {
int i,refon,dummy;
char response[80];
if (InitCVIRTE (hInstance, 0, 0) == 0)
return -1; /* out of memory */
 
SetSleepPolicy(VAL_SLEEP_MORE);
CmtNewThreadPool (MAX_THREADS, &poolHandle);
 
SetStdioWindowOptions (1000, 0, 0);
SetStdioWindowSize (150, 600);
SetStdioWindowPosition (825, 20);
 
istat = viOpenDefaultRM (&RMHandle);
istat = viOpen (RMHandle, "TCPIP0::178.172.43.73::5000::SOCKET", VI_NULL, VI_NULL, &RedPHandle);
istat = viSetAttribute (RedPHandle, VI_ATTR_TCPIP_KEEPALIVE, VI_TRUE);
istat = viSetAttribute (RedPHandle, VI_ATTR_TCPIP_NODELAY, VI_TRUE);
istat = viSetAttribute (RedPHandle, VI_ATTR_TERMCHAR, '\n');
istat = viSetAttribute (RedPHandle, VI_ATTR_TERMCHAR_EN, VI_TRUE);
istat = viSetAttribute (RedPHandle, VI_ATTR_TMO_VALUE, 1000);
 
if ((p1h = LoadPanel (0, "RedPitaya_ui.uir", P1)) < 0) return -1;
DisplayPanel (p1h);
istat = SetCtrlAttribute (p1h, P1_WF_G, ATTR_DATA_MODE, VAL_DISCARD);
 
istat = viQueryf (RedPHandle, "*IDN?\r\n", "%s",response);
istat = InsertTextBoxLine (p1h, P1_IO_TB, -1,response);
istat = ProcessDrawEvents ();
 
QueueUserEvent (1000, p1h, P1_RESET_PB);
 
do {
GetUserEvent (1, &pID, &rID);
switch (rID) {
case P1_TIMER_T:
ntics+=1;
GetCtrlVal (p1h, P1_REFON_CB, &refon);
if (refon) update_plots();
break;
case P1_REFRESH_PB:
update_plots();
break;
case P1_DAQ_S:
GetCtrlVal (p1h, P1_DAQ_S, &daq_on);
if (daq_on) {
CmtScheduleThreadPoolFunction (poolHandle, daq_run, (void *)&dummy, &tfID);
}
else {
CmtWaitForThreadPoolFunctionCompletion (poolHandle, tfID,
OPT_TP_PROCESS_EVENTS_WHILE_WAITING);
CmtReleaseThreadPoolFunctionID (poolHandle, tfID);
}
break;
case P1_RESET_PB:
for (i=0; i<MAXTDCCH; i++) {
dtdc[i]=0;
}
update_plots();
case P1_CLEAR_PB:
DeleteGraphPlot (p1h, P1_WF_G, -1, VAL_IMMEDIATE_DRAW);
break;
case P1_TDCLOG_S:
GetCtrlVal (p1h, P1_TDCLOG_S, &istat);
SetCtrlAttribute (p1h, P1_TDC_G, ATTR_YMAP_MODE, istat);
update_plots();
break;
default:
Delay(1.);
}
}
while ((rID != P1_EXIT_PB)||daq_on);
 
CmtDiscardThreadPool (poolHandle);
DiscardPanel (p1h);
 
istat = viClose (RedPHandle);
istat = viClose (RMHandle);
 
return 0;
}
 
/cvi/RedPitaya/RedPitaya.h
0,0 → 1,41
//==============================================================================
//
// Title: RedPitaya.h
// Purpose: A short description of the interface.
//
// Created on: 27. 01. 2017 at 13:29:33 by korpar.
// Copyright: . All Rights Reserved.
//
//==============================================================================
 
#ifndef __RedPitaya_H__
#define __RedPitaya_H__
 
#ifdef __cplusplus
extern "C" {
#endif
 
//==============================================================================
// Include files
 
#include "cvidef.h"
 
//==============================================================================
// Constants
 
//==============================================================================
// Types
 
//==============================================================================
// External variables
 
//==============================================================================
// Global functions
 
int Declare_Your_Functions_Here (int x);
 
#ifdef __cplusplus
}
#endif
 
#endif /* ndef __RedPitaya_H__ */
/cvi/RedPitaya/RedPitaya_ui.h
0,0 → 1,51
/**************************************************************************/
/* LabWindows/CVI User Interface Resource (UIR) Include File */
/* */
/* WARNING: Do not add to, delete from, or otherwise modify the contents */
/* of this include file. */
/**************************************************************************/
 
#include <userint.h>
 
#ifdef __cplusplus
extern "C" {
#endif
 
/* Panels and Controls: */
 
#define P1 1
#define P1_EXIT_PB 2 /* control type: command, callback function: (none) */
#define P1_IO_TB 3 /* control type: textBox, callback function: (none) */
#define P1_WF_G 4 /* control type: graph, callback function: (none) */
#define P1_CLEAR_PB 5 /* control type: command, callback function: (none) */
#define P1_RESET_PB 6 /* control type: command, callback function: (none) */
#define P1_CEVE_N 7 /* control type: numeric, callback function: (none) */
#define P1_TDC_G 8 /* control type: graph, callback function: (none) */
#define P1_NEVE_N 9 /* control type: numeric, callback function: (none) */
#define P1_TDCLOG_S 10 /* control type: binary, callback function: (none) */
#define P1_DAQ_S 11 /* control type: textButton, callback function: (none) */
#define P1_TIMER_T 12 /* control type: timer, callback function: cb_timer */
#define P1_REFON_CB 13 /* control type: radioButton, callback function: (none) */
#define P1_REFRESH_PB 14 /* control type: command, callback function: (none) */
#define P1_DEBUG_PB 15 /* control type: command, callback function: debug_pressed */
 
 
/* Control Arrays: */
 
/* (no control arrays in the resource file) */
 
 
/* Menu Bars, Menus, and Menu Items: */
 
/* (no menu bars in the resource file) */
 
 
/* Callback Prototypes: */
 
int CVICALLBACK cb_timer(int panel, int control, int event, void *callbackData, int eventData1, int eventData2);
int CVICALLBACK debug_pressed(int panel, int control, int event, void *callbackData, int eventData1, int eventData2);
 
 
#ifdef __cplusplus
}
#endif
/cvi/RedPitaya/RedPitaya_ui.uir
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
Property changes:
Added: svn:mime-type
+application/octet-stream
\ No newline at end of property