I'm having a little trouble getting this function of my code to write outThe Code Below now works:
void SendCTRL (String &input)
{
const char *hin = input.c_str(); // Get character array
int clen = input.length()/2;
unsigned char cmd[clen+1]; // Leave a byte for null terminator
for (int i=0; i < clen;2*clen; i++i+=2)
{
cmd[i/2] = dehex(hin[i])<<4 | dehex(hin[i+1]);
}
cmd[clen] = 0; // Null-byte terminator
digitalWrite(SSerialTxControl, RS485Transmit); // Enable RS485 Transmit
RS485Serial.writefor (cmd);int i=0; i< //clen; Sendi++)
string someplace{
delayRS485Serial.write(clen*20cmd[i]); // Send string someplace
// Wait for Serial.write(cmd[i]);
to complete?}
What rate?delay(clen/4);
digitalWrite(SSerialTxControl, RS485Receive); // Disable RS485 Transmit
Serial.printprintln(");
CMD Sent:"
}
byte dehex(char c);
{
Serial// Get nibble value 0.println..15 from character c
// Treat digit if c<'A', else letter
return c<'A'? c & 0xF : 9 + (cmdc & 0xF);
}
byte dehex(char c)
{
// Get nibble value 0...15 from character c
// Treat digit if c<'A', else letter
return c<'A'? c & 0xF : 9 + (c & 0xF);
}
Input is a series of ASCII-encoded hex digits and I'm trying to getgetting the output to print the byte values of the hex.
Right now cmd returns no value when called which makes me think I'm not writing to it correctly. Any advice would be greatly appreciated.