Netduino Serial to USB Resource Control

  • Topic Is Sticky
  • 554 Views
  • Last Post 18 October 2018
Chris posted this 18 October 2018

My Friends,

For interested parties, the Netduino, like most all MCU's can Send ( TX ) Commands and Receive ( RX ) Commands via a RS232 Serial to USB Interface.

For Netduino, you may need a Cable, Serial to USB:

 

Courtesy of Sparkfun Electronics.

 

Once the Cable is connected and the Serial is working, a Serial Com port should be available on your computers Hardware Management

 

On your Keyboard hold down Start ( Windows Key ) and push the R Key, type in the following command: compmgmt.msc

 

 

Click Ok, and you get this window:

 

 

Your COM Port number may be different, it may be COM7, un-plugging and then plugging in your USB Cable, it will give you a COM Port appear when connected, and disappear when not connected.

At this stage, you are able to start a serial Interface session. Code will be required on your Netduino and also on your PC.

Simple Serial Code examples to follow on this thread soon.

Lets start a MCU Powered revolution of smart controlled Experiments! Zanzal may be able to contribute on this thread if time permits.

   Chris

  • Liked by
  • cd_sharp
Order By: Standard | Newest | Votes
Chris posted this 18 October 2018

I want to cover the C# Netduino Serial Code first.

Simple Example:

namespace SCPM
{

   using System;
   using System.Text;
   using System.IO.Ports;
   using System.Threading;

   using SecretLabs.NETMF.Hardware;
   using SecretLabs.NETMF.Hardware.Netduino;


   // Configure a Serial Port:
   private static SerialPort serialPort = new SerialPort("COM1", 9600, Parity.None, 8, StopBits.One);


   public static void Main()
   {    

      // Attach the Data Received Event Handler:
      serialPort.DataReceived += new SerialDataReceivedEventHandler(serialPort_DataReceived);

      // Open the Port:
      serialPort.Open();

      // Wait infinately:
      Thread.Sleep(Timeout.Infinite);
   }

   static void serialPort_DataReceived(object sender, SerialErrorReceivedEventArgs e)
   {

      // Get the Byte Count:
      int byteCount = serialPort.BytesToRead;

      // Configure the RX Buffer:
      byte[] rxBuffer = new byte[byteCount];

      // Read the Bytes into the Buffer:
      serialPort.Read(rxBuffer, 0, byteCount);

      // Read the Bytes into a String:
      string stringFromBytes = Encoding.UTF8.GetString(rxBuffer);


      // Now you have a String that was sent over a USB to Serial Connection:


      // Write what we have received back to the Serial Port:
      byte[] txBuffer = Encoding.UTF8.GetBytes(stringFromBytes);
      serialPort.Write(txBuffer, 0, txBuffer.Length);
   }
}

 

Please note, this example is Pseudo Code. Some Netduino MCU's may require additional Code.

From here, you can work on a Serial Communication Architecture that you can transmit from your Computer through to your Netduino and so on.

Next, a Windows Form with a simple Serial command Window.

   Chris

  • Liked by
  • cd_sharp
Chris posted this 18 October 2018

 

My Friends,

A simple Windows Forms App is easy to make a Terminal Window. A Code example is as follows:

 

namespace SCOM
{

    using System;
    using System.Text;
    using System.IO.Ports;
    using System.Windows.Forms;

    public partial class Form1 : Form
    {

        private static SerialPort serialPort;

        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {

            // Some Date to Sendto your MCU:
            string txData = "Transmit me to your MCU<EOS>";

            // Display the Data:
            TXTextBox.Text = txData;

            // Initialise a new Serial Port:
            serialPort = new SerialPort();

            // Atach an Event Handler for Data Received:
            serialPort.DataReceived += new SerialDataReceivedEventHandler(serialDataReceived);

            // Configure the Serial Port to match settings on your MCU:
            serialPort.BaudRate = 9600;
            serialPort.DataBits = 8;
            serialPort.Parity = Parity.None;
            serialPort.PortName = "<PUT YOUR COM PORT HERE>"; // Dont forget this!!!
            serialPort.StopBits = StopBits.One;

            // For Testing:
            serialPort.PortName = "COM1";

            // Open Serial Ports and disable Buttons....
            serialPort.Open();
        }

