这种情况的确存在,对于这种情况的处理是: 如果发送的数据和切换到命令模式的命令(E3)相同时,要重复发送这个字节,这样就是告诉DS2480B要将0xE3作为数据处理而不是切换模式,下面的示例程序供您参考:
int OWBlock(unsigned char *tran_buf, int tran_len)
{
unsigned char sendpacket[320];
unsigned char sendlen=0,pos,i;
// check for a block too big
if (tran_len > 160)
return FALSE;
// construct the packet to send to the DS2480B
// check for correct mode
if (UMode != MODSEL_DATA)
{
UMode = MODSEL_DATA;
sendpacket[sendlen++] = MODE_DATA;
}
// add the bytes to send
pos = sendlen;
for (i = 0; i < tran_len; i++)
{
sendpacket[sendlen++] = tran_buf[i];
// duplicate data that looks like COMMAND mode
if (tran_buf[i] == MODE_COMMAND)
sendpacket[sendlen++] = tran_buf[i]; //重复发送和命令相同的字节
}
// flush the buffers
FlushCOM();
// send the packet
if (WriteCOM(sendlen,sendpacket))
{
// read back the response
if (ReadCOM(tran_len,tran_buf) == tran_len)
return TRUE;
}
// an error occured so re-sync with DS2480B
DS2480B_Detect();
return FALSE;
}