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

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

 

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???

Last Edited: Mon. Aug 10, 2020 - 09:13 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

:: Morten

 

(yes, I work for Microchip, yes, I do this in my spare time, now stop sending PMs)

 

The postings on this site are my own and do not represent Microchip’s positions, strategies, or opinions.

Topic locked