labwindows cvi串口采集数据与实时显示

来源:互联网 发布:日文拍照翻译软件 编辑:程序博客网 时间:2024/05/21 11:10
1. main()函数里初始化串口,函数的使用方法参考帮助手册即可
OpenComConfig (7, "", 115200, 0, 8, 1, 512, 512);  //打开串口SetCTSMode (7, LWRS_HWHANDSHAKE_OFF);             //无硬件交互  FlushInQ (7);                                     //清空缓冲区FlushOutQ (7);//PromptPopup ("Event Charter", "Enter the Enevnt Character", gEventChar, 1); InstallComCallback (7, LWRS_RECEIVE, 2, 0, Event_Char_Func, 0);    //绑定串口事件回调函数DisplayPanel (panelHandle);  RunUserInterface ();CloseCom(7);                            //软件关闭时关闭串口DiscardPanel (panelHandle);return 0;
2.  串口回调函数
void CVICALLBACK   Event_Char_Func(int portNo,int eventMask,void * callbackData){               char strBuf[20]={0};float dataBuf[200]={0.0} ;float InputVoltageMv;int  InjectedConvData= 0;unsigned int strLen=GetInQLen(7);  //获取串口接收的数据缓冲区长度ComRd(7, readBuf, strLen);  //读取指定长度数据PlotStripChart (panelHandle, PANEL_VOLTAGE_GRAPH,   readBuf, strLen, 0, 0, VAL_FLOAT);   //把数据在曲线图上从左至右实时更新

}

0 0
原创粉丝点击