Searching Incoming Serial Data

Greetings!
I was trying to get visual studio to filter through the incoming serial data it is receiving from an Arduino. The program shows the incoming data, so I know the serial port is working, but I'm not sure how to get it to look through that data ( I was thinking
I could use StreamReader to do this). My goal is this: When certain data is received, change the background color of a textbox. I am very new at this and any direction would be appreciated! I feel like i'm throwing spaghetti at a wall... 
Here is my current code:
Imports System
Imports System.Threading
Imports System.IO.Ports
Imports System.ComponentModel
Imports System.IO
Public Class Form1
Dim myPort As Array
Delegate Sub SetTextCallBack(ByVal [TEXT] As String)
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
myPort = IO.Ports.SerialPort.GetPortNames()
portCmbo.Items.AddRange(myPort)
End Sub
Private Sub startBtn_Click(sender As Object, e As EventArgs) Handles startBtn.Click
SerialPort1.PortName = portCmbo.Text
SerialPort1.BaudRate = baudCmbo.Text
SerialPort1.Open()
startBtn.Enabled = False
closeBtn.Enabled = True
End Sub
Private Sub closeBtn_Click(sender As Object, e As EventArgs) Handles closeBtn.Click
SerialPort1.Close()
startBtn.Enabled = True
closeBtn.Enabled = False
End Sub
Private Sub SerialPort1_DataReceived(sender As Object, e As SerialDataReceivedEventArgs) Handles SerialPort1.DataReceived
ReceivedText(SerialPort1.ReadExisting())
End Sub
Private Sub ReceivedText(ByVal [text] As String)
If Me.inputTxtBox.InvokeRequired Then
Dim x As New SetTextCallBack(AddressOf ReceivedText)
Me.Invoke(x, New Object() {(text)})
Else
Me.inputTxtBox.Text &= [text]
End If
End Sub
Private Sub outputTxtBx_TextChanged(sender As Object, e As EventArgs) Handles outputTxtBx.TextChanged
Dim myReader As StreamReader = New StreamReader("Me.inputTxtBox")
Dim line As String = ""
End Sub
End Class
ps: If there is an easier way of doing this, please let me know!

You should read a good book on "Communications".  When processing received data (from any device) you need to wait until you get the end of message before parsing the data.  The data will be received in chunks that can contain from 1
to a million bytes.  When you get the word "Hello" you could get "H" then "ello" or "Hel" and then "lo".  You can't start looking through the data until you get the entire word "Hello". 
So you first have to define a protocol for sending commands to the device and the amount of data that gets returned.  So normally you have to terminate a message using one of the following methods
1) Ascii : Terminate a message with a fix character like a return or EOM.
2) Ascii or binary : Includes a bytes count at the beginning of the message.
3) Ascii or binary : Each type message is a fixed length.
You can use combination of the 3 methods above.
jdweng

