




已阅读5页,还剩5页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
#include #include #include #include #include #include #include 串口通信.h#define text_length 2048static 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 devicename30; char send_datatext_length;char read_datatext_length;char tbox_read_datatext_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_ devicename0=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, PANEL) 0)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, CONFIG); 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 buffer512;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); break; ArrayToFile (c:UserswangleiDesktop串口数据.txt, tbox_read_data, VAL_CHAR, inputqueuelength, 1, VAL_DATA_MULTIPLEXED, VAL_GROUPS_AS_COLUMNS, VAL_CONST_WIDTH, 2, VAL_BINARY, VAL_APPEND);int CVICALLBACK clearcallback (int panel, int control, int event,void *callbackData, int eventData1, int eventData2)switch (event)case EVENT_COMMIT:ResetTextBox (panelHandle, PANEL_RECEIVEDATAPLOT, 0);break;return 0;int CVICALLBACK stopcallback (int panel, int control, int event,void *callbackData, int eventData1, int eventData2)switch (event)case EVENT_COMMIT:break;return 0;int CVICALLBACK checkgraphcallback (int panel, int control, int event,void *callbackData, int eventData1, int eventData2)switch (event)case EVENT_COMMIT:break;return 0;int CVICALLBACK checkdatacallback (int panel, int control, int event,void *callbackData, int eventData1, int eventData2)switch (event)case EVENT_COMMIT:break;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 flushoutputcallback (int panel, int control, int event,void *callbackData, int eventData1, int eventData2)switch (event)case EVENT_COMMIT:FlushOutQ (comport); MessagePopup (RS232 Message, Output queue flushed.);break;return 0;int CVICALLBACK flushinputcallback (int panel, int control, int event,void *callbackData, int eventData1, int eventData2)switch (event)case EVENT_COMMIT:FlushInQ (comport); MessagePopup (RS232 Message, Input queue flushed.);break;return 0;int CVICALLBACK closecallback (int panel, int control, int event,void *callbackData, int eventData1, int eventData2)switch (event)case EVENT_COMMIT: port_open = 0; /* initialize flag to 0 - unopened */ GetConfigParms (); DisableBreakOnLibraryErrors (); RS232Error = OpenComConfig (comport, devicename, baudrate, parity, databits, stopbits, inputq, outputq); EnableBreakOnLibraryErrors (); if (RS232Error)MessagePopup (RS232 Message, Please Reset the RS232 Configuer Content ); if (RS232Error = 0) port_open = 1; GetCtrlVal (config_handle, CONFIG_XMODE, &xmode); SetXMode (comport, xmode); GetCtrlVal (config_handle, CONFIG_CTSMODE, &ctsmode); SetCTSMode (comport, ctsmode); GetCtrlVal (config_handle, CONFIG_TIMEOUT, &timeout); SetComTime (comport, timeout); EnablePanelControls (0); else EnablePanelControls (1); DiscardPanel (config_handle);break;return 0;int CVICALLBACK ledcall
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 福建砖烟囱拆除施工方案
- 小学六年级信息技术授课设计方案
- 混凝土墙板保温施工方案
- 新入职周工作总结
- 物业管家转正申请述职报告
- 楼层经理述职报告
- 幼儿园双语教学活动方案与效果分析
- 护理临床教学病案讨论
- 2025年环境影响评价工程师技术方法考试真题及答案解析
- 罐头杀菌工岗位操作规程考核试卷及答案
- 心电图监护中患者护理查房
- 胃肠间质瘤诊疗指南2025年版
- 耳石症的诊断与治疗
- 2025年民政行业技能鉴定考试-殡仪服务员考试历年参考题库含答案解析(5套共100道单选题合辑)
- 医务人员职业道德与服务礼仪培训
- 加油站有限空间安全管理制度
- 煤炭洗选技术课件教学
- 《西门子触摸屏组态与应用》课件
- 专项训练:除法数字谜(除数是两位数的除法)(含解析)人教版小学数学四年级上册
- 企业IT权限管理制度
- ktv佳丽部管理制度
评论
0/150
提交评论