LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

RS 232

Hallo,

 

ich habe ein Problem und bitte um eure Hilfe. Ich habe eine Baugruppe, an die ich einen Befehl über die serielle schnittstelle RS 232 schicken möchte. Ich erwarte von der Baugruppe eine Antwort.

Mit dem "Hyper Terminal" unter windows funktioniert alles wunderbar, mit dem Program hterm klappt es auch. Nun wenn ich das LabWindows/CVI- Beispielprogramm "serial" von NI nehme reagiert die baugruppe erst nachdem dritten Versuch, d.h. ich klicke einmal auf "send" und dann muss ich 3 mal auf "receive" klicken bis ich eine Antwort von der baugruppe erhalten habe. warum klappt es nicht vom ersten mal??

kann mir jemand bitte helfen?

 

vielen dank!

0 Kudos
Message 1 of 4
(3,620 Views)

Hello,

Please check the configuration of the serial communication in the CVI example “serial”.
How many bytes do you read?
Which termination byte are you using?
For troubleshooting you can use the tool “NI Spy” (Start -> All Programs -> National Instruments -> NI Spy)

Serial Communication Overview

Regards

Ulrich
AE NI-CER

0 Kudos
Message 2 of 4
(3,541 Views)

Hello Ulrich,

 

Thank you for your reply, i checked the configuration of the serial communicaion, everything is ok!

Im reading 13 bytes und using CR as termination byte.

I dont think that this is the problem, because the device gives me the answer back, but after clicking three times on read,

and that is my question why is that? why doesnt the device respond from the first time?

 

Thank you for your help

 

Regards

Alisal

0 Kudos
Message 3 of 4
(3,497 Views)

You might want to check if you're getting "garbage" characters in the InQueue (including CR's) that cause a return without the expected data.  Some devices when you power them on will emit characters on a serial port that are meaningless.

 

You can flush the Inqueue, I've had issues with that function and now I just probe the InQLen and just read all the data that's in the queue.  If your device is in the mode of continuously emitting messages with the terminator, this can be a problem - how to get exactly the right message and not pieces of other messages.

 

You might want to verify that you're not timing out the first couple of times you try to read.  I see you hard coded the opencomconfig to com 5, is your timeout being set for that same port?  The bit rate is just that, the rate at which a frame of data is emitted from the sending port - but the timeout is for the time until the first byte appears and then the time in between bytes.  If any of these times exceeds the timeout, you'll get a timeout return.  A device configured for a specific baud rate doesn't mean it will emit frames at some rate - it just means that the bits in the frame will get emitted at the configured bit rate.  A perfectly fine 57600 bps message may take an arbitrarily long time to receive, depending upon the time until the first frame, and the time between frames.

 

You could just code a loop with ComRdByte that loops, reading every byte available until it sees the CR.  Stupid and inefficient, but it might allow you to see if there's anything in the incoming stream that you didn't expect.

 

Menchar

0 Kudos
Message 4 of 4
(3,468 Views)