LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 
Reply

VISA serial event create

Solved!
Go to solution

hi

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.

 

thank you.

0 Kudos
Message 1 of 10
(2,034 Views)

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.


There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
0 Kudos
Message 2 of 10
(2,012 Views)

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.

 

0 Kudos
Message 3 of 10
(2,003 Views)

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.


There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
0 Kudos
Message 4 of 10
(1,997 Views)

I 'm little confiused, can you show me a example for your idea? maybe from labview samples or other places.

0 Kudos
Message 5 of 10
(1,990 Views)
Highlighted

Something like this. 


There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
0 Kudos
Message 6 of 10
(1,976 Views)

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

 

thank you.

0 Kudos
Message 7 of 10
(1,913 Views)

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.

 

why?  

0 Kudos
Message 8 of 10
(1,886 Views)
Solution
Accepted by topic author meysam_b
08-27-2015 04:09 PM

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.


There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
Message 9 of 10
(1,867 Views)

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.

0 Kudos
Message 10 of 10
(1,863 Views)