4.17 - DigitalIO [U12 Datasheet] | LabJack
 
« Close

Datasheets and User Guides

App Notes

Software & Driver

 

4.17 - DigitalIO [U12 Datasheet]

Reads and writes to all 20 digital I/O. The order of execution within the U12 is:

  1. Set D states
  2. Set D directions
  3. Set IO states
  4. Set IO directions
  5. Read D states
  6. Read IO states

Even more detail of the execution order with the approximate time between each step:

  1. Set D7-D0 states
  2. 1 µs
  3. Set D12-D8 states
  4. 2 µs
  5. Set D15-D13 states
  6. 0.5 µs
  7. Set D7-D0 directions
  8. 1 µs
  9. Set D12-D8 directions
  10. 1 µs
  11. Set D15-D13 directions
  12. 16 µs
  13. Set IO states
  14. 16 µs
  15. Set IO directions
  16. 2 µs
  17. Read D7-D0 states
  18. 0.3 µs
  19. Read D12-D8 states
  20. 0.7 µs
  21. Read D15-D13 states
  22. 10 µs
  23. Read IO states

Execution time for this function is 20 milliseconds or less (typically 16 milliseconds in Windows).

Declaration:

long DigitalIO (    long *idnum,
                    long demo,
                    long *trisD,
                    long trisIO,
                    long *stateD,
                    long *stateIO,
                    long updateDigital,
                    long *outputD )

Parameter Description:
Returns: LabJack errorcodes or 0 for no error.
Inputs:

  • *idnum – Local ID, serial number, or -1 for first found.
  • demo – Send 0 for normal operation, >0 for demo mode. Demo mode allows this function to be called without a LabJack.
  • *trisD – Directions for D0-D15. 0=Input, 1=Output.
  • trisIO – Directions for IO0-IO3. 0=Input, 1=Output.
  • *stateD – Output states for D0-D15.
  • *stateIO – Output states for IO0-IO3.
  • updateDigital – If >0, tris and state values will be written. Otherwise, just a read is performed.

Outputs:

  • *idnum – Returns the local ID or –1 if no LabJack is found.
  • *trisD – Returns a read of the direction registers for D0-D15.
  • *stateD – States of D0-D15.
  • *stateIO – States of IO0-IO3.
  • *outputD – Returns a read of the output registers for D0-D15.

12 comments

When using DigitalIOX if you don't set the unused ports of trisIO and trisD to 0 you get an invalid input error (40)

Section 4.0 mentions these types of parameters.  The valid range for trisIO is 0-15, and for trisD is 0-65535.

I am unsure how to change/access the state of multiple IOs using the DigitalIO. I notice that the eDigitalOut has some examples on how to change the state but I wish to use DigitalIO to change multiple Outputs at once.

I wish to change channel 13 to ON and channel 14 to ON at the same time. With eDigitalOut this is done by typing:

d.eDigitalOut(channel=13, state=1, writeD=1) and

d.eDigitalOut(channel=14, state=1, writeD=1)

 

How can I do a similar thing using d.digitalIO ?

I think you are having trouble translating the IO lines that you want to change into a value to pass. It's a bit mask where the bit# corresponds to the IO number. Makes a lot of sense when look at it in binary. This page in the user's guide describes it in more detail: http://labjack.com/support/u12/users-guide/4

I which to read in digital inputs from two reed switches, I want if the switches are in state 0 and 1 or 1 and 0, matlab will send either a 0.0v or 5.0 volt as an analog output, please how do i go about it.

See Figure 2-5 to hook up your switch to IO0.  Test the hardware by running LJlogger.exe and watching the input state of IO0 as the switch opens and closes.

To get started in Matlab, see the Matlab - U12 page.  I suggest you make a loop where you call EDigitalIn and EAnalogOut.

MarcusBK201's picture

Hello,

Hope I can get some help, I am reading input data coming into my LabJack and am getting values back from the AISample function side. I want to be able to read the digital values from the DB25 connector with the DigitalIO function, but from what I am reading it seems that the function reads and returns the data from D0-D15 all in one value? Or would I have to recursively use the DigitalIO function to read each value from each D pin?

LabJack Support's picture

The DigitalIO function will read all digital I/O. We document digital I/O parameters where multiple digital I/O are in one value here:

https://labjack.com/support/datasheets/u12/programming-reference

You can parse out the individual states from the returned stateD/stateIO parameter's value.

If you want to read one state at a time, there is the EDigitalIn function:

https://labjack.com/support/datasheets/u12/programming-reference/edigitalin

When reading multiple digital I/O lines, the one DigitalIO will be more efficient than multiple EDigitalIn calls.

MarcusBK201's picture

I have inputted the DigitalIO function in my code to read input data and show the states of D0-D15 and the output value, but I keep getting a "Access violation at address in the LJACKUW.dll file. Read of address 00000000. Anyone recieved this message before?

LabJack Support's picture

The pointer parameters are pass by reference, so make sure memory is allocated for your variables. Basically something like this should work to read only the directions and states:

long idnum = -1;  //First found
long demo = 0;  //Normal operations
long trisD = 0;
long trisIO = 0;
long stateD = 0;
long stateIO = 0;
long updateDigital = 0;  //Read only
long outputD = 0;
long error = 0;

error = DigitalIO(&idnum, demo, &trisD, trisIO, &stateD, &stateIO, updateDigital, &outputD);

If the above doesn't help and you still get the access violation errors, can you pinpoint it to the DigitalIO function? If it is related to DigitaIO, provide the call you are using and how the variables you passed are declared/created.

MarcusBK201's picture

Thank you for your response, I have the function working correctly now (I didn't declare my variables correctly). When I run the function, I am able to see the stateD value which gives me 8192, but I was hoping to get to read some kind of voltage value. Should I use the Bit to Voltage function for that? Then again, the max binary value that function can deal with is 4092.

Toby's picture

The D lines are digital I/O, so when you read them each bit returns a 0 or 1.  Perhaps you are wanting to read analog inputs?