Next: tek222.bas Up: Code Listing Previous: purgelog.mak

rti-815.bas


'
'  Author:  Terence Kelly
'  Date:    31 August 1995
'
'  This module contains functions which communicate with the RTI-815
'  analog/digital I/O board.  From the user's manual, pinouts on board
'  are as follows:
'
'       Analog channel 0 = pin 39 (use pin 43 as ground)
'       Analog channel 1 = pin 40 (use pin 44 as ground)
'

'--------------------------------------------------------------------
' Following stolen from VBEX800.BAS (from Analog Devices Corp.):

Declare Sub Initialize Lib "LLWIN.DLL" (erstat%)
Declare Sub Ain815 Lib "LLWIN.DLL" (ByVal Lc%, ByVal Bd%, ByVal chan%, \
  ByVal gain%, erstat%)
Declare Sub Aot815 Lib "LLWIN.DLL" (ByVal Lc%, ByVal Bd%, ByVal chan%, \
  erstat%)
Declare Sub XAin Lib "LLWIN.DLL" (ByVal Lc%, rvalue!, erstat%)
Declare Sub XAot Lib "LLWIN.DLL" (ByVal Lc%, rvalue!, erstat%)

Global Const AotLc0% = 1, AotLc1% = 2

' Digital values added by T. Kelly:
Global Const DinLc% = 3, DotLc% = 4
' Logical channels 5 thru 12 reserved for DotB:
Global Const DotB_baseLc% = 5
' Logical channels 13 thru 20 reserved for DinB:
Global Const DinB_baseLc% = 13
' L.C.'s 21 thru 36 (at least!) reserved for XAin:
Global Const XAin_baseLc% = 21

Global Const board% = 1

' End of code from VBEX800.BAS
'--------------------------------------------------------------------

' Added by T. Kelly, following examples above:
Declare Sub Dot815 Lib "LLWIN.DLL" (ByVal Lc%, ByVal Bd%, erstat%)
Declare Sub Dot Lib "LLWIN.DLL" (ByVal Lc%, ByVal valueout%, erstat%)
Declare Sub Dotb815 Lib "LLWIN.DLL" (ByVal Lc%, ByVal Bd%, ByVal bit%, \
  erstat%)
Declare Sub Dotb Lib "LLWIN.DLL" (ByVal Lc%, ByVal valueout%, erstat%)
Declare Sub Din815 Lib "LLWIN.DLL" (ByVal Lc%, ByVal Bd%, erstat%)
Declare Function Din Lib "LLWIN.DLL" (ByVal Lc%, erstat%) As Integer

Function RTI_Ain (ByVal N$) As String
    '
    '  Assumes that appropriate initialization routines have
    '  been run.
    '
    '  Given an analog input channel number in the range 0-15,
    '  return the voltage on that wire or an error message.
    '

    On Error GoTo RTI_Ain_Error

    R$ = ""

    chan% = Val(N$)
    Call XAin(XAin_baseLc% + chan%, voltage!, Xerr%)
    If Xerr% <> 0 Then
        R$ = "Error " & Str$(Xerr%) & " (board) in function RTI_Ain: "
        R$ = R$ & RTI_ErrorMsg(Xerr%)
    Else
        R$ = "value = " & Format$(voltage!, "#0.000000")
        R$ = R$ & " at " & Format$(Now, "h:m:ss m/d/yy")
    End If

    RTI_Ain = R$

    Exit Function

RTI_Ain_Error:
    R$ = R$ & "Error " & Str$(Err) & " (VB) in RTI_Ain: "
    R$ = R$ & Error$(Err)
    Resume Next

End Function

