#include "toolbox.h"
#include <ansi_c.h>
#include <rs232.h>
#include <cvirte.h>
#include <userint.h>
#include "chuankou.h"
static int panelHandle;
int com;
void CVICALLBACK com_callback (int portNumber, int eventMask, void *callbackData);
int main (int argc, char *argv[])
{
if (InitCVIRTE (0, argv, 0) == 0)
return -1;
if ((panelHandle = LoadPanel (0, "chuankou.uir", PANEL)) < 0)
return -1;
DisplayPanel (panelHandle);
RunUserInterface ();
DiscardPanel (panelHandle);
return 0;
}
int CVICALLBACK PANEL_callback (int panel, int event, void *callbackData,
int eventData1, int eventData2)
{
switch (event)
{
case EVENT_GOT_FOCUS:
break;
case EVENT_LOST_FOCUS:
break;
case EVENT_CLOSE:
QuitUserInterface (0);
break;
}
return 0;
}
int CVICALLBACK COM_send_callback (int panel, int control, int event,
void *callbackData, int eventData1, int eventData2)
{ char buf[1024];
switch (event)
{
case EVENT_COMMIT:
memset(buf,0,1024);
GetCtrlVal (panelHandle, PANEL_send, buf);
if(strlen(buf)!=0)
{
ComWrt(com+1,buf,sizeof(buf));
}
break;
}
return 0;
}
int CVICALLBACK BINARYSWITCH_callback (int panel, int control, int event,
void *callbackData, int eventData1, int eventData2)
{
int val;
char lab_com[10];
int bod;
switch (event)
{
case EVENT_COMMIT:
memset(lab_com,0,10);
GetCtrlVal (panelHandle, PANEL_BINARYSWITCH, &val);
GetCtrlVal (panelHandle, PANEL_COM, &com);
GetLabelFromIndex (panelHandle, PANEL_COM, com, lab_com);
GetCtrlVal (panelHandle, PANEL_BOD, &bod);
if(val==1)
{
DisableBreakOnLibraryErrors();
OpenComConfig (com+1, lab_com, 9600, 0, 8, 1, 512, 512);
SetXMode (com+1, 0);
SetCTSMode (com+1, 0);
EnableBreakOnLibraryErrors();
SetComTime(com+1,0.1);
FlushInQ(com+1);
FlushOutQ(com+1);
InstallComCallback (com+1, LWRS_RECEIVE, 2, 0, com_callback, 0);
SetCtrlVal (panelHandle, PANEL_LED, 1);
SetCtrlAttribute (panelHandle, PANEL_TIMER, ATTR_ENABLED,1);
}
else
{
SetCtrlVal (panelHandle, PANEL_LED, 0);
CloseCom(com+1);
SetCtrlAttribute (panelHandle, PANEL_TIMER, ATTR_ENABLED,0);
}
break;
}
return 0;
}
int CVICALLBACK TIMER_callback (int panel, int control, int event,
void *callbackData, int eventData1, int eventData2)
{
double val;
switch (event)
{
case EVENT_TIMER_TICK:
GetCtrlVal (panelHandle, PANEL_NUMERIC, &val);
PlotStripChart (panelHandle, PANEL_STRIPCHART, &val, 1, 0, 0, VAL_DOUBLE);
break;
}
return 0;
}
void CVICALLBACK com_callback (int portNumber, int eventMask, void *callbackData)
{
char buf[1024];
memset(buf,0,1024);
ComRd (com+1,buf,1024);
InsertTextBoxLine (panelHandle, PANEL_recv, -1, buf);
SetCtrlVal (panelHandle, PANEL_NUMERIC,atof(buf));
}
|