Skip to main content

Reply to "Sending TMCC Commands to Legacy Base over Serial Connections"

Chaos, You re probably right on how serial.write works.  

I have to pass out  at the moment but will catch up on this thread when I get back up.  

Chris, I think Chaos has outlined some of your problems pretty well.  just keep it in mind that TMCC doesn't talk in bytes, but in bits.  your program needs to translate the bytes to bits and bits to bytes.  bitshift will be your friend here.  

I'm going to dump some code here for fun.  this is my routine to read incoming data.  

<code>

if (Serial1.available() > 2) { // check if there is enough data on serial buffer for a command.
inByte = Serial1.read(); // read the serial data
if (inByte == 0xFE) { // Check if the data is a vaild TMCC command starting with 0xFE
systemHALTclear(); // Clear HALT condition if any new commands are sent from TMCC Base.
byteTwo = Serial1.read(); // Read next byte of serial data as byteTwo
byteThree = Serial1.read(); // Read next byte of serial data as byteThree
}
else{
checkNextByte(); // If the data recived is not a valid command skip to next byte and try again.
}

byteTwoShifted = byteTwo<<8; // shift byteTwo 8 bits left.
fullWord = (byteTwoShifted + byteThree); // Combine the bytes into one 16 bit packet of data
}

void checkNextByte() {
int trashData = 0;
trashData = Serial1.read();
Serial.println(" ");
Serial.println("T R A S H D A T A :");
Serial.println(trashData, HEX);
Serial.println(" ");
//delay(500);
}

 

</code>

JGL

 

OGR Publishing, Inc., 1310 Eastside Centre Ct, Suite 6, Mountain Home, AR 72653
800-980-OGRR (6477)
www.ogaugerr.com

×
×
×
×
×