Saving Serial Port Data To File

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • crampio
    New Member
    • Nov 2007
    • 3

    Saving Serial Port Data To File

    Hello everyone,

    I generally look at Google and other websites before I post a question, but trust me I still cannot find and answer to this problem.

    I'm using VB.net. My problem being is that I don't know how to redirect the serial port output to a selected file. I looked in the forum but no luck.

    Here is the sequence of events.

    User selects a file to write to. No problem here.
    Sends a command to the equipment to start outputting text. No problem here.

    At the moment the text is going to text box. Is easy to wait for the output to finish and then save the file. But I do not want this. The user does not need to see the text. Just some sort of indication that data is being sent. No Problem here.

    Is more like a Serial Port Data Log.

    Friend Sub DataReceived(By Val sender As Object, ByVal e As SerialDataRecei vedEventArgs)

    Dim newReceivedData As String

    Try
    ' Get data from the COM port.

    newReceivedData = selectedPort.Re adExisting

    ' Save the number of characters received.

    receivedDataLen gth += newReceivedData .Length

    RaiseEvent UserInterfaceDa ta("AppendToMon itorTextBox", newReceivedData , Color.Black)

    ' I guess I could choose to Write the line to the file instead.

    Catch ex As Exception
    DisplayExceptio n(ModuleName, ex)
    End Try
    End Sub

    Any suggestions? Thanks!
  • Killer42
    Recognized Expert Expert
    • Oct 2006
    • 8429

    #2
    Isn't it just a matter of opening the text file in Append mode and writing the data to it?

    Comment

    • crampio
      New Member
      • Nov 2007
      • 3

      #3
      Originally posted by Killer42
      Isn't it just a matter of opening the text file in Append mode and writing the data to it?
      Hi Killer,

      Opening the data file and appending to it is not the problem. Is just where to put the code to write to the file while the serial port is outputting data. For example
      when the serialport read.existing happens then do a file writeline. That's all I need.

      Thanks for your reply.

      Comment

      Working...