Greetings!
I have my Serial port working like a champ thanks to you folks, now I need to take the data and store it, then I want to review it.
Heres the overview:
The data is coming into the serial port at 9.6k
The data is coming in every 50 milliseconds
The data streams in for about ten seconds and then stops
I would like to store this information some how and then be able to review it. Either as a TXT, CSV, or simply in a XOJO txt window.
9600 baud is really slow.
you could forward the stream into textfile or update into a sqlite database if you fear that something get lost.
but i think just a string property is enough.
you could get a block, process this block and remove it from buffer.
you not wrote what device send data. if you need to review it maybe a textarea or listbox would be ok.
if you have a file you also hava a logbook which you can open with a editor.
Open the examples files/documents then you’ll see how tonuse a textoutputstream to write your data to a line in a file, append the resulting data from the dataavalable event and write a line to the textoutputstream.
You’ll see how you do it, when ilusing one of the examples that ships with your xojo installation.
Edit; make sure you have all the data you expect in the dataavilable event. By using .lookahead, after it’s all ok, use .Read or .ReadAll and store that in your binary or text file.
minimal example for textstream, i used for Windows Desktop Apps
Var path As FolderItem = SpecialFolder.ApplicationData.Child("YourAppName")
If path.Exists = False Then path.CreateFolder
Var f As FolderItem = path.Child("Data.txt")
Var st As TextOutputStream = TextOutputStream.Create(f) ' or .Open(f) is the file exists if f.Exists
st.Write "Blah"
st.Close
System.DebugLog "Saved to " + f.NativePath
Probably I am the least qualified to give examples, but this is how I use it in one of my apps.
Application Properties
pFileName
pFileStream
On a checkBox to determine whether or not I want to log my serial content
Sub Action()
If Me.Value Then
// open file when checkbox is selected
// create unique log file name identifier
Dim s As String
Dim d As New Date
s = "Stream_" + d.SQLDate + "_" + Str(Ticks()/60,"0")
// open dialog for log file creation
pFileName=GetSaveFolderItem(FileTypes1.Text, s)
If pFileName <> Nil then
pFileStream=TextOutputStream.Create(pFileName)
Else
Me.Value = False
End if
Else
// close file when checkbox is de-selected
If pFileName <> Nil then
pFileStream.Close()
pFileName = Nil
End if
End If
End Sub
On the close event in case the file is still open when the application is closing
Sub Close()
// close log file if opened
If pFileName <> Nil then
pFileStream.Close()
pFileName = Nil
End if
End Sub
Making some progress, but I have a dilemma. My device sends three bytes and a /CR But:
“EndOfLine.Windows” wants to see a \CR + \LF
How do I set this up to only look for the \CR?
Var data As String
data = Me.LookAhead(Encodings.ASCII)
If data.IndexOf(EndOfLine.Windows) > -1 Then
TextArea1.Value = TextArea1.Value + Me.ReadAll(Encodings.ASCII)
End If