delaying digital output | LabJack
 

delaying digital output

5 posts / 0 new
Last post
Lalit
29.lalit's picture
delaying digital output

Hi,

I am controlling a Labjack U3 with matlab using the following code:

ljasm = NET.addAssembly('LJUDDotNet'); %Make the UD .NET assembly visible in MATLAB
ljudObj = LabJack.LabJackUD.LJUD;


[ljerror, ljhandle] = ljudObj.OpenLabJack(LabJack.LabJackUD.DEVICE.U3, LabJack.LabJackUD.CONNECTION.USB, '0', true, 0);


ljudObj.eDO(ljhandle,19,1);

ljudObj.eDO(ljhandle,15,1);

Pause(15 );

ljudObj.eDO(ljhandle,19,0);
ljudObj.eDO(ljhandle,15,0);

ljudObj.Close();

In this code I am using the matlab's pause command to set it high for 15secs and then turn it low. My question is, is it possible to to set a Pin high for some seconds and turn it low without using the pause command as in using a built in labjack command?

Any help would be appreciated.

Thank you,

Lalit

LabJack Support
labjack support's picture
The U3 has hardware delay

The U3 has hardware delay functionality. You can use AddRequests and a GoOne call to set the digital I/O to output-high, do a U3 hardware delay and set the digital I/O to output-low in one command/response. The IOType for the hardware delay is LJ_ioPUT_WAIT, which is LabJack.LabJackUD.IO.PUT_WAIT in .NET/MATLAB, and is documented here:

https://labjack.com/support/datasheets/u3/high-level-driver/example-pseu...

A quick example:

%Set CIO3 and EIO7 to output-high
ljudObj.AddRequest(ljhandle, LabJack.LabJackUD.IO.PUT_DIGITAL_BIT, 19, 1, 0, 0);
ljudObj.AddRequest(ljhandle, LabJack.LabJackUD.IO.PUT_DIGITAL_BIT, 15, 1, 0, 0);

%Wait for 1 second. The delay is performed in the U3 hardware, and delay time is in microseconds.
%Valid delay values are 0 to 4194176 microseconds, and resolution is 128 microseconds.
ljudObj.AddRequest(ljhandle, LabJack.LabJackUD.IO.PUT_WAIT, 0, 1000000, 0, 0);

%Set CIO3 and EIO7 to output-low
ljudObj.AddRequest(ljhandle, LabJack.LabJackUD.IO.PUT_DIGITAL_BIT, 19, 0, 0, 0);
ljudObj.AddRequest(ljhandle, LabJack.LabJackUD.IO.PUT_DIGITAL_BIT, 15, 0, 0, 0);

%Perform the operations/requests
ljudObj.GoOne(ljhandle);

%Check results for error. Refer to our MATLAB examples for example code.

Lalit
29.lalit's picture
Works perfectly well!

Works perfectly well!

Thank you.

Lalit
29.lalit's picture
Hi,

Hi,

I am facing another problem with the code. For one of my projects I have to send the above commands and continue executing some other operations in Matlab. When I run the above code, once it reached the GoOne command, it performs the task on labjack but it wait till the operation is done to move to the next line of code.

Is there anyway to send the command and continue executing the next line of code without the program waiting for the operation to be completed?

Thanks,

Lalit

LabJack Support
labjack support's picture
No, GoOne/GoOne waits for a

No, GoOne/GoOne waits for a response from the U3 before it returns, and LJ_ioPUT_WAIT requests add to the response delay. The UD driver doesn't provide functionality to send commands only without waiting for a response.

Usually in these cases when writing an application you use multiple threads that run in parallel. One thread would perform the LabJack operations, and the other thread runs your other code you don't want delayed by the LabJack calls.