|
小弟有个问题请教大侠:我需要通过串口读写数据,当PC发送一个数据后,PC会接收到一个反馈数据,用于标识是否正确。当反馈数据是正确,那么继续发送另一条数据,然后继续判断、继续发送。
程序如下
unsigned char hex1,hex2,hex;
unsigned char data[100];
int num=0;
m_strTXData.Remove(' ');
int len=m_strTXData.GetLength();
if(len%2!=0) {AfxMessageBox("输入数据长度错误!");return;}
for(int i=0;i<8;i++)
{
if(len==0) {AfxMessageBox("输入数据长度错误!");break;}
hex1=char2hex(m_strTXData.GetAt(i));
if(hex1==0xFF) {AfxMessageBox("输入数据类型错误!");return;}
else hex1=hex1<<4;
i++;
hex2=char2hex(m_strTXData.GetAt(i));
if(hex2==0xFF) {AfxMessageBox("输入数据类型错误!");return;}
else hex=hex1|hex2;
int n=(i-1)/2;
data[n]=hex;
}//以上字符全转为16进制
CByteArray array;
array.RemoveAll();
for(int i=0;i<len/2;i++)
{
array.InsertAt(i,data,1);
}
m_ctrlComm.set_Output(COleVariant(array));//发送数据
UpdateData(false);
以上我想把data[]里的数据一次发送n遍(比如两遍)如何实现?
如果for(int i=0;i<2;i++)
{
for(int i=0;i<len/2;i++)
{
array.InsertAt(i,data,1);
}
m_ctrlComm.set_Output(COleVariant(array));//发送数据
UpdateData(false);
}是不能实现的,因为下位机必须返回数据,你才能发第二遍,求教各位大哥?? |
阿莫论坛20周年了!感谢大家的支持与爱护!!
知道什么是神吗?其实神本来也是人,只不过神做了人做不到的事情 所以才成了神。 (头文字D, 杜汶泽)
|