#include
#define text_length 2048 static int config_handle; config_flag; portindex; port_open; RS232Error; comport; baudrate; parity; databits; stopbits; inputq; outputq; xmode; ctsmode; type; stringsize; bytes_sent; send_byte; send_mode; read_cnt; bytes_read;
char devicename[30]; char send_data[text_length]; char read_data[text_length];
char tbox_read_data[text_length]; double timeout;
static void *callbackdata;
static int panelHandle, graphpanel, config;
void ComCallback(int COMport, int eventMask, void *callbackdata); void SetConfigParms (); void GetConfigParms ();
void EnablePanelControls (int);
void SendAscii(void); void SendByte(void);
void DisplayRS232Error (void);
void SetConfigParms () { SetCtrlVal (config_handle, CONFIG_COMPORT, comport); SetCtrlVal (config_handle, CONFIG_BAUDRATE, baudrate); SetCtrlVal (config_handle, CONFIG_PARITY, parity);
SetCtrlVal (config_handle, CONFIG_DATABITS, databits); SetCtrlVal (config_handle, CONFIG_STOPBITS, stopbits); SetCtrlVal (config_handle, CONFIG_INPUTQ, inputq); SetCtrlVal (config_handle, CONFIG_OUTPUTQ, outputq); SetCtrlVal (config_handle, CONFIG_CTSMODE, ctsmode); SetCtrlVal (config_handle, CONFIG_XMODE, xmode);
SetCtrlIndex (config_handle, CONFIG_COMPORT, portindex); }
void GetConfigParms () { GetCtrlVal (config_handle, CONFIG_COMPORT, &comport); GetCtrlVal (config_handle, CONFIG_BAUDRATE, &baudrate); GetCtrlVal (config_handle, CONFIG_PARITY, &parity);
GetCtrlVal (config_handle, CONFIG_DATABITS, &databits); GetCtrlVal (config_handle, CONFIG_STOPBITS, &stopbits); GetCtrlVal (config_handle, CONFIG_INPUTQ, &inputq); GetCtrlVal (config_handle, CONFIG_OUTPUTQ, &outputq); GetCtrlVal (config_handle, CONFIG_CTSMODE, &ctsmode); GetCtrlVal (config_handle, CONFIG_XMODE, &xmode); GetCtrlVal (config_handle, CONFIG_TIMEOUT, &timeout); GetCtrlIndex (config_handle, CONFIG_COMPORT, &portindex); #ifdef _NI_unix_
devicename[0]=0; #else
GetLabelFromIndex (config_handle, CONFIG_COMPORT, portindex, devicename); #endif }
void EnablePanelControls (int enable) {
SetCtrlAttribute (panelHandle, PANEL_SENDMODE, ATTR_DIMMED, enable); SetCtrlAttribute (panelHandle, PANEL_SENDDATA, ATTR_DIMMED, enable); SetCtrlAttribute (panelHandle, PANEL_SENDNUMBER, ATTR_DIMMED, enable); SetCtrlAttribute (panelHandle, PANEL_RECEIVENUMBER, ATTR_DIMMED, enable); SetCtrlAttribute (panelHandle, PANEL_RECEIVEDATA, ATTR_DIMMED, enable); SetCtrlAttribute (panelHandle, PANEL_STOPRECEIVE, ATTR_DIMMED, enable); SetCtrlAttribute (panelHandle, PANEL_CHECKDATA, ATTR_DIMMED, enable); SetCtrlAttribute (panelHandle, PANEL_CHECKGRAPH, ATTR_DIMMED, enable); SetCtrlAttribute (panelHandle, PANEL_FLUSHINPUT, ATTR_DIMMED, enable); SetCtrlAttribute (panelHandle, PANEL_FLUSHOUTPUT, ATTR_DIMMED, enable); SetCtrlAttribute (panelHandle, PANEL_DATA, ATTR_DIMMED, enable); }
int main (int argc, char *argv[]) { if (InitCVIRTE (0, argv, 0) == 0) return -1; /* out of memory */ if ((panelHandle = LoadPanel (0, \串口通信.uir\ return -1; DisplayPanel (panelHandle); RunUserInterface (); DiscardPanel (panelHandle); return 0; }
int CVICALLBACK configcallback (int panel, int control, int event, void *callbackData, int eventData1, int eventData2) { switch (event) { case EVENT_COMMIT: config_handle = LoadPanel (panelHandle, \串口通信.uir\ InstallPopup (config_handle);
if (config_flag) /* Configuration done at least once.*/ SetConfigParms (); else config_flag = 1; break; } return 0; }
int CVICALLBACK sendmodecallback (int panel, int control, int event,
void *callbackData, int eventData1, int eventData2) { switch (event) { case EVENT_COMMIT: GetCtrlVal (panelHandle, PANEL_SENDMODE, &send_mode); if(send_mode) { SetCtrlAttribute (panelHandle, PANEL_SENDDATAPLOT, ATTR_DIMMED, 0); SetCtrlAttribute (panelHandle, PANEL_DATA, ATTR_DIMMED,1); } else { SetCtrlAttribute (panelHandle, PANEL_SENDDATAPLOT, ATTR_DIMMED, 1); SetCtrlAttribute (panelHandle, PANEL_DATA, ATTR_DIMMED,0); } } return 0; }
int CVICALLBACK sendcallback (int panel, int control, int event, void *callbackData, int eventData1, int eventData2) { switch (event) { case EVENT_COMMIT: GetCtrlVal (panelHandle, PANEL_SENDMODE, &type); if(type) SendAscii(); else SendByte(); RS232Error = ReturnRS232Err (); if (RS232Error)
DisplayRS232Error(); SetCtrlVal (panelHandle, PANEL_SENDNUMBER, bytes_sent); break; } return 0; }
void SendAscii() {
GetCtrlVal (panelHandle, PANEL_SENDDATAPLOT, send_data); stringsize = StringLength (send_data);
bytes_sent = ComWrt (comport, send_data, stringsize); }
void SendByte() { GetCtrlVal (panelHandle, PANEL_DATA,&send_byte); bytes_sent = ComWrtByte (comport, send_byte); }
int CVICALLBACK receivecallback (int panel, int control, int event, void *callbackData, int eventData1, int eventData2) { switch (event) { case EVENT_COMMIT: InstallComCallback (comport, LWRS_RECEIVE, 2, 0, ComCallback, callbackdata);
case EVENT_RIGHT_CLICK : break; } return 0; }
void ComCallback(int COMport, int eventMask, void *callbackdata) {
int inputqueuelength; int bytesread; char buffer[512]; char *matchedchar = 0; double value; int i; inputqueuelength = GetInQLen (comport); bytesread = ComRd (comport, buffer, inputqueuelength); for (i = 0; i <= bytesread; i ++) { matchedchar = buffer + i ; CopyString (tbox_read_data, 0, matchedchar, 0, inputqueuelength); SetCtrlVal (panelHandle, PANEL_RECEIVEDATAPLOT, tbox_read_data);
百度搜索“77cn”或“免费范文网”即可找到本站免费阅读全部范文。收藏本站方便下次阅读,免费范文网,提供经典小说综合文库基于labwindows的串口通信在线全文阅读。
相关推荐: