Skip to content
This repository has been archived by the owner on Feb 19, 2023. It is now read-only.

Commit

Permalink
feat: something after test
Browse files Browse the repository at this point in the history
  • Loading branch information
CCXXXI committed Jul 13, 2022
1 parent 3a17698 commit ae228d7
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 5 deletions.
18 changes: 17 additions & 1 deletion TcpClient.vb
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
Imports System.Net.Sockets
Imports System.Linq
Imports System.Net.Sockets

Public Class TcpClient
Const Host As String = "localhost"
Const Port As Integer = 8000
ReadOnly _readCmd As Byte() = New Byte() {&HFE, &H2, &H0, &H0, &H0, &H8, &H6D, &HC3}
Const YesCode As Byte = &H1
ReadOnly _report As Byte() = New Byte() {&HFE, &H5, &H0, &H0, &HFF, &H0, &H98, &H35}
ReadOnly _expectResponse As Byte() = New Byte() {&HFE, &H5, &H0, &H0, &HFF, &H0, &H98, &H35}

ReadOnly _tcpClient As New Net.Sockets.TcpClient()
Dim _networkStream As NetworkStream
Expand Down Expand Up @@ -34,4 +37,17 @@ Public Class TcpClient
' check
Return bytes(3) = YesCode
End Function

Public Function Report() As Boolean
_networkStream.Write(_report, 0, _report.Length)

Dim bytes(_tcpClient.ReceiveBufferSize) As Byte
_networkStream.Read(bytes, 0, CInt(_tcpClient.ReceiveBufferSize))

Return bytes.SequenceEqual(_expectResponse)
End Function

Public Function Connected() As Boolean
Return _tcpClient.Connected
End Function
End Class
12 changes: 8 additions & 4 deletions frmMain.vb
Original file line number Diff line number Diff line change
Expand Up @@ -2096,6 +2096,11 @@ LocalErrorHandler:
'finally, set up the focus appropriately on the user interface
Me.Cursor = mnOldMousePointer
ConfigButtonsBeforeRun()

If _client.Connected Then
FixBox.BackColor = IIf(_client.Report(), Color.Red, Color.Yellow)
End If
InitSerialInput()
Exit Sub

LocalErrorHandler:
Expand Down Expand Up @@ -2320,16 +2325,15 @@ LocalErrorHandler:
txtSerialNumber.Text = ""
End Sub

ReadOnly _client As New TcpClient()
Private Sub BackgroundThread()
Dim client As New TcpClient()

If Not client.Connect() Then
If Not _client.Connect() Then
Return
End If
SysBox.BackColor = Color.Green

While True
If client.Check() Then
If _client.Check() Then
FixBox.BackColor = Color.Green
Invoke(Sub()
cmdRun_Click(cmdRun, New System.EventArgs)
Expand Down

0 comments on commit ae228d7

Please sign in to comment.