LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

how I can use EVENT structure with read VISA functions ?

Hi.

I use VISA serial in my program in LV2013 for read data from MCU. each time MCU send 14 byte for LabVIEW and in LabVIEW I use this VI to read data. if data read count was 14 byte, my VI in the case will be executed. here is snippet from my code. (I simplify the VI and in case other functions will be executed and it worked well).

1.png

I run this code and it use pooling method and CPU worked always for it. it may be cause to VI run slowly.

then I meet EVENT structure in LabVIEW. it seem to be good and professional. so I use EVENT structure in my VI. but when I use below VI it doesn't work !!

in your opnion why this cannot work and what is your suggestion ?

2.png

I use and indicator that named " x= y? " for add compare function to event structure.  

in final LabVIEW code ,data will come with high baudrate like 460800bps. this worked well without EVENT structure.

 

Thanks.

0 Kudos
Message 1 of 12
(5,072 Views)

Hi everybody.

I right question in better explainations:

I use VISA read functions for communicate MCU with LV2013. each time I send 14 byte that contain a begin char (like 'T'), a termination char (like 'R') and 12 byte data between them. MCU send 14 byte with high baud rate like 460800bps or higher.(I use PL2303TA USB to Serial). time distance between each send is approximately 100us. I put my function and other stuff in a case loop. read function is in while loop which you can see a snip from VI below :

1.png

everything is OK.

but recently I met EVENT structure in LV and have been interest to it. I want to use EVENT structure for reduce CPU load. but when I put EVENT structure in my VI, it odesn't work. the picture o my VI is below :

2.png

I use an indicator for create an event on "equal " function output in EVENT structure. 

have anybody any idea for that ?

Thank you.

0 Kudos
Message 2 of 12
(5,059 Views)
You are not using the event structure correctly. The event will not fire for an indicator like your code expects. You would have to write to a value signaling property outside the event structure but it just seems you are complicating the code for no good reason. There is no real problem with your original code though the case statement seems pointless. There should be little cpu load.
Message 3 of 12
(5,045 Views)

first of all, thank you Dennis for reply.

how I can write to a value signaling property outside the event structure ?

in my final program in case statement I use more functions like filtering data, write data, calculate data, and showing on chart for 4 seerate data whici extract from incomig data from seial port. for this reason I sayed CPU load is high.

3.pngI want to use EVENT structure to save CPU time and power.

Thanks.

 

0 Kudos
Message 4 of 12
(5,028 Views)
Since you would be reading the serial port constantly anyway, there would be no difference in cpu loading. What benchmarks have you done that show a high load?

In any case, just create a separate loop or place the read in your timeout event.
Message 5 of 12
(5,016 Views)

I used 1ms delay before, but in this time data send from MCU every 100 us and I couldn't use delay function with value equal to 100us (it is ms).

but I want to read function work every 100 us and therefore while loop run in every 100 us . 

can I say my goal correctly ?


@Dennis_Knutson wrote:

In any case, just create a separate loop or place the read in your timeout event.

can you explain more about this ?

0 Kudos
Message 6 of 12
(4,991 Views)

By putting your reading of the serial port into a seperate loop, it can run completely independant of the rest of your code.  Your read loop does nothing but read the data on the serial port.  You can then use User Events or Queues to send the read data to whoever needs it.  This is how I set up all of my streaming serial applications.


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 7 of 12
(4,961 Views)

what is your point from "Queue" ? can yo axplain a litle example ?

0 Kudos
Message 8 of 12
(4,946 Views)

@ajapyy wrote:

what is your point from "Queue" ? can yo axplain a litle example ?


I use a form of the Producer/Consumer.


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
0 Kudos
Message 9 of 12
(4,923 Views)

Basically this (https://decibel.ni.com/content/docs/DOC-2431) or this (https://decibel.ni.com/content/docs/DOC-30005) except with visa instead of the DAQmx VIs or the event structure.

 

Edit: ^^his is better

0 Kudos
Message 10 of 12
(4,921 Views)