T7 stream quadrature python example | LabJack
 

T7 stream quadrature python example

6 posts / 0 new
Last post
Nora
abbaszadeh@ovgu.de's picture
T7 stream quadrature python example

Hello,

I need to read analog and quadrature signals together using the stream function. While it is very clear to me and worked out of the box to set up the stream for analog values, (with the given very nice example script)  I have some trouble with the quad signal and don not really understand, how to implement this:

Stream data is transferred as 16-bit values only.  In the normal case of an analog input such as AIN0, the 16-bit binary value is actually is what is transferred and LJM converts it to a float on the host using the calibration constants that LJM reads in before starting the stream.  Some registers in the list above (e.g. DIO4_EF_READ_A) have 32-bits data.  When streaming a register that produces 32-bit data, the lower 16-bits (LSW) will be returned and the upper 16-bits (MSW) will be saved in STREAM_DATA_CAPTURE_16. To get the full 32-bit value, add STREAM_DATA_CAPTURE_16 to the stream scan list after any applicable register, then combine the two values in software (LSW + 65536*MSW).  Note that it would not be unusual to put STREAM_DATA_CAPTURE_16 in multiple locations in the scan list.

I use the estreamRead() func to aquire the data which seem to work, but I always get 'float' values as a return values for

"DIO6_EF_READ_A" , "STREAM_DATA_CAPTURE_16"  in the tuple(List) that is returned by :

ret = ljm.eStreamRead(handle)

this leads to strange values for my position feedback.

Could you clearify me how to get the appropriate values for quadrature?

In older script using command-response eReadAddress() func I was using:

quad = ljm.eReadAddress(handle, addrA, ljm.constants.INT32)

to determine the output type, which resolved my problem.

Thank you very much for a code snippet or advice.

LabJack Support
labjack support's picture
It sounds like you figured it

It sounds like you figured it out (https://labjack.com/forums/t7/t7-stream-quadrature-python-example#commen...)—you need to combine the two 16-bit values (DIO6_EF_READ_A and STREAM_DATA_CAPTURE_16) into a 32 bit value as according to the T7 datasheet stream page describes:

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

Nora
abbaszadeh@ovgu.de's picture
Thank you for the reply and

Thank you for the reply and sorry for the double post!

I don't get the following  point:

Why do i get float values as return in:

ret = ljm.eStreamRead(handle)

I've attached:

-> the test script (streamLJ.py),

-> the .json dump  of the return tuple (AIN0(float), "DIO6_EF_READ_A"(float), "STREAM_DATA_CAPTURE_16"(float))  it is renamed to data.m to be able to upload)

-> a plot of the oscillation (real angle is between 20 and -20) by stream (return.png) and by ljm.eReadAddress() method (quadSignal.png)

So basically, I have the same problems like I had before switching to 'int32' to the ljm.eReadAddress(..., ljm.constants.INT32) method getting quadrature signals.

How can I build one int32 from 2 float values coming as a tuple with the other values from AIN#?

LabJack Support
labjack support's picture
The LJM function LJM

The LJM function LJM_eStreamRead returns stream data as double precision floats (double), and LJM Python does the same with ljm.eStreamRead.

DIO6_EF_READ_A is the lower 16-bits and STREAM_DATA_CAPTURE_16 is the upper 16-bits of the 32-bit quadrature value. Here is one method to convert these two float values to the single int32 quadrature value, demonstrated with the first scan of data (import ctypes beforehand):

ain0 = data[0]
quadlo = int(data[1])
quadhi = int(data[2])
quad = int(quadhi*65536 + quadlo)  # Unsigned 32-bit value
quad = ctypes.c_int32(quad).value # Signed 32-bit value

Nora
abbaszadeh@ovgu.de's picture
Thank you very much. I haven

Thank you very much. I haven't worked with changing data types in python yet, this answer really helped me. I really appreciate your perfect support!

Just one thing: I had to add .value to your example:

quad = ctypes.c_int32(quad).value 

if someone else will have the same question, it maybe helps.

Now streaming works fine.

LabJack Support
labjack support's picture
Thanks for catching that. I

Thanks for catching that. I edited my previous post to have ".value".