?? control.c
字號:
#include <ansi_c.h>
#include <rs232.h>
#include <cvirte.h> /* Needed if linking in external compiler; harmless otherwise */
#include <userint.h>
#include "control.h"
static int panelHandle;
int statu,com=1;
int main (int argc, char *argv[])
{
if (InitCVIRTE (0, argv, 0) == 0) /* Needed if linking in external compiler; harmless otherwise */
return -1; /* out of memory */
if ((panelHandle = LoadPanel (0, "control.uir", PANEL)) < 0)
return -1;
DisplayPanel (panelHandle);
RunUserInterface ();
return 0;
}
int CVICALLBACK QuitCallback (int panel, int control, int event,
void *callbackData, int eventData1, int eventData2)
{
switch (event)
{
case EVENT_COMMIT:
QuitUserInterface (0);
break;
}
return 0;
}
int CVICALLBACK ConfigCallback (int panel, int control, int event,void *callbackData, int eventData1, int eventData2)
{
char devicename[10];
switch (event)
{
case EVENT_COMMIT:
// GetCtrlVal(panelHandle,PANEL_COMPORT,&com);
// GetLabelFromIndex(panelHandle,PANEL_COMPORT, com-1,devicename);
/* statu = OpenComConfig (1, "COM1", 9600, 0, 8, 1, 0, 0);
if (statu!=0) MessagePopup ("Error", "Config failed!") ;
else MessagePopup ("Sucess", "Config failed!");
//SetCtrlAttribute (panel, PANEL_ANGLE, ATTR_DIMMED, -statu);
//SetCtrlAttribute (panel, PANEL_SEND, ATTR_DIMMED, -statu);
// SetCtrlAttribute (panel, PANEL_ROTATE, ATTR_DIMMED, -statu);
*/
statu = OpenComConfig (1, "COM1", 9600, 0, 8, 1, 0, 0);
if(statu!=0) MessagePopup ("Error", "Config failed!");
else
{
SetCtrlAttribute (panel, PANEL_SEND, ATTR_DIMMED, -statu);
MessagePopup ("Success", "Config Success!");
}
break;
}
return 0;
}
int CVICALLBACK SendCallback (int panel, int control, int event,
void *callbackData, int eventData1, int eventData2)
{
int bytes;
float angle,rotate;
char senddata[15];
int c,m,n,i,l;
float b;
char s[5];
switch (event)
{
case EVENT_COMMIT:
FlushInQ (1);
FlushOutQ (1);
GetCtrlVal (panelHandle, PANEL_ANGLE, &angle);
GetCtrlVal (panelHandle, PANEL_ROTATE, &rotate);
strcpy(senddata,"a");
if(angle<0)
{
strcat(senddata, "-");
angle=-angle;
}
else strcat(senddata, "+");
angle=angle/0.225;
m=0;
n=0;
i=0;
l=0;
bytes=0;
c=(int)angle;
b=angle-c;
if (b>=0.5)
{
c=c+1;
c=1942;//11.24
}
if(c>1000)
{
m=1;
c=c-1000;
}
if(c>100)
{
n=(int)(c/100);
c=c-n*100;
}
if(c>10)
{
i=(int)(c/10);
c=c-i*10;
}
l=c;
s[0]=m+48;
// strcat(senddata, s);
s[1]=n+48;
//strcat(senddata, s);
s[2]=i+48;
//strcat(senddata, s);
s[3]=l+48;
s[4]='\0';
strcat(senddata, s);
//itoa(c,s,5);
strcat(senddata, s);
strcat(senddata,"d");
statu=ComWrt(1,senddata,9);
if(statu!=9)
{
MessagePopup ("Error", "Send data failed please send again");
}
bytes=ComRdByte(1);
if(bytes>=0)
{
MessagePopup ("Error", "Send data failed please send again");
}
FlushInQ (com);
FlushOutQ (com);
CloseCom (com);
break;
}
return 0;
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -