U3 on VBA/Excel | LabJack
 

U3 on VBA/Excel

8 posts / 0 new
Last post
dgholstein
dgholstein's picture
U3 on VBA/Excel

I've created a VBA class for Excel, cLabJack.cls (attached) and most of it works. Problem is I can't read the digital inputs:

            lngErrorcode = eGet(lngHandle, LJ_ioGET_DIGITAL_PORT, i, pFIO(i).Value, 0)

File Attachment: 
LabJack Support
labjack support's picture
With that call you are not

With that call you are not reading anything. When using the IOType LJ_ioGET_DIGITAL_PORT, the Channel parameter specifies the starting digital input line and the x1 parameter specifies how many bits (digital lines) to read. You have those set to i and 0. Change your last parameter from 0 to how many bits you want to read. Judging from your code, it looks like you want it set to 1. Alternatively, if you are only reading one digital I/O line you can use the IOType LJ_ioGET_DIGITAL_BIT instead and pass 0 for x1 (it is not used).

For UD library digital I/O documentation, look here:

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

dgholstein
dgholstein's picture
Thanks, but neither of those

Thanks, but neither of those work.

BTW: I had already been using LJ_ioGET_DIGITAL_BIT and switching to PORT was just a flailing attempt on my part.

BBTW: The documentation you link to has no reference to "eGet"

LabJack Support
labjack support's picture
For testing, simplify your

For testing, simplify your code to something similar to this and check that the returned state reading looks correct:

lngErrorcode = eGet(lngHandle, LJ_ioGET_DIGITAL_BIT, 4, state, 0)

Confirm that if you have FIO4 connected to GND the state reads 0, and if FIO4 is has no connection it reads 1.

The documentation I pointed to was digital I/O documentation. eGet is basically AddRequest/Go/GetRequest in one call and shares the same parameters. Functions are documented here:

https://labjack.com/support/datasheets/u3/high-level-driver/function-ref...

If that doesn't help, please describe the error you are getting or how things are not working.

 

dgholstein
dgholstein's picture
That seems to have done the

That seems to have done the trick - kinda.

I had created a class for the DIO with members .Type and .Value (VBA double). When I pass .Value in the DLL call, it doesn't work, when I use a local variable and assign it to .Value, it works.

Maybe it's a bug in VBA related to ByRef arguments of class members... I suppose I can try using OpenOffice.

dgholstein
dgholstein's picture
I read through the

I read through the documentation several times, how do I read the configuration? How do I read if a port is AIN, DI or DO?

dgholstein
dgholstein's picture
Actually, I think I have the

Actually, I think I have the answer, namely:


            lngErrorcode = eGet(lngHandle, LJ_ioGET_DIGITAL_BIT_DIR, i, state, 0)

But what I don't understand is the "U3 Test Panel" shows FIO6/7 as inputs, the above code shows them as output (they're open circuit)

LabJack Support
labjack support's picture
When the U3 test panel opens,

When the U3 test panel opens, it changes FIO4-7, EIO and CIO to digital inputs. In your code I see a "Property Let FIO" that sets lines to digital outputs. I'm guessing that is being called before your LJ_ioGET_DIGITAL_BIT_DIR call to make the direction output.

It looks like you figured out reading the direction. LJ_ioGET_DIGITAL_PORT_DIR will also read one or more digital directions.

To check if a line is a analog input (1 = analog input, 0 = digital I/O), use the IOTypes LJ_ioGET_ANALOG_ENABLE_BIT or LJ_ioGET_ANALOG_ENABLE_PORT:

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