looking for documentation on triggered acquisition | LabJack
 

looking for documentation on triggered acquisition

32 posts / 0 new
Last post
blindgoat
blindgoat's picture
looking for documentation on triggered acquisition

I recently came across some LabJack documentation which I believe discussed a way to achieve triggered data streaming on a T7.  I can't find it now and I'm hoping that this is not a figment of my imagination.  If it's not, would you please point me to the docs?

Thanks.

LabJack Support
labjack support's picture
Do you mean a trigger to

Do you mean a trigger to start stream mode scanning, or an external clock that controls the scan rate of stream mode? Towards the bottom of the page here we mention the triggered stream feature to start scanning when a trigger is detected: 

https://labjack.com/support/datasheets/t7/communication/stream-mode

For an external clock that controls the scan rate of stream mode, we mention also on the stream mode page: "The scan rate is generated from the internal crystal oscillator. Alternatively, the scan rate can be a division of an external clock provided on CIO3.". Refer to the STREAM_CLOCK_SOURCE and STREAM_EXTERNAL_CLOCK_DIVISOR register documentation as you set these two before starting stream mode.

LabJack Support
labjack support's picture
Also, if you're using LJM,

Also, if you're using LJM, the LJM_eStreamStart page has some important information.

We're always trying to make our documentation easier to read / find, so please feel free to let us know where you get lost. Thank you!

Bob
BBEC's picture
I want to start a AIN0

I want to start a AIN0 acquisition with a trigger (FIO0 edge) on a  T7 model (firmware 1.0188).

Before to start a eStreamStart a set STREAM_SCANS_RETURN to STREAM_SCANS_RETURN_ALL, STREAM_RECEIVE_TIMEOUT_MODE to STREAM_RECEIVE_TIMEOUT_MODE_MANUAL and STREAM_RECEIVE_TIMEOUT_MS to 0. 

In the eStreamStart i use  ["AIN0_NEGATIVE_CH", "AIN0_RANGE", "AIN0_RESOLUTION_INDEX", "STREAM_TRIGGER_INDEX"] with the values [199, 1, 1, 0, 2000] in the eStreamStart parameter.

Two problems are there :

  1. a eStreamRead stops after +- 10s (or 5s) with error LJM library error code 1306 LJME_SYNCHRONIZATION_TIMEOUT
  2. no reaction of the FIO0 input.

What is forgotten ?

LabJack Support
labjack support's picture
Hello,

Hello,

Try setting LJM_STREAM_SCANS_RETURN to LJM_STREAM_SCANS_RETURN_ALL_OR_NONE (_ALL_OR_NONE instead of _ALL).

Also, you might want to see the example stream_triggered.c.

blindgoat
blindgoat's picture
This may not help much, but I

This may not help much, but I've attached a python module of mine that uses triggered burst streaming.  If you look near the bottom of the file, starting at line 310, you'll see a code snippet that invokes the module code to perform a triggered burst.  It seems to work very reliably.  It's been a while since I hacked this code out, but if you have any questions about this particular code, post them here and I'll try to answer.

File Attachment: 
jdragustinovis
jdragustinovis's picture
LabJack suppot:

LabJack suppot:

Could you tranlate "stream_triggered.c" to VB .NET, Please?

Thanks in advance.

LabJack Support
labjack support's picture
We will look into making this

We will look into making this example.

LabJack Support
labjack support's picture
Here is a VB.NET version of

Here is a VB.NET version of the stream triggered example.

File Attachment: 
bruno
bafonso's picture
I've been trying to setup a

I've been trying to setup a triggered stream using my T7 on FIO0 from a TTL signal (0 to 5V) but something is not working on the T7's side. I have c++ code similar to the triggered c example and its behavior is erratic. I can correctly setup a non-triggered stream with a calback. With triggered neither works and I get a ton of C++ First-chance exceptions while waiting for the trigger, eg:  Microsoft C++ exception: int at memory location 0x000000000015EE60. I'm guessing these are from the LJM library.

Fundamentally, the triggered streams works erratically or I get the following error:

------------

eReadName result: SERIAL_NUMBER = 470013836.000000

......................LJM_eStreamRead error: "LJME_TRANSACTION_ID_ERR" (ErrorCode: 1279)

Closing all devices and exiting now

Press enter to continue

--------------

The visual basic example also does not work all the time and I get the same error sometimes. This was a major interest in getting the T7 for me, so this is critical to me. Otherwise I will need to do a bunch of number wizardy on the software side to align things to my trigger sequence. 

