Serial Comm problems with laser controller
Zak
Posts: 7
Hi
I am using the BS2p, and I am trying to interface over rs232 to a laser controller.· The laser controller does not implement handshaking, so i am doing no flow control at a slow baud rate.· IU am able to send a command over, but I am not able to get a response from a query.· I should be able to have the following conversation with the controller:
I am just trying to send the first command and get the answer into a variable.· Here is where I am at now:
Even if I replace the byte array with a single byte, i still hang in the same place.
Any suggestions you might have for how to move forward would be greatly appreciated.· In case anyone is interested, the box i am talking to is the vortex 6000 by newfocus.
Thanks
Zak
Post Edited (Zak) : 6/12/2006 7:50:46 PM GMT
I am using the BS2p, and I am trying to interface over rs232 to a laser controller.· The laser controller does not implement handshaking, so i am doing no flow control at a slow baud rate.· IU am able to send a command over, but I am not able to get a response from a query.· I should be able to have the following conversation with the controller:
Me> :SOUR:VOLT:PIEZ? It> :77.3V Me> :SOUR:VOLT:PIEZ 77.2 Me> :SOUR:VOLT:PIEZ? It> :77.2V
I am just trying to send the first command and get the answer into a variable.· Here is where I am at now:
' {$STAMP BS2p} ' {$PBASIC 2.5} LcdCls CON $0C ' clear LCD (use PAUSE 5 after) Baud1200 CON 2063 Baud2400 CON 1021 Baud4800 CON 500 Baud19200 CON 110 Baud9600 CON 240 DispBaud CON Baud19200 COMBaud CON Baud2400 resp VAR Byte(6) SEROUT 16, COMBaud, [noparse][[/noparse]":SOUR:VOLT:PIEZ?", CR, LF] SERIN 16, COMBaud, [noparse][[/noparse]STR resp\5] SEROUT 15, DispBaud, [noparse][[/noparse]LcdCls] resp(5) = 0 SEROUT 15, DispBaud, [noparse][[/noparse]"::", STR resp]
Even if I replace the byte array with a single byte, i still hang in the same place.
Any suggestions you might have for how to move forward would be greatly appreciated.· In case anyone is interested, the box i am talking to is the vortex 6000 by newfocus.
Thanks
Zak
Post Edited (Zak) : 6/12/2006 7:50:46 PM GMT
Comments
Oh, wait, you're using the pseudo-port "16". You're aware that everything written to that port is 'echoed' back to the sender, right? That could confuse the Laser.
And where are you hanging, anyway? And how do you know?
And with the hanging, SERIN waits for data to come over on the wire. If I add a timeout by doing:
SEROUT 16, COMBaud, [noparse][[/noparse]":SOUR:VOLT:PIEZ?", CR, LF]
SERIN 16, COMBaud, 2000, handle, [noparse][[/noparse]STR resp\5]
goto resume
handle:
....handle it somehow
resume:
...keep going
Then it just continues on with the string uninitialized after waiting the two seconds.
Thanks for your reply. I did not know that information about the pseudo port. Seems like that would confuse a lot of things.
·· Do you have a BASIC Stamp Logic Analyzer or Scope?· If so you could watch the line to see how quickly the data is being returned.· That might indicate whether or not the device is sending data before the BS2 is ready to receive it.· Are the commands you're sending affecting the device, regardless of not getting a response?
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support
csavage@parallax.com
Baud2400 CON 1021
Baud4800 CON 500
Baud19200 CON 110
Baud9600 CON 240
DispBaud CON Baud19200
COMBaud CON Baud2400
COMOUT CON 13
COMIN CON 14
r VAR Byte
resp VAR Byte(6)
DEBUG "Sending Message", CR, LF
DEBUG ":SOUR:VOLT:PIEZ 70.0", LF
SEROUT COMOUT, COMBaud, [noparse][[/noparse]":SOUR:VOLT:PIEZ 70.0", CR, LF]
DEBUGIN r ''see if voltage on device changed.
'Device Has Addressed and Remote leds, neither come on.
Update: I am now using the rig up that I made for the rs232 communication going to HyperTerminal. There is just the stamp and the computer now for the testing. Thanks to all for help.
Ugh this is frustrating. The Terminal program is giving no response over rs232 with the above program. Is there something that I am missing with only using the three wires? Thats what the laser controller uses. Any ideas?
Post Edited (Zak) : 6/13/2006 4:34:26 PM GMT
you are sending out i/o 13 and receiving on i/o14. Just note that these are not the physical pins of the actual stamp, but labeled pins (don't have an image on this computer to reference to say what it actually is).
If that isn't what's mucking you up, then you should be aware that if you use port 16 for your serial tasks, you use the TRUE values (1021 for 2400baud)....but if you use any other I/O, you MUST use the Inverted numbers (see the PBasic help file under SERIN.....so for 2400baud it would be 17405 for inverted.
Now, your stamp is then sending out a pseudo-RS232 signal.....typical RS232 voltages are -12V to +12V (or 8volts....not much of a standard if it's never the same). Most devices don't care about the negative voltage as they usually only detect whether the voltage is over/under a certain threshold...which is usually about 1.8 volts or so (some say 2.5).
So, you should expect long distances to be achieved running rs232 from a stamps I/O pin.
Now....here's the tricky part.
Normal logic levels are 0volts and 5volts. 0volts = logic 0 and 5volts = logic 1; this is the binary that makes the computer world hum!
Well, proper RS232 is inverted.....so a logic 0 = -12V and a logic 1 = +12V (these are known as spaces and marks).
So, when you tell the stamp to send serial data out of one of its I/O ports in an inverted fashion, a logic 1 = 0volts and a logic 0 = 5volts.
When you are talking to a serial device (computer/modem/gps/etc.) you must use inverted when coming out of an I/O port (I/O not being the programming port).
Now, you can talk to other stamps in either true or inverted....just so long as the other end is set to match.
Hope I didn't get too wordy!
Cheers
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
·
Steve
"Inside each and every one of us is our one, true authentic swing. Something we was born with. Something that's ours and ours alone. Something that can't be learned... something that's got to be remembered."
Do I need to adjust the outputs of the i/o pins for sending to the laser controller so that the 0 turns to a -12 and the 5 turns to a +12 somehow?
Thanks a lot for this information
A quick look (hint hint) at the PBasic help file will give you some tips on how to handle serial comms with your stamp.
Essentially you need to put in a current limiting resistor...it goes inline with your receiving line from your device under test.
The stamp has internal clamping diodes that can handle the 12volts....but it's the current that it can't handle. So, check the SERIN command under the help file and note the circuit there.
Within your code, you simply need code what your baudvalue is (the SERIN command has a table with the appropriate values) and it'll understand if your incoming signal is inverted or not....
Cheers
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
·
Steve
"Inside each and every one of us is our one, true authentic swing. Something we was born with. Something that's ours and ours alone. Something that can't be learned... something that's got to be remembered."
The 'sense' (Inverted or not) of the SEROUT signal depends on if you have a MAX232 in there or not, or if your external device is using a MAX232 or not. There's no standard definition of what's "Inverted", unfortunately, so you may have to experiment.
How close is your Laser device, anyway? If it's further than 10 feet, you may be forced into using the MAX232. Note there do exist reasonably priced adapters ($15 or so) from www.kronos-robotics.com and others to simplify using the MAX232.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Truly Understand the Fundamentals and the Path will be so much easier...
Allan and Tom are right....you may need to use a MAX232 chip ( go to www.maxim.com for specs...can be ordered from digikey).
The MAX232 requires 5capacitors to get the "charge pump" running. I personally like using this one...however, if you want to limit the number of components on a board, the MAX233 works the same as the MAX232, but the 233 has the capacitors built in. Makes for a cleaner looking project!
In my experience, my laptop has had no problem understanding the lower voltage levels coming from one of my stamp I/O ports. I've also talked to other devices the same way without the MAX chips....however, this won't always be the case, so some experimenting is required.
As far as whether the device knows things are coming at it inverted or not....well, if it's a normal RS232 port, it expects them to be RS232 signals (so yes, it'll translate a -12V/0V as a logic 1 and +12V/5V as a logic 0....no additional work is required at that point).
Cheers
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
·
Steve
"Inside each and every one of us is our one, true authentic swing. Something we was born with. Something that's ours and ours alone. Something that can't be learned... something that's got to be remembered."