Serial output of ASCII commands

Hi folks,
I am working with a Mega 2560 that will, in the final project, be receiving signals from multiple RFID readers which will result in the Mega sending serial commands via RS-232 to an audio repeater.

The command structure required by the audio repeater needs all commands in ASCII with a format of various letter commands

I am able to send the various letter commands, "p+19" in this case, no problem. Its the and the commands that I haven't been able to send. I know the ASCII keystrokes for these are ctrl-a and ctrl-c respectively but I have not been able to send these through the Serial.print command.

Currently I have been trying the decimal and now Hex number equivalents for these commands but that isn't working either.

I have successfully sent this command string from my terminal emulator (Tera Term) and the audio repeater has played the file as directed. I just cant get it from my Mega.

Here's my test code:

int loopstate=1;

void setup() {
  Serial.begin(2400); //baude rate slowed down for CFSoundIII
 // while (!Serial); // wait for serial port to connect. Needed for native USB port only
  }

void loop()
  // Send string to tell CFSoundIII - start of header, play file 25 - in HEX -, and end of text:
 {
  if(loopstate==1){  
    Serial.print(0x1);
    Serial.print("p+19");
    Serial.println(0x3);
 }
 {
   loopstate=loopstate-1; //This sets the loopstate so the Serial.print commands send only once
   //The following lines are for debugging
   //Serial.print(loopstate);
   //Serial.println(" ");  
   delay (1000);
 }
  
}

So, any thoughts from the collective mind?

Thanks, I appreciate any feedback.

Try:-

Serial.write(0x01);  // Ctrl-A
Serial.write(0x03);  // Ctrl-C

Hi, OldSteve,

So, the proper format for the hex code is 0x01 vs. 0x1 (which is what I had been using).

Thanks for the note on that!

mhall:
Hi, OldSteve,

So, the proper format for the hex code is 0x01 vs. 0x1 (which is what I had been using).

Thanks for the note on that!

Either is fine. I just use 0x01 out of habit.

The real point was to use 'Serial.write()' instead of 'Serial.print()'
Edit: 'Serial.print(0x1)' will send '1', (which equals 0x31), instead of 1, (0x1).

Hmmmmm.

Thanks, OldSteve,

It doesn't look like that is working either. I'm going to spend some time playing around with the formats of the commands, such as adding quotes, etc.

It certainly seems odd to me that I can get this to operate from a terminal emulator, but not from the Mega.

Again, Thanks for your suggestions.