When I tried the latest beta I could not even have it triggered at all, so you've been changing the code causing this behavior. I am triggering right now the FIO0 with a 5V signal out of a signal generator. The Labjack can definitely see the signal as I setup a quick DaqFactory page that shows it going from 0 to 1. 

I can test whatever code you want me to using VS2013. Let me know!

LabJack Support
labjack support's picture
The First-chance exceptions

The First-chance exceptions are expected and occur during normal, successful operation.

In regards to the LJME_TRANSACTION_ID_ERROR, I have confirmed that there is a problem and I will fix it as soon as possible. For now, a possible workaround is to use an Ethernet connection type instead of a USB connection. Also, the problem does not occur on Mac OS (and may not occur on Linux either), though changing operating systems is probably not viable for you. Again, I hope to fix this soon.

I will update this thread when more information is available.

bruno
bafonso's picture
Thanks Labjack Support, that

Thanks Labjack Support, that sounds good. I think I can easily interface to the T7 w/ a spare network port on my computer, so I will also give that a go ! 

LabJack Support
labjack support's picture
bruno—I apologize for the

bruno—I apologize for the delay in updating this thread. I've discovered that there is a problem with a lowlevel stream read on Windows when timeout is less than ~2500 milliseconds. To manually set the stream read timeout, LJM_STREAM_RECEIVE_TIMEOUT_MS may be written (using LJM_WriteLibraryConfigS). (Note: some LJM C examples, such as stream_triggered.c, set LJM_STREAM_RECEIVE_TIMEOUT_MS <2500—we'll fix those settings in the next C examples release.) I haven't yet had any luck in determining why the <2500 ms timeout causes the problem, unfortunately.

Massimo
massimom's picture
I'd like to use the external

I'd like to use the external clock option for a streamed acquisition with a T7 and I am still not clear how to set it up in such a way the scan is triggered by the rising edge of the clock signal. The documentation of eStreamStart reports: "Externally clocked stream is when a signal is received on CIO3, for which each edge a single scan is triggered. This allows for variable scan rates and synchronized streaming.".  It sounds like that the scan is triggered on both the rising and falling edges of the clock signal. If so, how do I select either the rising or falling edge as the trigger?

Can somebody clarify the settings to use for an externally clocked streamed acquisition in which each scan is triggered by the rising edge of the clock signal?

Also, the API documentation includes SetStreamCallback function, but I cannot find this method in the .NET interface. Is this function available in C#?

Thanks!

LabJack Support
labjack support's picture
Actually, each rising edge

Actually, each rising edge triggers a scan. (I've fixed that on the eStreamStart page now.)

There is no option to select using the falling edge and also there is no option to select using both the rising and falling edges.

SetStreamCallback is currently not supported in .NET C#.

Massimo
massimom's picture
Thanks for the clarification.

Thanks for the clarification. Triggering a scan on the rising edge is what my application needs, so that works fine for me.

I still have some difficulties with the triggered scans though. In my application the external clock source generates a finite number of pulses and this number is known before the streaming starts.  After configuring the T7 with the suggested settings ( LJM_STREAM_SCANS_RETURN_ALL_OR_NONE,  LJM_STREAM_RECEIVE_TIMEOUT = 5000, STREAM_CLOCK_SOURCE = 2, STREAM_EXTERNAL_CLOCK_DIVISOR = 1), I issue eStreamStart with ScansPerRead set to the expected number of pulses, wait long enough, but the T7 does not seem to ever return the expected number of samples (I do have a loop that keeps executing eStreamRead if a LJME_NO_SCANS_RETURNED exception is thrown). I can see that samples are collected, but always less than expected. I tried increasing the internal buffer size, increasing the value of ScanRate (which is about 5kHz), reducing the value of ScanPerRead, but so far I was not able to get it work correctly.

Any suggestion as to how troubleshoot this issue?

Thanks!

LabJack Support
labjack support's picture
What is the number of pulses

What is the number of pulses that will be sent from the external clock source and how many scans do you receive? With LJM_STREAM_SCANS_RETURN_ALL_OR_NONE, LJM will wait until it receives ScansPerRead scans before returning LJME_NOERROR. For this, you can:

  1. Use LJM_StreamBurst
  2. Write to STREAM_NUM_SCANS before calling LJM_eStreamStart
  3. Set ScansPerRead to a multiple of the number of external clock pulses.
Massimo
massimom's picture
Thanks Labjack Support for

Thanks Labjack Support for your reply. By tweaking the value of ScansPerRead in the eStreamStart function, I can determine how many values I receive. For instance, with 4541 pulses I received 4536 values. With 1041 pulses I receive 864 values. Both 4536 and 864 are multiple of 24, which is the number of samples per packet, not sure if that is just a coincidence, but hopefully it is a clue.  

Regarding your suggestions:

  1. I tried LJM_StreamBurst, but using LJM_STREAM_SCANS_RETURN_ALL_OR_NONE resulted in the LJME_NO_SCANS_RETURNED exception to be thrown. On the other hand, without using it the StreamBurst function hung.
  2. Writing the number of scans to STREAM_NUM_SCANS register before eStreamStart made no difference
  3. I tried with setting the number of external pulses to be a multiple of ScansPerRead, but again no difference

Thanks.

LabJack Support
labjack support's picture
I'm able to collect 4541

I'm able to collect 4541 scans using the attached program (which is adapted from the examples/stream/stream_external_clock.c C example). To use it, you need to connect a wire from FIO0 to CIO3. The important things it does differently from the original stream_external_clock.c:

  • Calls EnableFIO0PulseOut to set up the FIO0 pulse out after LJM_eStreamStart (instead of before eStreamStart)
  • Writes 4541 to STREAM_NUM_SCANS
  • Uses a ScansPerRead of 1 (ScansPerRead limits the number of scans per packet)
  • Ignores a STREAM_BURST_COMPLETE error from eStreamRead (STREAM_BURST_COMPLETE is equal to 2944. STREAM_BURST_COMPLETE happens on the 4541st read of eStreamRead)

Also, note that it needs 1 more pulse than the value written to STREAM_NUM_SCANS, though I'm not sure why. The first pulse may be getting used to synchronize between CIO3. (I'm hoping to get more information from the firmware guys soon.)

