Skip to content

Commit b4ff0c6

Browse files
brijeshbrijesh
brijesh
authored and
brijesh
committed
Added ability to display user text in terminal window.
1 parent b70fdf0 commit b4ff0c6

File tree

3 files changed

+178
-71
lines changed

3 files changed

+178
-71
lines changed

SimPlot.suo

0 Bytes
Binary file not shown.

SimPlot/mainForm.Designer.vb

+112-67
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

SimPlot/mainForm.vb

+66-4
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,54 @@
6868

6969
End If
7070

71+
72+
73+
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
74+
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
75+
'Serial port loop back test. Transmitting a packet that is meant to be looped back into serial port.
76+
'Short the Tx pin to Rx pin externally.
77+
78+
Dim txBuffer(100) As Byte
79+
Dim byteArray As Byte()
80+
Static Dim ANGLE As Double = 0
81+
82+
txBuffer(0) = &HAB 'Header byte1
83+
txBuffer(1) = &HCD 'Header byte2
84+
txBuffer(2) = 6 'Packet size high byte
85+
txBuffer(3) = 0 'Packet side low byte
86+
87+
ANGLE += Math.PI / 53
88+
89+
byteArray = BitConverter.GetBytes(CShort(100 * Math.Cos(ANGLE)))
90+
txBuffer(4) = byteArray(0)
91+
txBuffer(5) = byteArray(1)
92+
93+
byteArray = BitConverter.GetBytes(CShort(100 * Math.Sin(ANGLE)))
94+
txBuffer(6) = byteArray(0)
95+
txBuffer(7) = byteArray(1)
96+
97+
byteArray = BitConverter.GetBytes(CShort(100 * Math.Sin(ANGLE) / 2))
98+
txBuffer(8) = byteArray(0)
99+
txBuffer(9) = byteArray(1)
100+
101+
102+
If connectDisconnectButton.Text = "Disconnect" Then
103+
104+
SerialPort1.Write(txBuffer, 0, (2 + 2 + 6))
105+
106+
If (tickCount Mod 10 = 0) Then
107+
SerialPort1.WriteLine("hello")
108+
End If
109+
End If
110+
111+
112+
113+
114+
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
115+
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
116+
117+
118+
71119
' '''''''''''''''Simulating data '''''''''''''''''''''''
72120
'Static Dim ANGLE As Double = 0
73121

@@ -157,11 +205,22 @@
157205
Next
158206
End While
159207

160-
161208
Chart1.Series.ResumeUpdates()
162209
' Adjust Y & X axis scale
163210
Chart1.ResetAutoValues()
164211

212+
''House keeping jobs perform periodically but at low frequency
213+
If (tickCount Mod 10 = 0) Then
214+
If (TerminalWindow.Lines.Length > 2100) Then
215+
Array.Resize(TerminalWindow.Lines, 2000)
216+
TerminalWindow.AppendText(vbNewLine)
217+
End If
218+
If (textBox.Lines.Length > 2100) Then
219+
Array.Resize(textBox.Lines, 2000)
220+
textBox.AppendText(vbNewLine)
221+
End If
222+
223+
End If
165224
End If
166225

167226
End Sub
@@ -216,7 +275,7 @@
216275
Private Function parseData() As Boolean
217276
Dim tempByte As Byte
218277
Static Dim tempBuf(2) As Byte
219-
Static Dim asciBuf As New ArrayList
278+
Static Dim asciBuf As New List(Of String)
220279

221280
Dim byteCount As Integer = 0
222281

@@ -236,7 +295,7 @@
236295
If tempByte = &HAB Then
237296
parseState = ParseState_MC.HEADER1
238297
Else
239-
asciBuf.Add(CStr(tempByte))
298+
asciBuf.Add(CChar(ChrW(tempByte)))
240299
parseState = ParseState_MC.IDLE
241300
End If
242301

@@ -247,7 +306,7 @@
247306
If tempByte = &HCD Then
248307
parseState = ParseState_MC.HEADER2
249308
Else
250-
asciBuf.Add(CStr(tempByte))
309+
asciBuf.Add(CChar(ChrW(tempByte)))
251310
parseState = ParseState_MC.IDLE
252311
End If
253312

@@ -291,7 +350,10 @@
291350
'tempstr = String.Join("", CType(asciBuf.ToArray(GetType(String)), String()))
292351
'textBox.AppendText(tempstr)
293352
'textBox.AppendText(tempstr)
353+
Dim text As String = String.Join("", asciBuf)
354+
TerminalWindow.AppendText(text)
294355
asciBuf.Clear()
356+
295357
If pointsArray.Count > 0 Then
296358
Return True
297359
Else

0 commit comments

Comments
 (0)