Go Down

Topic: PC to Arduino Serial.Read: display incoming with Serial.Print? (Read 1 time) previous topic - next topic

gcm2

I've written a .Net program to send text strings to the Arduino thru serial port - it's working fine. I grabbed code from this posting:

http://www.adafruit.com/forums/viewtopic.php?f=8&t=9918

and here's some sample .Net code (I used VB because that's what I had loaded: MSoft VB Express, free - I know C# just as well):

====
    Dim port As SerialPort
====
        Try
            port = New SerialPort("COM4", 9600, Parity.None, 8, StopBits.One)
            port.DtrEnable = True
            port.Open()
            If Not port.IsOpen Then
                btnOn.Enabled = False
                btnOff.Enabled = False
            End If
        Catch ex As Exception
            MessageBox.Show("Could not open port")
        End Try
====
        port.Write("LEDOn" + vbCr)
====

All I did in the 1st attempt was turn on/off led's at button_click events.

Anyway - here's the question. When the PC opens the port (COM4), it holds it so that a Serial.Print statement in the Arduino will fail saying the port is in use by another app. Quite understandable, however what if I don't know what text is coming and I want to see what it is and debug? Is there another way to intercept the Serial stuff coming in over the port?

OK, to be fair, I also had a LCD hooked up so I could display the received text, but is not my intention to have to hook up LCD in future projects - too many wires!

Thanks!

zoomkat

Quote
When the PC opens the port (COM4), it holds it so that a Serial.Print statement in the Arduino will fail saying the port is in use by another app. Quite understandable, however what if I don't know what text is coming and I want to see what it is and debug? Is there another way to intercept the Serial stuff coming in over the port?


You need to write your pc code to accomidate bidirectional communication while the pc com port is open (the arduino really doesn't know weather a com port is open or closed). You might use the serial monitor to debug your code. Note that the arduino is normally reset every time the pc com port is opened.
Google forum search: Use Google Search box in upper right side of this page.
Why I like my 2005 Rio Yellow Honda S2000  https://www.youtube.com/watch?v=pWjMvrkUqX0

liuzengqiang

Google something like serial peek or sniff or virtual serial. Some virtual serial software can let you create virtual serial to attach to actual serial and redirect. They can also show the traffic.
Serial LCD keypad panel,phi_prompt user interface library,SDI-12 USB Adapter

gcm2

I'm sorry I should have worded my original to say that I'm attempting to use the Serial Monitor in the IDE, and the Monitor says the port is in use (PC program is running), and will not display Serial.Print statements.
I didn't get the point across how I wanted to!  :(

Go Up