Dean,
My code is a little different.
In setup(), it calls Serial.begin() and Serial.flush() like your code.
My CAT handling is done in a Serial.event() function. This is called whenever there is a character available to read (or so says the documentation).?
void?serialEvent(void)?{
??long?frequency;
??byte?temp1,?temp2;
??int?c?=?Serial.read();
??if?(c?>?-1)?{
????cmd_buffer[cmd_byte_ct++]?=?(byte)?c;
??}
??if?(cmd_byte_ct?==?5)?{
????cmd_byte_ct?=?0;
?
Then process the command. cmd_buffer is a 5 element byte array. cmd_byte_ct is a global variable initially set to 0.
My original code was like yours in that it assumed that if Serial.available() returned 5 or more that Serial.read would always be able to read 5 bytes (I actually used Serial.readbytes(buffer, 5), but the way my program behaved, I'm not sure that was a valid assumption.? With a few hours testing WSJT-X versions 2.1.2 and 2.2.2 and with FLDigi (using hamlib) it seems to work, after a firmware upload or after a power cycle.? It was a little less reliable until I added the Serial.flush() in setup(). Thank you for that idea.
73,
Mark, N8ME
73,
Mark, N8ME