Go to most recent revision |
Blame |
Compare with Previous |
Last modification |
View Log
| RSS feed
#include <cvirte.h>
#include <userint.h>
#include "fourier.h"
#include <utility.h>
#include <ansi_c.h>
#include <rs232.h>
int read_term_index
;
int read_term
;
int read_cnt
;
int bytes_read
;
int pCOM1
;
int pCOM2
;
#define TEXT_LENGTH 2000
char read_data
[TEXT_LENGTH
];
char read_data2
[TEXT_LENGTH
];
static int panel
;
#define MAX_THREADS 10
static CmtThreadPoolHandle poolHandle
= 0;
void SetDimming
(int state
) {
SetCtrlAttribute
(panel
, p1_START
, ATTR_DIMMED
, state
);
SetCtrlAttribute
(panel
, p1_EXIT
, ATTR_DIMMED
, state
);
SetCtrlAttribute
(panel
, p1_STOP
, ATTR_DIMMED
, state
);
}
int main
(int argc
, char *argv
[])
{
SetStdioPort
(CVI_STDIO_WINDOW
);
SetStdioWindowOptions
(10000, 0, 0);
SetStdioWindowVisibility
(1);
if (InitCVIRTE
(0, argv
, 0) == 0)
return -1; /* out of memory */
if ((panel
= LoadPanel
(0, "fourier.uir", p1
)) < 0)
return -1;
//CmtNewThreadPool (MAX_THREADS, &poolHandle);
DisplayPanel
(panel
);
SetDimming
(0);
//StartCB(panel, 0, EVENT_COMMIT, NULL, 0 ,0);
RunUserInterface
();
DiscardPanel
(panel
);
return 0;
}
int CVICALLBACK ExitCB
(int panel
, int control
, int event
,
void *callbackData
, int eventData1
, int eventData2
)
{
switch (event
)
{
case EVENT_COMMIT
:
QuitUserInterface
(0);
break;
}
return 0;
}
int CVICALLBACK StopCB
(int panel
, int control
, int event
,
void *callbackData
, int eventData1
, int eventData2
)
{
switch (event
)
{
case EVENT_COMMIT
:
CloseCom
(pCOM1
);
CloseCom
(pCOM2
);
break;
}
return 0;
}
/* Callback Function */
void ComCallback1
(int portNumber
, int eventMask
, void *callbackdata
) {
if (eventMask
& LWRS_RXFLAG
) {
//printf("Received specified character\n");
int strLen
= GetInQLen
(pCOM1
);
bytes_read
= ComRd
(pCOM1
, read_data
, strLen
);
float voltage
;
sscanf(read_data
,"%f",&voltage
);
//printf("%f %d %d#%s#", temp,state[0], state[1], read_data);
int RS232Error
= ReturnRS232Err
();
if (ReturnRS232Err
()) {
sprintf(read_data
,"#%s\n", GetRS232ErrorString
(RS232Error
));
MessagePopup
("RS232Err",read_data
);
} else {
//float ohm;
//double tset;
//char onoff;
//double Voltage, Current;
//char cres[200];
//int i=0;
//int onoff1 = 0;
SetCtrlVal
(panel
, p1_VMON
, voltage
);
//Voltage =K617_vsource_get();
//Current =K617_get(cres,&i);
//K617_vsource_set(vset);
//K617_vsource_operate(onoff1);
//SetCtrlVal(pa,PA_VOLTAGE,Voltage);
//SetCtrlVal(pa,PA_CURRENT,Current);
PlotStripChart
(panel
, p1_GRAPH
, &voltage
, 1, 0, 0, VAL_FLOAT
);
}
}
if (eventMask
& LWRS_TXEMPTY
) printf("Transmit queue now empty\n");
if (eventMask
& LWRS_RECEIVE
) {
printf("50 or more bytes in input queue\n");
}
}
int pozicija
= 0;
int SetPosition
(int pos
){
int nb
=0;
char str
[20];
sprintf(str
, "X%d\n", pos
);
int len
= strlen(str
);
nb
= ComWrt
(pCOM2
, str
, len
);
return nb
;
}
float vx
= 100.0;
int SetSpeed
(float v
){
int nb
= 0;
char vxset
[20];
sprintf(vxset
, "$110=%.2f\n", v
);
printf("Speed %s", vxset
);
int len1
= strlen(vxset
);
nb
= ComWrt
(pCOM2
, vxset
, len1
);
return nb
;
}
int first
= 1;
/* Callback Function */
void ComCallback2
(int portNumber
, int eventMask
, void *callbackdata
) {
if (eventMask
& LWRS_RXFLAG
) {
//printf("Received specified character\n");
int strLen
= GetInQLen
(pCOM2
);
bytes_read
= ComRd
(pCOM2
, read_data2
, strLen
);
printf("%s\n", read_data2
);
if(first
){
SetSpeed
(100.00);
first
= 0;
}
GetCtrlVal
(panel
,p1_POZICIJA
, &pozicija
);
SetPosition
(pozicija
);
//printf("%f %d %d#%s#", temp,state[0], state[1], read_data);
int RS232Error
= ReturnRS232Err
();
if (ReturnRS232Err
()) {
sprintf(read_data2
,"#%s\n", GetRS232ErrorString
(RS232Error
));
MessagePopup
("RS232Err",read_data2
);
} else {
//float ohm;
//double tset;
//char onoff;
//double Voltage, Current;
//char cres[200];
//int i=0;
//int onoff1 = 0;
//SetCtrlVal(panel, p1_VMON, voltage);
//Voltage =K617_vsource_get();
//Current =K617_get(cres,&i);
//K617_vsource_set(vset);
//K617_vsource_operate(onoff1);
//SetCtrlVal(pa,PA_VOLTAGE,Voltage);
//SetCtrlVal(pa,PA_CURRENT,Current);
//PlotStripChart (panel, p1_GRAPH, &voltage, 1, 0, 0, VAL_FLOAT);
}
}
//if (eventMask & LWRS_TXEMPTY) printf("Transmit queue now empty\n");
if (eventMask
& LWRS_RECEIVE
) {
printf("50 or more bytes in input queue\n");
}
}
int CVICALLBACK StartCB
(int panel
, int control
, int event
,
void *callbackData
, int eventData1
, int eventData2
)
{
int ierr
;
int ierr2
;
switch (event
) {
case EVENT_COMMIT
:
first
= 1;
GetCtrlVal
(panel
,p1_COM1
,&pCOM1
);
GetCtrlVal
(panel
,p1_COM2
,&pCOM2
);
//printf("%d %d\n", pCOM1, pCOM2);
ierr
= OpenComConfig
(pCOM1
, "", 115200, 0, 8, 1, 512, 512);
/* Turn off Hardware handshaking (loopback test will not function with it on) */
SetCTSMode
(pCOM1
, LWRS_HWHANDSHAKE_OFF
);
/* Make sure Serial buffers are empty */
FlushInQ
(pCOM1
);
FlushOutQ
(pCOM1
);
int notifyCount1
= 50; /* Wait for at least 50 bytes in queue. */
int eventChar1
= 10; /* Wait for LF. */
int eventMask1
= LWRS_RXFLAG
| LWRS_TXEMPTY
| LWRS_RECEIVE
;
ierr2
= OpenComConfig
(pCOM2
, "", 115200, 0, 8, 1, 512, 512);
/* Turn off Hardware handshaking (loopback test will not function with it on) */
SetCTSMode
(pCOM2
, LWRS_HWHANDSHAKE_OFF
);
printf("ierr %d %d\n", ierr
, ierr2
);
/* Make sure Serial buffers are empty */
FlushInQ
(pCOM2
);
FlushOutQ
(pCOM2
);
int notifyCount2
= 50; /* Wait for at least 50 bytes in queue. */
int eventChar2
= 10; /* Wait for LF. */
int eventMask2
= LWRS_RXFLAG
| LWRS_TXEMPTY
| LWRS_RECEIVE
;
//InstallComCallback (pCOM1, eventMask1, notifyCount1, eventChar1, ComCallback1, NULL);
InstallComCallback
(pCOM2
, eventMask2
, notifyCount2
, eventChar2
, ComCallback2
, NULL
);
break;
}
return 0;
}
int CVICALLBACK GoToEndCB
(int panel
, int control
, int event
,
void *callbackData
, int eventData1
, int eventData2
)
{
switch (event
)
{
case EVENT_COMMIT
:
break;
}
return 0;
}
int CVICALLBACK GoToZeroCB
(int panel
, int control
, int event
,
void *callbackData
, int eventData1
, int eventData2
)
{
switch (event
)
{
case EVENT_COMMIT
:
int nb
= 0;
nb
= ComWrt
(pCOM2
, "X0\n", 4);
return nb
;
break;
}
return 0;
}
int CVICALLBACK ResetCB
(int panel
, int control
, int event
,
void *callbackData
, int eventData1
, int eventData2
)
{
switch (event
)
{
case EVENT_COMMIT
:
break;
}
return 0;
}