Private Sub Command25_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Command25.Click
Dim _Color As Color
Dim counter1 As Integer
Dim check As String
Dim hereagain As Integer = 0
If Me.Command25.Text = "Stop" Then GoTo here1
My.Application.DoEvents()
Me.Command25.Text = "Stop"
Me.Command25.Update()
Me.Text = "IP-Pad Display. Written by XXXXXXXXXXXXXXXXXXXXXXXX"
Me.Update()
With SerialPort1
.PortName = ListBox1.SelectedItem
.BaudRate = ListBox2.SelectedItem
.Parity = IO.Ports.Parity.None
.DataBits = 8
.StopBits = IO.Ports.StopBits.One
.Handshake = IO.Ports.Handshake.RequestToSend
.DtrEnable = True
.RtsEnable = True
End With
Dim y As Integer
SerialPort1.Open()
If TextBox1.Text = "" Then GoTo here3
SerialPort1.WriteLine("atdt" & TextBox1.Text & vbCr)
For x = 1 To 1000000000
For y = 1 To 10
Next
Next
here3:
SerialPort1.WriteLine("/F53 0475 ")
here2:
For x = 1 To 8
If hereagain > 0 Then
SerialPort1.DtrEnable = True
If chk = 0 Then SerialPort1.WriteLine("/F53 0475 ")
End If
If chk > 0 Then SerialPort1.WriteLine(vbCr)
Do Until chk = x
My.Application.DoEvents()
Loop
For counter1 = 1 To 32
check = Mid(padst, counter1, 1)
If Mid(padst, counter1, 1) = "1" Then _Color = Color.Lime Else _Color = Color.Red
CType(findcontrolbyreflection("Button" & (counter1 + (32 * (chk - 1)))), Button).BackColor = _Color
CType(findcontrolbyreflection("Button" & (counter1 + (32 * (chk - 1)))), Button).Update()
Next
Next x
x = 0
chk = 0
hereagain = 1
GoTo here2
here1:
SerialPort1.Close()
Me.Command25.Text = "Start"
Me.Command25.Update()
For chk = 1 To 8
For counter1 = 1 To 32
check = Mid(padst, counter1, 1)
_Color = Color.Red
CType(findcontrolbyreflection("Button" & (counter1 + (32 * (chk - 1)))), Button).BackColor = _Color
CType(findcontrolbyreflection("Button" & (counter1 + (32 * (chk - 1)))), Button).Update()
Next
Next
chk = 0
Me.Text = "IP-Pad Display"
Me.Update()
End Sub
Public Function findcontrolbyreflection(ByVal Name As String) As Control
Dim info As System.Reflection.FieldInfo = Me.GetType().GetField("_" & Name, _
System.Reflection.BindingFlags.NonPublic Or _
System.Reflection.BindingFlags.Instance Or _
System.Reflection.BindingFlags.Public Or _
System.Reflection.BindingFlags.IgnoreCase)
If info Is Nothing Then Return Nothing
Dim o As Object = info.GetValue(Me)
Return o
End Function
Private Sub SerialPort1_DataReceived(ByVal sender As System.Object, ByVal e As System.IO.Ports.SerialDataReceivedEventArgs) Handles SerialPort1.DataReceived
SerialPort1.DtrEnable = True
My.Application.DoEvents()
Dim counter As Integer
Dim carstr As String = ""
Dim teststr As String = ""
Dim chan24to31 As String = ""
Dim chan16to23 As String = ""
Dim chan8to15 As String = ""
Dim chan0to7 As String = ""
Dim revstr As Integer
Dim check As String
Dim i As Integer = 0
Dim gotit As Integer = 0
Control.CheckForIllegalCrossThreadCalls = False
teststr = SerialPort1.ReadExisting()
'This cleans out any spurious characters
For counter = 1 To Len(teststr) - 1
If Asc(Mid(teststr, counter, 1)) > 31 Then
If Asc(Mid(teststr, counter, 1)) < 125 Then
Dim debstr As String = Mid(teststr, counter, 1)
carstr = carstr & Mid(teststr, counter, 1)
debstr = Asc(Mid(teststr, counter, 1))
End If
End If
Next
'I then have to strip the hex codes from the end of the string NB. they always follow a ":"
counter = 0
For counter = 1 To Len(carstr) - 1
check = Mid(carstr, counter, 1)
If Mid(carstr, counter, 1) = ":" Then
chk = chk + 1
chan24to31 = Microsoft.VisualBasic.Right(carstr, 2)
chan16to23 = Mid(carstr, (Len(carstr) - 4), 2)
chan8to15 = Mid(carstr, (Len(carstr) - 7), 2)
chan0to7 = Mid(carstr, (Len(carstr) - 10), 2)
End If
Next
'then convert to Binary and reverse the string of digits so that I can use right to left presentation
If chk > 0 Then
i = Convert.ToInt32(chan24to31, 16)
Dim ind24to31 As String = Convert.ToString(i, 2)
If Len(ind24to31) = 1 Then ind24to31 = "0000000" & ind24to31
If Len(ind24to31) = 2 Then ind24to31 = "000000" & ind24to31
If Len(ind24to31) = 3 Then ind24to31 = "00000" & ind24to31
If Len(ind24to31) = 4 Then ind24to31 = "0000" & ind24to31
If Len(ind24to31) = 5 Then ind24to31 = "000" & ind24to31
If Len(ind24to31) = 6 Then ind24to31 = "00" & ind24to31
If Len(ind24to31) = 7 Then ind24to31 = "0" & ind24to31
Dim revind24to31 As String = ""
For revstr = 8 To 1 Step -1
revind24to31 = revind24to31 + Mid(ind24to31, revstr, 1)
Next
i = Convert.ToInt32(chan16to23, 16)
Dim ind16to23 As String = Convert.ToString(i, 2)
If Len(ind16to23) = 1 Then ind16to23 = "0000000" & ind16to23
If Len(ind16to23) = 2 Then ind16to23 = "000000" & ind16to23
If Len(ind16to23) = 3 Then ind16to23 = "00000" & ind16to23
If Len(ind16to23) = 4 Then ind16to23 = "0000" & ind16to23
If Len(ind16to23) = 5 Then ind16to23 = "000" & ind16to23
If Len(ind16to23) = 6 Then ind16to23 = "00" & ind16to23
If Len(ind16to23) = 7 Then ind16to23 = "0" & ind16to23
Dim revind16to23 As String = ""
For revstr = 8 To 1 Step -1
revind16to23 = revind16to23 + Mid(ind16to23, revstr, 1)
Next
i = Convert.ToInt32(chan8to15, 16)
Dim ind8to15 As String = Convert.ToString(i, 2)
If Len(ind8to15) = 1 Then ind8to15 = "0000000" & ind8to15
If Len(ind8to15) = 2 Then ind8to15 = "000000" & ind8to15
If Len(ind8to15) = 3 Then ind8to15 = "00000" & ind8to15
If Len(ind8to15) = 4 Then ind8to15 = "0000" & ind8to15
If Len(ind8to15) = 5 Then ind8to15 = "000" & ind8to15
If Len(ind8to15) = 6 Then ind8to15 = "00" & ind8to15
If Len(ind8to15) = 7 Then ind8to15 = "0" & ind8to15
Dim revind8to15 As String = ""
For revstr = 8 To 1 Step -1
revind8to15 = revind8to15 + Mid(ind8to15, revstr, 1)
Next
i = Convert.ToInt32(chan0to7, 16)
Dim ind0to7 As String = Convert.ToString(i, 2)
If Len(ind0to7) = 1 Then ind0to7 = "0000000" & ind0to7
If Len(ind0to7) = 2 Then ind0to7 = "000000" & ind0to7
If Len(ind0to7) = 3 Then ind0to7 = "00000" & ind0to7
If Len(ind0to7) = 4 Then ind0to7 = "0000" & ind0to7
If Len(ind0to7) = 5 Then ind0to7 = "000" & ind0to7
If Len(ind0to7) = 6 Then ind0to7 = "00" & ind0to7
If Len(ind0to7) = 7 Then ind0to7 = "0" & ind0to7
Dim revind0to7 As String = ""
For revstr = 8 To 1 Step -1
revind0to7 = revind0to7 + Mid(ind0to7, revstr, 1)
Next
'put them together to depict all 32 channels
padst = revind0to7 & revind8to15 & revind16to23 & revind24to31
End If
here1:
End Sub