Similar Messages

  • Precise time stamping of serial data

    I am having trouble with precise timestamping  of incoming serial data recived on 4 ports using 4 separate threads that continually attempt to read a byte.
    When the expected frame is recieved the data is tagged with a time stamp.
    The issue seems to be windows xp or the serial ports themselves.  I am using an xsens serial to usb, 2 lavaport serial cards and the built in serial port.
    Any suggestions for precise timing?

    there is some hints:
       -for milisecond precise timestamp, you can use GetLocalTime,GetSystemTime or GetTickCount.
        But to achieve true milisecond scale, you need use timeBeginPeriod(1)/timeEndPeriod(1) otherwise you get 10-16ms scale depend on system
        (please read help pages on msdn for timeBeginPeriod function)
       - create your program to not use CPU too much(no pooling,just message and/or sync wait),
         or even better, do not run any other apllication which consume lot of CPU/DISK resources on the same PC
       - for serial communication (but this also depend on baud rate) you can try to set send/receive driver buffer to 1 (from windows device manager)
       - try different serial port card/converter(with different drivers)
       - if still need something to try, set higher process and thread priority (SetPriorityClass,SetThreadPriority)
    After all of this, on windows, there are no precise timing.Even if you do everything you can do, there is still chance to get time gap, but you can detect it (in milisecond precision)

  • Reading and analyzing serial data

    Hello,
    My question is about interpreting periodic serial data.
    I'm trying to read a serial rs232 port, through which I'm receiving periodic data which is made up of 4 repeating messages.
    Each message consists of several parameters of various length and fomates (for example, the first parameter could be an unisgned byte while the second parameter could be a word-long float). Each message begins and terminates with known character sequences.
    I need to read this periodic data and display it to the user, so that each of the parameters (of which the messages are made) is displayed
    by a different indicator.
    Right now, I've used the basic read/write rs232 LabView tutorial but now I'm pretty much stuck...
    I've built a similar program using Visual Basic and I've started using LabView in order to build better user interfaces but so far I'm stuck...
    Any suggestions?

    First, I think you really could have come up with a better user name then falling asleep on your "N" key.
    Data that comes in through the serial port is a string.  So your problem really comes down to how to parse the string into its respective parts.  Look at the functions on the string pallete.  Functions such as Match String, Search/Split String, or Scan String for Tokens, should do what you need.  Once you have the parts broken up, the String to Number conversion functions would convert the strings into their appropriate datatypes.

  • Handling serial data

    I'm not sure how to handle the serial data I'm receiving from a touchscreen panel.
    All I want to do is display the two sets of coordinates, which are made up of two 4 digit numbers.
    What I'm struggling with, is the carriage return/line feeds (Cr/Lf).
    For example I receive,
    TP  CrLf                  TP = touchscreen pressed
    0100 CrLf             0100 = first set X of coordinates where these values may be anything from 0000 to 4000 and like wise for all coordinates
    0200 CrLf             0200 = first set Y of coordinates
    TR CrLf                   TR = touchscreen released
    0100 CrLf             0100 = last set of X coordinates
    0200  CrLf            0200 = last set of Y coordinates
    If the stylus is dragged on the touchscreen, then I may receive numerous TP CrLf plus the coordinates before I final get the touchscreen release set. 
    If I didn't have all the CrLf's but just one CrLf' after TP nnnn nnnn it wouldn't be problem.
    I've had a go using shift registers, but I'm unsure of the best way forward.
    Some guidance would be most appreciated.
    Solved!
    Go to Solution.
    Attachments:
    Shift1.vi ‏17 KB

    I would advise to have several readouts in one iteration of the main loop:
    First readout - search the received string for valid command (TP or TR).
    If found: run the FOR LOOP to read 2 more times - you will get a string array of your coordinates.
    If not found: skip, go to next iteration.
    First check this: Each readout should give you one message (TP, TR, or coordinates) and properly terminates on linefeed.
    You do not need string concatenations from previous iterations, all shift registers. If not, something is wrong with ViSA settings: wrong termination char, etc.

  • Using Serial Port for Non-Serial Data Acquisiton

    I searched the forums and couldn't find anything related to this topic.
    I saw that it was possible to use the parallel port for simple digital I/O and I was hoping the serial port can be configured the same. It seems all the VISA VI's only want to use the serial port to recieve ASCII chars at a given baud rate, but is it possible to simply poll the status of the serial line at my own speed to see if it is high or low, kind of like a single pin DAQ?
    It seems it would be possible as long as the serial data is read and controlled by labview and not by Windows. Let me know if you have any ideas how to approach this problem, or any feedback as to why it is not possible.
    Thanks everyone!
    Solved!
    Go to Solution.

    Select Property>Serial Settings>Modem Line Settings. For example, the CTS State is an input to the pc.
    Using these lines is a very poor replacement for a scope or DAQ board. The only things you can get back is Asserted, Unasserted, or Unknown. The range of acceptable signals is quite large. Anything between +3 and -3 is an unknown state. Your other signals are +/3 to 15 volts. what kind of signals do you actually want to capture?
    edit: There is no such thing as VISA Status so I have no idea what you are actually using.
    Message Edited by Dennis Knutson on 07-20-2009 11:09 AM

  • Search help for date in VC

    Hi, 
    I have created an iview in Visual Composer for a query. it contains date field on selection variable fomr. i tried entering date in various format, but it gives an error : variable expects interval value ; enter an interval".
    can we provide search help for date field in VC?
    Regards,
    Sonali.

    Hi,
    You have to create search help it avoid inconsistency.
    Thanks & Regards,
    Venkat.

  • "Searching for movie data in file [filename]" and iDVD hangs.

    I have a project I saved and I want to open and make a change to. iDVD loads the project and displays the title. When I click to edit one of the scene selection menus, it goes off "searching for movie data" and hangs until I kill it.
    Anyone have any ideas how to fix this? I really don't want to have to re-do my project.
    Thanks!
    Scott

    This frequently helps solve some problems. Quit iDVD. Search for the file named com.apple.iDVD.plist and trash it. (A new one will be created next launch of iDVD.) Or look in: User/Library/Preferences. This may solve project loading errors too. Restart and use Disk Utility to Repair Permissions.
    You'll need to reset some Preferences.

  • Can't open MOV files in FCP: "Searching for movie data in file..."

    I know this has been posted before, but none of them seem to match up to what I'm all of a sudden dealing with. I have 4 MOV files that I'm converting to WMV. Movie 1 & 2 exported fine. Now, however, any time I try to open another MOV file, I get an error that it's "Searching for movie data in file..." and the file name is ALWAYS the same. The weird thing is, the file it's looking for is none of the 4 movies I'm working with. So how did the first two work and this pop out of nowhere??
    I have cleared out the render cache. Dumped all the cache and prefs files I can find, etc. Restarted the machine. Started FCP with the Option key held down.
    I've searched everywhere, but people usually seem to come across this error while opening FCP (I'm running 6.0.6). This only happens when I open a MOV file (oddly, I can open WMV files in FCP without issue).
    HELP!

    So, I open the movies in QT and the EXACT same thing is happening. So it appears the guy who created the videos did something when he was making them (probably made a reference files along the way). I'm having him re-export the MOV files.
    So, it's not a FCP issue.....

  • Sometimes, when I click on a link, I see in the address bar the words: "Search bookmarks and history" (greyed out) just before I am taken to the link. Should I be worried? Is someone searching my personal data? Is this just a FireFox error msg?

    Sometimes, when I click a link on a web page, I see in the address bar the words: "Search bookmarks and history" (greyed out) just before I am taken to the link I clicked. A moment later, when I'm at the link, its address appears in the address bar, and all is normal. It seems that this happens only from some particular sites. Is FireFox reporting that my bookmarks and history are being searched?
    Should I be worried? Is someone searching my personal data? Is this just a FireFox error msg when it has trouble finding the website I requested?

    That is OK. Firefox will only display the link in the location bar after the DNS look up has succeeded and a connection to the server has been established. Until that has been done you see the default setting for the location bar: Tools > Options > Privacy > Location Bar: When using the location bar, suggest

  • Simple Question: How to search for a date value in SELECT

    Probabily a simple question, but in a SELECT statement, how do you do a search for a date value in the WHERE clause?
    example:
    Select * From Example
    Where date = 01/01/2001
    I know its not as simple as that, but what change has to occur to make it do what that example implies?
    Thanks In Advance.

    If you want to avoid the conversion part(to_date) you will need to specify the date in the format as ur nls date format.so the same query might not work if you change ur nls date format.
    so it is advisable to give it in general format.
    ie where date_col=to_date(01-01-2000,'dd-mm-yyyy')

  • Steady Stream of "Searching for movie data in the file..." Error Messages

    My iMovie has been crippled by error messages that pop up whenever I try to accomplish anything in iMovie. I always see "Searching for movie data in the file 'healyintro.mov'" for a few minutes, then "The movie file 'healyintro.mov' cannot be found. Without this file, the movie cannot play properly." I cannot actually use iMovie because of these errors.
    I've tried everything from reinstalling iMovie to removing application support files to removing my iMovie Events and iMovie Projects folders to creating a .mov file, calling it healyintro.mov and seeing if that'll shut iMovie up – nothing works.
    Once in a while, iMovie will ask for a different movie file, with the same problem.
    Any ideas?

    I am having the same issue. I don't know what the previous poster means by allowing the system to continue, since I'm prompted with a "Cancel" / "Search" dialog after each missing clip. Slight digression: "Search" is not even the correct term here according to UI guidelines ("Choose" or "Locate" might be better choices given the file picker dialog that results).
    I'm actually using Aperture to relocate my video masters on removable media, which is a very nice feature of Aperture, but completely breaks iMovie unless it's connected. Seems like a pretty major oversight.... can we just have it fail more gracefully here and allow us to work with new stuff without getting hung up on missing movie clips from the past?

  • How to list searched email in dATE ORDER

    There seems to be a problem with searching for email with my iphone5s.Unlike with my iphone 4s it does not display the results in date order. The most recent emails are shown buried further down in the list. I have asked the gurus at two Apple shops and nobody seems to be aware of the problem or can assist. I would have imagined this would have been readily observed by Apple in the initial beta testing so am surprised it has not been sorted before release. I have uploaded ios7.0.3 so I am up to date.

    i think there is no settings to sort the search results by date, in order to search by time, you can type the month name followed by your search query
    something like "February meeting"
    look into mails section  in the ios& manual
    http://manuals.info.apple.com/MANUALS/1000/MA1565/en_US/iphone_user_guide.pdf

  • Using Digital I/O to generate serial data stream

    Hello All,
    I am in need to generate a serial data stream. HW I use is MIO-16E-10.
    I am planning to use the digital line out to generate the serial data stream.
    I seems that if I use the wait timer the minimum pulse width I can get is
    1ms. But for my application the pulses have to be shorter than that. I was
    wondering about an alternative way to achive this. Any one who has worked
    with a similar application please help!
    Thanks in advance!
    Anand.

    Anand,
    What you are looking to do is not possible with the digital lines on the board you have.
    Depending on what other connections you have on the board, you could use one of the two analog outputs to generate your required serial data stream using pattern generation. Check the DAQ solution wizard=>Custom DAQ applications=>Analog Output=>Generate continuous sine wave. This example should give you a baseline to get started. Substitute the sine wave generator for your desired digital stream Logic 0 =0V, Logic 1=5V.
    If you need more than 2 lines, or some form of handshaking, I would suggest using the PCI-6534 or (DIO-32-HS as it was previously called) This will give you the ability to generate serial data streams with timing and/or handshaking.

  • Search help for DATE field

    HI all,
    I want to attach search help for a DATE field created in screen painter.
    For PERNR, PREM is attached. Similarly what is the statndard search help name for DATE field?
    Thanks,
    Shanthi.

    Hi ,
    Declare the date field as sy-datum ,
    parameters : date type sy-datum .
    This shud bring the standard search help for date .
    Thanks ..Get back for any issues.
    Anil

  • To implement search help for date and time fields details

    how can i implement search help for date and time fields in screen painter

    Hi
    Declare the variables as sy-datum and sy-uzeit or any other pre-defined data typ of date and ime types. Serach help will automatically comes.
    Aditya