Function RTI_Aot (ByVal CH$, ByVal V$) As String
    '
    '  Assumes that appropriate initialization routines have been run.
    '
    '  Given strings containing a physical channel and a voltage, use
    '  RTI -815 routines to place given voltage on given channel.
    '  Return string containing error messages.
    '

    On Error GoTo RTI_Aot_Error

    R$ = ""
    
    If CH$ = "0" Then
        Call XAot(AotLc0%, Val(V$), Xerr%)
    ElseIf CH$ = "1" Then
        Call XAot(AotLc1%, Val(V$), Xerr%)
    Else
        RTI_Aot = "Error in routine RTI_Aot: invalid channel argument"
        Exit Function
    End If

    If Xerr% <> 0 Then
        R$ = "Error " & Str$(Xerr%) & " (board) in routine RTI_Aot: "
        R$ = R$ & RTI_ErrorMsg(Xerr%)
    End If

    RTI_Aot = R$

    Exit Function

RTI_Aot_Error:
    R$ = R$ & "Error " & Str$(Err) & " in routine RTI_Aot: "
    R$ = R$ & Error$(Err)
    Resume Next

End Function

Function RTI_Din () As String
    '
    '  Returns a hex value in the range 0-FF read from the digital
    '  inputs of the RTI-815, or error messages.
    '

    On Error GoTo RTI_Din_Error

    R$ = ""

    val_read% = Din(DinLc%, Xerr%)
    If Xerr% <> 0 Then
        R$ = "Error " & Xerr% & " (board) in function RTI_Din: "
        R$ = R$ & RTI_ErrorMsg(Xerr%)
    Else
        R$ = "value = " & Hex$(val_read%) & " at "
        R$ = R$ & Format$(Now, "h:m:ss m/d/yy")
    End If

    RTI_Din = R$

    Exit Function

RTI_Din_Error:
    R$ = R$ & "Error " & Str$(Err) & " (VB) in routine RTI_Din: "
    R$ = R$ & Error$(Err)
    Resume Next
End Function

Function RTI_Dot (ByVal N$) As String
    '
    '  Assumes that appropriate initialization routines have been run.
    '  Given a string containing a decimal or hex number in range
    '  0-255, use RTI-815 to put this value on output wires.  String
    '  returned contains error messages.
    '
    '  Hex numbers must begin with "H" or "h" and be no longer than
    '  two digits long.  Decimal numbers must be in range 0-255.
    '
    
    On Error GoTo RTI_Dot_Error

    R$ = ""

    If Mid$(N$, 1, 1) = "H" Or Mid$(N$, 1, 1) = "h" Then
        Num% = HexToDecimal(Mid$(N$, 2))
    Else
        Num% = Val(N$)
    End If

    If Num% < 0 Or Num% > 255 Then
        R$ = "Error in routine RTI_Dot:  out-of-range parameter"
    Else
        Call Dot(DotLc%, Num%, Xerr%)
        If Xerr% <> 0 Then
            R$ = "Error " & Str$(Xerr%) & " (board) in routine RTI_Dot: "
            R$ = R$ & RTI_ErrorMsg(Xerr%)
        End If
    End If

    RTI_Dot = R$

    Exit Function

RTI_Dot_Error:
    R$ = R$ & "Error " & Str$(Err) & " (VB) in routine RTI_Dot: "
    R$ = R$ & Error$(Err)
    Resume Next
End Function

Function RTI_DotB (ByVal B$, ByVal V$) As String
    '
    '  Assumes that Initialize and DOTB815 have been called.
    '
    '  Given a bit position in the range 0-7 and a value of 0 or 1,
    '  write the given value to the given bit of the digital output.
    '  Return an error message if applicable.
    '
    On Error GoTo RTI_DotB_Error

    R$ = ""
    bit% = Val(B$)
    value% = Val(V$)
    
    If value% < 0 Or value% > 1 Or bit% < 0 Or bit% > 7 Then
        RTI_DotB = "Error in function RTI_DotB: invalid parameter"
        Exit Function
    End If
    
    Call Dotb(DotB_baseLc% + bit%, value%, Xerr%)
    If Xerr% <> 0 Then
        R$ = "Error " & Xerr% & " (board) in function RTI_DotB: "
        R$ = R$ & RTI_ErrorMsg(Xerr%)
    End If

    RTI_DotB = R$

    Exit Function

