LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Special RS232 communication implementation

Hi all, 

 

I want to develop a vi which does the following operation :

- The RS232 port of PC is connected to a PIC microcontroller hardware.

- The VI has to send a byte from PC to the PIC and then it has to wait for an echo of the same byte which is sent back to PC by the PIC controller to ensure that the byte is sent properly.

- If the echo is matched with the byte sent, it has to send the next byte and again wait for its echo and repeat the process for other bytes to be sent or else if the echo doesnt match/ no echo received, it has to give an error message/wait for a predefined time to make sure a timeout has occured respectively.

- Once all the bytes are sent from VI, and all corresponding echoes are received from the PIC, the vi has to wait for the output series of  bytes from the PIC which can come immediately after the last echo was sent or after some time.

 

This should work for all baud rates over RS232 serial port.

 

Can anyone here guide me in implementing this as I am new to labview?..All suggestions are welcome.

0 Kudos
Message 1 of 10
(3,940 Views)

Look in the examples, under HARDWARE INPUT and OUTPUT - SERIAL for examples of Serial port access (start with SIMPLE SERIAL and go from there).

 

It's an unusual situation where you have to wait for an acknowledgement of every.  single.  byte...  Are you sure you can't do that a better way?

 

I would recommend a state-machine architecture, if you don't want to tie of the whole computer waiting for this handshake process.

 

Steve Bird
Culverson Software - Elegant software that is a pleasure to use.
Culverson.com


LinkedIn

Blog for (mostly LabVIEW) programmers: Tips And Tricks

0 Kudos
Message 2 of 10
(3,936 Views)
Hi,
I have written these vis but facing some problems. I guess the vis lack something. Please help.

Best regards

http://forums.ni.com/t5/LabVIEW/Problem-in-execution-when-putting-a-vi-inside-another-vi/m-p/2924394...
0 Kudos
Message 3 of 10
(3,908 Views)

Hi mnx,

 

Please try following

1. create standard state machine

2. Have 1 start button to start sending bytes

3. have case structure with cases send,read,error

4. Now when user clicks start button go to send case and send 1st byte (assign that byte to some variable to use later), after sending go to read, once read is complete, check received byte is same as sent byte if not go to error and indicate error of mismatch.

5. send all bytes one by one. when you send last byte read response related to it but this time wait in reading for some extra time, check whether it is 1 byte or more bytes? if it is 1 byte that means you have received only response and not the other part.

 

The tricky part is while sending initial bytes you have to read for small time but while reading response of last byte you have to wait for extra time. I had done same things in past, I am sure you will fet it right.

With Regards

Miraz
Kudos is better option to thank somebody on this forum
------------------------------------------------------------------------------
0 Kudos
Message 4 of 10
(3,877 Views)

And one other suggestion, which sadly adds to the complexity, if the PIC is actually decoding and then sending back the "echo", think of reversing the byte sent. The reason for this is that if xmit and receive wires are shorted anything sent by the vi will be looped back. Reversing the byte means you can be sure it is the PIC sending it back.

 

Post your code, we don't have much to work with when you say "the vis lack something" as the possibilities, while not actually infinite, are asymptotically close to infinite! 😉

Putnam
Certified LabVIEW Developer

Senior Test Engineer North Shore Technology, Inc.
Currently using LV 2012-LabVIEW 2018, RT8.5


LabVIEW Champion



Message 5 of 10
(3,873 Views)

Please find the attached application vi which I developed. Are there any betterment which I can do for this?

0 Kudos
Message 6 of 10
(3,851 Views)

Hi mnx,

 

- use wires instead of all those local variables and "value" property nodes. THINK DATAFLOW!

- use FOR loops for loops with known iteration count.

- remove all those RubeGoldbergs (like x := TRUE OR x)

- don't use BytesAtPort when all you need is a proper TimeOut setting

- why do you reinit Tx to default when you set a new value one millisecond later anyway?

- use a proper statemachine instead of that big flat sequence!

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 7 of 10
(3,840 Views)

Hi GerdW,

 

What function can I use to receive bytes efficiently instead of "bytes at port"?

0 Kudos
Message 8 of 10
(3,831 Views)

Hi mnx,

 

when you send your single byte commands and want to receive a single byte answer you need to read exactly one byte. No need for BytesAtPort here…

When you want to read the devices measurement data later on it seems you don't know the exact number of bytes, but you provide a timeout. So you need to read bytes in a loop until your time out is reached: BytesAtPort isn't needed for that!

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 9 of 10
(3,826 Views)

Hello GerdW,

 

can you please post a demo vi for this? thanks

 

0 Kudos
Message 10 of 10
(3,824 Views)