|
#include <ansi_c.h>
#include <cvirte.h>
#include <userint.h>
#include "rs232.h"
#include <rs232.h>
#include <formatio.h>
static int panelHandle;
int comselect;
int status;
char info[20],readBuf[20];
int main (int argc, char *argv[])
{
if (InitCVIRTE (0, argv, 0) == 0)
return -1; /* out of memory */
if ((panelHandle = LoadPanel (0, "rs232.uir", PANEL)) < 0)
return -1;
DisplayPanel (panelHandle);
RunUserInterface ();
DiscardPanel (panelHandle);
return 0;
}
int CVICALLBACK Config (int panel, int control, int event,
void *callbackData, int eventData1, int eventData2)
{
int btlselect,jhselect,longselect,stopselect;
int comvalue,btlvalue,longvalue,stopvalue,jhvalue;
switch (event)
{
case EVENT_COMMIT:
GetCtrlVal (PANEL, PANEL_COMSELECT, &comvalue); /* 获取端口号 */
switch (comvalue)
{
case 1:
comselect=1;
break;
case 2:
comselect=2;
break;
case 3:
comselect=3;
break;
case 4:
comselect=4;
break;
}
GetCtrlVal (PANEL, PANEL_BTLSELECT, &btlvalue); /* 波特率*/
switch (btlvalue)
{
case 1:
btlselect=1200;
break;
case 2:
btlselect=2400;
break;
case 3:
btlselect=4800;
break;
case 4:
btlselect=9600;
break;
case 5:
btlselect=19200;
break;
}
GetCtrlVal (PANEL, PANEL_JYSELECT, &jhvalue); /* 奇偶校验*/
switch (jhvalue)
{
case 1:
jhselect=0;
break;
case 2:
jhselect=1;
break;
case 3:
jhselect=2;
break;
}
GetCtrlVal (PANEL, PANEL_LONGSELECT, &longvalue); /* 字长 */
switch (longvalue)
{
case 1:
longselect=7;
break;
case 2:
longselect=8;
break;
case 3:
longselect=9;
break;
}
GetCtrlVal (PANEL, PANEL_STOPSELECT, &stopvalue); /* 停止位*/
switch (stopvalue)
{
case 1:
stopselect=1;
break;
case 2:
stopselect=2;
break;
}
status=OpenComConfig(comselect,"",btlselect,jhselect,longselect,stopselect,512,512); /* 打开串口*/
if(status!=0)
{
MessagePopup("Error","config failed!");
return 0;
}
SetCTSMode(comselect,LWRS_HWHANDSHAKE_OFF); /*禁止硬件握手 */
break;
}
return 0;
}
int CVICALLBACK Send (int panel, int control, int event,
void *callbackData, int eventData1, int eventData2)
{
switch (event)
{
case EVENT_COMMIT:
FlushInQ(comselect); /* 清空串口输入队列 */
FlushOutQ(comselect); /* 清空串口输出队列 */
GetCtrlVal (PANEL, PANEL_SENDTEXT, info);
status=ComWrt(comselect,info,strlen(info));
if(status!=strlen(info))
MessagePopup("Error","Send data failed!");
break;
}
return 0;
}
int CVICALLBACK Receive (int panel, int control, int event, /* 接收数据函数 */
void *callbackData, int eventData1, int eventData2)
{
switch (event)
{
case EVENT_COMMIT:
status=ComRd(comselect,readBuf,strlen(info));
if(status!=strlen(info))
{
MessagePopup("Error","Read data failed!");
break;
}
SetCtrlVal (PANEL, PANEL_RECEIVETEXT, readBuf);
SetActiveCtrl (PANEL, PANEL_RECEIVETEXT);
break;
}
return 0;
}
int CVICALLBACK Clearsend (int panel, int control, int event, /* 清空发送框 */
void *callbackData, int eventData1, int eventData2)
{
switch (event)
{
case EVENT_COMMIT:
ResetTextBox(PANEL,PANEL_SENDTEXT,"\0");
break;
}
return 0;
}
int CVICALLBACK Clearreceive (int panel, int control, int event, /* 清空接收框 */
void *callbackData, int eventData1, int eventData2)
{
switch (event)
{
case EVENT_COMMIT:
ResetTextBox(PANEL,PANEL_RECEIVETEXT,"\0");
break;
}
return 0;
}
int CVICALLBACK Quit (int panel, int control, int event, /* 退出 */
void *callbackData, int eventData1, int eventData2)
{
switch (event)
{
case EVENT_COMMIT:
QuitUserInterface (0);
break;
}
return 0;
}
|
|