I want to have a commiunication by serial port, my old code is pooling mode and now I need event mode, how can I do it? I need a simple sample that wait with serial event and when receive bytes on port then I find out in event stucture and jump to that place.
Solved! Go to Solution.
Unfortunately, VISA does not work with the Event Structure (at least not when I tried). But VISA does have its own version of a Wait function that might be of use to you. Look in the Example Finder for Detect Serial Break Event. It shows how to use the VISA events.
I see that example but I think program freez and wait on "VISA wait on" block, am I true? if your answer is yes, so I can say you it is not a real event.
I need interrupt on serial, means that I enable it and go to my work when a package receive from serial port, bang! call me and I go for drive it's task.
It kind of is an interrupt, just not the way you want it. The function sits there and waits for the interrupt saying there is data on the port. Once you get the event, you can then do what it is you need to do.
Personally, I would put this reading of the port in a loop all on its own. It can use this VISA Event function to wait for data and then read it once it is there. I would then use a User Event to pass the read data up to your event structure for processing as you are imagining.
I'm late for holidays!
now i test your code but in read visa block get an error like this :
"An input parameter is invalid. For example if the input is a path, the path might contain a character not allowed by the OS such as ? or @."
why? please test it
hey man it is working! but I have my old problem.
my hardware on serial port send one string data like this "30,20,N,F,F,F,F,R" and length of string is vary. so I use byte at port block, but I take string sometimes correct and sometimes incomplete.
Does your instrument use a termination character? Do you have the termination character enabled? If your instrument sends a termination character for each message, then enable that and set your VISA Read to read way more bytes than you would ever expect. Do not use the Bytes at Port. With the termination character enabled, the VISA Read will stop when it finds the termination character or the desired number of bytes are read, whichever comes first.
If your instrument doesn't send a termination character, then you need to add a wait to allow all of the data to be transmitted before checking the number of bytes at the port. This is definately not the prefered way.
About one hour ago I solved my problem with termination char! are we have tlpaty!!
my device code written by myself and I add termination code on the end of string and enable on VISA block and delete Byte at port and finally everythings is OK now, work it.
thank you man.