Long delay to start measuring | LabJack
 

Long delay to start measuring

9 posts / 0 new
Last post
ElmarJ
ElmarJ's picture
Long delay to start measuring

Since a few day`s I'm playing around with a T7 Pro, to automate a lab setup to measure some analog signals. As I also need to combine some data, I really want to use Python3 as as software. I have a piece of code I use to log some AIN channels, and I'm running via ethernet. However it takes almost 20 seconds before the data transfer starts. The data in the T7 is acquired only a few seconds after start, but the transfer starts after ~25 seconds. I think this is rather long, am I doing something wrong?

This is the output of my script:

runfile('C:/Users/EJE/Desktop/EJE Repo/0154/sources/trunk/LabSetup/main.py', wdir='C:/Users/EJE/Desktop/EJE Repo/0154/sources/trunk/LabSetup')
Backend TkAgg is interactive backend. Turning interactive mode on.
tic: Start timer
> SERIAL_NUMBER = 470018653.000000
toc: 0.0 [s]
toc: 0.0 [s]
Stream started with a scan rate of 500 Hz.
toc: 0.062400102615356445 [s]
Performing 1000 stream scans.
toc: 0.062400102615356445 [s]
eStreamRead 1
toc: 24.6860454082489 [s]
eStreamRead 2
toc: 25.044846057891846 [s]
eStreamRead 3
toc: 25.7000470161438 [s]
eStreamRead 4
toc: 26.19924807548523 [s]
eStreamRead 5
toc: 26.64004921913147 [s]
Total scans = 1250
Time taken = 26.733649 seconds
LJM Scan Rate = 500.000000 scans/second
Timed Scan Rate = 46.757553 scans/second
Timed Sample Rate = 233.787763 samples/second
Skipped scans = 0
Stop Stream

 

File Attachment: 
LabJack Support
labjack support's picture
What part of the while loop

What part of the while loop is taking the most time?

What happens if you change the ScansPerRead to 1?

If you start from the basic Examples\More\Stream\stream_basic.py Python LJM example, does the same thing happen?

ElmarJ
ElmarJ's picture
The first ljm.eStreamRead

The first ljm.eStreamRead(handle) takes approx 20 seconds to return.

- Trying to use the stream_basic.py over Ethernet takes just as long.

- Setting scansPerRead=1 acttually works over Ethernet, which is really nice! I will use that.

Over USB I get a lot of "skipped samples". This was the reason for me to start playing with Ethernet.

Comparison (STREAM_RESOLUTION_INDEX= 0) via Ethernet works at least up to 12.5kHz with 4 ADC channels and one FIO

Over USB I cannot get higher than 300 Hz which was a bit dissappointing ;)

ElmarJ
ElmarJ's picture
The first eStreamRead() takes

The first eStreamRead() takes all the time (~20 - 24sec), also on the example of stream_basic.py.

 

Changing to scansPerRead to 1:

Over Ethernet that works great. I'll use it.

Over USB however I was gettting skipped samples etc, so I started playing with it. (That was the reason I changed it).

 

To give an idea, 4 ADC channels and 1 FIO input (ADC resolution index = 1) over Ethernet goes up to 12.5kHz, where USB wo`nt even get to 350Hz.

LabJack Support
labjack support's picture
I've attached a version of

I've attached a version of stream_basic.py that measures the amount of time per loop and per eStreamRead call. It uses the method from "Determining What's Slow" here: https://labjack.com/support/software/api/ljm/function-reference/timing-functions/ljmgethosttick

For me, it outputted the following:

Opened a LabJack with Device type: 7, Connection type: 1,

...

Stream started with a scan rate of 1000 Hz.

Performing 25 stream reads.

eStreamRead 1
  1st scan out of 500: AIN0 = -0.00090, AIN1 = -0.84426, 
  Scans Skipped = 0, Scan Backlogs: Device = 0, LJM = 4
The code section took 505283 microseconds;
  the whole loop took 505382 microseconds

eStreamRead 2
  1st scan out of 500: AIN0 = 0.00037, AIN1 = -2.45552, 
  Scans Skipped = 0, Scan Backlogs: Device = 0, LJM = 8
The code section took 493735 microseconds;
  the whole loop took 493924 microseconds

...

eStreamRead 25
  1st scan out of 500: AIN0 = 0.00037, AIN1 = -2.45142, 
  Scans Skipped = 0, Scan Backlogs: Device = 0, LJM = 16

Total scans = 12500
Time taken = 12.519253 seconds
LJM Scan Rate = 1000.000000 scans/second
Timed Scan Rate = 998.462129 scans/second
Timed Sample Rate = 1996.924257 samples/second
Skipped scans = 0

Stop Stream 

All of the timings were close to .5 seconds.

If you run the attached example, unaltered, can does it replicate my results? If so, try making small changes, one by one, until you see the issue occur.

Also, I notice that the end of your output suggests that the whole stream session took 26.733649 seconds—which suggests that each eStreamRead could not have taken 25 seconds:

Time taken = 26.733649 seconds

File Attachment: 
ElmarJ
ElmarJ's picture
I did not mean to say that

I did not mean to say that every read takes 25 s, only the first one ttakes 25 s. Setting a sampling rate of 1000, scansPerRead = 500; I would expect that this takes like 500 ms + maybe some connection time, eg, approx 2 - 3 seconds to start worst case.

