Netduino home hardware projects downloads community

Jump to content


The Netduino forums have been replaced by new forums at community.wildernesslabs.co. This site has been preserved for archival purposes only and the ability to make new accounts or posts has been turned off.
Photo

Serial Port Problem


  • Please log in to reply
10 replies to this topic

#1 Joe Griffith

Joe Griffith

    Advanced Member

  • Members
  • PipPipPip
  • 32 posts

Posted 01 January 2011 - 11:21 PM

I'm attempting to use both serial ports at the same time and have run into a problem. I've narrowed the problem to a single line of code but don't know what to do about it. In a test program I'm using COM1 to listen for a string from a PC and turn the LED on or off. This works fine while I'm still connected to the Netduino through the USB but when I disconnect the USB and power up through power connector it fails. The problem is caused by attempting to also use COM2. Instantiating the port and opening it don't cause a problem but adding a handler for the DataReceived event does. Once the handler for COM2 is added the DataReceived event no longer seems to fire for COM1 while using external power. It works fine when powered throught the USB port. I've attached a small test program that illustrates the problem (along with a little VB app to test it). I'm using an original Netduino (not the plus or mini) and I'm using firmware version 4.1.0.5.

Attached Files



#2 Chris Walker

Chris Walker

    Secret Labs Staff

  • Moderators
  • 7767 posts
  • LocationNew York, NY

Posted 02 January 2011 - 12:48 AM

Very interesting. We'll load this up on a test machine and see what we can find. Two quick questions: 1. have you tried wiring up the DataReceived event handler after opening the port (instead of before opening it)? We're currently working on an issue in the .NET MF core where the order of wiring it up makes a difference... 2. Have you tried reading data for both in a loop (not using events--but just looking for data to be received on two threads in a tight loop over and over again)? This narrows down the problem to UART vs. delegate issues... Chris

#3 Joe Griffith

Joe Griffith

    Advanced Member

  • Members
  • PipPipPip
  • 32 posts

Posted 02 January 2011 - 02:13 AM

Adding the handler after the port is open works!!! It works if I do it for both ports or if I just do it for the second one. If you only do it for the first one it still fails. This solves a problem I've had for weeks (it's very hard to debug a problem that only occurs when you aren't running in visual studio). I'll try to build something that reads the ports in a loop although that doesn't fit in with the application I'm trying to work on. In any case thanks for solving my problem.

#4 Chris Walker

Chris Walker

    Secret Labs Staff

  • Moderators
  • 7767 posts
  • LocationNew York, NY

Posted 03 January 2011 - 07:05 AM

Hi Joe, That code sample was just what we needed. This bug has been around since .NET MF 3.0, and we weren't able to reliably reproduce it until you posted this sample. Long story short, uninitialized values that were being initialized during the SerialPort.Open() function call...but were needed when the event was being wired up. We'll post the bugfix back to the .NET MF core so that it's fixed on all .NET MF boards. Anyway, this has been fixed in the v4.1.1 alpha 5 firmware. If you have a chance to test your application against the new firmware (with the event wiring before SerialPort.Open), we'd really appreciate it. :) Thanks! Chris

#5 Joe Griffith

Joe Griffith

    Advanced Member

  • Members
  • PipPipPip
  • 32 posts

Posted 04 January 2011 - 02:49 AM

I flashed 4.1.1.0 a5 and am happy to report that, for me at least, everything now works regardless of the relative positions of adding the handler for the DataReceived event and opening the port, and it works both when connected through the USB port or when powered from an external source. Thanks for publishing the fix so quickly!

#6 Chris Walker

Chris Walker

    Secret Labs Staff

  • Moderators
  • 7767 posts
  • LocationNew York, NY

Posted 04 January 2011 - 03:10 AM

I flashed 4.1.1.0 a5 and am happy to report that, for me at least, everything now works regardless of the relative positions of adding the handler for the DataReceived event and opening the port, and it works both when connected through the USB port or when powered from an external source.


Awesome. Thank you for testing the bugfix!

Chris

#7 Charles

Charles

    Advanced Member

  • Members
  • PipPipPip
  • 192 posts

Posted 04 January 2011 - 11:58 PM

And thanks for the insight in the first place! I had actually just encountered this problem last night and hadn't had a chance to write it up yet!

#8 EvanLaske

EvanLaske

    New Member

  • Members
  • Pip
  • 6 posts

Posted 02 June 2011 - 03:13 PM

Anyway, this has been fixed in the v4.1.1 alpha 5 firmware.


I know this is probably a stupid question, but is this fix included in the 4.1.1 beta firmware as well. (I just don't want to be wrong in assuming that everything from alpha made it into the beta)

Joe,

I also wanted to make sure the problem that was occuring is the same one I am experiencing: As long as I didn't put the code loaded on the netduino into debug mode through VS (whether that's because I reset it with the reset button, unplugged and re-plugged in the USB cord, or booted with only the power port). The only way that COM2 worked was through starting the code by deploying in VS and having it boot it up.