File Attachment: 
Massimo
massimom's picture
Thanks Labjack Support, the

Thanks Labjack Support, the suggested settings are working for me as well.

I would appreciate if you could confirm that it is the first pulse that does not trigger a scan. I can live with missing one sample as long as I know which one it is and it is either at the beginning or the end of the stream burst. 

Thanks!

LabJack Support
labjack support's picture
Correct. The first pulse is

Correct. The first pulse is not detecetd by hardware, subsequent pulses are.

Bob
BBEC's picture
Using a T7 with AIN0, AIN2 en

Using a T7 with AIN0, AIN2 en FIO0 as streaming inputs @ 20000 sps, triggered on the falling edge of FIO0.

I have a lot of problems with "LJME_SYNCHRONIZATION_TIMEOUT", until I increase the "LJM_STREAM_TRANSFERS_PER_SECOND" configuration parameter to a high value.  Default value is 25, now the huge value of 1000.  This huge value gives 100/100 success.

What is the real meaning of this configuration parameter ?

LabJack Support
labjack support's picture
LJM_STREAM_TRANSFERS_PER

LJM_STREAM_TRANSFERS_PER_SECOND sets the frequency at which LJM reads data from the device.

LJM_STREAM_RECEIVE_TIMEOUT_MS is the configuration I would have expected to fix the issue for you:

https://labjack.com/support/software/api/ljm/constants/ljmstreamreceivet...

George McBane
GMcBane's picture
So how should I handle this

So how should I handle this if I don't know the number of scans that will be accumulated in advance?

I have an external clock pulse that varies smoothly between about 100 Hz and 1 kHz running into CIO3.

I have about a 0.5 Hz square-wave control pulse going into FIO0. I want to collect all the scans that occur while this pulse is high. During that time the clock pulse will start out slow, then speed up to around 1 kHz, then slow down again.  I don't know how many total clock pulses there will be; it depends on how my users have set up the experiment.  There won't be enough to fill either the T7 onboard buffer or the LJM buffer, though, so that shouldn't be a problem.

I'm okay with either setting up an externally triggered (as well as clocked) stream, or polling FIO0 and calling eStreamStart when I see it go high.  But then how do I arrange things to collect the appropriate number of scans from the stream, since that number probably won't be a multiple of scansPerRead? If I set "LJM_STREAM_SCANS_RETURN" to  STREAM_SCANS_RETURN_AVAILABLE, how do I know how many valid data I received?

-G.

LabJack Support
labjack support's picture
The easy solution is to

The easy solution is to stream the trigger signal along with your other date. Then in post-processing, select the data that was measured while the signal was high.

mina
Synapticon's picture
Hello, I am really struggling

Hello, I am really struggling to make triggered stream work. Could you please verify that I understood this functionality properly. 

