我用SerialPort类编写串口通信程序,定义数组c[8]并初始化,用WriteToPort写入串口,现在我想通过一个按钮“发送数据”,实现两个不同数组的发送,先发c[8],在发a[8],要怎么实现。我的程序是
void CSerialPortTestDlg::OnButtonSend()
{
char c[8];
c[0]='\xA4';
...
c[7]='\x22';
m_port.WriteToPort((LPCTSTR)c);
char a[8]
a[0]='\x12';
...
a[8]='\x56';
m_port.WriteToPort((LPCTSTR)a);
}
void CSerialPortTestDlg::OnButtonSend()
{
char c[8];
c[0]='\xA4';
...
c[7]='\x22';
m_port.WriteToPort((LPCTSTR)c);
char a[8]
a[0]='\x12';
...
a[8]='\x56';
m_port.WriteToPort((LPCTSTR)a);
}
我以前也遇到过这样的问题
在要发送的数组中间sleep下就可以了
用定时器
WriteToPort(数组1)
settimer(1,2000,Null);
在timer消息里面
WriteToPort(数组2)
我以前也遇到过这样的问题
在要发送的数组中间sleep下就可以了
[/Quote]
是要这样写吗?
void CSerialPortTestDlg::OnButtonSend()
{
char c[8];
c[0]='\xA4';
...
c[7]='\x22';
m_port.WriteToPort((LPCTSTR)c);
Sleep(2000);
char a[8]
a[0]='\x12';
...
a[8]='\x56';
m_port.WriteToPort((LPCTSTR)a);
}
但是运行后点击按钮,会先延时在同时发出两个数组