LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Synchronize Read/Write to USB

I am plugging a device (via USB) that sends measurements to PC when a command ('A') is sent to the device. 

What I am trying to do to have a known frequency of read/write is to have a square wave be my trigger for acquiring data. That is, every time there's a rising edge it should send the command to acquire the measurement and then read the measurement. When there is no rising edge, it should not send the command to acquire measurement. To control this rate of acquiring data, I should be able to change the frequency of the square wave to get faster/slow number of readings.

When changing the frequency of the square wave it does not change the acquisition rate. It seems to be independent.

What I want to do is equivalent to an interrupt-interrupt handler.

Any ideas for what I may be doing wrong or if there's a better way to synchronize the data acquisition?

 Rising Edge.png

 

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

Seems overly complex to me.  If you want a timed event, why not simply wire the desired inter-event time into a Wait(ms) function?

 

When you have many things going on in a program, a sensible way to test it out (yourself) is to copy pieces to a Test VI and run them in isolation.  So you write the "Square wave Rising Edge" routine by itself, run it (changing Hi/Lo to boolean On/Off and wiring it to a Boolean indicator), and see if it does what you want (I'll bet it does not).  With a simple routine of 4-6 functions, you should be able to "figure it out".  Once that works, add a little more on, test, debug, repeat as needed.

 

Bob Schor

0 Kudos
Message 2 of 12
(5,116 Views)

Hi Bob_Schor,

What is the inter-event you have mentioned?

 

Instead of using a simulated square wave, I followed your advice about the complexity and I am using the Wait(ms) with a constant value. Although I am not sure if it's the best way to having a set frequency for the data collection? I put it to 20 milliseconds as its the lowest the VISA Read/Write can operate. I need to get to at least 1 millisecond (1000 Hz) of data reading/writing. LabVIEW.png

0 Kudos
Message 3 of 12
(5,086 Views)

I think Bob was speaking towards the time between events instead of an event type itself. What happens when you try to VISA write or read quicker than that? Does it throw an error or do you start missing bytes? There will be a transmission speed limit with VISA at some point, especially working with Windows (where jitter gets in the way), but I'm not sure exactly where that is.

Claire M.
Technical Support
National Instruments
Certified LabVIEW Developer
0 Kudos
Message 4 of 12
(5,062 Views)

Would that be the Timed Loop structure?


I start missing bytes. For instance, putting the wait time at 5 ms for 10 seconds with a baud rate of 9600, it will give me 1218 instead of 2000. Therefore I have increased the baud rate to 115,200 and I am getting 2000 (under the mentioned time). It even works with a wait time of 4 ms, which is okay for now in the data collection. Although now I have 8 'Bytes at serial port' that I can't find how to fix. It only does it when increasing the baud rate to 115,200.

0 Kudos
Message 5 of 12
(5,050 Views)

Furthermore, I have been having the following error show up in the first run of the program:

 

VISA error.png

The second problem is that anything more than 100 seconds, I come to the blue screen of death:

"DRIVER_IRQL _NOT_LESS_OR_EQUAL"


The third problem is that as more time passes by, the number of iterations in the loop does not correspond to what the wait time should be: Here I have it wired to 8 ms, therefore after 100 seconds, there should be 12500 loops (ideally), but it has about 12480.

Any guidance would help!

0 Kudos
Message 6 of 12
(5,023 Views)

@Joaquinh wrote:


The second problem is that anything more than 100 seconds, I come to the blue screen of death:

"DRIVER_IRQL _NOT_LESS_OR_EQUAL"

Something in the device driver does not like this. That is unfortunately far beyond LabVIEW or VISA's control.

 

The third problem is that as more time passes by, the number of iterations in the loop does not correspond to what the wait time should be: Here I have it wired to 8 ms, therefore after 100 seconds, there should be 12500 loops (ideally), but it has about 12480.

Any guidance would help!


You are working on a Windows system. You can be happy if on a Windows system the timing is accurate to about 10ms. Trying to go lower is asking for problems and only something a realtime system can provide to some extend.

12480 out of 12500 (99.84%) is VERY accurate for a non-realtime system.

 

Basically you are trying to do fairly high speed time accurate measurement. Software timing on a non-realtime system is not really suited for that, and having to communcate through RS-232 for this is not only suboptimal but pretty much a killer.

Rolf Kalbermatter
My Blog
Message 7 of 12
(5,010 Views)

UPDATE: By changing the the 'Synchronous I/O Mode from Asynchronous to Synchronous on the READ Visa it has solved the problem of the "DRIVER_IRQL _NOT_LESS_OR_EQUAL"

As far as the timing, I have not been able to solve it and have defaulted to only receiving measurements and at a slower rate.

The only problem that I have now is that when first running the VI, it gives me a: VISA Read Timeout Error. I have to force stop it, and then it will run great afterwards. Anyone know what this could be?


 

timeouterror.png

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

There have been numerous posts regarding VISA that say, over and over, "Configure VISA to use recognize the Terminator Character your device uses (usually <LF>, 0x0A) and do not use Bytes at Port".  What is probably happening is you send "A" and immediately start to read when the device is "just getting started".  Let it tell you when it is ready, and then read, oh, 1000 bytes (more than you ever expect), knowing it will terminate when it sees the Terminator Character.

 

Bob Schor

0 Kudos
Message 9 of 12
(4,976 Views)

Hi Bob,
I am not using the Bytes at Port, in my code it's there only as an indicator. I have 1000 bytes connected to the VISA Read. Also, I have the Terminator Character set to 35 which represents #, the serial I receive has the following format: *(measurement here)$(iterations)#

How would I let it tell me when it's ready? I tried having a wait time outside of 1000 ms and the problem persists always in the first run.Smiley Indifferent

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