Instrument Control (GPIB, Serial, VISA, IVI)

cancel
Showing results for 
Search instead for 
Did you mean: 

rs 232 serial reading data

Solved!
Go to solution
Dear community, I'm currently doing an internship at Robert Bosh GmbH, and right now I'm trying to read information from a self built device via a serial connection (RS 232). I didn't build the device myself and it is a bit itchy. It was read out before using MATLAB and caused all kinds of difficulties, however none of the problems I experience, using LabVIEW, showed up. I’m currently running Version 7.1 but we will upgrade next week. I started my project with the “Basic serial write and read” example and the first problem showed up. I didn't get a return string when running the example once, however when running it continuously I got my expected reply. Does anyone know how that can happen? As I want to send 4 commands, I decided to put them in a “Flat sequence Structure” basically copying the example I was testing with. The only change I made was to get rid of the while loops for write and read. I have to say that the problem I described so far only happens with the first command which returns a total of 133 byte. The next to commands only return 13 Bytes and I have no problems whatsoever. The last command is supposed to return 257 byte but all I get is "Status µAI:" which equals about 14byte. As I added an indicator that shows me how many bytes are supposed to be returned it baffles me that I don’t get them. Here is the first output as it is supposed to be returned: OK 00000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000010000000 As I said, I only get it when running the example continually or in “Highlight execution” mode. The next readout is supposed to look like this: Status µAI:Software-Version            : V 0.8Ausgangspegel nach Befehl   : hochohmiguntere Toleranzgrenze Strom :  4.0 mAobere Toleranzgrenze Strom  :  8.0 mABaud Rate (RS232)           : 19200Rücklesen für Chipfamilie   : XXXXX

Status Ende.

 And this is what I get: 

Status µAI:

   I’m guessing that the carriage return after the first line might cause the problem.  The next two returns show no problems, they are only about 14 byte long and have no carriage return or linefeed within them.  I would really appreciate some help,Thanks in advance Florian P.s.:  I don't know if it is of any help but the returned data is followed by a Carriage return and a line feed according to the documentation of the device.
Windows XP Professional, Labview 9
0 Kudos
Message 1 of 7
(4,578 Views)

Ok everyone,

 

I solved one problem, I now get all my data. If anyone is interested, I put the the read VISA in a while loop that ends when the number of bytes to read equals the bytes that are actually received and the string is not an empty string ( I think that's a double check and is actually not needed ...)

 

I still have a problem with the termination char, how can I tell my connection to use a carriage return  followed by a line feed (\r\n) as a termination char?

 

thx Florian

Windows XP Professional, Labview 9
0 Kudos
Message 2 of 7
(4,568 Views)

Florian,

 

Can you post a copy of your vi?

0 Kudos
Message 3 of 7
(4,550 Views)
Solution
Accepted by FlorianJ
vi.JPG
Windows XP Professional, Labview 9
0 Kudos
Message 4 of 7
(4,547 Views)

Florian,

 

There are a couple of problems with your code.  You really don't need the first while loop at all.  Since you know how many bytes to expect in return for each command, something simple like this should work.  See if you can get this simple vi working.

 

Message Edited by Wayne.C on 04-09-2010 09:27 AM
0 Kudos
Message 5 of 7
(4,544 Views)

Hello Weyne!

 

The example you showed is how i started, and it didnt't work. Now with my version I get my data the way I should.

 

But thanks!!

Windows XP Professional, Labview 9
0 Kudos
Message 6 of 7
(4,541 Views)

Florian,

 

Logic in second loop has a problem.  Try adding some time delay between the first while loop and the "Bytes at Port".

0 Kudos
Message 7 of 7
(4,534 Views)