LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

want to use visa read only when bits are at the port

Solved!
Go to solution

Hello all,

 

I do a lot of serial data communication and visa read does not have an abort function.  So heres the issue.  If i am in the middle of the visa read, configured as in the photo and block diagram, and i press the stop button i have to wait for the visa read to timeout, in this case 2 seconds, before i can move to the next step in the shutdown sequence.  Now i know there is some way to use the bus specefic events, but i havent found a good example yet.  Any help or advice for a workarond for this issue?

 

 

 

visa read example.PNG

 

Thanks,

 

Matt



-Matt
0 Kudos
Message 1 of 34
(3,796 Views)

I've just always used the Bytes at Port property to know whether or not to Read from the port. If nothing there, I don't wait around.

This has one downfall in that you can end up cutting a set of data coming through the port in half. Example: Bytes at Port = 8 when the total command is 16, but hasn't come in yet.

The workaround for that is to use a longer timeout if you see bytes at port.

Cheers


--------,       Unofficial Forum Rules and Guidelines                                           ,--------

          '---   >The shortest distance between two nodes is a straight wire>   ---'


0 Kudos
Message 2 of 34
(3,781 Views)

James,

 

Something like this?

 

And yes, see i tried that at first and was losing data, thats why i just had it timeout and read until the term char.

 

visa read example.PNG



-Matt
0 Kudos
Message 3 of 34
(3,778 Views)

The case structure should be 1, Default. for reading.

 

The other case that doesn't have a VISA read shold be 0.

 

(Think about right now what case would run in your case structure if there were 2 bytes at the port ......)

0 Kudos
Message 4 of 34
(3,760 Views)

Hi Ravensfan,

 

I saw that and fixed when i went back to play with it, but in labview do i always have to poll the serial port when there may be data or can i use the events and have the serial port wait until an event?  I figure its possible, but i cant seem to make it work or find a good example of this.

 

Thanks,

Matt



-Matt
0 Kudos
Message 5 of 34
(3,755 Views)

I actually just got the events to work, but once again this doesnt give any benefit, i still have to wait for the timeout on the even now. 

At this point i assume you have to poll the serial port if i want to give immediate stop functionality.



-Matt
0 Kudos
Message 6 of 34
(3,753 Views)

Matt, in every VISA application I can think of that I've worked on, I never needed a timeout of greater than 100ms for a single dataset. If I did have a longer dataset coming in, it was usually a really long string of data that I would have parse in chunks anyways. Are you trying to reduce your timeout/lag just for user experience? Do you really need a 500ms timeout?

 

I say this because, yeah the above method for polling the bytes at port is the best way to eliminate that long wait if you need the 500ms. Ideally, you don't need the 500ms timeout though and can just get rid of the polling.

Cheers


--------,       Unofficial Forum Rules and Guidelines                                           ,--------

          '---   >The shortest distance between two nodes is a straight wire>   ---'


0 Kudos
Message 7 of 34
(3,735 Views)

James,

 

I was actually just looking at a way to get around the polling, but ive done a bit more research and it appears thats not really possible.  I had my visa read timeout set too 2000ms prior, but realistically i only need around 20-100ms, im reading less than 500 bytes of data and 2000ms is way too long for ui purposes. Ill give the bytes at port a whirl, I havent used the bytes at port node and the termination char read before.  Will i lose data using the bytes at port in front of the read with term char? I feel like i was doing this before and losing data, but i may not have had the term char defined.



-Matt
0 Kudos
Message 8 of 34
(3,724 Views)

The attached VIs may/may not help you. They are simple communication subVIs. You need to set the port correctly for them to work. They poll and see if there are any messages.

 

Cheers,

mcduff

 

 

Download All
0 Kudos
Message 9 of 34
(3,704 Views)

Hi Mcduff,

 

Cant open the VI, still using 2011 Smiley Frustrated .I actually think the bytes at port image from earlier in the post is going to be my best bet though.



-Matt
0 Kudos
Message 10 of 34
(3,700 Views)