基于labwindows的串口通信
更新时间:2023-10-23 00:13:01 阅读量: 综合文库 文档下载
#include #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);
break; } ArrayToFile (\串口数据.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, \ 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 (\ 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 (\ 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 (\Message\\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 ledcallback (int panel, int control, int event, void *callbackData, int eventData1, int eventData2) {
if (event == EVENT_TIMER_TICK) { } return 0; }
void DisplayRS232Error (void) {
char ErrorMessage[200]; switch (RS232Error) {
default :
if (RS232Error < 0) {
Fmt (ErrorMessage, \ MessagePopup (\ } break; case 0 :
MessagePopup (\ break; case -2 :
Fmt (ErrorMessage, \ \ MessagePopup (\ break; case -3 :
Fmt (ErrorMessage, \ \ MessagePopup (\ break; case -99 :
Fmt (ErrorMessage, \
\
\ check COM Port setting, or\\n\ \ check device.\
MessagePopup (\ break; } }
正在阅读:
基于labwindows的串口通信10-23
司法公正12-13
兰州牛肉拉面作文450字06-12
文件一:广晟公司项目创新简介04-09
氧化锆及四种全冠修复材料磨耗性能的对比研究 - 图文02-28
职业卫生监督检查制度04-15
湖南省2016年初中教师专业适岗培训(第二期)模拟语文试题04-30
有关赞美母亲的诗歌11-21
- 多层物业服务方案
- (审判实务)习惯法与少数民族地区民间纠纷解决问题(孙 潋)
- 人教版新课标六年级下册语文全册教案
- 词语打卡
- photoshop实习报告
- 钢结构设计原理综合测试2
- 2014年期末练习题
- 高中数学中的逆向思维解题方法探讨
- 名师原创 全国通用2014-2015学年高二寒假作业 政治(一)Word版
- 北航《建筑结构检测鉴定与加固》在线作业三
- XX县卫生监督所工程建设项目可行性研究报告
- 小学四年级观察作文经典评语
- 浅谈110KV变电站电气一次设计-程泉焱(1)
- 安全员考试题库
- 国家电网公司变电运维管理规定(试行)
- 义务教育课程标准稿征求意见提纲
- 教学秘书面试技巧
- 钢结构工程施工组织设计
- 水利工程概论论文
- 09届九年级数学第四次模拟试卷
- 串口
- labwindows
- 基于
- 通信
- 2012 大跨授课文稿7(预悬索屋盖) Word 03 文档
- 两种空间插值方法的比较研究
- 县医院医师依法执业情况自查报告
- 绩效管理是怎么一回事?
- 中标公告
- 人教版小学一年级下学期语文全册课文范读朗读诵读课堂教学实录公开课视频录像
- 2017-2023年中国面包车市场前景研究与行业前景预测报告(目录) - 图文
- 四级写作高分策略:准确把握题目要求
- 单片机原理复习题1111
- MFC Windows应用程序设计复习题2
- 机械设计基础课程设计ZDD-3
- 曲柄冲床的结构及工作原理 - 图文
- 《白杨》表格式教学设计
- the-person-i-admire-most
- 档案题1
- 多功能提取罐使用标准操作规程
- 证券投资学复习思考题及答案
- 编导文艺常识试题
- 榫槽成型半自动切削机机械系统设计说明书(1)
- 我为谁而工作演讲稿