        private void SendButton_Click(object sender, EventArgs e)
        {

            // Make sure the Port is Open:
            if (serialPort.IsOpen)
                if (TXTextBox.Text.Length > 0)
                {

                    // Convert and fill the Teext to a Byte Array:
                    byte[] txBuffer = Encoding.UTF8.GetBytes(TXTextBox.Text);

                    // Write the Buffer to the Serial Port:
                    serialPort.Write(txBuffer, 0, txBuffer.Length);

                }

        }

        private void serialDataReceived(object sender, SerialDataReceivedEventArgs e)
        {

            try
            {

                // Read the Received Byte Array and Convert to String:
                string rxString = serialPort.ReadLine();

                // Display String:
                Invoke(new Action(() => { RXTextBox.Text = rxString; }));
            }
            catch (System.IO.IOException iOEX)
            {

                // Catch Exception:
            }
            catch (System.TimeoutException timEX)
            {

                // Catch Exception:
            }
        }
    }
}

 

A simple windows Form can be constructed:

 

 

The Zipped Project File is attached below.

   Chris

Attached Files

  • Liked by
  • cd_sharp
Chris posted this 18 October 2018

My Friends,

The point of all this, is simply, one can control your Netduino or any other MCU from your Computer. A click of a button can change your PWM Duty Cycle, or Frequency, or get a Current reading from a Current Sensor or Voltage Sensor.

There is great benefit to the quick fast and simple communication to the MCU!

One Example, my software, I built, I can control Frequency and Duty Cycle:

 

 

One can gain a huge benefit to MCU Control!

   Chris

  • Liked by
  • cd_sharp
We're Light Years Ahead!
Members Online:
What is a Scalar:

In physics, scalars are physical quantities that are unaffected by changes to a vector space basis. Scalars are often accompanied by units of measurement, as in "10 cm". Examples of scalar quantities are mass, distance, charge, volume, time, speed, and the magnitude of physical vectors in general.

You need to forget the Non-Sense that some spout with out knowing the actual Definition of the word Scalar! Some people talk absolute Bull Sh*t!

The pressure P in the formula P = pgh, pgh is a scalar that tells you the amount of this squashing force per unit area in a fluid.

A Scalar, having both direction and magnitude, can be anything! The Magnetic Field, a Charge moving, yet some Numb Nuts think it means Magic Science!

Message from God:

Hello my children. This is Yahweh, the one true Lord. You have found creation's secret. Now share it peacefully with the world.

Ref: Message from God written inside the Human Genome

God be in my head, and in my thinking.

God be in my eyes, and in my looking.

God be in my mouth, and in my speaking.

Oh, God be in my heart, and in my understanding.

Your Support:

More than anything else, your contributions to this forum are most important! We are trying to actively get all visitors involved, but we do only have a few main contributors, which are very much appreciated! If you would like to see more pages with more detailed experiments and answers, perhaps a contribution of another type maybe possible:

PayPal De-Platformed me!

They REFUSE to tell me why!

We now use Wise!

Donate
Use E-Mail: Chris at aboveunity.com

The content I am sharing is not only unique, but is changing the world as we know it! Please Support Us!

Thank You So Much!

Weeks High Earners:
The great Nikola Tesla:

Ere many generations pass, our machinery will be driven by a power obtainable at any point of the universe. This idea is not novel. Men have been led to it long ago by instinct or reason. It has been expressed in many ways, and in many places, in the history of old and new. We find it in the delightful myth of Antheus, who drives power from the earth; we find it among the subtle speculations of one of your splendid mathematicians, and in many hints and statements of thinkers of the present time. Throughout space there is energy. Is this energy static or kinetic? If static, our hopes are in vain; if kinetic - and this we know it is for certain - then it is a mere question of time when men will succeed in attaching their machinery to the very wheelwork of nature.

Experiments With Alternate Currents Of High Potential And High Frequency (February 1892).

Close