LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

LabVIEW Serial port Wait Event with Serial Termchar

Solved!
Go to solution

Hi everyone!

 

I am quite new working with LabVIEW and I am having some problems trying to communicate using serial port.

 

I am trying to detect a data frame with an "X" as terminal character sended to serial port.

The problem is that with the VI you can see attached on this post I am not being able to detect the serial term char.

 

I have tried to make some changes to solve this but I can't.

 

In the VI I used a Type Cast function in case I was using the wrong ASCII value for the "X", but it still the same.

 

Can anyone help with this??

 

Thanks!

Best regards,

Omar

0 Kudos
Message 1 of 10
(6,194 Views)
A better way of doing this is to read whatever is coming in and look for the X in the output yourself.

Mike...

Certified Professional Instructor
Certified LabVIEW Architect
LabVIEW Champion

"... after all, He's not a tame lion..."

For help with grief and grieving.
0 Kudos
Message 2 of 10
(6,180 Views)

Why are you closing the event inside the loop?

0 Kudos
Message 3 of 10
(6,175 Views)
Good catch! Didn't notice that. The code as written would probably work on the first iteration and then die.

Mike...

Certified Professional Instructor
Certified LabVIEW Architect
LabVIEW Champion

"... after all, He's not a tame lion..."

For help with grief and grieving.
0 Kudos
Message 4 of 10
(6,161 Views)

An even simpler solution would be to just call the VISA Read with number of bytes to read that is guaranteed to be larger than the longest instance between your two term chars. Since you enable the term char in the VISA Intialize the VISA Read will return in following cases:

 

1) an error occurred 

2) the termination character has been received

3) the amount of requested data has been received

3) the timeout occurred

 

I don't see any advantage in the explicit event programming. Your program will either block in the Wait for Event function or the VISA Read, but the VISA Read only solution is much more clear and concise.

Rolf Kalbermatter
My Blog
Message 5 of 10
(6,140 Views)

thanks guys for your fast replays!!

 

Forgive my noob errors in the VI I attached, but I began to work with LabVIEW last month so I need time to know the environment.

 

I have tried to make some changes based on what you suggested me but I don't know whether I am in the right way; I deleted the Wait on event and the event config function, so now I am just making the Read serial port inside the loop but the problem is now with the number of char in the buffer. If I send the data with the term char selected all is OK, but if two data packets arrives wrong without the term char, because they reach the amount of bytes selected by a constant they still are readed by the VISA Read (what I am trying to avoid using the term char).

So I think I am doing it well.

 

I attach the changes in my VI.

 

Thanks!

Omar

0 Kudos
Message 6 of 10
(6,127 Views)
Solution
Accepted by osuarez

This will only work if your message never can be more than 8 characters including the term char. Set that value to 1000 or something that is guaranteed to always be bigger than your message size and everything should be fine.

Rolf Kalbermatter
My Blog
Message 7 of 10
(6,119 Views)

That makes sense now, and seems to work fine.

 

But my original idea was trying to avoid the pooling from LabVIEW to serial port, and that was why I decided to use the Wait on event function.

 

The next step for me would be adding this part to the current VI, is there any way to do this?

 

Thanks again,

Omar

0 Kudos
Message 8 of 10
(6,102 Views)

So what would the event solution give you? In either way your loop will be suspended while it is waiting on the event or the entire message to arrive. It is both polling too, one polls the event and the other polls directly the serial data receiving. And the VISA Read internally is using exactly the same infrastructure that the VISA event is using to wait for the message to arrive as complete frame.

 

Unless you want to play with VISA Events just for the sake of using them, the much more simple VISA Read is not a tiny bit less efficient than the event and has the advantage to be much more clean and concise in your diagram.

Rolf Kalbermatter
My Blog
0 Kudos
Message 9 of 10
(6,090 Views)

You are totally right, the loop is actually suspended until the data arrives.

 

So you have persuaded me, I think this would be my finally app to receive data from serial port. 😉

 

Thanks all for help me with that!

Omar

0 Kudos
Message 10 of 10
(6,076 Views)