переделанный мною код DS2480B_ChangeBaud на всякий случай:
int DS2480B_ChangeBaud watcher_port_t* port, unsigned char newbaud){ unsigned char readbuffer[5],sendpacket[5],sendpacket2[5]; unsigned char rt=FALSE, sendlen=0, sendlen2=0; speed_t newspeed; switch(newbaud){ case PARMSET_9600 :newspeed=B9600 ;break; case PARMSET_19200 :newspeed=B19200 ;break; case PARMSET_57600 :newspeed=B57600 ;break; case PARMSET_115200:newspeed=B115200;break; default: return UBaud; } if (UBaud == newbaud) return UBaud; // see if diffenent then current baud rate else { // build the command packet check_correct_mode_command(&UMode, sendpacket, &sendlen);// check for correct mode sendpacket[sendlen++] = CMD_CONFIG | PARMSEL_BAUDRATE | newbaud; // build the command //ответ не читаем ибо он приходит на новой скорости newspeed а uart мы ещё не переключили if (!FlushWriteCOM(port,sendlen,sendpacket)) // send the packet rt = FALSE; else { proto_sleep((double)(5)/(double)1000.0); // make sure buffer is flushed watcher_port_set_baud(port,newspeed); // change our baud rate UBaud = newbaud; proto_sleep((double)(5)/(double)1000.0); // wait for things to settle // build a command packet to read back baud rate sendpacket2[sendlen2++] = CMD_CONFIG | PARMSEL_PARMREAD | (PARMSEL_BAUDRATE >> 3); //проверяем корректность отработки предыдущей команды // send the packet/read back the 1 byte response if (FlushWriteReadCOM(port, sendlen2,sendpacket2, 1,readbuffer) == 1) { if (((readbuffer[0] & 0x0E) == (sendpacket[sendlen-1] & 0x0E))) rt = TRUE; } // verify correct baud } } if (rt != TRUE) DS2480B_Detect(port); // if lost communication with DS2480B then reset return UBaud; }