如何将串口接收到的数据显示在编辑框中? 5
小弟用的是serialPort,MFC,怎么才能把串口接收到的数据显示在编辑框中?求大侠帮助!voidCRBAS_ODBCView::OnButtonSurveyStar...
小弟用的是serialPort,MFC,怎么才能把串口接收到的数据显示在编辑框中?求大侠帮助!
void CRBAS_ODBCView::OnButtonSurveyStart()
{
/**************发数据*********************************/
SerialPort^ _serialPort = gcnew SerialPort("COM3", 38400, Parity(0), 8, StopBits(1));//设置串口信息
_serialPort->DataReceived += gcnew SerialDataReceivedEventHandler(DataReceived);
array<unsigned char>^ SendBuf = {0x01,0xF0,0X01,0X08,0XF9,0X0D};
if (!_serialPort->IsOpen)
_serialPort->Open();
for (int i = 0;i < SendBuf->Length;i++)
{
_serialPort->Write(SendBuf, i, 1);
Sleep(10);
}
//Draw();
}
void CRBAS_ODBCView::DataReceived(Object^ sender, SerialDataReceivedEventArgs^ e)
{
SerialPort^ _serialPort = (SerialPort^)sender;
Sleep(100);
int count = _serialPort->BytesToRead;
array<unsigned char>^ ReadBuf = gcnew array<unsigned char>(count);
_serialPort->Read(ReadBuf, 0, count);
//解析
double m_dInFlow = (ReadBuf[2] * 65536 + ReadBuf[3] * 256 + ReadBuf[4]) / 1000.000;
_serialPort->Close();
}
怎么才能把串口接收到的数据返回给主线程? 展开
void CRBAS_ODBCView::OnButtonSurveyStart()
{
/**************发数据*********************************/
SerialPort^ _serialPort = gcnew SerialPort("COM3", 38400, Parity(0), 8, StopBits(1));//设置串口信息
_serialPort->DataReceived += gcnew SerialDataReceivedEventHandler(DataReceived);
array<unsigned char>^ SendBuf = {0x01,0xF0,0X01,0X08,0XF9,0X0D};
if (!_serialPort->IsOpen)
_serialPort->Open();
for (int i = 0;i < SendBuf->Length;i++)
{
_serialPort->Write(SendBuf, i, 1);
Sleep(10);
}
//Draw();
}
void CRBAS_ODBCView::DataReceived(Object^ sender, SerialDataReceivedEventArgs^ e)
{
SerialPort^ _serialPort = (SerialPort^)sender;
Sleep(100);
int count = _serialPort->BytesToRead;
array<unsigned char>^ ReadBuf = gcnew array<unsigned char>(count);
_serialPort->Read(ReadBuf, 0, count);
//解析
double m_dInFlow = (ReadBuf[2] * 65536 + ReadBuf[3] * 256 + ReadBuf[4]) / 1000.000;
_serialPort->Close();
}
怎么才能把串口接收到的数据返回给主线程? 展开
1个回答
2015-11-20
展开全部
龚建伟 的 教程 很好的
建议去 看看
建议去 看看
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
迪凯特科技(北京)有限公司
2023-07-28 广告
2023-07-28 广告
首先,获取单片机和串口屏的通信协议; 其次,在PC中编写串口通信软件,分别控制两个设备即可; 调试的时候,可以先用现有的串口助手类软件如串口调试助手,或者自定义协议功能的通信软件如格西烽火,测试和验证你定义的协议…...
点击进入详情页
本回答由迪凯特科技(北京)有限公司提供
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询