From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Event structure on serial read byte

Hi, Can we use Event structure upon some serial byte read.

for example if a serial read  matches with a byte "A" go to event A 

else if it matches with byte "B" go to event structure B

is it a good programming practice to use event on serial read.

 

0 Kudos
Message 1 of 7
(2,530 Views)

You certainly could find a way of doing that, but a case structure would probably be a more fitting approach.

Message 2 of 7
(2,527 Views)

@DMic wrote:

is it a good programming practice to use event on serial read.


Events are primarily to handle user interactions, so no! Why not use a case structure?

 

What is your code architecture? Is your event structure in a parallel loop? Can you give us more details?

Message 3 of 7
(2,524 Views)

I typically have a loop that does nothing but the serial port interactions.  Any messages can be sent from this through via a Queue or User Event.  Going any further in that discussion would require a lot more knowledge of the protocol being used by your device.


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 4 of 7
(2,516 Views)

Well you could.... maybe... But why?

 

All you need is a case structure.

 

 

========================
=== Engineer Ambiguously ===
========================
0 Kudos
Message 5 of 7
(2,477 Views)

I think what the OP is asking is if there is a built-in way to receive characters and pull them out of the serial buffer using Event Structures, similar (bot not exactly) like the DAQmx events. I'm assuming you want a "Character arrived at serial port" event you can register for, and have your characters execute that way.

 

If that is your question, then no, that's not built into LabVIEW (AFAIK). You could create something similar with a case structure, like the other replies have said. If you have some sort of UI that already has events happening, and you want to also generate events on keys transmitted, I would suggest making a parallel serial handling loop. Create a user event and register for it in the main Event loop, and have the helper loop send a User Event containing the character you received to the main loop.

0 Kudos
Message 6 of 7
(2,470 Views)

@BertMcMahan wrote:

I think what the OP is asking is if there is a built-in way to receive characters and pull them out of the serial buffer using Event Structures, .


I don't think so. In his description the event is decided (A or B) only  after the character has already been received.

 

(Unless they post some code, all we can do is guess. :D)

0 Kudos
Message 7 of 7
(2,459 Views)