如何将串口接收到的数据显示在编辑框中? 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
展开全部
龚建伟 的 教程 很好的
建议去 看看
建议去 看看
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询