INTRODUCTION December 7, 1997 Railroaders, If you're writing code to tie your EasyDCC Command Station to your PC, you might find the following code useful. I've spent several hours finding the right combinations that make the communications link work. I used Lee Rayburn's Basic code as a starting point. The Code was extracted from the communicatons module of my Software Command Station (SOCS) which was written using Microsoft's Visual Basic 5.0. If you're interested in getting a copy of SOCS, send E-mail to me at maresk@swbell.net. Model Railroading is FUN, Mark Eskew '************************************************************************** Public Sub AddLocoGroupNormal(MyGroupString As String, MyDecoder As String) ' Sends "GN" command to CS with MyGroupString appended ' ASSUMPTION: Only one group sent at a time! ' *************************************************************** ' * Programmed by Mark F. Eskew in Microsoft Visual Basic 5.0 * ' * To contact, send E-mail to maresk@swbell.net * ' *************************************************************** Dim MyMsg As String, MyHexGroup As String Dim MyCSString As String ' Define hex characters MyHexGroup = Hex(Val(MyGroupString)) ' Convert letters to hex) If Len(MyHexGroup) = 1 Then ' Make sure 2 characters are sent to CS MyHexGroup = "0" & MyHexGroup End If MyHexDecoder = Hex(Val(MyDecoder)) If Len(MyHexDecoder) = 1 Then ' Make sure 2 characters are sent to CS MyHexDecoder = "0" & MyHexDecoder End If mdiSOCS.MSComm1.PortOpen = True ' Open the COM port mdiSOCS.MSComm1.InBufferCount = 0 ' Empty the input buffer ' Send GN command & group # to CS MyCSString = "GN" & MyHexGroup & MyHexDecoder mdiSOCS.MSComm1.Output = MyCSString & Chr$(13) WaitPort (2) MyString = mdiSOCS.MSComm1.Input ' Return string 'MyMsg = "Sent hex " & MyHexGroup & " to CS. The CS returned: " & MyString If MyString = "O" & Chr$(13) Then ' ' The following deleted to avoid showing a success for each loco ' MyMsg = "Consist " & MyGroupString & " was updated at the Command Station." ' MsgBox MyMsg, vbInformation, "Consist Comm Info" Else MyMsg = "Consist " & MyGroupString & " was NOT updated. Check communication link." MsgBox MyMsg, vbCritical, "Consist Comm Info" End If mdiSOCS.MSComm1.PortOpen = False ' Close the COM port End Sub Sub Dequeue() ' Sends the dequeue command (Dxx xx) to the CS ' *************************************************************** ' * Programmed by Mark F. Eskew in Microsoft Visual Basic 5.0 * ' * To contact, send E-mail to maresk@swbell.net * ' *************************************************************** Dim MyAddress As String Dim MyMsg As String, MyMsg1 As String, MyString As String ' Get user's input MyAddress = InputBox("Enter the 4-digit hex address to dequeue", "Dequeue") If MyAddress = "" Then Exit Sub ' Exit if user cancels MyAddress = UCase(MyAddress) ' Convert letters to upper case Screen.MousePointer = vbHourglass ' Set the cursor to hourglass mdiSOCS.MSComm1.PortOpen = True ' Open the COM port mdiSOCS.MSComm1.InBufferCount = 0 ' Empty the input buffer ' Send dequeue command, D, and hex address to CS mdiSOCS.MSComm1.Output = "D" & MyAddress & Chr$(13) WaitPort (2) MyString = mdiSOCS.MSComm1.Input ' Return string is O ' Check for CS return character of "O" If Left(MyString, 1) <> "O" Then MyMsg = "Illegal hexadecimal input. Unable to dequeue the packet. " MsgBox MyMsg & Chr$(13) & "'" & MyAddress & "'", vbCritical, "Dequeue" GoTo ExitDequeue End If ' Display address and CS return character MyMsg = "Dequeue command sent for address '" MyMsg1 = "The Command Station returned: '" MsgBox MyMsg & MyAddress & "'. " & Chr$(13) & MyMsg1 & "'" & MyString & "'", _ vbInformation, "Dequeue" ExitDequeue: mdiSOCS.MSComm1.PortOpen = False ' Close the COM port Screen.MousePointer = vbDefault ' Set the cursor to default End Sub Public Sub AddLocoGroupReverse(MyGroupString As String, MyDecoder As String) ' Sends "GR" command to CS with MyGroupString appended ' ASSUMPTION: Only one group sent at a time! ' *************************************************************** ' * Programmed by Mark F. Eskew in Microsoft Visual Basic 5.0 * ' * To contact, send E-mail to maresk@swbell.net * ' *************************************************************** Dim MyMsg As String, MyHexGroup As String Dim MyCSString As String ' Define hex characters MyHexGroup = Hex(Val(MyGroupString)) ' Convert letters to hex) If Len(MyHexGroup) = 1 Then ' Make sure 2 characters are sent to CS MyHexGroup = "0" & MyHexGroup End If MyHexDecoder = Hex(Val(MyDecoder)) If Len(MyHexDecoder) = 1 Then ' Make sure 2 characters are sent to CS MyHexDecoder = "0" & MyHexDecoder End If mdiSOCS.MSComm1.PortOpen = True ' Open the COM port mdiSOCS.MSComm1.InBufferCount = 0 ' Empty the input buffer ' Send GR command & group # to CS MyCSString = "GR" & MyHexGroup & MyHexDecoder mdiSOCS.MSComm1.Output = MyCSString & Chr$(13) WaitPort (2) MyString = mdiSOCS.MSComm1.Input ' Return string 'MyMsg = "Sent hex " & MyHexGroup & " to CS. The CS returned: " & MyString If MyString = "O" & Chr$(13) Then ' ' The following deleted to avoid showing a success for each loco ' MyMsg = "Consist " & MyGroupString & " was updated at the Command Station." ' MsgBox MyMsg, vbInformation, "Consist Comm Info" Else MyMsg = "Consist " & MyGroupString & " was NOT updated. Check communication link." MsgBox MyMsg, vbCritical, "Consist Comm Info" End If mdiSOCS.MSComm1.PortOpen = False ' Close the COM port End Sub Public Function ReadGroupInformation(MyGroup As String) As String ' Calls DisplayGroupInfo(MyGroup) which uses the "GD XX" command where XX is ' the hex equivalent of MyGroup. ' *************************************************************** ' * Programmed by Mark F. Eskew in Microsoft Visual Basic 5.0 * ' * To contact, send E-mail to maresk@swbell.net * ' *************************************************************** Dim MyString As String, MyConsistString As String Dim MyMsg As String ', MyMsg1 As String, MyMsg2 As String Dim MyTempString As String Dim MyLoco As String Dim MyCounter As Integer Screen.MousePointer = vbHourglass ' Set the cursor to hourglass MyHexGroup = Hex(MyGroup) ' Convert letters to hex If Len(MyHexGroup) = 1 Then ' Make sure 2 characters are sent to CS MyHexGroup = "0" & MyHexGroup End If mdiSOCS.MSComm1.PortOpen = True ' Open the COM port mdiSOCS.MSComm1.InBufferCount = 0 ' Empty the input buffer ' Send Display Group command, GD, and hex address to CS mdiSOCS.MSComm1.Output = "GD" & MyHexGroup & Chr$(13) WaitPort (100) ' At least 8 chars will be returned MyString = mdiSOCS.MSComm1.Input ' The string ends with O ' Show the consist If MyString = "R" & Chr$(13) Then MyMsg = "An illegal consist number was requested from the CS." MsgBox MyMsg, vbCritical, "Consist Information" GoTo ExitThisSub Else ' The consist string was successfully returned from the CS MyStringLen = Len(MyString) MyConsistString = Mid(MyString, 4, MyStringLen - 6) ' Get decoder #'s If MyConsistString = "00" Then ' Check for existing consist information. MyMsg = "The requested consist does not exist." MsgBox MyMsg, vbCritical, "Consist Information" GoTo ExitThisSub Else MyTempString = "" For MyCounter = 1 To Len(MyConsistString) Step 2 ' Note the clever hex-to-decimal conversion below MyTempString = MyTempString & _ Str(Val("&H" & Mid(MyConsistString, MyCounter, 2))) & "+" Next MyCounter MyConsistString = Left(MyTempString, Len(MyTempString) - 1) MyMsg = "Consist " & MyGroup & ": The loco addresses were " ' MyMsg1 = "Press [Yes] to update the PC's consist information." & Chr$(13) ' MyMsg2 = "Press [No] to continue." ' MyResponse returned as vbYes or vbNo MsgBox MyMsg & MyConsistString, vbInformation, "Consist Information" ' MyResponse = MsgBox(MyMsg & MyConsistString & Chr$(13) & MyMsg1 & MyMsg2, vbYesNo, "Consist Information") mdiSOCS.MSComm1.PortOpen = False ' Close the COM port ' New code to update PC data with CS data (decided to handle w/ syncrhronze ' in Utilities folder) ' If MyResponse = vbYes Then ' Update PC's consist information ' For MyCounter = 1 To Len(MyConsistString) Step 3 ' 3 since '+' inserted above ' MyTempString = Mid(MyConsistString, MyCounter, 2) ' If Len(MyGroup) = 1 Then MyGroup = "0" & MyGroup ' MyTempString = LTrim(MyTempString) ' If Len(MyTempString) = 1 Then MyTempString = "0" & MyTempString ' MyAddressString = MyGroup & ":" & MyTempString ' MyLocoAddr = LTrim(Str(Val(MyTempString))) '' Call ReadLoco(False) ' Read data for each loco in consist ' Call UpdatePCConsist(MyGroup, MyLocoAddr) ' Next MyCounter ' MsgBox "The PC was updated with information from the CS.", vbInformation, _ ' "Consist Information" ' End If End If End If ExitThisSub: Screen.MousePointer = vbDefault ' Set the cursor to default ' mdiSOCS.MSComm1.PortOpen = False ' Close the COM port End Function Public Sub KillConsist(MyGroup As String) ' Sends "O" command to CS with MyGroupString appended ' Deletes the consist, MyGroup, from the CS ' IMPORTANT NOTE, 10/30/97, per Lee Rayburn: This function doesn't work. ' The CS disables clocks on execution of this command; locos go to full on!! ' Write CVP for a new E-Prom that corrects this problem. ' *************************************************************** ' * Programmed by Mark F. Eskew in Microsoft Visual Basic 5.0 * ' * To contact, send E-mail to maresk@swbell.net * ' *************************************************************** Dim MyString As String Dim MyMsg As String Screen.MousePointer = vbHourglass MyHexGroup = Hex(MyGroup) ' Convert letters to hex If Len(MyHexGroup) = 1 Then ' Make sure 2 characters are sent to CS MyHexGroup = "0" & MyHexGroup End If mdiSOCS.MSComm1.PortOpen = True ' Open the COM port mdiSOCS.MSComm1.InBufferCount = 0 ' Empty the input buffer ' mdiSOCS.MSComm1.Output = "GK" & MyHexGroup & Chr$(13) ' Send "GK" (Group Kill) WaitPort (2) MyString = mdiSOCS.MSComm1.Input ' Return string Screen.MousePointer = vbDefault MyMsg = "Consist " & MyConsist & " was successfully deleted." MsgBox MyMsg, vbInformation, "Kill Consist" mdiSOCS.MSComm1.PortOpen = False ' Close the COM port End Sub Sub EnableMain() ' Causes all clocks to MainTrack to be resumed. ' Sends "E" command to CS. ' *************************************************************** ' * Programmed by Mark F. Eskew in Microsoft Visual Basic 5.0 * ' * To contact, send E-mail to maresk@swbell.net * ' *************************************************************** Dim MyString As String Dim MyMsg As String mdiSOCS.MSComm1.PortOpen = True ' Open the COM port mdiSOCS.MSComm1.InBufferCount = 0 ' Empty the input buffer ' Stop clocks to Main Track mdiSOCS.MSComm1.Output = "E" & Chr$(13) ' Send "E" (resumes clocks to Main Track) WaitPort (2) MyString = mdiSOCS.MSComm1.Input ' Return string MyMsg = "All clocks to Main Track resumed. The Command Station returned: " MsgBox MyMsg & Chr$(13) & "'" & MyString & "'", vbInformation, "Enable Main" mdiSOCS.MSComm1.PortOpen = False ' Close the COM port End Sub Sub ExitProgrammingMode() ' Put the CS into operation mode ' Sends "X" command to CS. ' *************************************************************** ' * Programmed by Mark F. Eskew in Microsoft Visual Basic 5.0 * ' * To contact, send E-mail to maresk@swbell.net * ' *************************************************************** Dim MyString As String ' Dim MyMsg As String mdiSOCS.MSComm1.PortOpen = True ' Open the COM port mdiSOCS.MSComm1.InBufferCount = 0 ' Empty the input buffer ' Put the CS into Operation Mode mdiSOCS.MSComm1.Output = "X" & Chr$(13) ' Send "X" (enter operation mode) WaitPort (2) MyString = mdiSOCS.MSComm1.Input ' Return string ' MyMsg = "Check the CS display for 'Normal Operation'. The return string was: " ' MsgBox MyMsg & Chr$(13) & "'" & MyString & "'", vbInformation, "Exit Programming Mode" mdiSOCS.MSComm1.PortOpen = False ' Close the COM port End Sub Sub KillMain() ' Causes all clocks to Main Track to stop ' Sends "K" command to CS. ' *************************************************************** ' * Programmed by Mark F. Eskew in Microsoft Visual Basic 5.0 * ' * To contact, send E-mail to maresk@swbell.net * ' *************************************************************** Dim MyString As String Dim MyMsg As String mdiSOCS.MSComm1.PortOpen = True ' Open the COM port mdiSOCS.MSComm1.InBufferCount = 0 ' Empty the input buffer ' Stop clocks to Main Track mdiSOCS.MSComm1.Output = "K" & Chr$(13) ' Send "K" (stop clocks to Main Track) WaitPort (2) MyString = mdiSOCS.MSComm1.Input ' Return string MyMsg = "All clocks to the Main Track stopped. The Command Station returned: " MsgBox MyMsg & Chr$(13) & "'" & MyString & "'", vbInformation, "Kill Main" mdiSOCS.MSComm1.PortOpen = False ' Close the COM port End Sub Sub ProgrammingMode() ' Put CS in programming mode ' Sends "M" command to CS. ' *************************************************************** ' * Programmed by Mark F. Eskew in Microsoft Visual Basic 5.0 * ' * To contact, send E-mail to maresk@swbell.net * ' *************************************************************** Dim MyString As String ' Dim MyMsg As String mdiSOCS.MSComm1.PortOpen = True ' Open the COM port mdiSOCS.MSComm1.InBufferCount = 0 ' Empty the input buffer ' Put the CS into Programming Mode mdiSOCS.MSComm1.Output = "M" & Chr$(13) ' Send "M" (enter programming mode) WaitPort (2) MyString = mdiSOCS.MSComm1.Input ' Return string ' MyMsg = "Check the CS display for 'Controlled by Computer'. The return string was: " ' MsgBox MyMsg & Chr$(13) & "'" & MyString & "'", vbInformation, "Programming Mode" mdiSOCS.MSComm1.PortOpen = False ' Close the COM port End Sub Public Sub ReadCV() ' Reads configuration variable "MyCV" using the "R" command ' Sub is UNCHECKED. See following note. ' NOTE: This Sub needs a programming track & loco to check out. If not, it takes 1.5 ' minutes to return the "--" characters indicating no CV was found (Lee R., 9/9/97). ' So, be sure your programming track is activatied! ' *************************************************************** ' * Programmed by Mark F. Eskew in Microsoft Visual Basic 5.0 * ' * To contact, send E-mail to maresk@swbell.net * ' *************************************************************** Dim MyCV As String, MyString As String, HexMyCV As String, MySendString As String Dim LenMyCV As Integer, ValMyCV As Integer Dim MyCheck As Boolean Screen.MousePointer = vbHourglass ' Set cursor to hourglass ' Read the CV & check validity On Error GoTo MyInputError Do MyCV = InputBox("Enter CV") LenMyCV = Len(MyCV) If LenMyCV = 0 Then Screen.MousePointer = vbDefault Exit Sub ' Exit if [Cancel] pressed End If ValMyCV = Val(MyCV) HexMyCV = Hex(MyCV) If (ValMyCV < 0) Or (MyCV > 1025) Then MyInputError: MsgBox "Illegal Configuration Variable '" & MyCV & "' Entered.", _ vbCritical, "Error (ReadCV)" MyCheck = False Else MyCheck = True On Error GoTo MyReadCVError End If Loop Until MyCheck = True ' Legal CV was read; now define the string to send to the CS. LenMyHexCV = Len(HexMyCV) Select Case LenMyHexCV Case 1 ' One character entered MySendString = "R00" & HexMyCV Case 2 ' Two charaters entered MySendString = "R0" & HexMyCV Case 3 ' Three charaters entered MySendString = "R" & HexMyCV Case Else End Select Screen.MousePointer = vbDefault ' TEMPORARY ' Open the port, & go into programming mode mdiSOCS.MSComm1.PortOpen = True ' Open the COM port mdiSOCS.MSComm1.InBufferCount = 0 ' Empty the input buffer mdiSOCS.MSComm1.Output = "M" & Chr$(13) ' Send "M" (enter programming mode) WaitPort (2) MyString = mdiSOCS.MSComm1.Input ' Return string: "P" mdiSOCS.MSComm1.Output = MySendString & Chr$(13) WaitPort (10) MyString = mdiSOCS.MSComm1.Input ' Returns CVxxxyyP MsgBox "CS sent '" & MyString & "'to PC", vbInformation, "ReadCV" ' Return to operation mode & close the comm port mdiSOCS.MSComm1.Output = "X" & Chr$(13) ' Send "X" (enter operation mode) WaitPort (2) MyString = mdiSOCS.MSComm1.Input ' Return string MyReadCVError: If mdiSOCS.MSComm1.PortOpen = True Then mdiSOCS.MSComm1.PortOpen = False ' Close the COM port End If Screen.MousePointer = vbDefault ' Return cursor to default End Sub Public Function ReadLocoInformation(MyAddress As String) As String ' Read speed, direction, speed steps, functions for decoder address from CS. ' *************************************************************** ' * Programmed by Mark F. Eskew in Microsoft Visual Basic 5.0 * ' * To contact, send E-mail to maresk@swbell.net * ' *************************************************************** Dim MyString As String If MyAddress = "" Then Exit Function Screen.MousePointer = vbHourglass ' Set the cursor to hourglass MyHexAddress = Hex(MyAddress) ' Convert letters to hex If Len(MyHexAddress) = 1 Then ' Make sure 2 characters are sent to CS MyHexAddress = "0" & MyHexAddress End If If Len(MyAddress) = 1 Then ' Make sure 2 characters are sent to CS MyAddress = "0" & MyAddress End If mdiSOCS.MSComm1.PortOpen = True ' Open the COM port mdiSOCS.MSComm1.InBufferCount = 0 ' Empty the input buffer ' Send Read Loco Information command, L, and hex address to CS mdiSOCS.MSComm1.Output = "L" & MyHexAddress & Chr$(13) WaitPort (10) MyString = mdiSOCS.MSComm1.Input ' Return string is O ' Check for CS return character of "O" If Left(MyString, 1) <> "L" Then MyMsg = "An illegal address, " & MyAddress & ", was entered. " MsgBox MyMsg, vbCritical, "Read Loco Information" ReadLocoInformation = "Error" GoTo ExitReadLocoInformation Else ReadLocoInformation = MyString End If ExitReadLocoInformation: Screen.MousePointer = vbDefault ' Set the cursor to hourglass mdiSOCS.MSComm1.PortOpen = False ' Open the COM port End Function Sub SetLocoCharacteristics(My_xxByte, My_ssByte, My_yyByte, My_zzByte) ' Writes loco characteristics to CS. ' See "Read Loco Information" writeup in Lee's doc for def's of xx,ss,yy,zz ' *************************************************************** ' * Programmed by Mark F. Eskew in Microsoft Visual Basic 5.0 * ' * To contact, send E-mail to maresk@swbell.net * ' *************************************************************** Screen.MousePointer = vbHourglass ' Set the cursor to hourglass mdiSOCS.MSComm1.PortOpen = True ' Open the COM port mdiSOCS.MSComm1.InBufferCount = 0 ' Empty the input buffer ' Send Set Loco Characteristics command, C, and hex address to CS MyOutput$ = "C" & My_xxByte & My_yyByte & My_zzByte & Chr$(13) mdiSOCS.MSComm1.Output = MyOutput$ WaitPort (2) MyString = mdiSOCS.MSComm1.Input ' Return string is O mdiSOCS.MSComm1.InBufferCount = 0 ' Empty the input buffer ' Check for CS return character of "O" If Left(MyString, 1) <> "O" Then MyMsg = "An illegal address, " & My_xxByte & ", was entered. " MsgBox MyMsg, vbCritical, "Set Loco Characteristics" GoTo ExitSetLocoCharacteristics Else MyMsg = "The loco characteristics were updated." MsgBox MyMsg, vbInformation, "Set Loco Characteristics" End If ExitSetLocoCharacteristics: mdiSOCS.MSComm1.PortOpen = False ' Close the COM port Screen.MousePointer = vbDefault ' Set the cursor to default End Sub Public Sub SubtractLocoGroup() ' Removes loco from group, MyConsist. Loco's decoder is MyLocoAddr. ' Called from imgTrash_DragDrop in frmConsists1 ' Globals: MyLocoAddr, MyConsist ' *************************************************************** ' * Programmed by Mark F. Eskew in Microsoft Visual Basic 5.0 * ' * To contact, send E-mail to maresk@swbell.net * ' *************************************************************** Dim MyMsg As String, MyHexGroup As String Dim MyDecoder As String, MyCSString As String Call GetLocoData(MyLocoAddr, MyConsist, MyDecoder) ' MyDecoder = GetLocoDecoder(MyLocoAddr) ' MsgBox "Consist = " & MyConsist & " Decoder = " & MyDecoder, vbInformation, "Here I is" If (Len(MyConsist) = 0) Or (Len(MyLocoAddr) = 0) Then MsgBox "Bad data sent to 'SubtractLocoGroup'", vbCritical, "ModuleComm" Exit Sub End If ' Define hex characters MyHexConsist = Hex(Val(MyConsist)) ' Convert letters to hex) If Len(MyHexConsist) = 1 Then ' Make sure 2 characters are sent to CS MyHexConsist = "0" & MyHexConsist End If ' MyHexDecoder = Hex(Val(MyLocoAddr)) MyHexDecoder = Hex(Val(MyDecoder)) If Len(MyHexDecoder) = 1 Then ' Make sure 2 characters are sent to CS MyHexDecoder = "0" & MyHexDecoder End If ' Exit Sub mdiSOCS.MSComm1.PortOpen = True ' Open the COM port mdiSOCS.MSComm1.InBufferCount = 0 ' Empty the input buffer ' Send GS command & group # to CS MyCSString = "GS" & MyHexConsist & MyHexDecoder mdiSOCS.MSComm1.Output = MyCSString & Chr$(13) WaitPort (2) MyString = mdiSOCS.MSComm1.Input ' Return string MyMsg = "Sent hex " & MyHexConsist & " to CS. The CS returned: " & MyString MsgBox MyMsg, vbInformation, "Test" If MyString = "O" & Chr$(13) Then ' The following deleted to avoid showing a success for each loco MyMsg = "Consist " & MyConsist & " was updated at the Command Station." MsgBox MyMsg, vbInformation, "Consist Comm Info" Else MyMsg = "Consist " & MyConsist & " did not exist at the Command Station." MsgBox MyMsg, vbInformation, "Consist Comm Info" End If mdiSOCS.MSComm1.PortOpen = False ' Close the COM port End Sub Sub TestPort() ' Two phase port test ' 1. Put CS in programming mode ' 2. Put the CS back into operation mode ' *************************************************************** ' * Programmed by Mark F. Eskew in Microsoft Visual Basic 5.0 * ' * To contact, send E-mail to maresk@swbell.net * ' *************************************************************** Dim MyString As String, MyMsg As String Screen.MousePointer = vbHourglass ' Set the cursor to hourglass mdiSOCS.MSComm1.PortOpen = True ' Open the COM port ' Put the CS into Programming Mode mdiSOCS.MSComm1.InBufferCount = 0 ' Empty the input buffer mdiSOCS.MSComm1.Output = "M" & Chr$(13) ' Send "M" (enter programming mode) WaitPort (2) MyString = mdiSOCS.MSComm1.Input ' Return string If Right(MyString, 2) = "P" & Chr$(13) Then MyMsg = "Check the CS display for 'Controlled by Computer'. The return string was: " MsgBox MyMsg & Chr$(13) & "'" & MyString & "'", vbInformation, "TestPort" Else MyMsg = "The communication link is not working." MsgBox MyMsg, vbCritical, "TestPort" mdiSOCS.MSComm1.PortOpen = False ' Close the COM port Screen.MousePointer = vbDefault ' Set the cursor to default Exit Sub End If ' Put the CS back into Operation Mode mdiSOCS.MSComm1.InBufferCount = 0 ' Empty the input buffer mdiSOCS.MSComm1.Output = "X" & Chr$(13) ' Send "X" (enter operation mode) WaitPort (2) MyString = mdiSOCS.MSComm1.Input ' Return string MyMsg = "Check the CS display for 'Normal Operation'. The return string was: " MsgBox MyMsg & Chr$(13) & "'" & MyString & "'", vbInformation, "TestPort" mdiSOCS.MSComm1.PortOpen = False ' Close the COM port Screen.MousePointer = vbDefault ' Set the cursor to default End Sub Sub WaitPort(Counter As Integer) ' Waits for a response from the CS ' Note: The CS always responds with {0, P, R, ?} & Chr$(13) ' If counter is big, WaitPort poles for ElapTime seconds before returning. This was ' necessary because, for example, "GD" (display group) commands returns a variable ' number of bytes. ' *************************************************************** ' * Programmed by Mark F. Eskew in Microsoft Visual Basic 5.0 * ' * To contact, send E-mail to maresk@swbell.net * ' *************************************************************** Dim MyMsg As String, MyMsgHdr As String Dim ElapTime As Integer Dim MyLen As Integer Dim MyChar As String Start = Timer ' Timer is the elapsed time since midnight ElapTime = 3 ' 3 seconds ' Wait for a response from the CS Do Dummy = DoEvents() Loop Until (mdiSOCS.MSComm1.InBufferCount >= Counter) _ Or (Timer >= Start + ElapTime) ' ' Check to see if a time out occured ** Old stuff on hold ' If Timer >= Start + ElapTime Then ' MyMsgHdr = "Communications Error (WaitPort)" ' MyMsg = "The PC's serial port is NOT communicating with the CS. " & Chr$(13) & _ ' "Make sure you are in 'Normal Operation' mode." ' MsgBox MyMsg, vbCritical, MyMsgHdr ' End If End Sub Sub Version() ' Request the version number from the EasyDCC Comand Station. ' Sends "V" command to CS. ' Note: This is a good command to use while checking out the PC-to-CS serial ' communications link. ' *************************************************************** ' * Programmed by Mark F. Eskew in Microsoft Visual Basic 5.0 * ' * To contact, send E-mail to maresk@swbell.net * ' *************************************************************** Dim MyString As String, MyMsg As String mdiSOCS.MSComm1.PortOpen = True ' Open the COM port mdiSOCS.MSComm1.InBufferCount = 0 ' Empty the input buffer ' Request the Version Number Screen.MousePointer = vbHourglass ' Set cursor to hourglass mdiSOCS.MSComm1.Output = "V" & Chr$(13) ' Send "V" (request version number) WaitPort (12) MyString = mdiSOCS.MSComm1.Input ' Return string Screen.MousePointer = vbDefault ' Reset cursor to default MyMsg = "The Command Station's version is: " MsgBox MyMsg & Chr$(13) & "'" & MyString & "'", vbInformation, "Version" mdiSOCS.MSComm1.PortOpen = False ' Close the COM port End Sub