VERSION 5.00 Object = "{648A5603-2C6E-101B-82B6-000000000014}#1.1#0"; "MSCOMM32.OCX" Begin VB.Form Form1 Caption = "Form1" ClientHeight = 7740 ClientLeft = 60 ClientTop = 450 ClientWidth = 8655 FillStyle = 0 'Solid LinkTopic = "Form1" ScaleHeight = 7740 ScaleWidth = 8655 StartUpPosition = 3 'Windows Default Begin VB.Timer Timer1 Enabled = 0 'False Interval = 50 Left = 960 Top = 240 End Begin VB.ListBox MessageList Height = 2595 Left = 120 TabIndex = 46 Top = 4920 Width = 8415 End Begin VB.Frame SendFrame Caption = "Send Commands" Height = 735 Left = 120 TabIndex = 40 Top = 4200 Width = 8415 Begin VB.CommandButton Resend Caption = "Resend" Height = 375 Left = 7080 TabIndex = 45 Top = 240 Width = 975 End Begin VB.CommandButton Version Caption = "Version" Height = 375 Left = 5760 TabIndex = 44 Top = 240 Width = 975 End Begin VB.CommandButton HelloBTN Caption = "Hello" Height = 375 Left = 4320 TabIndex = 43 Top = 240 Width = 1215 End Begin VB.CommandButton Send Caption = "Send" Height = 375 Left = 3000 TabIndex = 42 Top = 240 Width = 1095 End Begin VB.TextBox SendText Height = 405 Left = 240 TabIndex = 41 Top = 240 Width = 2415 End End Begin VB.Frame AddrFrame Caption = "AddrFrame" Height = 1695 Left = 4560 TabIndex = 36 Top = 2400 Width = 4095 Begin VB.CommandButton ChangeAddr Caption = "Change Address" Height = 375 Left = 2160 TabIndex = 39 Top = 840 Width = 1695 End Begin VB.TextBox AddrText Height = 375 Left = 1320 TabIndex = 38 Top = 840 Width = 495 End Begin VB.Label Label9 Caption = "Pod Address:" Height = 255 Left = 240 TabIndex = 37 Top = 840 Width = 1095 End End Begin VB.Frame DetectFrame Caption = "Autodetect Address" Height = 1695 Left = 2520 TabIndex = 32 Top = 2400 Width = 2055 Begin VB.CommandButton StopDetect Caption = "StopDetect" Height = 375 Left = 360 TabIndex = 34 Top = 1080 Width = 1335 End Begin VB.CommandButton AutoDetect Caption = "Auto Detect" Height = 375 Left = 360 TabIndex = 33 Top = 240 Width = 1335 End Begin VB.Label DetectLabel Height = 255 Left = 360 TabIndex = 35 Top = 720 Width = 1455 End End Begin VB.Frame ComFrame Caption = "Com Settings" Height = 1695 Left = 120 TabIndex = 26 Top = 2400 Width = 2415 Begin VB.CommandButton Connect Caption = "Connect" Height = 375 Left = 360 TabIndex = 31 Top = 1200 Width = 1455 End Begin VB.TextBox PortText Height = 285 Left = 960 TabIndex = 30 Text = "5" Top = 840 Width = 975 End Begin VB.Label Label8 Caption = "Com Port:" Height = 255 Left = 120 TabIndex = 29 Top = 840 Width = 735 End Begin VB.Label Label7 BorderStyle = 1 'Fixed Single Caption = "9600" Height = 255 Left = 1080 TabIndex = 28 Top = 360 Width = 495 End Begin VB.Label Label6 Caption = "Baud Rate:" Height = 255 Left = 120 TabIndex = 27 Top = 360 Width = 855 End End Begin VB.CommandButton Start Caption = "Start Aquiring Data" Height = 375 Left = 5760 TabIndex = 25 Top = 1440 Width = 2175 End Begin VB.Frame KeyFrame Caption = "Key" Height = 615 Left = 2040 TabIndex = 1 Top = 120 Width = 3615 Begin VB.Label KeyLow BackColor = &H000000FF& Height = 255 Left = 2160 TabIndex = 5 Top = 240 Width = 255 End Begin VB.Label Label3 Caption = "LOW:" Height = 255 Left = 1560 TabIndex = 4 Top = 240 Width = 495 End Begin VB.Label Label2 Caption = "HI:" Height = 255 Left = 360 TabIndex = 3 Top = 240 Width = 255 End Begin VB.Label KeyHi BackColor = &H0000FF00& Height = 255 Left = 840 TabIndex = 2 Top = 240 Width = 255 End End Begin VB.CommandButton Exit Caption = "E&xit" Height = 375 Left = 6960 TabIndex = 0 Top = 240 Width = 1095 End Begin MSCommLib.MSComm Commo Left = 120 Top = 120 _ExtentX = 1005 _ExtentY = 1005 _Version = 393216 DTREnable = -1 'True RThreshold = 1 End Begin VB.Label InputLabel BackColor = &H000000FF& Height = 255 Index = 1 Left = 4560 TabIndex = 24 Top = 1320 Width = 255 End Begin VB.Label InputLabel BackColor = &H000000FF& Height = 255 Index = 0 Left = 5040 TabIndex = 23 Top = 1320 Width = 255 End Begin VB.Label InputLabel BackColor = &H000000FF& Height = 255 Index = 7 Left = 1680 TabIndex = 22 Top = 1320 Width = 255 End Begin VB.Label OutputLabel BackColor = &H000000FF& Height = 255 Index = 0 Left = 5040 TabIndex = 21 Top = 1800 Width = 255 End Begin VB.Label Label5 Caption = " 7 6 5 4 3 2 1 0" Height = 255 Left = 1560 TabIndex = 20 Top = 960 Width = 3855 End Begin VB.Label OutputLabel BackColor = &H000000FF& Height = 255 Index = 2 Left = 4080 TabIndex = 19 Top = 1800 Width = 255 End Begin VB.Label OutputLabel BackColor = &H000000FF& Height = 255 Index = 1 Left = 4560 TabIndex = 18 Top = 1800 Width = 255 End Begin VB.Label OutputLabel BackColor = &H000000FF& Height = 255 Index = 6 Left = 2160 TabIndex = 17 Top = 1800 Width = 255 End Begin VB.Label OutputLabel BackColor = &H000000FF& Height = 255 Index = 5 Left = 2640 TabIndex = 16 Top = 1800 Width = 255 End Begin VB.Label OutputLabel BackColor = &H000000FF& Height = 255 Index = 4 Left = 3120 TabIndex = 15 Top = 1800 Width = 255 End Begin VB.Label OutputLabel BackColor = &H000000FF& Height = 255 Index = 3 Left = 3600 TabIndex = 14 Top = 1800 Width = 255 End Begin VB.Label InputLabel BackColor = &H000000FF& Height = 255 Index = 3 Left = 3600 TabIndex = 13 Top = 1320 Width = 255 End Begin VB.Label InputLabel BackColor = &H000000FF& Height = 255 Index = 2 Left = 4080 TabIndex = 12 Top = 1320 Width = 255 End Begin VB.Label OutputLabel BackColor = &H000000FF& Height = 255 Index = 7 Left = 1680 TabIndex = 11 Top = 1800 Width = 255 End Begin VB.Label InputLabel BackColor = &H000000FF& Height = 255 Index = 5 Left = 2640 TabIndex = 10 Top = 1320 Width = 255 End Begin VB.Label InputLabel BackColor = &H000000FF& Height = 255 Index = 4 Left = 3120 TabIndex = 9 Top = 1320 Width = 255 End Begin VB.Label InputLabel BackColor = &H000000FF& Height = 255 Index = 6 Left = 2160 TabIndex = 8 Top = 1320 Width = 255 End Begin VB.Label Label4 Caption = "Output To Card" Height = 255 Left = 240 TabIndex = 7 Top = 1800 Width = 1215 End Begin VB.Label Label1 Caption = "Input From Card" Height = 255 Left = 240 TabIndex = 6 Top = 1320 Width = 1215 End End Attribute VB_Name = "Form1" Attribute VB_GlobalNameSpace = False Attribute VB_Creatable = False Attribute VB_PredeclaredId = True Attribute VB_Exposed = False Option Explicit Private Declare Sub Sleep Lib "kernel32.dll" (ByVal dwMilliseconds As Long) Const CLEAR_TEXT = 1 'the messages are just be pushed to the list box Const AQUIRING = 2 'recieving the status of the inputs Const HELLO = 3 'attempting to open the POD check for hello MSG Const CONFIRM = 4 'we sent a command we are awaiting a CR acknowledgement Const SEARCHING = 5 'we are attempting to autodetect the POD Const FOUND = 6 'POD was located while attempting to autodetect Dim mode As Integer Dim connected As Boolean Dim toPod As Integer Dim fromPod As Integer Dim msg As String Dim isAquiring As Boolean Private Sub AutoDetect_Click() Dim count As Integer Dim addrString As String mode = SEARCHING count = 0 Do count = count + 1 If count < &H10 Then addrString = "0" + Hex(count) Else addrString = Hex(count) End If Commo.Output = "!" + addrString + vbCr DetectLabel.Caption = "Searching at: " + addrString Sleep 500 DoEvents Loop While count < 255 And mode = SEARCHING If mode = FOUND Then AddrText.Text = Hex(count) End If mode = CLEAR_TEXT End Sub Private Sub ChangeAddr_Click() If Len(AddrText.Text) = 2 Then Commo.Output = "POD=" + Hex(AddrText.Text) + vbCr Else Commo.Output = "POD=0" + Hex(AddrText.Text) + vbCr End If End Sub Private Sub Commo_OnComm() Dim temp As Integer Dim tempString As String 'When data is received via the com port Visual Basic does not ensure that 'it ends with a carriage return. So we have to hold on to the data 'until a carriage return is encountered. Then we have to use everything 'before the return and save whatever comes after msg = msg + Commo.Input temp = InStr(1, msg, vbCr) 'if temp doesn't equal 0 after this, there is a 'carriage return in the String If temp <> 0 Then tempString = Mid(msg, temp + 1) 'temp string becomes everything after the carriage return msg = Left(msg, temp) 'message becomes everything up to the carriage return End If If Commo.CommEvent = comEvReceive Then If temp <> 0 Then 'if no end of line was received there is no point in trying to process the message Select Case mode Case HELLO mode = CLEAR_TEXT connected = True AddrFrame.Visible = True SendFrame.Visible = True Case CLEAR_TEXT If Len(msg) > 1 Then MessageList.AddItem msg, 0 End If Case SEARCHING mode = FOUND connected = True AddrFrame.Visible = True SendFrame.Visible = True Case CONFIRM mode = AQUIRING Case AQUIRING inputRecieved msg mode = CONFIRM End Select msg = tempString 'msg now becomes everything that was after the carriage return to be held on to for next time End If End If End Sub Private Sub Connect_Click() If Connect.Caption = "Connect" Then Commo.CommPort = Val(PortText.Text) Commo.Settings = "9600, e, 7, 1" Commo.PortOpen = True Connect.Caption = "Disconnect" mode = HELLO Sleep 500 Commo.Output = "H" + vbCr DetectFrame.Visible = True Else Commo.PortOpen = False Connect.Caption = "Connect" 'this will be where we make ALL the frames invisible DetectFrame.Visible = False AddrFrame.Visible = False SendFrame.Visible = False End If End Sub Private Sub Exit_Click() Unload Me End Sub Private Sub Form_Load() Dim i As Integer For i = 0 To 7 InputLabel(i).BackColor = vbRed OutputLabel(i).BackColor = vbRed Next i toPod = 0 fromPod = 0 DetectFrame.Visible = False AddrFrame.Visible = False SendFrame.Visible = False End Sub Private Sub HelloBTN_Click() Commo.Output = "H" + vbCr End Sub Private Sub OutputLabel_Click(Index As Integer) Select Case Index Case 0 toPod = toPod Xor &H1 Case 1 toPod = toPod Xor &H2 Case 2 toPod = toPod Xor &H4 Case 3 toPod = toPod Xor &H8 Case 4 toPod = toPod Xor &H10 Case 5 toPod = toPod Xor &H20 Case 6 toPod = toPod Xor &H40 Case 7 toPod = toPod Xor &H80 End Select switchBit Index If mode = CLEAR_TEXT Then writeOutPod End If End Sub Private Sub switchBit(Index As Integer) If OutputLabel(Index).BackColor = vbRed Then OutputLabel(Index).BackColor = vbGreen Else OutputLabel(Index).BackColor = vbRed End If End Sub Private Sub Resend_Click() Commo.Output = "N" + vbCr End Sub Private Sub Send_Click() Commo.Output = SendText.Text + vbCr End Sub Private Sub Start_Click() If Start.Caption = "Start Aquiring Data" Then mode = CONFIRM isAquiring = True Timer1.Enabled = True Start.Caption = "Stop" ComFrame.Enabled = False DetectFrame.Enabled = False AddrFrame.Enabled = False SendFrame.Enabled = False Else isAquiring = False Start.Caption = "Start Aquiring Data" ComFrame.Enabled = True DetectFrame.Enabled = True AddrFrame.Enabled = True SendFrame.Enabled = True End If End Sub Private Sub StopDetect_Click() mode = CLEAR_TEXT End Sub Private Sub Timer1_Timer() Timer1.Enabled = False writeOutPod Do DoEvents Loop While mode = CONFIRM Commo.Output = "i" + vbCr Do DoEvents Loop While mode = AQUIRING If isAquiring = True Then Timer1.Enabled = True Else mode = CLEAR_TEXT End If End Sub Private Sub Version_Click() Commo.Output = "V" + vbCr End Sub Private Sub writeOutPod() Dim valueString As String If toPod > &H9 Then valueString = Hex(toPod) Else valueString = "0" + Hex(toPod) End If Commo.Output = "o" + valueString + vbCr End Sub Private Sub inputRecieved(msg As String) Dim i As Integer fromPod = "&H" + msg For i = 0 To 7 If ShiftRight(fromPod, i) And &H1 = 1 Then InputLabel(i).BackColor = vbGreen Else InputLabel(i).BackColor = vbRed End If Next i End Sub