Skip to main content

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

Professor Chaos, 

I had the chance to look at your TMCC buffer in your _interface file. 

You use the following code in your code to send and buffer the TMCC commands it seems. 

void sendTMCCCommand (SysTypes deviceType, byte deviceID, byte commandField, byte dataField, byte repeats) // deposit TMCC command in buffer
{
const byte TMCCCommand0 = 0xfe;
byte TMCCCommand1;
byte TMCCCommand2;

TMCCCommand1 = deviceType | (deviceID >> 1); // Byte 2 is combination of type field and first 7 bit of TMCC address
TMCCCommand2 = (deviceID << 7) | (commandField << 5) | dataField; // Byte 3 is last bit of TMCC address, command field (2 bits), plus data field

while (repeats > 0) {
TMCCBuffer.put(TMCCCommand0);
TMCCBuffer.put(TMCCCommand1);
if (TMCCBuffer.put(TMCCCommand2) == 0) { // write data to buffer; returns 0 if buffer capacity exceeded
debug << F("TMCC command buffer overflow") << endl;
FAULT();
}

repeats--;
}

processTMCCBuffer(); // attempt immediate execution
}

void processTMCCBuffer() // if minimum interval has elapsed, transmit one TMCC command
{
if (TMCCBuffer.getSize() == 0) return;


if ((millis() - lastTMCCTransmit) > TMCCMinInterval) {
TMCCPort.write(TMCCBuffer.get());
TMCCPort.write(TMCCBuffer.get());
TMCCPort.write(TMCCBuffer.get());
lastTMCCTransmit = millis();
}
//else debug << "waiting for TMCC interval" << endl;
}

 

My question is are you using the send function to try to send the command first and then buffer it? It seems in your train control code you are just using the buffer function. 

Thanks in advance, 

Chris

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

×
×
×
×
×