Sending ASCII strings to RS232 device

Hi,

We've got a laser, it responds to text/string commands.

The device can communicate using it's RS232 cable
baud:19200
bits: 7
Parity: even
Stop bits: 1

We're using the following hardware:
a leonardo and using the hardware serial.
an XC-4227 RS232 shield

Prior to trying to use the arduino to communicate with the laser we did a check with HyperTerminal.
When we use HyperTerminal to send a command "s0o" (to turn the laser on for example).
The laser does not turn on.

We go to settings within HyperTerminal and select a tick box "Send line ends with line feeds". We press ok. Now try the commands again.
We try to send "S0o" again and the laser turns on.

Ok, so by sending commands through hyperterminal we can control the laser. Now we want to send the commands by hardware serial of the leonardo to the laser. First we decided to make sure we had our communication setup by essentially making a circle of communication, I'll explain.

  1. PC com port 1 to arduino
  2. Arduino hardware serial1 to RS232 shield
  3. RS232 shield to RS232 cable
  4. RS232 cable to PC com port 2
  5. We then use the Serial Monitor to act as the monitor for port 1
  6. We use HyperTerminal to act as the monitor for port 2

Ok, now we run a simple sketch

void setup()
{
  Serial1.begin(19200,SERIAL_7E1);
  Serial.begin(19200,SERIAL_7E1);

}

void loop()
{
    
while(Serial1.available()) {
Serial.write(Serial1.read());
}
while(Serial.available()) {
Serial1.write(Serial.read());
}

}

We run it and it works. When I say it works I mean the following:

  1. I type in any random text into the serial monitor, press enter and it appears over in HyperTerminal monitor
  2. I type a random string of text in the HyperTerminal and it appears over in the arduino Serial Monitor.

Ok, things are looking good at this point. We now go and remove the RS232 cable from our loop and plug the laser in it's place. No Luck. I type in "s0o", laser is not on.

At this point we were thinking it was related to the 'line ending' character.

So we went to Serial Monitor and tried all the line ending options.
"no line"
"Newline"
"Carriage Return"
"Both NL & CR"
I've also edited the code such that it ends in "CR and NL" incase the order of the CR and NL is important.

Ok still not working.

At this point I'm coming to you guys/girls for help.

Here is a quote from the user manual which may be of interest.

"All commands are ASCII based and terminated with ".

Taking the above quote and the tickbox from HyperTerminal into account ("Send line ends with line feeds"), I changed the code such that it sends the following:

Serial1.write("s0o\r\n);

Still not working.

Can anyone confirm if "Send line ends with line feeds" simply means the \n (newline) code or is there yet another code called "line ends" which I am not aware of? How to denote a "line ends" in code?

So if anyone knows of something which I am obviously missing, I would very much like to know.

Help is much appreciated

Based on what you've said so far, I would have expected this to work:

Serial1.write("s0o\r\n");

I assume the missing quote mark was just a typo but can you post the code that you actually used?

Also, are there any commands that cause the laser to send you a response that you could try?

jockwr:
We try to send "S0o" again and the laser turns on.

I type in "s0o", laser is not on.

Why did you use lowercase s instead of capital S?

johnwasser, apologies, the correct case is lower case s. So to turn the laser on I type:

"s0o"

wildbill, you are correct, the quotation was a typo. There is supposed to be a response every time I tell it to turn on or off. The response that it is supposed to give back is "g0?". I don't receive this response when using the arduino but I do recieve the response when using the HyperTerminal.

Here's the code I tried last time:

void setup()
{
  Serial1.begin(19200,SERIAL_7E1);
  Serial.begin(19200,SERIAL_7E1);

}

void loop()
{

   Serial1.print("s0o\r\n");
   Serial.println("Laser On");
       delay(5000);

   Serial1.print("s0p\r\n");
   Serial.print("Laser Off");
          delay(5000);
}

So It's not turning on with the above code.

Maybe new line versus carriage return plus new line.

What happens when you remove the '\r'?

If you are trying to send ASCII data to the device, why are you using write()? Do you know the difference between print() and write()?

Hi,

Thanks for the replies. I've actually tried so many different combinations.

I've tried putting a '\n' at the end, a '\r' at the end, a '\n' at the start and '\r' at the start and a whole heap more permutations.

PaulS - I have also tried using write and print
The latest I tried was write them in DEC.

Ok, I have noticed something, I'm not sure if it is proper function of ther RS232 shield, I doubt it.

The MAX232 chip on the shield gets very hot (I burnt my finger) when plugged it into the laser. The power used for the laser is 10V @ 0.2A.

It is noticeably cooler when I have a serial to usb cable plugged in when making a 'communication circle' as described in the original post. Note that the serial to usb cable will be supplied with 5v.

I don't see any help in the 'datasheet' (if you can call it that) regarding voltage ranges. https://www.jaycar.com.au/medias/sys_master/images/8957096722462/XC4227-dataSheetMain.pdf

From my google searches, For RS232 communication the High state needs to be equal to the voltage input (10V for the case of the laser).

Now I thought MAX232 chips were meant to handle the range of RS232 voltages (From google the range is something like 7 volts to 25v depending on the device).

Worth a try to get a USB shield instead and try the RS232 to USB cable I have. Any thoughts?
Maybe something like this? https://www.arduino.cc/en/Main/ArduinoUSBHostShield

If you have burned your finger on a max232, something is seriously wrong. That chip should be absolutely cool.

Time for a schematic; a photo/scan of a handdrawn will do. All wiring including all power connections.

sterretje,

I've attached a picture of how I've connected it up.

I've also tried powering the arduino with the power supply for the laser, it didn't help the situation.