such as the Tiny Spectrum Analyser
'--------------------------------------------------------------------------------------------Public Sub writeCmdSerial
Dim str As String = "scan 527000000 532000000 21 3" 'This is the command to the instrument
Private byteBuffer() As Byte
Private bc As ByteConverter
str = str.ToLowerCase & Chr(13)
byteBuffer = bc.StringToBytes(str, "UTF8")
Log(str)
astream.Write(byteBuffer)
End Sub
Private Sub processingLoop For i = 0 To 6
'Do a batch of 6 scans for this scanTimer Tick
startTime = DateTime.Now
Log("Start Time = " & DateTime.Time(startTime))
writeCmdSerial
'Wait here for all of the data to be processed.
Do While processComplete = False
Sleep(10)
Loop
processComplete = False
endTime = DateTime.Now
delta_ms = endTime - startTime
Log("End period = " & delta_ms)
Log(" ")
Next
End Sub
'--------------------------------------------------------------------------------------------
Private Sub AStream_NewData (Buffer() As Byte)
cleanUpScanData(Buffer)
End Sub
'--------------------------------------------------------------------------------------------
Private Sub cleanUpScanData(buffer() As Byte)
Private sb As StringBuilder
sb.Initialize
Private charset As String = "UTF8"
Private newDataStart As Int = sb.Length
sb.Append(BytesToString(buffer, 0, buffer.Length, charset))
Private s As String = sb.ToString
Private start As Int = 0
For i = newDataStart To s.Length - 1
noOfPackets = noOfPackets + 1
Dim c As Char = s.CharAt(i)
If i = 0 And c = Chr(10) Then '\n...
start = 1 'might be a broken end of line character
Continue
End If
If c = Chr(10) Then '\n
CallSubDelayed2(Me, "checkAndProcessScanLine", s.SubString2(start, i))
' checkAndProcessScanLine(s.SubString2(start, i))
start = i + 1
Else If c = Chr(13) Then '\r
CallSubDelayed2(Me, "checkAndProcessScanLine", s.SubString2(start, i))
' checkAndProcessScanLine(s.SubString2(start, i))
If i < s.Length - 1 And s.CharAt(i + 1) = Chr(10) Then '\r\n
i = i + 1
End If
start = i + 1
End If
Next
If start > 0 Then sb.Remove(0, start)
End Sub
'--------------------------------------------------------------------------------------------
private Sub checkAndProcessScanLine(scanLineStr As String) As ResumableSub
Private somevar As Double
If scanLineStr.Contains("level") Or scanLineStr.Contains("scan") Then
Return False
End If
scanDataStreamText = scanDataStreamText & Chr(10) & scanLineStr
' Log(scanDataStreamText)
noValidScanLines = noValidScanLines + 1
If noValidScanLines = 21 Then
noValidScanLines = 0
For i = 1 To 10000
somevar = Sqrt(3458.9)
Next
'(...)
End If
processComplete = True
Return True
End Sub
Public Sub scanTimer_Tick startTime = DateTime.Now
processingLoop
End Sub
[*][CODE lang="b4x" title="Serial Port (Sniffer) Log - Abridged" highlight="47-54"]<20240322130541.234 TX>
scan 527000000 532000000 21 3 'comment Scan 1 complete response shown
<20240322130542.741 RX>
527000000 -8.793750e+01 0.000000000
527250000 -8.993750e+01 0.000000000
527500000 -8.946875e+01 0.000000000
527750000 -8.996875e+01 0.000000000
528000000 -8.896875e+01 0.000000000
528250000 -8.896875e+01 0.000000000
528500000 -8.846875e+01 0.000000000
528750000 -8.796875e+01 0.000000000
529000000 -8.896875e+01 0.000000000
529250000 -8.946875e+01 0.000000000
529500000 -8.996875e+01 0.000000000
529750000 -9.096875e+01 0.000000000
530000000 -8.796875e+01 0.000000000
530250000 -9.046875e+01 0.000000000
530500000 -8.996875e+01 0.000000000
530750000 -8.696875e+01 0.000000000
531000000 -8.946875e+01 0.000000000
531250000 -9.046875e+01 0.000000000
531500000 -8.896875e+01 0.000000000
531750000 -8.996875e+01 0.000000000
532000000 -8.996875e+01 0.000000000
ch> scan 527000000 532000000 21 3 'comment Scan 2
<20240322130544.252 RX>
527000000 -8.943750e+01 0.000000000
527250000 -9.043750e+01 0.000000000
'(...) comment removed these to shorten log
531750000 -8.946875e+01 0.000000000
532000000 -8.996875e+01 0.000000000
ch> scan 527000000 532000000 21 3 'comment Scan 3
<20240322130545.762 RX>
527000000 -8.943750e+01 0.000000000
527250000 -9.093750e+01 0.000000000
'(...) comment removed these to shorten log
531750000 -8.996875e+01 0.000000000
532000000 -8.896875e+01 0.000000000
ch> scan 527000000 532000000 21 3 'comment Scan 4
<20240322130547.170 RX>
527000000 -8.843750e+01 0.000000000
527250000 -8.793750e+01 0.000000000
'(...) comment removed these to shorten log
531750000 -9.046875e+01 0.000000000
532000000 -9.046875e+01 0.000000000
ch> scan 527000000 532000000 21 3 'comment Scan 5
<20240322130547.689 TX> 'comment anomaly (
scan 527000000 532000000 21 3 ' ...
<20240322130548.691 TX> ' ...
scan 527000000 532000000 21 3 ' ...
<20240322130550.203 TX> ' ...
scan 527000000 532000000 21 3 ' ...
<20240322130551.616 TX> ' ...
scan 527000000 532000000 21 3 ')
<20240322130553.121 RX>
527000000 -8.843750e+01 0.000000000
527250000 -9.093750e+01 0.000000000
'(...) comment removed these to shorten log
531750000 -8.896875e+01 0.000000000
532000000 -8.846875e+01 0.000000000
ch> scan 527000000 532000000 21 3
<20240322130554.533 RX>
527000000 -8.943750e+01 0.000000000
527250000 -8.843750e+01 0.000000000
'(...) comment removed these to shorten log
531750000 -9.046875e+01 0.000000000
532000000 -8.896875e+01 0.000000000
ch> scan 527000000 532000000 21 3
<20240322130556.043 RX>
'(...)
Start Time = 13:05:39
scan 527000000 532000000 21 3 'comment: Scan 1
End period = 1547
Start Time = 13:05:41
scan 527000000 532000000 21 3 'comment: Scan 2
End period = 1511
Start Time = 13:05:42 'comment: Scan 3
scan 527000000 532000000 21 3
Start Time = 13:05:43
scan 527000000 532000000 21 3 'comment: anomaly scan 4?
End period = 567
Start Time = 13:05:445?4 'comment: anomaly
End period = 1507
Start Time = 13:05:45
scan 527000000 532000000 21 3
End period = 1414
Start Time = 13:05:47
scan 527000000 532000000 21 3
Start Time = 13:05:47
scan 527000000 532000000 21 3
End period = 1002
Start Time = 13:05:48
scan 527000000 532000000 21 3
End period = 1511
Start Time = 13:05:50
scan 527000000 532000000 21 3
End period = 1414
Start Time = 13:05:51
scan 527000000 532000000 21 3
Start Time = 13:05:51
scan 527000000 532000000 21 3
End period = 1438
Hey I just ordered one (the 2.8" original) and apparently it'll be on my doorstep April 12th.
get it linked up to B4J via USB serial too. What could possibly go rwong?
Sub Process_Globals
'Private fx As JFX
'Private MainForm As Form
'Private xui As XUI
'Private Button1 As B4XView
Dim bc As ByteConverter
Private sp As Serial
Private astr1 As AsyncStreams
End Sub
Sub AppStart (Form1 As Form, Args() As String)
'MainForm = Form1
'MainForm.RootPane.LoadLayout("Layout1")
'MainForm.Show
sp.Initialize("")
Dim ports As List = sp.ListPorts
If ports.Size = 0 Then
Log("No serial ports found")
Return
End If
For I = 0 To ports.Size - 1
Log(I & TAB & ports.Get(I))
Next
Log("Opening serial port " & ports.Get(0))
sp.Open(ports.Get(0))
astr1.Initialize(sp.GetInputStream, sp.GetOutputStream, "Astr1")
Dim TestCommands() As String = Array As String("", "", "version", "help", "data 2", "")
For Each S As String In TestCommands
Astr1_SendCommand(S)
Sleep(500)
Next
End Sub
Sub Astr1_SendCommand(S As String)
astr1.Write(bc.StringToBytes(S, "UTF8"))
astr1.Write(Array As Byte(13))
Log(DateTime.Now & " > " & TAB & """" & S & "<CR>""")
End Sub
Sub Astr1_NewData (Buffer() As Byte)
Dim s As String = BytesToString(Buffer, 0, Buffer.Length, "UTF8")
s = s.Replace(Chr(10), "<LF>").Replace(Chr(13), "<CR>")
Log(DateTime.Now & " " & TAB & """" & s & """")
End Sub
Waiting for debugger to connect...
Program started.
0 COM4
Opening serial port COM4
1712210949954 > "<CR>"
1712210949974 "<CR><LF>?<CR><LF>ch> "
1712210950467 > "<CR>"
1712210950509 "<CR><LF>?<CR><LF>ch> "
1712210950974 > "version<CR>"
1712210950990 "version<CR><LF>tinySA_v1.4-40-g2f63e1c<CR><LF>ch> "
1712210951485 > "help<CR>"
1712210951493 "help"
1712210951504 "<CR><LF>commands: version reset freq dac sweep_voltage saveconfig clearconfig data frequencies scan scanraw zero sweep test touchcal touchtest pause resume repeat status caloutput save recall trace trigger marker line usart usart_cfg capture refresh touch release vbat vbat_offset help info color if actual_freq attenuate level sweeptime leveloffset levelchange modulation rbw mode spur load ext_gain output deviceid selftest correction calc threads<CR><LF>ch> "
1712210951994 > "data 2<CR>"
1712210952011 "data 2<CR><LF>-1.124062e+02<CR><LF>-1.139062e+02<CR><LF>-1.124062e+02<CR><LF>-1.124062e+02<CR><LF>-1.124062e+02<CR><LF>-1.139062e+02<CR><LF>-1.139062e+02<CR><LF>-1.124062e+02<CR><LF>-1.139062e+02<CR><LF>-1.154062e+02<CR><LF>-1.154062e+02<CR><LF>-1.154062e+02<CR><LF>-1.124062e+02<CR><LF>-1.154062e+02<CR><LF>-1.109062e+02<CR><LF>-1.139062e+02<CR><LF>-1.124062e+02<CR><LF>-1.134062e+02<CR><LF>-1.124062e+02<CR><LF>-1.109062e+02<CR><LF>-1.154062e+02<CR><LF>-1.124062e+02<CR><LF>-1.134062e+02<CR><LF>-1.139062e+02<CR><LF>-1.139062e+02<CR><LF>-1.139062e+02<CR><LF>-1.124062e+02<CR><LF>-1.109062e+02<CR><LF>-1.124062e+02<CR><LF>-1.139062e+02<CR><LF>-1.154062e+02<CR><LF>-1.124062e+02<CR><LF>-1.139062e+02<CR><LF>-1.109062e+02<CR><LF>-1.154062e+02<CR><LF>-1.154062e+02<CR><LF>-1.109062e+02<CR><LF>-1.139062e+02<CR><LF>-1.154062e+02<CR><LF>-1.139062e+02<CR><LF>-1.124062e+02<CR><LF>-1.124062e+02<CR><LF>-1.124062e+02<CR><LF>-1.154062e+02<CR><LF>"
1712210952013 "-1.109062e+02<CR><LF>-1.109062e+02<CR><LF>-1.139062e+02<CR><LF>-1.154062e+02<CR><LF>-1.124062e+02<CR><LF>-1.139062e+02<CR><LF>-1.139062e+02<CR><LF>-1.139062e"
1712210952015 "+02<CR><LF>-1.124062e+02<CR><LF>-1.139062e+02<CR><LF>-1.124062e+02<CR><LF>-1.154062e+02<CR><LF>-1.124062e+02<CR><LF>-1.139062e+02<CR><LF>-1.139062e+02<CR><LF>-1.124062e+02<CR><LF>-1.124062e+02<CR><LF>-1.154062e+02<CR><LF>-1.124062e+02<CR><LF>-1.139062e+02<CR><LF>-1.139062e+02<CR><LF>-1.124062e+02<CR><LF>-1.154062e+02<CR><LF>-1.139062e+02<CR><LF>-1.154062e+02<CR><LF>-1.124062e+02<CR><LF>-1.109062e+02<CR><LF>-1.124062e+02<CR><LF>-1.124062e+02<CR><LF>-1.154062e+02<CR><LF>-1.139062e+02<CR><LF>-1.109062e+02<CR><LF>-1.109062e+02<CR><LF>-1.154062e+02<CR><LF>-1.139062e+02<CR><LF>-1.139062e+02<CR><LF>-1.139062e+02<CR><LF>-1.104062e+02<CR><LF>-1.139062e+02<CR><LF>-1.139062e+02<CR><LF>-1.124062e+02<CR><LF>-1.139062e+02<CR><LF>-1.139062e+02<CR><LF>-1.154062e+02<CR><LF>-1.139062e+02<CR><LF>-1.154062e+02<CR><LF>-1.109062e+02<CR><LF>-1.109062e+02<CR><LF>-1.109062e+02<CR><LF>-1.109062e+02<CR><LF>-1.154062e+02<CR><LF>-1.109062e+02<CR><LF>-1.124062e+02<CR><LF>-1.139062e+02<CR><LF>-1.124062e+02<CR><LF>-1.124062e+02<CR><LF>-1.139062e+02<CR><LF>-1.139062e+02<CR><LF>-1.109062e+02<CR><LF>-1.139062e+02<CR><LF>-1.139062e+02<CR><LF>-1.109062e+02<CR><LF>-1.094062e+02<CR><LF>-1.124062e+02<CR><LF>-1.154062e+02<CR><LF>-1.139062e+02<CR><LF>-1.139062e+02<CR><LF>-1.109062e+02<CR><LF>-1.109062e+02<CR><LF>-1.094062e+02<CR><LF>-1.139062e+02<CR><LF>-1.139062e+02<CR><LF>-1.124062e+02<CR><LF>-1.139062e+02<CR><LF>-1.154062e+02<CR><LF>-1.139062e+02<CR><LF>-1.139062e+02<CR><LF>-1.119062e+02<CR><LF>-1.119062e+02<CR><LF>-1.134062e+02<CR><LF>-1.094062e+02<CR><LF>-1.094062e+02<CR><LF>-1.109062e+02<CR><LF>-1.089062e+02<CR><LF>-1.089062e+02<CR><LF>-1.124062e+02<CR><LF>-1.039062e+02<CR><LF>-1.074062e+02<CR><LF>-1.104062e+02<CR><LF>-9.990625e+01<CR><LF>-1.049062e+02<CR><LF>-9.940625e+01<CR><LF>"
1712210952016 "-1.024062e+02<CR><LF>-1.024062e+02<CR><LF>-9.640625e+01<CR><LF>-9.740625e+01<CR><LF>-9.540625e+01<CR><LF>-9.490625e+01<CR><LF>-9.840625e+01<CR><LF>-9.740625e+01<CR><LF>-9.640"
1712210952031 "625e+01<CR><LF>-9.640625e+01<CR><LF>-9.590625e+01<CR><LF>-9.440625e+01<CR><LF>-9.190625e+01<CR><LF>-9.690625e+01<CR><LF>-9.790625e+01<CR><LF>-9.990625e+01<CR><LF>-1.009062e+02<CR><LF>-1.004062e+02<CR><LF>-9.990625e+01<CR><LF>-1.009062e+02<CR><LF>-1.059062e+02<CR><LF>-1.054062e+02<CR><LF>-1.094062e+02<CR><LF>-1.089062e+02<CR><LF>-1.074062e+02<CR><LF>-1.079062e+02<CR><LF>-1.124062e+02<CR><LF>-1.139062e+02<CR><LF>-1.089062e+02<CR><LF>-1.109062e+02<CR><LF>-1.109062e+02<CR><LF>-1.124062e+02<CR><LF>-1.124062e+02<CR><LF>-1.124062e+02<CR><LF>-1.154062e+02<CR><LF>-1.139062e+02<CR><LF>-1.124062e+02<CR><LF>-1.139062e+02<CR><LF>-1.124062e+02<CR><LF>-1.089062e+02<CR><LF>-1.109062e+02<CR><LF>-1.124062e+02<CR><LF>-1.139062e+02<CR><LF>-1.124062e+02<CR><LF>-1.094062e+02<CR><LF>-1.139062e+02<CR><LF>-1.139062e+02<CR><LF>-1.139062e+02<CR><LF>-1.109062e+02<CR><LF>-1.124062e+02<CR><LF>-1.124062e+02<CR><LF>-1.124062e+02<CR><LF>-1.124062e+02<CR><LF>-1.124062e+02<CR><LF>-1.139062e+02<CR><LF>-1.109062e+02<CR><LF>-1.154062e+02<CR><LF>-1.109062e+02<CR><LF>-1.109062e+02<CR><LF>-1.124062e+02<CR><LF>-1.124062e+02<CR><LF>-1.139062e+02<CR><LF>-1.109062e+02<CR><LF>-1.139062e+02<CR><LF>-1.109062e+02<CR><LF>-1.124062e+02<CR><LF>-1.119062e+02<CR><LF>-1.109062e+02<CR><LF>-1.139062e+02<CR><LF>-1.124062e+02<CR><LF>-1.124062e+02<CR><LF>-1.089062e+02<CR><LF>-1.124062e+02<CR><LF>-1.134062e+02<CR><LF>-1.124062e+02<CR><LF>-1.139062e+02<CR><LF>-1.124062e+02<CR><LF>-1.139062e+02<CR><LF>-1.109062e+02<CR><LF>-1.134062e+02<CR><LF>-1.109062e+02<CR><LF>-1.139062e+02<CR><LF>-1.139062e+02<CR><LF>-1.124062e+02<CR><LF>-1.139062e+02<CR><LF>-1.139062e+02<CR><LF>-1.124062e+02<CR><LF>-1.139062e+02<CR><LF>-1.139062e+02<CR><LF>-1.124062e+02<CR><LF>-1.124062e+02<CR><LF>-1.139062e+02<CR><LF>-1.109062e+02<CR><LF>-1.139062e+0"
1712210952038 "2<CR><LF>-1.124062e+02<CR><LF>-1.139062e+02<CR><LF>-1.094062e+02<CR><LF>-1.124062e+02<CR><LF>-1.139062e+02<CR><LF>-1.154062e+02<CR><LF>-1.124062e+02<CR><LF>-1.124062e+02<CR><LF>-1.124062e+02<CR><LF>-1.109062e+02<CR><LF>-1.154062e+02<CR><LF>-1.124062e+02<CR><LF>-1.109062e+02<CR><LF>-1.109062e+02<CR><LF>-1.124062e+02<CR><LF>-1.139062e+02<CR><LF>-1.139062e+02<CR><LF>-1.154062e+02<CR><LF>-1.154062e+02<CR><LF>-1.119062e+02<CR><LF>-1.139062e+02<CR><LF>-1.124062e+02<CR><LF>-1.094062e+02<CR><LF>-1.094062e+02<CR><LF>-1.154062e+02<CR><LF>-1.154062e+02<CR><LF>-1.139062e+02<CR><LF>-1.124062e+02<CR><LF>-1.154062e+02<CR><LF>-1.109062e+02<CR><LF>-1.154062e+02<CR><LF>-1.154062e+02<CR><LF>-1.139062e+02<CR><LF>-1.124062e+02<CR><LF>-1.154062e+02<CR><LF>-1.124062e+02<CR><LF>-1.139062e+02<CR><LF>-1.109062e+02<CR><LF>-1.139062e+02<CR><LF>-1.139062e+02<CR><LF>-1.109062e+02<CR><LF>-1.139062e+02<CR><LF>-1.109062e+02<CR><LF>-1.139062e+02<CR><LF>-1.124062e+02<CR><LF>-1.124062e+02<CR><LF>-1.109062e+02<CR><LF>-1.154062e+02<CR><LF>-1.124062e+02<CR><LF>-1.139062e+02<CR><LF>-1.109062e+02<CR><LF>-1.154062e+02<CR><LF>-1.154062e+02<CR><LF>-1.139062e+02<CR><LF>-1.109062e+02<CR><LF>-1.154062e+02<CR><LF>-1.124062e+02<CR><LF>-1.139062e+02<CR><LF>-1.124062e+02<CR><LF>-1.139062e+02<CR><LF>ch> "
1712210952503 > "<CR>"
1712210952523 "<CR><LF>?<CR><LF>ch> "
Log output:scan 527000000 532000000 21 3 'comment Scan 1 complete response shown <20240322130542.741 RX> 527000000 -8.793750e+01 0.000000000 527250000 -8.993750e+01 0.000000000 527500000 -8.946875e+01 0.000000000
I'll have a go at receiving response for this command
Sub Process_Globals
'Private fx As JFX
'Private MainForm As Form
'Private xui As XUI
'Private Button1 As B4XView
Dim bc As ByteConverter
Private sp As Serial
Private AStream As AsyncStreams
Private TsaCommand As String 'the command that was sent (so that when we get a response, we know for what)
Private TsaBuffer As StringBuilder 'collect up incoming response bytes
Private TsaStartOfPacket As String 'marker string immediately before response bytes
Private TsaEndOfPacket As String 'marker string immediately after response bytes
Private TsaCommandQueue As List 'list of commands still to be sent
End Sub
Sub AppStart (Form1 As Form, Args() As String)
'MainForm = Form1
'MainForm.RootPane.LoadLayout("Layout1")
'MainForm.Show
'Dim SupEnc() As String = bc.SupportedEncodings
'For I = 0 To SupEnc.Length - 1
' Log(I & TAB & SupEnc(I))
'Next
sp.Initialize("")
Dim ports As List = sp.ListPorts
If ports.Size = 0 Then
Log("No serial ports found")
Return
End If
For I = 0 To ports.Size - 1
Log(I & TAB & ports.Get(I))
Next
Log("Opening serial port " & ports.Get(0))
sp.Open(ports.Get(0))
AStream.Initialize(sp.GetInputStream, sp.GetOutputStream, "AStream")
Dim TestCommands() As String = Array As String( _
"" , _
"version" , _
"help" , _
"data 2" , _
"capture" , _ 'returns binary data 320 x 240 pixels x 2 bytes, with no terminating CR LF
"scan 527000000 532000000 21 3" , _
"howdy" , _ 'invalid
"DATA 2" , _ 'invalid
"daTa 2" , _ 'invalid
"data" , _ 'invalid
"data -1" , _ 'invalid
"data 7" , _ 'invalid
"" _
)
TsaCommandQueue.Initialize
TsaCommandQueue.AddAll(TestCommands)
TsaSendNextCommand 'start automatic processing of queued commands
Sleep(2000) 'enough time for 6 commands, given 300 ms gap between commands
TsaCommandQueue.Clear 'delete commands still in queue
End Sub
'reveal control codes
Sub Readable(S As String) As String
Return S.Replace(Chr(10), "<LF>").Replace(Chr(13), "<CR>")
End Sub
'cap string length at specified maximum
Sub CapLength(S As String, MaxLength As Int) As String
If S.Length > MaxLength Then
Return S.SubString2(0, MaxLength - 3) & "..."
Else
Return S
End If
End Sub
'log label + quoted string
Sub LogString(L As String, S As String)
Log(L & TAB & S.Length & TAB & "= """ & CapLength(Readable(S), 200) & """")
End Sub
'send command to TSA
Sub TsaSendCommand(S As String)
TsaCommand = S
TsaBuffer.Initialize
AStream.Write(bc.StringToBytes(TsaCommand & Chr(13), "ISO-8859-1"))
TsaStartOfPacket = S & Chr(13) & Chr(10)
TsaEndOfPacket = "ch> "
'prepend CR LF to TsaEndOfPacket except for binary data responses
If TsaCommand.StartsWith("capture") Then
Else
TsaEndOfPacket = Chr(13) & Chr(10) & TsaEndOfPacket
End If
End Sub
'is called when receive TSA response
Sub TsaHandleResponse(LaCommand As String, LaResponse As String)
LogString(" Command", LaCommand)
LogString(" Response", LaResponse)
Sleep(300) '300 ms gap between commands
TsaSendNextCommand
End Sub
Sub TsaSendNextCommand
If TsaCommandQueue.Size > 0 Then
Dim NextCommand As String = TsaCommandQueue.Get(0)
TsaCommandQueue.RemoveAt(0)
TsaSendCommand(NextCommand)
Log("<<< sent command """ & NextCommand & """ with " & TsaCommandQueue.Size & " more to go >>>")
End If
End Sub
Sub AStream_NewData (Buffer() As Byte)
TsaBuffer.Append(bc.StringFromBytes(Buffer, "ISO-8859-1"))
Dim BufferContainsSpaceFlag As Boolean = False
For I = 0 To Buffer.Length - 1
If Buffer(I) = 32 Then 'ASCII 32 = space
BufferContainsSpaceFlag = True
Exit
End If
Next
If BufferContainsSpaceFlag Then 'might have just received terminating sequence CR LF ch> space
Dim TempBuffer As String = TsaBuffer.ToString
Dim I2 As Int = TempBuffer.IndexOf(TsaEndOfPacket)
If I2 > -1 Then
Dim I1 As Int = TempBuffer.IndexOf(TsaStartOfPacket)
If I1 > -1 Then
If I1 < I2 Then
Dim TempResponse As String = TempBuffer.SubString2(I1 + TsaStartOfPacket.Length, I2)
TsaHandleResponse(TsaCommand, TempResponse)
End If
End If
TsaBuffer.Remove(0, I2 + TsaEndOfPacket.Length)
End If
End If
End Sub
Dim TestCommands() As String = Array As String( _
"" , _
"version" , _
"help" , _
"data 2" , _
"capture" , _ 'returns binary data 320 x 240 pixels x 2 bytes, with no terminating CR LF
"scan 527000000 532000000 21 3" , _
"howdy" , _ 'invalid
"DATA 2" , _ 'invalid
"daTa 2" , _ 'invalid
"data" , _ 'invalid
"data -1" , _ 'invalid
"data 7" , _ 'invalid
"" _
)
WARNING: package com.sun.javafx.embed.swing.oldimpl not in javafx.swing
Waiting for debugger to connect...
Program started.
0 COM4
Opening serial port COM4
<<< sent command "" with 12 more to go >>>
Command 0 = ""
Response 1 = "?"
<<< sent command "version" with 11 more to go >>>
Command 7 = "version"
Response 23 = "tinySA_v1.4-40-g2f63e1c"
<<< sent command "help" with 10 more to go >>>
Command 4 = "help"
Response 441 = "commands: version reset freq dac sweep_voltage saveconfig clearconfig data frequencies scan scanraw zero sweep test touchcal touchtest pause resume repeat status caloutput save recall trace trigger..."
<<< sent command "data 2" with 9 more to go >>>
Command 6 = "data 2"
Response 4348 = "-8.646875e+01<CR><LF>-8.696875e+01<CR><LF>-8.846875e+01<CR><LF>-8.896875e+01<CR><LF>-8.796875e+01<CR><LF>-8.746875e+01<CR><LF>-8.846875e+01<CR><LF>-8.546875e+01<CR><LF>-8.646875e+01<CR><LF>-8.79687..."
<<< sent command "capture" with 8 more to go >>>
Command 7 = "capture"
Response 153600 = "ÿÿÿÿ..."
<<< sent command "scan 527000000 532000000 21 3" with 7 more to go >>>
Command 30 = "scan 527000000 532000000 21 3"
Response 796 = "527000000 -8.696875e+01 0.000000000 <CR><LF>527250000 -8.796875e+01 0.000000000 <CR><LF>527500000 -8.546875e+01 0.000000000 <CR><LF>527750000 -8.796875e+01 0.000000000 <CR><LF>528000000 -8.696875e+..."
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?