C# Serial Communication failure-- Adafruit Metro M4 and Grand Central M4

Go To Last Post
7 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Serial Communication -- Adafruit Metro M4 and Grand Central M4

Background:  VS2017 & Windows 10.  Some time ago I put together a C# data acquisition program to collect data from different experiments using different MCUs.  The app collected CSV text strings and stored the data in a text file for later data evaluation.   The process worked well.

I recently started working with the Metro & Grand Central M4 processor, wanting to use them for additional data acquistion data collections.  
I started by writing simple CSV text string and capturing them with VS2017 monitor screen and Arduino 1.8 monitor screens.  Every thing worked well.

Next, I fired up my old program and -- It failed.  

I started termite and it didn't capture any data.

I started  PUTTY and I captured data.

I stared a console monitor from a 3rd development program -- it did not capture data.

I stared a Hercules.  It didn't capture data.

I started a 4'th development program monitor -- it did not capture data.

This is my code that opens the port

         srPort = new SerialPort();
         srPort.PortName = portName;
         srPort.BaudRate = baud;
         srPort.DtrEnable = false;
         srPort.Handshake = System.IO.Ports.Handshake.None;
         srPort.RtsEnable = false;
         srPort.StopBits = System.IO.Ports.StopBits.One;
         try
         {
            srPort.Open();
            if (srPort.IsOpen)
            {
               this.srPort.DataReceived += new System.IO.Ports.SerialDataReceivedEventHandler(this.srPort_DataReceived);
               //this.srPort.ErrorReceived += new System.IO.Ports.SerialErrorReceivedEventHandler(this.srPort_ErrorReceived);
               srPort.DtrEnable = true;
               Thread.Sleep(20);
               srPort.DtrEnable = false;
               MessageBox.Show("Port: " + portName + " Open \r\n");
            }
         }
         catch (Exception ex)
         {
            MessageBox.Show("Opening Port:  " + portName + " Failed \n\n" + ex.Message);
            srPort = null;
         }
         return srPort;

This is the event handler for receiving the code
      private void srPort_DataReceived(object sender, SerialDataReceivedEventArgs e)
      {
         int numbytes = srPort.BytesToRead;
         if (numbytes > 0)
         {
            byte[] bytes = new byte[numbytes];
            int knt = srPort.Read(bytes, 0, numbytes);
            this.ScanStreamForValidMsg(bytes);
         }
      }
      

My program reports that the port is opened properly but never receives data. I placed a breakpoint in the event handler and it is never hit.

So...What am I missing???

Any Suggestions???

This topic has a solution.
Last Edited: Fri. Aug 14, 2020 - 04:28 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

greyfrodo wrote:
So...What am I missing???

An AVR?  This is an AVR forum.

 

Jim

 

 

(Possum Lodge oath) Quando omni flunkus, moritati.

"I thought growing old would take longer"

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I've never used C# (Python would be my choice), but going to guess you are not setting "portName" to the same value that Putty is using.

 

I would try Putty's session logging.

 

https://www.viktorious.nl/2013/01/14/putty-log-all-session-output/

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Mice Try but only 2 ports to work with.  Hard not to get the right one.  The description if brief, i actually want to eventually  filter the incoming string

 

BTW:   writing to the port causes it to hang.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

greyfrodo wrote:
My program reports that the port is opened properly but never receives data

Modem control lines - RTS; DTR ?

 

Debugging serial comms: https://www.avrfreaks.net/commen...

 

 

 

 

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
Last Edited: Wed. Aug 12, 2020 - 11:42 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thanks --- You're right.  Apparently it is not enough to set Handshaking = none.  The RTS has to be set to high.  When I did that, I started to receive data for the MCU. 

 

Thanks.

This reply has been marked as the solution. 
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

You're welcome.

 

Now please mark the solution - see Tip #5 in my signature, below:

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...