ex. I can generate a pulse on FIO0 (let's say f=1kHz). I could then stream data on any analog port, say AIN0, by detecting the rising or falling edge of my pulse on FIO0. Is this correct? Or should I feed this pulse to another digitalIO, say FIO1, and then stream data on rising/falling edges of FIO1?  

I am using Python and your LJM wrapper for Python. I followed your stream_triggered.c code and this is what I set up. 

ljm.writeLibraryConfigStringS("LJM_STREAM_SCANS_RETURN","LJM_STREAM_SCANS_RETURN_ALL")
ljm.writeLibraryConfigS("LJM_STREAM_RECEIVE_TIMEOUT_MS", 0)
ljm.eWriteName(handle, "STREAM_TRIGGER_INDEX", 2000)

I then set FIO0 to 1kHz pulse out, and then changed DIO0_EF_INDEX from initial 0 to 3. (I am not sure if that is even possible with DIO0_EF enabled) 

ljm.eWriteName(handle, "DIO0_EF_INDEX", 3)

I am using streamBurst to read data on AIN0. The error I receive is always LJME_SYNCHRONIZATION_TIMEOUT.  

Any pointers would be great. 

LabJack Support
labjack support's picture
Stream can only be triggered

Stream can only be triggered by a DIO_EF set to Frequency In, Pulse Width In, or Conditional Reset. So it is not possible to both generate and trigger from the same IO.

The triggered stream section is at the bottom fo this page: https://labjack.com/support/datasheets/t-series/communication/stream-mode

 

mina
Synapticon's picture
Hello, 

Hello, 

thanks for the clarification. However I am still receiving LJME_SYNCHRONIZATION_TIMEOUT error. 

My setup is then as follows. I generate 200Hz pulse on FIO0. I connect FIO0 to FIO1. I setup trigger_index on FIO1 and attempt to stream data on AIN0. I stream using streamBurst, with scanRate = 1000Hz, numScans =  40. I receive the same error even when i play around with frequency and scanrate values. Am I missing something? Code lines below: 

ljm.writeLibraryConfigStringS("LJM_STREAM_SCANS_RETURN","LJM_STREAM_SCANS_RETURN_ALL")
ljm.writeLibraryConfigS("LJM_STREAM_RECEIVE_TIMEOUT_MS", 0)
ljm.eWriteName(handle, "STREAM_TRIGGER_INDEX", 2001)
ljm.eWriteName(handle, "DIO1_EF_ENABLE", 0)
ljm.eWriteName(handle, "DIO1_EF_INDEX", 3)
ljm.eWriteName(handle, "DIO1_EF_ENABLE", 1)

numScans=40
aData=ljm.streamBurst(handle, 1, [0], 1000, 40)[1]

LabJack Support
labjack support's picture
Before enabling DIO1,

Before enabling DIO1, configure your frequency in as continuous:

ljm.eWriteName(handle, "DIO1_EF_CONFIG_A", 2)

DIO#_EF_CONFIG_A for frequency in defaults to one shot, so it is likely stopping before your streamBurst call and the stream start cannot be triggered.

mina
Synapticon's picture
Hello, thank you very much

Hello, thank you very much for the support. This worked. I am now able to use triggered stream with streamBurst call. Steps are repeated below for anyone else searching for guidance in Python:

ljm.writeLibraryConfigStringS("LJM_STREAM_SCANS_RETURN","LJM_STREAM_SCANS_RETURN_ALL")
ljm.writeLibraryConfigS("LJM_STREAM_RECEIVE_TIMEOUT_MS", 0)
ljm.eWriteName(handle, "STREAM_TRIGGER_INDEX", 2001)
ljm.eWriteName(handle, "DIO1_EF_ENABLE", 0)
ljm.eWriteName(handle, "DIO1_EF_INDEX", 3)

ljm.eWriteName(handle, "DIO1_EF_CONFIG_A", 2)
ljm.eWriteName(handle, "DIO1_EF_ENABLE", 1)

#numScans=40
aData=ljm.streamBurst(handle, 1, [0], 1000, 40)[1]

Akshay Gulati
akshaygulati26's picture
Hello,

Hello,

I want to measure a bunch of analog values using external triggers. Duration between two triggers would vary from 50 ms to 1 sec. I tried using the strean_triggered.py example but as I understand this code starts streaming with one trigger. However I want to run the code in an infinite loop and take one or two readings at each trigger.  Is there an example you have in python that I can use?

LabJack Support
labjack support's picture
We do not have any examples

We do not have any examples specifically for what you want to do. One potential option would be to modify stream_burst.py to include triggered stream code and run stream burst in a loop where you "reload" the trigger after each burst. Another option may be to use externally clocked stream, which would take a scan every time you clock an edge:

https://labjack.com/support/datasheets/t-series/communication/stream-mod...