03-17-2015 10:51 AM
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
Solved! Go to Solution.
03-17-2015 11:49 AM
03-17-2015 11:56 AM
Why are you closing the event inside the loop?
03-17-2015 12:38 PM
03-18-2015 02:32 AM - edited 03-18-2015 02:34 AM
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.
03-18-2015 04:09 AM
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
03-18-2015 04:29 AM
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.
03-18-2015 06:08 AM
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
03-18-2015 06:41 AM
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.
03-18-2015 07:39 AM
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