LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Half-duplex RS232 serial communication

Hi,

 

I am stuck with a serial communication problem. I have a device that collects data from 4 pressure sensors (PressureMAT from Pendotech). I would like to read the data via a RS-232 port using LabView.I connected the device to the PC via a RS-232 cable and a NI USB-232/4 adapter to the PC. I am using LabView v2011.

 

In the manual of the device, the following port settings are specified:

 

9600 Baud

No Parity

8 data bits

1 stop bit

No flow control

 

It also says in the manual: "The command AZK <cr> can be also used to generate a report as desired. The unit operates using half duplex request-and-reply protocol. After sending the request DO NOT send anything else until the resulting expected response is received. THEN the requestor is free to proceed. i.e. send on AZK <cr>, THEN make sure a successful response is received".

 

I can communicate with the device using the "Basic serial read and write.vi" from the examples library. If I add a while loop to this example to read the data continuously, the "bytes at port" increase and at some point (when about 6000-8000 bytes are shown in the "bytes at port"), the device basically crashes and reboots.

I need some kind of flow control (e.g. XON/XOFF?)or follow the manual more closely, but my LabView knowledge is too limited.

From how things are explained in the manual, I am not sure if the specified port settings also apply if the AZK<cr> method is used, because when I dug into half-duplex I found something about using flow control in the "configure port" command.

 

Any help is MUCH appreciated!

0 Kudos
Message 1 of 23
(6,647 Views)

The problem with the Bytes At Port is that it often creates interesting race conditions with the serial port.  For instance, say you send your command and then it takes 100ms for the report to be sent.  If you ask for the number of bytes in the port 50ms after you sent the command, you will only get about half of your report.  And the timing of that report getting to you is likely variable.  So you either have to wait a "long" time doing nothing in the hopes that you waited long enough or you can configure your serial port to use the proper termination character.  Unfortunately, The smiley face the manual mentions that ends the report is not in any ASCII table I know of.  Could you do a capture of a full report, save it to a file, and post it?  Then we could figure out what the termination character for the report is and tell you how to do a proper report capture.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 2 of 23
(6,624 Views)

Using the "Basic serial read and write.vi" read the complete answer, save it as a new vi, with the answer in the indicator, change the read indicator to '\' display ,  make current values default , save again 😉 and post the vi.

Greetings from Germany
Henrik

LV since v3.1

“ground” is a convenient fantasy

'˙˙˙˙uıɐƃɐ lɐıp puɐ °06 ǝuoɥd ɹnoʎ uɹnʇ ǝsɐǝld 'ʎɹɐuıƃɐɯı sı pǝlɐıp ǝʌɐɥ noʎ ɹǝqɯnu ǝɥʇ'


0 Kudos
Message 3 of 23
(6,617 Views)

Hi,

 

thanks for the quick reply.

I googled the black smiling face and it seems to be decimal 9787 (http://www.codetable.net/decimal/9787). However I did not manage to use it as termination character in LabView (probably my fault). Here is the LabView output after sending AZK and termination character set to <cr> = \r = decimal13:

\10\02AZ,00000.01,4,\s\s\s\s\s\s\s0.00,\s\s\s\s\s\s\s0.00,\s\s\s\s\s\s\s0.00,\s\s\s\s\s\s\s0.00,00592,X,X,X,X,X,E1\r\nAZ,00000.03,4,\s\s\s\s\s\s\s0.00,\s\s\s\s\s\s\s0.00,\s\s\s\s\s\s\s0.00,\s\s\s\s\s\s\s0.00,00592,X,X,X,X,X,DF\r\nAZ,00000.05,4,\s\s\s\s\s\s\s0.00,\s\s\s\s\s\s\s0.00,\s\s\s\s\s\s\s0.00,\s\s\s\s\s\s\s0.00,00592,X,X,X,X,X,DD\r\nAZ,00000.07,4,\s\s\s\s\s\s\s0.00,\s\s\s\s\s\s\s0.00,\s\s\s\s\s\s\s0.51,\s\s\s\s\s\s\s0.51,00592,X,X,X,X,X,CF\r\n\10\03

 

I highlighted the pressure data of the 4 sensors in RED.

 

 

Apart from LabView, I tested the connection to the instrument also with a little program called "Termite" (http://www.compuphase.com/software_termite.htm). If I send AZK and set the termination character to <cr> in the settings of Termite, I get the following report:

[10][02]AZ,00000.01,4,       0.00,       0.00,       0.00,       0.00,00592,X,X,X,X,X,E1
AZ,00000.03,4,       0.00,       0.00,       0.00,       0.00,00592,X,X,X,X,X,DF
AZ,00000.05,4,       0.00,       0.00,       0.00,       0.00,00592,X,X,X,X,X,DD
AZ,00000.07,4,       0.00,       0.00,       0.51,       0.51,00592,X,X,X,X,X,CF
[10][03]

0 Kudos
Message 4 of 23
(6,606 Views)

I don't understand your reference to the black smiling face.  You never talked about that anywhere before.  And it won't apply to your serial communication because, as shown in the link you provided, it is a unicode character which doesn't apply to serial port communication.

 

For your LabVIEW response vs. your Termite response, they look identical.

 

So it is unclear where your issue is.  Perhaps if you attach the actual VI you have created that is giving you problems.

 

It looks like you could use the linefeed character as a termination character and execute multiple reads for each line.  It looks like you could set the termination charcater to be hex 03 and execute a single read since you entire packet of data ends in that byte.

0 Kudos
Message 5 of 23
(6,599 Views)

here is a quick tryout.. since I had to reconstruct the response (posting the vi would have been better 😉 )  I'm not shure if it will work on the first try....   set the COM port and hit the run button

 

Greetings from Germany
Henrik

LV since v3.1

“ground” is a convenient fantasy

'˙˙˙˙uıɐƃɐ lɐıp puɐ °06 ǝuoɥd ɹnoʎ uɹnʇ ǝsɐǝld 'ʎɹɐuıƃɐɯı sı pǝlɐıp ǝʌɐɥ noʎ ɹǝqɯnu ǝɥʇ'


0 Kudos
Message 6 of 23
(6,585 Views)

From what I am seeing in the data, you actually want 0x03 to be your termination character.  You will also want your "Bytes To Read" to be fairly large, like 100 (or possibly more, I did not go and count your bytes).  The VISA Read will stop when it reads the number of bytes it was told or it reads a termination character.  So by setting the number of bytes to read to a large number (larger than your message), then the read will finish with the termination character.

 

Have a good look at Henrik's code.  It is at least a good start for you.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 7 of 23
(6,540 Views)

Hi Henrik,

 

thank you very much for the vi. Unfortunately I am using v2011 and cannot open your file. Could you re-save it in an older version?

 

 

0 Kudos
Message 8 of 23
(6,531 Views)

 

 

0 Kudos
Message 9 of 23
(6,531 Views)

here we go...

 

I set the termination character to x03 .....

And hope the command is rigth, the termination character for send is turned off since I assume a \r ..

 

Greetings from Germany
Henrik

LV since v3.1

“ground” is a convenient fantasy

'˙˙˙˙uıɐƃɐ lɐıp puɐ °06 ǝuoɥd ɹnoʎ uɹnʇ ǝsɐǝld 'ʎɹɐuıƃɐɯı sı pǝlɐıp ǝʌɐɥ noʎ ɹǝqɯnu ǝɥʇ'


0 Kudos
Message 10 of 23
(6,523 Views)