LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

VISA Read Write and User Events

I am trying to read and write on VISA Serial port along with user trigger events on UI. There will be data coming on the serial port that gets sorted based on first character received and based on user action on the UI, commands are sent on the serial port. Using event structures or Producer/Consumer architecture, I have not been able to write commands to the serial port. I am able to read but not write.

0 Kudos
Message 1 of 10
(594 Views)

I recommend that you post the latest version of your VI.

 

It is difficult to guide you what to do when you say you can't do something, because we can't see what you've tried!

0 Kudos
Message 2 of 10
(588 Views)

I have worked on this quiet a bit but didn't put all the elements together. I have chunks of code handling file management, and then some other tasks. The real problem I am having is in serial communication. The attached file is what I put together based on reading lots of forums and examples. What happens here is that my MCU sends data every 500 ms with the status of the device.

 

And the user can trigger the device sending commands over Serial. Here I have a home button that sends an H command to home the Z axis of the device. The button clicks and holds for a long moment whereas I have it set up as momentary latch. It also sends multiple H sometimes with just one click. With certain commands, the MCU will record a burst of data and send them over, ranging from 5000 to 6500 bytes, and then I need to look at the first character and make decisions on how to handle that data. I can do that, but I get stuck on this flow of constant data back and forth.

 

Any advice on how to handle this will be appreciated.

0 Kudos
Message 3 of 10
(523 Views)

You don't have a serial port problem.  You have a problem setting the wrong mechanical action for your home button.

 

Switch until released causes a value change on both the down action and the up action.

 

That button should be Latch Until Released.  And place the button in the event case that handles it.

0 Kudos
Message 4 of 10
(519 Views)

Hey!

 

I changed the button mechanical action.

 

The problem is with the serial port. As soon as I send a write VISA serial command on pressing the button, it stops the VISA read completely. Sometimes on pressing the button again, it reads the serial port for one character and then does nothing.

0 Kudos
Message 5 of 10
(513 Views)

There is no reason for it to stop the serial port.  What it will do is shortcut the timeout and write the data, then you'll have to wait a full 250 msec for the timeout case to run again.

 

You'd be better off putting the VISA communication in its own loop.  Send commands to write data via a queue in what is known as a producer/consumer architecture.

 

You should get rid of the Bytes at Port node.  You aren't using it.  And even if you were, it is the wrong thing to use 99% of the time in serial communication.

I would also get rid of the VISA Enable Event.  That is used in conjunction with a VISA Wait on Event that you aren't using.  Honestly, in all my years of LabVIEW programming, I've never needed to use VISA Enable Event or Wait on Event.

0 Kudos
Message 6 of 10
(508 Views)

I found an example of the Consumer Producer loop for reading and writing on the com port along with events based on UI button interaction but have had no luck so far. Is there an example you can point me towards?

 

The read commands when put in timeout flood the queue, and I am not able to successfully write on the com port with the button events. And as soon as I am successfully able to write to the com port, the read stops working. 

0 Kudos
Message 7 of 10
(459 Views)

It should be as simple as this.

 

If this doesn't work, then you'll have to tell us more about the device you are talking to and its communication protocol.

0 Kudos
Message 8 of 10
(452 Views)

So I was able to make it work. Reading the serial buffer with 200ms timeout, and executing button presses in event structure. 

 

The problem I am now facing is that when I create an exe file, the serial port doesn't work at all but the program works fine when I run it in NXG. Any ideas on why this would be happening will be helpful.

Download All
0 Kudos
Message 9 of 10
(413 Views)

Are you running the executable on the same PC as you developed it?

 

If not, then I'd say you hadn't installed VISA on the PC the exe is running on.

If it is the same PC, then I have no idea.  I have not touched NXG so I don't know what quirks it has that are still being worked out.

0 Kudos
Message 10 of 10
(343 Views)