Home > Software > Programming and SDK > Forum > DI-148/158 Reading Digital Input

DI-148/158 Reading Digital Input

Sep 03, 2015
Michael Crumpler wrote
Hi all,
I'm trying to do what should be fairly simple: read a digital input line (port) from a DI-158 module.

I know there is the "AnaDigAcq" example online, but this plots the digital port state on a graph. I don't need that, I need to be able to determine what the value of that state is (and then do something based on whether the state is "high" or "low").

The dataqxc.chm file lists, among other functions, the "DigitalInput" function. It states: This is an immediate function that reads a word from the digital input port which defines the states of the bits (on or off). The value read from the digital input port depends on the device you use (how many bits are being read). A digital input reading of 255 means that bits 0 through 7 are on.

Also: Syntax variable=DataqSdk1.DigitalInput

I've tried this but ALWAYS receive a value of 0 (zero). I've got a 4 VDC signal applied to all 6 of the digital inputs on my DI-158, yet the function still returns 0 (zero).

The DI-158 reads correctly in the WinDAQ software (it reads analog input signals and also shows the digital inputs), so I know the module is working correctly.

I've been working on this for a few days now with no success. I've searched the "old" forums here at the DATAQ website and found similar issues, but there doesn't appear to be any solutions that I can find. If I can't get a solution soon I'll have to punt and use another vendors product (the boss is tired of me continuing to put my time into something that is not producing results).

Any ideas? I would be very grateful.

Thanks!

Here is a portion of my code (in VB6):
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Private Sub Form_Load()

DataqSdk1.DigitalOutput = &H8000 + 255 'set all digital ports to INPUT

Dim q As Integer

For q = 0 To 31 'for the channels in the dataq 158U module
GainList(q) = 0 'sets up the gain list settings - all channels are set to gain index of 0
DiffList(q) = 0 'sets up the differential settings list - all channels are set as single-ended - same as default
Next

With DataqSdk1
.DeviceID = "COM6 158 38400" 'the DI-158 device is on COM 6 with baud rate 38400
.MaxBurstRate = 50000 'sets MaxBurstRate
.SampleRate = Val(Text1.Text) 'allows user to set attempted SampleRate
.EventPoint = Val(txtPointsToGet.Text) 'sets EventPoint - should try to make it multiple of channel count)
End With

'define the channels in the list (2 analog input and 4 digital input)
ChannelList(0) = 0
ChannelList(1) = 1
ChannelList(2) = -1
ChannelList(3) = -1
ChannelList(4) = -1
ChannelList(5) = -1
ChannelList(6) = -1
ChannelList(7) = -1
DataqSdk1.ADChannelCount = 8
DataqSdk1.ADChannelList (ChannelList)
DataqSdk1.EventPoint = DataqSdk1.ADChannelCount
DataqSdk1.Start

End Sub


Private Sub Timer_Timer()
'periodically read the digital input ports
Dim retvalue As Long
retvalue = DataqSdk1.DigitalInput
......... do something with the returned value................

End Sub
Reply
7 Answers
Sep 03, 2015
Chen agent wrote
DigitalInput is for immediate mode only, I don't think DI-148/158 supports that

You will need to look into the return from GetData, such as variable = v(0, 0), and watch for the change of lower nibble of the high byte
Sep 03, 2015
Michael Crumpler wrote
Hi Chen,
thanks for the reply.

I have already started looking into how data is extracted from the GetData method. I was thinking (hoping) that perhaps the information might be there.

What is "immediate mode"?

Thanks,

Mike
Sep 03, 2015
Ken agent wrote
The DigitalInput property uses "immediate mode", but dataqxc.chm also states:
This property is not available when scanning.
Call Stop before examining DigitalInput.

Unless you have to also scan some analog inputs, you only need to set up DeviceDriver and DeviceID before examining DigitalInput. Since the DI-148/158 powers up with all digital bits configured as inputs, there is no need to call DigitalOutput.

Sep 04, 2015
Michael Crumpler wrote
Ken,
thanks for the reply. Can you explain to me what "immediate mode" is? And what other mode(s) is/are there? When would I want to use immediate mode versus another mode?

Thanks,

Mike
Sep 04, 2015
Ken agent wrote
Immediate mode returns the current values of the digital inputs in the lower four bits when scanning has not started or has been stopped.

If you also need to examine any analog inputs, avoid immediate mode and start a scan with a digital channel in the input list. The digital inputs will be found in the low four bits of the upper byte of data for the digital channel.

Since digital inputs have 4.7K pullup resistors to +5V, floating inputs will read as 1. To read as 0, the inputs should be brought below 1.4V.
Sep 04, 2015
Michael Crumpler wrote
Ken,
thanks for the explanation. It's starting to make more sense.

I've added the digital channels to the scan list (which returns the data in the variant). Now I'm working on looping through the array and extracting the data.

Do you have any info on the structure of the array? I'm guessing that it's multi-dimensional?

Mike
Sep 04, 2015
Ken agent wrote
The array is two-dimensional. In dataqxc.chm under "Reference Materials" see topic "How to Extract Information from a Variant". Although Visual Basic.NET does not directly support the Variant type, see www.ultimaserial.com/vbnettutor.html for details about a workaround that avoids the complexity of marshaling.