Jump to content

Need Help Serial Write and Read


mrgsdsjg

Recommended Posts

Hi everyone, I am fairly new to LabVIEW and have been having a problem programing some code to write and read over the same serial port. Here goes: I need to be able to both write and read over the same serial port, but the trick is that I need to be able to write a message whenever one of several buttons is pressed, and read at all other times. The examples I have loaded up and played with all have selectors for either reading or writing, and if both are turned on, it will wait for me to write something, then read(whatever is in the read buffer), then wait for me to write something, then read again. Any help or examples would be greatly appreciated. I am loading a modified version of the Advanced serial write and read VI. Thanks for your help!

Link to comment

QUOTE (mrgsdsjg @ Mar 13 2008, 11:12 AM)

Any help or examples would be greatly appreciated. I am loading a modified version of the Advanced serial write and read VI. Thanks for your help!

You're on the right track. And good job consulting the examples. That's half the battle :).

But rather than modifying the Advanced Serial Write and Read example to behave like an event-driven UI, a better approach would be to take something like the User Interface Event Handler template (File >> New... >> User Interface Event Handler) and add the serial read & write code that you need from the serial example.

A really simple way to do it is to put your write operations in cases of an Event Structure (just like you've already done, although I'd probably use a Value Change event rather than a Mouse Up event, and set the booleans to Latch When Released). Then put your read operation in the Timeout case of the Event structure and wire something reasonable, like 100 ms to the timeout terminal of the Event Structure (see the LabVIEW Help for more info).

This way, your program will execute the serial read every time the Event Structure times out (which is almost every time). But whenever you press one of the buttons, the event for that button will fire, triggering the associated serial write.

Welcome to LabVIEW, and welcome to LAVA!

Link to comment

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.