Jump to content
  • 0

DOut() DigitalPortType USB-ERB24 issue


TFisherIRA

Question

The section of code is supposed to convert an integer (value) into a byte string that tells the relay board which bits to flip on and flip off at once.

    Private Sub OutputValue(value As Integer)
        Dim ULStat As ErrorInfo

        ' Output the value using DOut(), converting it to UShort
        ' Parameters:
        '   PortNum : The output port
        '   DataValue: The value to be written to the port
        ULStat = DaqBoard.DOut(PortNum, CUShort(value))
        If ULStat.Value <> ErrorInfo.ErrorCode.NoErrors Then
            MessageBox.Show("Error occurred while outputting value: " & ULStat.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
        End If
    End Sub

This code works perfectly for the bitValues 0-7 but does nothing for bitValues 8-11 on my USB-ERB24 relay board. I believe this issue may be related to the DigitalPortType which I currently have set as AuxPort. I believe USB-ERB24 may use FIrstPortA and FirstPortB (?) The program works perfectly when I use the DBitOut() function, but I need to be able to use DOut() as well for the final program. I do not understand the DigitalPortType stuff at all. Are there any suggestions on how I should proceed to get this to work with Dout()?

Link to comment
Share on other sites

2 answers to this question

Recommended Posts

  • 0

I resolved the issue by just using DigitalPortType.FirstPortA for bitValues 0-7 and then using DigitalPortType.FirstPortB for bitValues 8-11 when using the Dout() command.

   Private Sub OutputValue(value As Integer)
        Dim ULStat As ErrorInfo
        Dim PortType As DigitalPortType

        ' Determine the port type based on the state of CheckBox1
        If CheckBox1.Checked Then
            PortType = DigitalPortType.FirstPortB
        Else
            PortType = DigitalPortType.FirstPortA
        End If

        ' Output the value using DOut(), converting it to UShort
        ' Parameters:
        '   PortType : The output port type
        '   DataValue: The value to be written to the port

        ULStat = DaqBoard.DOut(PortType, CUShort(value))
        If ULStat.Value <> ErrorInfo.ErrorCode.NoErrors Then
            MessageBox.Show("Error occurred while outputting value: " & ULStat.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
        End If
    End Sub
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...