#9 Joe Griffith

Joe Griffith

    Advanced Member

  • Members
  • PipPipPip
  • 32 posts

Posted 02 June 2011 - 05:02 PM

It's been a while since I worked with this issue and I'm very very old so my memory may fail me. As I recall everything was fine while running in debug mode but when I disconnected the USB cable and tried to run with just the serial connection it would fail. It was definietly fixed in 4.1.1.0 a5 but I don't know if the fix is included in 4.1.1 beta (I would really like to see a field guide to Netduino firmware versions). In addition to the fix in 4.1.1.0 a5 you can work around the issue by just opening the ports before adding the DataReceived event handler.

#10 Chris Walker

Chris Walker

    Secret Labs Staff

  • Moderators
  • 7767 posts
  • LocationNew York, NY

Posted 02 June 2011 - 06:20 PM

Quick field guide to bugfixes: beta > alpha 4.1.1 beta includes all bugfixes from 4.1.1 alpha. All current versions of firmware (including 4.1.0.6) include the serial port bugfix. If you are experiencing any other serial port issues with the latest firmware releases...please let us know! Chris

#11 Fahdil

Fahdil

    Advanced Member

  • Members
  • PipPipPip
  • 59 posts
  • LocationJakarta, Indonesia

Posted 08 September 2013 - 09:38 PM

I'm attempting to use both serial ports at the same time and have run into a problem. I've narrowed the problem to a single line of code but don't know what to do about it. In a test program I'm using COM1 to listen for a string from a PC and turn the LED on or off. This works fine while I'm still connected to the Netduino through the USB but when I disconnect the USB and power up through power connector it fails. I've attached a small test program that illustrates the problem (along with a little VB app to test it). I'm using an original Netduino (not the plus or mini) and I'm using firmware version 4.1.0.5.

 

Oh God Thanks,

 

 

Love this thread.... so much helpful... thanks... it's really  show me how to communicate to my GSMshield Icomsat v1.1...  i need to convert your code to Vb Language (it's the only Programming Language I understand). I planed to use netduino as weather station and send its data trought GSMsheild. Formerly I'm using arduino uno board, but since netduino has more option to develop, so I decide to learn netduino.

thanks to all of you guys. here is your code on vb lnguage

Imports SystemImports System.TextImports System.ThreadingImports System.IO.PortsImports Microsoft.VisualBasic.ConstantsImports Microsoft.SPOTImports Microsoft.SPOT.HardwareImports SecretLabs.NETMF.HardwareImports SecretLabs.NETMF.Hardware.NetduinoPlusNamespace Uart    Public Class Com_UART        Private Shared GSM_UART As SerialPort        Private Shared OnboardLed As OutputPort        Private Shared DataIn As String        Public Shared Sub Main()            ' write your code here            OnboardLed = New OutputPort(Pins.ONBOARD_LED, False)            GSM_UART = New SerialPort("COM1", 9600, Parity.None, 8, StopBits.One)            AddHandler GSM_UART.DataReceived, New SerialDataReceivedEventHandler(AddressOf RecieveData)            If GSM_UART.IsOpen = False Then                GSM_UART.Open()                Debug.Print("Port Opening" & " : at baudRate= " & GSM_UART.BaudRate)            Else                Debug.Print("Port is ready...")            End If            Thread.Sleep(1000)            Dim bytesTosend As Byte() = Encoding.UTF8.GetBytes("AT+CMGF=1" & vbCr)            Debug.Print("Send port : AT+CMGF=1")            GSM_UART.Write(bytesTosend, 0, bytesTosend.Length)            Debug.Print("Port is writing...")            Thread.Sleep(Timeout.Infinite)        End Sub        Private Shared Sub RecieveData(ByVal sender As Object, ByVal e As SerialDataReceivedEventArgs)            Dim Length As Integer = GSM_UART.BytesToRead            Dim bufferData As Byte() = New Byte(Length - 1) {}            GSM_UART.Read(bufferData, 0, Length)            DataIn += New String(Encoding.UTF8.GetChars(bufferData))            If DataIn.IndexOf(vbLf) >= 0 Then                Debug.Print("Command: " & DataIn)                DataIn = DataIn.Trim()          ' Get rid of the line feed                If DataIn <> "" Then                    OnboardLed.Write(state:=True)                    Debug.Print(DataIn)                End If                If DataIn = "" Then                    OnboardLed.Write(state:=False)                    Debug.Print("Command should be Cleared :" & DataIn)                End If                ' Clear the string for the next transmission            End If        End Sub    End ClassEnd Namespace

I wish to share my final code later....

 

 

best regards






0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

home    hardware    projects    downloads    community    where to buy    contact Copyright © 2016 Wilderness Labs Inc.  |  Legal   |   CC BY-SA
This webpage is licensed under a Creative Commons Attribution-ShareAlike License.