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.
- PC com port 1 to arduino
- Arduino hardware serial1 to RS232 shield
- RS232 shield to RS232 cable
- RS232 cable to PC com port 2
- We then use the Serial Monitor to act as the monitor for port 1
- 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:
- I type in any random text into the serial monitor, press enter and it appears over in HyperTerminal monitor
- 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