However the first eStreamRead takes approx 25 sec.

Some results:

Running the code you suggested resulted in this:

(Ethernet)

Opened a LabJack with Device type: 7, Connection type: 3,
Serial number: 470018653, IP address: 192.168.2.205, Port: 502,
Max bytes per MB: 1040
Stream started with a scan rate of 1000 Hz.
Performing 25 stream reads.
eStreamRead 1
  1st scan out of 500: AIN0 = 0.62055, AIN1 = 0.21741,
  Scans Skipped = 0, Scan Backlogs: Device = 0, LJM = 12
The code section took 450890 microseconds;
  the whole loop took 450997 microseconds

...

eStreamRead 25
  1st scan out of 500: AIN0 = 0.62055, AIN1 = 0.21962,
  Scans Skipped = 0, Scan Backlogs: Device = 0, LJM = 44
Total scans = 12500
Time taken = 30.483047 seconds
LJM Scan Rate = 1000.000000 scans/second
Timed Scan Rate = 410.063994 scans/second
Timed Sample Rate = 820.127988 samples/second
Skipped scans = 0
Stop Stream

However there are some interesting things in this code:

  1. The scansPerRead is set to (it is faster when set to 1): scansPerRead = int(scanRate / 2)
  2. The first eStreamRead loop timing is not printed. This is where the magic happens. Therefore I commentted out this if, so that the loop code is always printed: #if tloop != 0: print("The code section took %ld microseconds;" % (t1 - t0)) print(" the whole loop took %ld microseconds" % (t1 - tloop))

    and got this as first result:
    Stream started with a scan rate of 1000 Hz.
    Performing 25 stream reads.
    The code section took 21861157 microseconds; (First eStreamRead portion --> almost 22 sec)
      the whole loop took 176685973163 microseconds (Invalid reading because t1oop is invalid in first run)
    eStreamRead 1
      1st scan out of 500: AIN0 = 0.62055, AIN1 = 0.21709,
      Scans Skipped = 0, Scan Backlogs: Device = 0, LJM = 12
    The code section took 590034 microseconds;

Trying the same over USB:

Opened a LabJack with Device type: 7, Connection type: 1,
Serial number: 470018653, IP address: 0.0.0.0, Port: 0,
Max bytes per MB: 64
Stream started with a scan rate of 1000 Hz.
Performing 25 stream reads.
The code section took 1324730 microseconds;
  the whole loop took 177138218571 microseconds
eStreamRead 1
  1st scan out of 500: AIN0 = 0.61960, AIN1 = 0.21772,
  Scans Skipped = 0, Scan Backlogs: Device = 0, LJM = 820
The code section took 51 microseconds;
  the whole loop took 186 microseconds

...

eStreamRead 25
  1st scan out of 500: AIN0 = 0.62087, AIN1 = 0.21772,
  Scans Skipped = 0, Scan Backlogs: Device = 9, LJM = 148
Total scans = 12500
Time taken = 12.716023 seconds
LJM Scan Rate = 1000.000000 scans/second
Timed Scan Rate = 983.011748 scans/second
Timed Sample Rate = 1966.023496 samples/second
Skipped scans = 253
Stop Stream

So, here the delay is no problem, but I'm missing samples (which is even more annoying).

Summary:

- Over Ethernet there is a large startup delay when scansPerRead is set to a higher value. It does work as expected when set to 1, so I'm using that.

- This delay is normally not showed in your example.

- Over USB I get a lot of skipped samples, but no startup delay. So this is basically a strange problem ?

LabJack Support
labjack support's picture
Sorry—I didn't understand

Sorry—I didn't understand that it was only the first eStreamRead that was taking so long.

1. Make sure you're running the latest software:

https://labjack.com/support/software/installers/ljm

2. Also, please update to the latest firmware using Kipling:

https://labjack.com/support/software/applications/t-series/kipling/devic...

3. Ensure triggered stream is disabled by writing 0 to STREAM_TRIGGER_INDEX.

4. Please enable the LJM debug log as described here:

https://labjack.com/support/software/api/ljm/function-reference/debugging-functions

Then, after getting the problem to occur, send us the ljm.log file (C:\Program Data\LabJack\LJM\ljm.log, probably) before opening any other programs that use LJM. Either Ethernet or USB is fine, since it seems like the delay is at least partially independent from the connection type.

ElmarJ
ElmarJ's picture
I performed your suggested

I performed your suggested tests.

 

Attached are the logs:

- over USB (skipped scans)

- over Ethernet (~30 sec delay!) @ scansPerRead = int(scanRate / 2)

- over Ethernet @ scansPerRead = 1 (fast, no missing scans)

LabJack Support
labjack support's picture
I ran your code but was

I ran your code but was unable to replicate the behavior. I tried all three configurations. They all had negligible delay between the stream enable packet and the first stream packet.

The log file doesn't provide any insight, either.

1. Please try with direct Ethernet:

https://labjack.com/support/app-notes/networking/direct-connection-ethernet-app-note

2. Please try disconnecting everything from the T7 besides the USB and Ethernet cable and try again.

3. Please try performing a factory reset:

https://labjack.com/support/datasheets/t-series/spc