Maybe you are looking for

  • How do I use my new External Hard Drive on my Macbook?!?

    I recently bought an external hard drive for my PC/Macbooks and have run into a little problem. To make a long story short, I reformatted the external hard drive in Window's XP (NFIT Format, not FAT) because that's the only way it would recognize the

  • Why are GarageBand .aif files in trash after session

    Hello, After doing several hours of recording in GarageBand 10.0.2, saving take,1, 2, 3, all different for reference later I close. In the TRASH there are this Why are they deleted to the trash and is it ok to EMPTY with out effecting the song? Thank

  • Interface with Peoplesoft for Org structure

    Please let me know if there is way to interface with Peoplesoft to get the org chart (employees and their reporting details along with Org structure) and update the SAP Org hierarchy (PPOME). Any type of interfacing (file, RFCs, real time) options av

  • Can't click newer Flash banners

    Hello. I'm a web developer for a small Danish marketing company, and get sent Flash banners from advertisers, but we don't own Flash ourselves, so I can't get official support. I'm also not very good at Flash myself, so bear with me. Problem is, that

  • 1080 x 1440 comes out as 1440 x 810

    I am sending a 1080x1440 hdv sequence out to compressor 3 for export as a HD Mpeg 2 file with audio (HD high quality 30 minuites preset) after about 10 attempts and hours of time wasted the resulting video files keeps coming out at 1440x810! I have t