Hopefully this will be a quick solution and I am just overlooking something stupid!
Briefly, I am making a LabView program to control a syringe pump via RS-232. I am using a Keyspan USB-Serial adapter to hook up my laptop to the device. After some troubleshooting on my own, I was able to download a HyperTerminal-like program, and can communicate with my pump just fine (changing position, speed, initializing, etc). However, when I try to do the same with LabView, nothing happens.
First, I can tell that LabView is sending my pump data, because the light on the USB-Serial adapter blinks rapidly once (its indication that it is Rx/Tx). The same thing happens when I am communicating with it via the HyperTerm program. So it seems to be in working order.
After a lot of reading posts on this forum and developer examples, I believe that the problem is in sending a termination character with my data string. For example, when I have the HyperTerminal program open, I can enter "/1ZR", which will initialize the pump. That moves the pump to the home position and prepares it for other data. When I go to the "termination character" properties in that software, it says: "13,10" (with the quotes). As far as I know, 13 in decimal is a carriage return (or 0xD in hex) and 10 is a line feed. I am not sure if it sends them both. The company says that my program isn't working because most likely my LabView program isn't sending the right termination character.
I've tried almost everything I can think of to change the termination character. I do know that the VISA Configure Serial Port VI is using the same settings as my COM port indicates when I open control panel (9600 baud, etc). I had a stroke of brilliance and thought maybe I should check MAX and see what its settings are... they are the same. HOWEVER, when I open up the "VISA test panel" on MAX for my COM port, under "I/O Settings", the termination character is set to line feed \n. I change it to carriage return \r, but when I click "apply changes", I get this:
SET Termination Character to 0xD
And when I close the test panel and re-open it, it still goes back to line feed \n. I've also tried changing the "termination char" parameter in the VISA Configure Serial Port to both a constant (as a 13) or a control (which I've tried as hex 0xD as well as decimal 13).
I'm pretty convinced that this is the issue... so does anyone have any idea on how I can force it to use a carriage return? I've even tried disabling "enable termination char" and manually sending a string with a \r at the end, but it doesn't work either...
I've attached a picture of a simple VI which shows what I want to do (the 2000ms wait was put there just so that it wouldn't close the COM port before the initialization finished... its unnecessary I think).
Thanks for your help in advance!
Solved! Go to Solution.
I should note that I need to send a carriage return as the termination character, not a line feed. That might not have been clear.
It appears that your terminal software is sending both 0x13 and 0x10 at the end of commands. This is common in terminal emulators because it moves the cursor to the beginning of the line (CR) and starts a new line (LF). Using only one makes the terminal display appear ugly. If you only use CR then you only have one line that is constantly being over-written, and if you have only LF you find your commands stretching down the screen and to the right until they spill off the edge.
It also seems that using both CR and LF is working with your device, so you should try doing that in LabVIEW. You can manually add a CR to the end of every command and set the termination character to LF, or you can manually add CR and LF to the end of every command and turn off the termination char completely when you initialize the serial port. The extra characters are added to your commands by using string concatenation.
Agree with Richard:
-Your device needs both the CR and LF. To accomplish this:
option 1: Concatenate the "end of line" string constant (this is a combination of CR and LF, located in the string pallete) to all your outgoing commands. Make sure in the "Visa configure serial port" the "Termination character enable" flag is false.
option 2: Concatenate only a CR to your command's strings. Make sure in the "Visa configure serial port" the "Termination character enable" flag is TRUE AND that the termination character is set to 10 (meaning LF) which I think is the default.
Details can be seen in this link:
"Adding Termination Characters to VISA Serial Writes in LabVIEW"
Interesting would be to configure the serial port to accept not one but two termination characters. The above links refers to the document "Developer Zone Tutorial: Termination Characters in NI-VISA.", where this is supposed to be possible. The document however is 404'ed.
If someone find a working link please post it.
Dennis was right, I could either:
- use the advanced serial write, if I changed the termination character from 0xA to 0xD (using the front panel) that worked.
- changing the write string to have \ Codes Display and adding \r OR \r\n at the end also worked.