看到的这个程序
void CPC_SimpleDlg::OnSend() { unsigned char sendbuf[10] = {0x01,0x01,0x02,0x03,0x04, 0x05,0x06,0x07,0x08,0x09}; //发送的数据 unsigned char recbuf[10]; //接收缓冲区
for (int i = 0; i < 10; i++) recbuf = 0; //清空接收缓冲区 int ret; ret = WriteData(3,sendbuf,1,1000); if (ret != 1) //发送10个字节 { MessageBox("发送数据错误!"); return; }
ret = ReadData(2,recbuf,8,1000); //接收10个字节 if (ret != 8) { MessageBox("接收数据错误!"); return; }
m_ReceiveByte = ""; //显示收到的字节 for (i = 0; i < 10; i++) m_ReceiveByte.Format("%s",recbuf); //m_ReceiveByte += IntToASCII(recbuf) + " ";
UpdateData(FALSE);
}
可以理解为,上位机发送数据后,等待slave发送数据
有没有办法用中断方式, slave发送数据后, 上位机接收数据,不用查询的方式.
|