LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Write and read serial port simultaneously

Hello,

 

 

I am trying to learn how to read and write data frames simultaneously using serial communication.

 

The different loops (write and read) worked fine individually but they seems to go wrong when working at the same VI.

 

I was reading some stuff about duplicate VISA session but I am not sure how should I implemet this inside my design.

 

I want to send the data packet when press a button, this is the third loop inside my VI (it is not in the file attached, but you can see the variable that is writting from there).

 

Can anyone help??

 

thanks!!

Omar

 

 

0 Kudos
Message 1 of 14
(7,939 Views)
Why do you want to do this? Why do you need to keep sending the same during over and over again In the top loop? The architecture does not make much sense. Typically, you would use an event structure to send a packet when a button is pressed. The timeout event could have your read.
Message 2 of 14
(7,928 Views)

As Dennis said, you really should be using an event structure to only send the command when desired.

 

You do not need to set the buffer.  You do not need to clear the bus with each read.  You do not need the Wait inside of the read loop (the VISA Read will do the waiting 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
Message 3 of 14
(7,902 Views)

Thanks both of you for your replies!

 

As you metion I have changed mi VI and deleted the buffer set, the buffer clear and add the event structure to detect when the button is pressed.

 

The other issue I have is the slowness writting and reading the serial port, when I press the button labVIEW takes some seconds until the data is written at the port.

what could be causing this problem??

 

Thanks,

Omar

0 Kudos
Message 4 of 14
(7,845 Views)

Is it the data going out of the serial port that is slow or is it your instrument that is taking that long to respond?  Are you supposed to send an 'X' at the end of your message to let the instrument that the command is complete?

 

As a side note, move ther terminal of your buttong into the event case that handle's that button's value change.  This will allow the latching mechanism of the button work.


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 5 of 14
(7,828 Views)

The problem comes from the VI, is too much slow and do not respond well to the mouse actions.

 

Yes, I am trying to send and X as a final character for the messages reading from serial port.

 

Thanks,

Omar

0 Kudos
Message 6 of 14
(7,821 Views)

After doing some testing, it looks like the VISA Read is blocking the VISA Write.  This will only be a problem if you are not constantly getting data (which it sounds like is the case).  So I would recommend adding a check for the number of bytes in the port.  If there are more than 0 bytes, read a message.  Otherwise put in some sort of wait.


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
Message 7 of 14
(7,806 Views)

I don't know whether I understand your example, this would put in waiting state the Read function but not the Write?

It seems to be quite complex  establishing constant and simultaneous serial port communication.

 

Is there no other way to add the functionality you describes?

I read something about the Duplicate session option inside the VISA Open function but I don't know whether I can use this on my VI.

 

thanks a lot!

Omar

0 Kudos
Message 8 of 14
(7,773 Views)
No, the write is waiting for your front panel event to fire. The above example fixes your mistakes that you were complaining about.
0 Kudos
Message 9 of 14
(7,765 Views)

@osuarez wrote:

I don't know whether I understand your example, this would put in waiting state the Read function but not the Write?

It seems to be quite complex  establishing constant and simultaneous serial port communication.


It isn't that complicated.  The write only happens when you press the button.  That is done with the Event Structure.  The actual reading of the data is only done when there is actually data there to read.  Otherwise the VISA Read is blocking your ability to send data with the VISA Write.  I would imagine this happens since VISA can also work with other buses that are not full duplex.  So if no data is there to be read, there is no reason to actually perform a read.  I just throw in a wait in the FALSE case in order to keep the loop from using up all of the CPU resources to accomplish nothing.


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 10 of 14
(7,755 Views)