RTI_DotB_Error:
    R$ = R$ & "Error " & Str$(Err) & " (VB) in routine RTI_DotB: "
    R$ = R$ & Error$(Err)
    Resume Next

End Function

Function RTI_ErrorMsg (ByVal ErrNo%) As String
    '
    '  Given a number corresponding to an Analog Devices RTI-815 error
    '  code, return a string describing the error.  See p. A-1 of the
    '  Software Manual for a listing of these error codes.  I just
    '  typed in all the error messages. I carefully checked all of
    '  this for accuracy, but there's a chance I made a typo or other
    '  error.  When in doubt, rely on the error number and consult
    '  the Software Manual.
    '

    Select Case ErrNo%
    Case 0
        R$ = "No error detected. (For CHECK routine, operation is "
        R$ = R$ & "not complete.)"
    Case 101
        R$ = "Channel number is out of range."
    Case 102
        R$ = "Operation is not valid for board type."
    Case 103
        R$ = "Board number is out of range."
    Case 104
        R$ = "Configuration file not found."
    Case 105
        R$ = "Value argument is too large."
    Case 106
        R$ = "Value argument is too small."
    Case 107
        R$ = "Gain argument is invalid."
    Case 109
        R$ = "Conversion timeout error occurred."
    Case 110
        R$ = "For AIN/XAIN and AING/XAING operations, an analog "
        R$ = R$ & "input operation is in progress.  For COLLECT/XCOLL"
        R$ = R$ & " and SCAN/XSCAN operations, the selected DMA "
        R$ = R$ & "buffer is in use."
    Case 111
        R$ = "DMA is not available."
    Case 112
        R$ = "Scan or collect operation in progress is not for this"
        R$ = R$ & " logical channel."
    Case 114
        R$ = "Range argument is invalid."
    Case 115
        R$ = "Mult argument is invalid."
    Case 116
        R$ = "Count argument is invalid."
    Case 117
        R$ = "Terminal count was reached (not an error)."
    Case 118
        R$ = "Overrun error was detected. (Mult x range is too small.)"
    Case 119
        R$ = "Trigger source is invalid."
    Case 120
        R$ = "Digital channel (bit #) value is out of range (must be"
        R$ = R$ & " (0-7)."
    Case 121
        R$ = "Value argument is out of range (must be 1 or 0)."
    Case 122
        R$ = "Gate argument is out of specified range."
    Case 123
        R$ = "Gate channel is already in operation."
    Case 124
        R$ = "Specified channel is in operation."
    Case 125
        R$ = "Specified channel has not been initialized."
    Case 127
        R$ = "Specified channel is not presently in operation."
    Case 128
        R$ = "Operation is not finished."
    Case 129
        R$ = "Counter overflow was detected."
    Case 130
        R$ = "Edge argument is out of range."
    Case 131
        R$ = "Specified mode is invalid."
    Case 132
        R$ = "Oncycle argument is out of range."
    Case 133
        R$ = "Offcycle argument is out of range."
    Case 134
        R$ = "Period argument is out of range."
    Case 135
        R$ = "Counter value read is too large for integer variable "
        R$ = R$ & "(>32767)."
    Case 136
        R$ = "Timeout occurred waiting for gate channel to go high."
    Case 137
        R$ = "Operation can not be performed on this channel."
    Case 138
        R$ = "Digital I/O port number is out of range."
    Case 139
        R$ = "Error occurred reading configuration file."
    Case 140
        R$ = "AOT overrun error occurred."
    Case 141
        R$ = "DMA buffer was not allocated. (Use MLTDLOAD.)"
    Case 142
        R$ = "Library for the board was not included in the link "
        R$ = R$ & "statement."
    Case 143
        R$ = "Logical channel number is either too big or invalid."
    Case 144
        R$ = "Logical channel is in use."
    Case 145
        R$ = "Channel sequence list is full."
    Case 146
        R$ = "In Turbo Pascal, drivers were not loaded. (Run PASL800"
        R$ = R$ & " or USERPASL.)"
    Case 158
        R$ = "The logical channel buffer is full."
    Case 159
        R$ = "The logical channel buffer contains more than 40K bytes."
    Case 164
        R$ = "The SETOUT table is full."
    Case 165
        R$ = "The SETOUT table is invalid."
    Case 166
        R$ = "The board specified cannot be used as an ACTIO "
        R$ = R$ & "interrupt source."
    Case 172
        R$ = "The values you were attempting to convert were returned"
        R$ = R$ & " by an unsupported routine."
    Case 175
        R$ = "An invalid modtype was assigned to the channel."
    Case 176
        R$ = "Floating point positive overflow."
    Case 177
        R$ = "Floating point negative overflow."
    Case 184
        R$ = "The modtype for the CJC channel is not set."
    Case 192
        R$ = "DMA is not configured for this board."
    Case Else
        R$ = "Not a valid Analog Devices RTI-815 error number, "
        R$ = R$ & "according to T. Kelly's error message function."
        R$ = R$ & "  Refer to the Software Manual to be sure."
    End Select

    caveat$ = "  (Check this translation of error number in manual!)"
    RTI_ErrorMsg = R$ & caveat$

