A brief overview, I have a device that is streaming data every thirty seconds via the serial port. The Python program, within a thread, is capturing the data and is adding a date and time to a line of data which is then appended to a csv file. I am also working on a way of analyzing the data that is in the file, probably will be using a spreadsheet.
The Python program, in the foreground, can start a log file, stop a log file, capture an instance of incoming data, and other things. I am trying to see if I can replicate this in freeBasic console mode, then if I am satisfied with the results try, to make it a GUI program
Thanks
Code: Select all
' tthread.bas
'
' November 5, 2017
'
Dim Shared As String inBuff, buffer
Dim As String baud,port
baud = "115200"
port = "/dev/ttyUSB0:"
Open Com port & baud & ",n,8,1,cs0,ds0,cd0,rs" As #1
If Err <> 0 Then
Print "Error opening", port
End If
Print port+" open"
' Thread for incoming data stream
' Runs in the background???
Sub commthread(param As Any Ptr)
print "mythread is running"
'Open "test1.csv" For Append As #2
Open "test1.csv" For Append As #2
' Keep the thread running
do
' Check Com port for activity
While LOC(1) > 0
buffer = Input(LOC(1),#1)
Wend
sleep 200,1
'Put #2, ,buffer
loop
End Sub
'' Launch commthread thread
Dim As Any Ptr thread1 = ThreadCreate(@commthread, 0, 64)
'' Main
' Runs in the foreground???
Print
do
' Terminal user I/O
input "> ",inBuff
If inBuff = "quit" Then
Exit Do
Elseif inBuff = "data" then
Print buffer ' Print out what is in the com buffer
Else
Print " Invalid Command"
End If
Sleep 1,0
loop until multikey(&H01) ' Esc to end program
Print "Program End!"
Close #1
End