Storing serial data for later review

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.

Suggestions? I am using XOJO Lite

Jim

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.

Thats what I would like to do ideally…How is what I do not know how to do as I am quite the beginner with this.

Thats what I have to work with.

Its a simple serial device. 4 byte payload. Three databytes and a /CR. Nothing special.

JIm

Simple:

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.

Your hard drive is way faster than a 9600 bauds communication so you can write directly to disk any time you get some data.

  1. Create a binary or text output stream to a file
  2. Start your Serial process
  3. Write everything coming from Serial to the output stream
  4. Close the output stream

That way, you get all the data

Use TextOutputStream in the same location you use Serial.ReadAll

Ok, I am reviewing the Create Text File example.

Some good tips I see posted…now if only I understood everything that has been suggested…More reading!!

Thanks
Jim

Easy relax, take some coffee and go for it…:wink:

1 Like

Don’t drink coffee, but I get the point LOL

1 Like

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
1 Like

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

String.ReplaceLineEndings(EndOfLine.Windows, EndofLine.Unix)

Converts all windows crlf to new line LF

Thank you but the EOL.Unix looks for CHR(10) and the \CR is CHR(13)

I am only outputting a \CR…no \LF

you could also use .ReplaceAll

So what I am understanding is that there is no simple way to detect the \CR as the EndOfLine?

EDIT:
This Works:

If data.IndexOf(Chr(13)) > -1 Then

Ok, back to creating the storage file :slight_smile:

Jim

something like
data=data.ReplaceAll(chr(13),chr(13)+chr(10))

surprised no one thought to suggest a sqlite database since thats usable in a lite license

1 Like

Sorry for being dense, but what does that do?

EDIT:
I see what that does but my reply in post 14 works so I am good there. I will try the suggestions in creating the text file now Thanks

that replace your 13 with 13 10 the
windows line break.

1 Like