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

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);   //把数据在曲线图上从左至右实时更新

}
 
  

你可能感兴趣的:(labview,进击的嵌入式)