PulseOut and DigitalIO | LabJack
 

PulseOut and DigitalIO

5 posts / 0 new
Last post
TaletovicM
TaletovicM's picture
PulseOut and DigitalIO

Hello,

I am trying to use PulseOut and DigitalIO commands with LabJackPython. I am getting the Errorcode 40 (Illegal Input).

Unfortunately, I didn't find any useful examples for this command. Could you please post some Python example to make a pulse of 50Hz?

Thanks in advance!

LabJack Support
labjack support's picture
Someone else can follow up

Someone else can follow up specifically about Python, but here is the driver code that throws that error:

    //Make sure each input is within the proper range
    if ((bitSelect<0) || (bitSelect>255))
    {
        errorcode=ILLEGAL_INPUT_ERROR_LJ;
        *idnum=-1;
        return errorcode;
    }
    if ((numPulses<1) || (numPulses>32767))
    {
        errorcode=ILLEGAL_INPUT_ERROR_LJ;
        *idnum=-1;
        return errorcode;
    }
    if ((timeB1<1) || (timeB1>255))
    {
        errorcode=ILLEGAL_INPUT_ERROR_LJ;
        *idnum=-1;
        return errorcode;
    }
    if ((timeC1<1) || (timeC1>255))
    {
        errorcode=ILLEGAL_INPUT_ERROR_LJ;
        *idnum=-1;
        return errorcode;
    }
    if ((timeB2<1) || (timeB2>255))
    {
        errorcode=ILLEGAL_INPUT_ERROR_LJ;
        *idnum=-1;
        return errorcode;
    }
    if ((timeC2<1) || (timeC2>255))
    {
        errorcode=ILLEGAL_INPUT_ERROR_LJ;
        *idnum=-1;
        return errorcode;
    }

LabJack Support
labjack support's picture
Likely you are passing a

Likely you are passing a parameter value that is invalid. General documentation on these functions can be found here:

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

For Python doc., use the help function on digitalIO, pulseOutCalc and pulseOut U12 class methods.

A quick example:

import u12

dev = u12.U12()

# Set D0 and D1 to output-low, the rest as inputs. Lines for pulses need to be
# outputs.
dev.digitalIO(idNum=-1, demo=0, trisD=3, trisIO=0, stateD=0, stateIO=0,
              updateDigital=1)

# Get B and C values for 50 Hz frequency.
dev.pulseOutCalc(frequency=50)
timeB = res['timeB']
timeC = res['timeC']
# Pulse D0 and D1 500 times, 50 Hz frequency
dev.pulseOut(bitSelect=3, numPulses=500, timeB1=timeB, timeC1=timeC,
             timeB2=timeB, timeC2=timeC, idNum=-1, demo=0, lowFirst=0)

TaletovicM
TaletovicM's picture
Thanks for quick answer!

Thanks for quick answer!

I tried the code but I believe I am still missing the point here.

D0 and D1 stands for AI0 and AI1? What does this trisD parameter really? How to use bitSelect?

I've measured the output on A01 with a scope and the result is in the attachment.

Thank you!

File Attachment: 
LabJack Support
labjack support's picture
The D lines are digital I/O

The D lines are digital I/O available through the DB25 connector, and do not stand for AI lines which are analog inputs and can't perform pulses:

https://labjack.com/support/datasheets/u12/hardware-description/d0-d15

TrisD and bitSelect are documented like so:

TrisD - Directions for D0-D15. 0=Input, 1=Output
bitSelect - Set bits 0 to 7 to enable pulsing on each of D0-D7 (0-255).

With these kind of settings, each bit represents an I/O setting, where bit 0 is a D0 setting, bit 1 is a D1 setting, bit 2 is a D2 setting, etc..

With TrisD, which sets D0-D15 line directions, say you want D0 and D2 as digital outputs, and the rest of the lines as inputs. In binary that looks like b0000000000000101, which is decimal value 5 (20 + 22) that you pass for TrisD.

With bitSelect, which sets what D0-D7 lines to pulse on, setting a line's bit to 1 enables pulsing and 0 is don't pulse. So similar to TrisD, if you want to send the pulses through D0 and D2 only, in binary that is b00000101, decimal value 5.