77范文网 - 专业文章范例文档资料分享平台

基于labwindows的串口通信

来源:网络收集 时间:2018-11-11 下载这篇文档 手机版
说明:文章内容仅供预览,部分内容可能不全,需要完整文档或者需要复制内容,请下载word后使用。下载word有问题请添加微信号:或QQ: 处理(尽可能给您提供完整文档),感谢您的支持与谅解。点击这里给我发消息

#include #include #include #include #include #include #include \串口通信.h\

#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的串口通信在线全文阅读。

基于labwindows的串口通信.doc 将本文的Word文档下载到电脑,方便复制、编辑、收藏和打印 下载失败或者文档不完整,请联系客服人员解决!
本文链接:https://www.77cn.com.cn/wenku/zonghe/266540.html(转载请注明文章来源)
Copyright © 2008-2022 免费范文网 版权所有
声明 :本网站尊重并保护知识产权,根据《信息网络传播权保护条例》,如果我们转载的作品侵犯了您的权利,请在一个月内通知我们,我们会及时删除。
客服QQ: 邮箱:tiandhx2@hotmail.com
苏ICP备16052595号-18
× 注册会员免费下载(下载后可以自由复制和排版)
注册会员下载
全站内容免费自由复制
注册会员下载
全站内容免费自由复制
注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信: QQ: