Home > Software > Programming and SDK > Forum > Anyone been able to set A/D channel range using .NET SDK classes?

Anyone been able to set A/D channel range using .NET SDK classes?

Mar 08, 2014
Paul Mathews wrote
I've been trying to set analog input ranges of DI155 channels using the .NET using members of the dataq.simple namespace.

The connection works fine, using code imitating examples in the help file:

dataqdevices = Discovery.DiscoverAllDevices()
If dataqdevices IsNot Nothing Then
DI155one = dataqdevices(0)
Else
Exit Sub
End If

ConnectedFlag = DI155one.Connect()
'If connect was not successful then exit.
If ConnectedFlag <> ConnectResultCode.Success Then
Exit Sub
End If

To change the analog input range, I've tried 2 different types of VB.NET code:

DI155one.ChannelArray(0).InputRange.Maximum = 5
DI155one.ChannelArray(0).InputRange.Minimum = -5

and
Dim Ch0Range As dataq.Range(Of Double)
Ch0Range = DI155one.ChannelArray(0).InputRange
Ch0Range.Minimum = -25
Ch0Range.Maximum = 25

Both approaches appear to work, in that they both seem to change the values of the properties. However, neither seem to have any effect on the binary readings from the channel. No matter settings I use, the channel acts as if its range is +/- 12.5 volts. For example, for a 5.0V input, the binary reading is always around 820. These values come from method GetInterleavedBinaryData. When I use GetInterleavedScaledData instead, the scaled values DO vary depending on .Maximum and .Minimum, but not as expected. Instead, as you narrow the input range, the scaled values get bigger, but they are only scaled correctly when you use either the default range values or set the range values to +/-12.5V. This looks like a bug to me, but I may be doing something wrong. Any clues will be appreciated.

Reply
2 Answers
Mar 11, 2014
Chuck agent wrote
Can you try the following code?

Dim Ch0Range As new dataq.Range(Of Double) 'creates an instance of "range" object
Ch0Range.Minimum = -25 'assign minimum value to range
Ch0Range.Maximum = 25 'assign maximum value to range
DI155one.ChannelArray(0).InputRange = Ch0Range 'assign range to channel's InputRange property
Mar 11, 2014
Paul Mathews wrote
Thanks. That was the problem: Needed the keyword 'new' to execute the Constructor for the instance.The examples in the Dataq help file have this line near the top:

Dim measurementRange As New dataq.Range(Of Double)

but 'measurementRange never appears again in the examples. So, the examples should be corrected to assign measurementRange to the channel properties, like this:

Incorrect example code:

myDevice.ChannelArray(0).InputRange.Maximum = 10
myDevice.ChannelArray(0).InputRange.Maximum = -10
myDevice.ChannelArray(1).InputRange.Maximum = 10
myDevice.ChannelArray(1).InputRange.Maximum = -10
myDevice.ChannelArray(3).InputRange.Maximum = 10
myDevice.ChannelArray(3).InputRange.Maximum = -10

Corrected example code:

measurementRange .Minimum = -10 'assign minimum value to range
measurementRange .Maximum = 10 'assign maximum value to range
myDevice.ChannelArray(0).InputRange = measurementRange
myDevice.ChannelArray(1).InputRange = measurementRange
myDevice.ChannelArray(3).InputRange = measurementRange

Thanks again.