|
68 | 68 |
|
69 | 69 | End If
|
70 | 70 |
|
| 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 | + |
71 | 119 | ' '''''''''''''''Simulating data '''''''''''''''''''''''
|
72 | 120 | 'Static Dim ANGLE As Double = 0
|
73 | 121 |
|
|
157 | 205 | Next
|
158 | 206 | End While
|
159 | 207 |
|
160 |
| - |
161 | 208 | Chart1.Series.ResumeUpdates()
|
162 | 209 | ' Adjust Y & X axis scale
|
163 | 210 | Chart1.ResetAutoValues()
|
164 | 211 |
|
| 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 |
165 | 224 | End If
|
166 | 225 |
|
167 | 226 | End Sub
|
|
216 | 275 | Private Function parseData() As Boolean
|
217 | 276 | Dim tempByte As Byte
|
218 | 277 | Static Dim tempBuf(2) As Byte
|
219 |
| - Static Dim asciBuf As New ArrayList |
| 278 | + Static Dim asciBuf As New List(Of String) |
220 | 279 |
|
221 | 280 | Dim byteCount As Integer = 0
|
222 | 281 |
|
|
236 | 295 | If tempByte = &HAB Then
|
237 | 296 | parseState = ParseState_MC.HEADER1
|
238 | 297 | Else
|
239 |
| - asciBuf.Add(CStr(tempByte)) |
| 298 | + asciBuf.Add(CChar(ChrW(tempByte))) |
240 | 299 | parseState = ParseState_MC.IDLE
|
241 | 300 | End If
|
242 | 301 |
|
|
247 | 306 | If tempByte = &HCD Then
|
248 | 307 | parseState = ParseState_MC.HEADER2
|
249 | 308 | Else
|
250 |
| - asciBuf.Add(CStr(tempByte)) |
| 309 | + asciBuf.Add(CChar(ChrW(tempByte))) |
251 | 310 | parseState = ParseState_MC.IDLE
|
252 | 311 | End If
|
253 | 312 |
|
|
291 | 350 | 'tempstr = String.Join("", CType(asciBuf.ToArray(GetType(String)), String()))
|
292 | 351 | 'textBox.AppendText(tempstr)
|
293 | 352 | 'textBox.AppendText(tempstr)
|
| 353 | + Dim text As String = String.Join("", asciBuf) |
| 354 | + TerminalWindow.AppendText(text) |
294 | 355 | asciBuf.Clear()
|
| 356 | + |
295 | 357 | If pointsArray.Count > 0 Then
|
296 | 358 | Return True
|
297 | 359 | Else
|
|
0 commit comments