End Function

Function RTI_Initialize () As String
    '
    '  Initialize RTI-815 for digital and analog I/O.  Return string
    '  of error messages.
    '

    R$ = ""

    Call Initialize(Xerr%)
    If (Xerr% <> 0) Then
        R$ = "RTI_Initialize Error " & Str$(Xerr%) & " (board): "
        RTI_Initialize = R$ & RTI_ErrorMsg(Xerr%)
        Exit Function
    End If

    Call Dot815(DotLc%, board%, Xerr%)
    If (Xerr% <> 0) Then
        R$ = R$ & "Dot815 Setup error " & Str$(Xerr%) & ": "
        R$ = R$ & RTI_ErrorMsg(Xerr%) & CRLF()
    End If

    Call Aot815(AotLc0%, board%, 0, Xerr%)
    If (Xerr% <> 0) Then
        R$ = R$ & "Aot815 Setup error LC " & Str$(AotLc0%) & ": "
        R$ = R$ & Str$(Xerr%) & ": " & RTI_ErrorMsg(Xerr%) & CRLF()
    End If

    Call Aot815(AotLc1%, board%, 1, Xerr%)
    If (Xerr% <> 0) Then
        R$ = R$ & "Aot815 Setup error LC " & Str$(AotLc1%) & ": "
        R$ = R$ & Str$(Xerr%) & ": " & RTI_ErrorMsg(Xerr%) & CRLF()
    End If

    For I% = 0 To 7
        Call Dotb815(DotB_baseLc% + I%, board%, I%, Xerr%)
        If (Xerr% <> 0) Then
            R$ = R$ & "Dotb815 Setup error at bit " & Str$(I%) & ": "
            R$ = R$ & Str$(Xerr%) & ": " & RTI_ErrorMsg(Xerr%) & CRLF()
        End If
    Next

    Call Din815(DinLc%, board%, Xerr%)
    If (Xerr% <> 0) Then
        R$ = R$ & "Din815 error " & Str$(Xerr%) & ": "
        R$ = R$ & RTI_ErrorMsg(Xerr%) & CRLF()
    End If

    For I% = 0 To 15
        Call Ain815(XAin_baseLc% + I%, board%, I%, 1, Xerr%)
        If (Xerr% <> 0) Then
            R$ = R$ & "Ain815 Setup error at channel " & Str$(I%)
            R$ = R$ & ": " & Str$(Xerr%) & ": " & RTI_ErrorMsg(Xerr%)
            R$ = R$ & CRLF()
        End If
    Next

    RTI_Initialize = R$

End Function


tpkelly@cs.CS.Princeton.EDU
Thu Sep 14 02:35:48 EDT 1995