Instrument Control (GPIB, Serial, VISA, IVI)

cancel
Showing results for 
Search instead for 
Did you mean: 

Serial communication

I have to ask this question again. Hope someone can help. I'm trying to make serial communication between a computer and RTE 140 Bath/Circulator (from NESLAB). I use "serial communication.vi", it works well both on write and read. Since I want to write from a file, I replaced sub vi, "VISA Write.vi" in "Serial communication.vi", with sub vi "VISA Write from File.vi". I didn't change anything on "READ" part. Then, I run this new vi and got "Write" correct and "Read" wrong (gave me a "?"). Please help.
0 Kudos
Message 1 of 11
(5,307 Views)
I'm not sure what you mean by getting the read wrong. "?" is not a valid error message so I must assume that is the reponse you recorded from your instrument. If that is the case you should consult it's user manual. By the way, your instrument many not be sending ASCII characters, it may be sending binary data. Either way, the manual is the best place to get more information.

With respect to whether your are programming correctly, attached is some example code. Drop the VI and the text file into the same directory on your computer. Short pins 2 and 3 on your serial port (loopback test for serial) and run the code.
Download All
Message 2 of 11
(5,308 Views)
Thanks a lot, Ray. I can't open the vi you sent to me since my LabVIEW version is 6.0 and yours is 6.1. Do you have it at version 6.0? Thanks again.
0 Kudos
Message 3 of 11
(5,308 Views)
I converted it to 6.0. All I did to Serial Communication.vi was replace the VISA write with a VISA Write from file.
Download All
0 Kudos
Message 4 of 11
(5,308 Views)
Since it works well when I use "Serial communication.vi", I think the problem is in the modified vi program. The only difference between the modified one and original one is that "VISA Write" function was replaced by "VISA Write from File" function. I checked the help for both functions and found that in "VISA Write from File" the file specified in filename is opened in binary mode. Does that mean I need to convert input command to binary mode? How to do it? Appreciate if you can help.
0 Kudos
Message 5 of 11
(5,308 Views)
Use the text file I included with a loopback connection (pins 2&3, assuming no handshaking used) and the modified serial communication VI(use a file path constant to specify the path of the file exactly). All that is in the text file is the text "hello" followed by a carriage return and linefeed. If that does not work, let me know. I can't help you if you ignore my instructions.
0 Kudos
Message 6 of 11
(5,308 Views)
I used the modified serial communication VI and the text file you sent to me with a loopback connection as your instructions. It gave me an error"Error-1073807246 occurred at Property Node [arg 1] in VISA Configure Serial port-. Serial Communication.vi. Possible reasons: VISA: [Hex 0xBFFF0072] The resource is valid, but VISA cannot currently access it." I use COM2 as serial port. Also, I used Loopback.vi to test it, it works correctly (use COM2 port). I am looking forward your sugestions. Thanks.
0 Kudos
Message 7 of 11
(5,308 Views)
That error corresponds to another application accessing your serial port. For example, if you run the loopback.vi example program on the web(which uses legacy serial VIs), then run the modified serial loopback program you will generate that error. If you run the loopback.vi, you need to exit completely out of LabVIEW before opening and running the Serial communication VI.
0 Kudos
Message 8 of 11
(5,308 Views)
Yes, you are right. When I close the loopback.vi and run the serial communication.vi, I got response "hello\r\n". Now, I guess the problem is that when I use text file as input commands, each time we hit "enter", it was read as "\r\n". In the instrument manual, at end of each command, a "\r" is needed, but no "\n". How to edit Commands in a binary mode in order that there is no "\r\n" added.

Another case I tried is that I delete "enter" after "hello" in "test.txt", then I got error-1073807339 occurred at VISA Read in Serial Read with Timeout.vi-. Serial Communication.vi, Possible reasons: VISA: (Hex 0xBFFF0015) Timeout expired before operation completed. Does that mean that the command doesn't finish, the vi always wait.


Hopfully, we can solve the problem this time. Please help.
0 Kudos
Message 9 of 11
(5,308 Views)
Whenever you perform a serial read, you specify a particular number of bytes to read. Serial reads terminate after reading that exact number of bytes, when encounter a "\n" is read, or if the read times out. By taking out the linefeed, you are then depending on the read to termination by reading in the number of bytes specified.

Creating a file that contains linefeeds but not carriage returns is not feasible with a normal text editor since linefeeds and carriage returns are invisible characters. If you insist on writing from a file, just use LabVIEW to create your file. Use a string control in \ codes display so that linefeeds are visible. There are examples programs of reading and writing text files that
come with LabVIEW under Fundamentals>>File Input and Output.
0 Kudos
Message 10 of 11
(5,308 Views)