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

Documentation for .NET MF

doc netmf

Best Answer Gutworks, 28 February 2013 - 04:27 PM

Hi JamesBrown,

 

You can find the API here: http://msdn.microsof...y/hh401281.aspx

 

Though I do find that from time to time there is stuff missing from the API docs. Sometimes I just use Visual Studio's Object Browser to look through some of the classes. You'll more than likely find a few more methods, etc that way.

 

Cheers,

Steve

Go to the full post


  • Please log in to reply
5 replies to this topic

#1 JamesBrown

JamesBrown

    Member

  • Members
  • PipPip
  • 21 posts
  • LocationNear San Diego

Posted 28 February 2013 - 04:09 PM

Where can I find the docs for .Net MF?



#2 Gutworks

Gutworks

    Advanced Member

  • Members
  • PipPipPip
  • 363 posts
  • LocationOttawa, Ontario

Posted 28 February 2013 - 04:27 PM   Best Answer

Hi JamesBrown,

 

You can find the API here: http://msdn.microsof...y/hh401281.aspx

 

Though I do find that from time to time there is stuff missing from the API docs. Sometimes I just use Visual Studio's Object Browser to look through some of the classes. You'll more than likely find a few more methods, etc that way.

 

Cheers,

Steve



#3 JamesBrown

JamesBrown

    Member

  • Members
  • PipPip
  • 21 posts
  • LocationNear San Diego

Posted 28 February 2013 - 04:41 PM

Thanks Steve.  I'm still finding my way around VS 2012 and the Netduino.

NOW if I could only find an example of using the UARTS on the Netduino 2 plus I would be in good shape.



#4 NooM

NooM

    Advanced Member

  • Members
  • PipPipPip
  • 490 posts
  • LocationAustria

Posted 28 February 2013 - 05:08 PM

its sad if you _cant_ find one.

 

but ok, for the lazy guys:

SerialPort serialPort; serialPort = new SerialPort("yourcomport", 115200);serialPort.DataReceived += DataReceivedHandler;serialPort.Open();------ok this is non standard, but i send the "packet" lenght all the timevoid DataReceivedHandler(object sender, SerialDataReceivedEventArgs e)        {            Int32 identifier = serialPort.ReadByte();            if (identifier == 0)            {                Int32 length = serialPort.ReadByte();                Byte[] packet = new Byte[length];                serialPort.Read(packet, 0, packet.Length);                Byte[] decodedData = COBS.Decode(packet);                if (DataReceived != null)                    DataReceived(decodedData);            }        }public void Send(Byte[] Data)        {            Byte[] encodedData = COBS.Encode(Data);            Byte[] packet = new Byte[encodedData.Length + 2];            packet[0] = 0;            packet[1] = (Byte)(encodedData.Length);            encodedData.CopyTo(packet, 2);            serialPort.Write(packet, 0, packet.Length);        }

 

if your are interested, the encode/decode functions are linked in my signature, i find them pretty usefull, since its possible to loose data, it resyncs automatically.



#5 Gutworks

Gutworks

    Advanced Member

  • Members
  • PipPipPip
  • 363 posts
  • LocationOttawa, Ontario

Posted 28 February 2013 - 06:40 PM

Hi James,

 

Here is a simple serial example I put together for you. This example is not a comprehensive example and is missing some of the error correction and data validation you may want to add to make it more robust. But it should serve a good enough example to get you going. No external devices are needed for this example except for a jumper wire from Digital port 1 to D3. D1 is the Transmit (Tx) pin for COM1 and D2 is the Receiver (Rx) pin for COM2. In this example I'm using the Netduino as the receiver and sender, but in many cases one of these ports would be replaced by another device, and generally there would be some two-way communication, which can be easily added. For instance, in the code below you can send an acknowledgement command back to COM1 to let it know the transmission was successful. But of course, you would then have to add a wire from D0 to D2 to connect the Rx of COM1 to the TX of COM2. I will let you tackle that scenario. 

 

Hopefully this helps. Let us know if you have any other questions.

 

Cheers,

Steve

 

Edit: I confused the WriteRead method of the SPI class with the Read method of the SerialPort class. There is only one Read method for SerialPort and not "many". I have changed the comments to reflect that change. 

using System;using System.Net;using System.Net.Sockets;using System.Threading;using Microsoft.SPOT;using Microsoft.SPOT.Hardware;using SecretLabs.NETMF.Hardware;using SecretLabs.NETMF.Hardware.Netduino;using System.IO.Ports; //Required for the SerialPortsusing System.Text; // Required for the Encodingnamespace SimpleSerialExample{    public class Program    {        static SerialPort serialPort1;        static SerialPort serialPort2;        static OutputPort led;        public static void Main()        {            // Define our LED. We will toolge the on/off state with serial commands.             led = new OutputPort(Pins.ONBOARD_LED, false);            // Define the port, "COM1" Netduino digital pins 0(RX), 1(TX)            // We will use COM1 as the transmitting serial port for our example.            serialPort1 = new SerialPort("COM1", 115200, Parity.None, 8, StopBits.One);            // Define the port, "COM2" Netduino digital pins 2(RX), 3(TX)            //We will use COM2 as the receiving serial port for our example            serialPort2 = new SerialPort("COM2", 115200, Parity.None, 8, StopBits.One);            // Since we are using COM2 as the receiving port we need to             // define an event handler for incoming data.            serialPort2.DataReceived += new SerialDataReceivedEventHandler(RecievedData);            // Open both of the ports making them available to send and receive data.            serialPort1.Open();            serialPort2.Open();            // For a simple test, we will create an infinite loop and manually send the commands to COM2            while (true)            {                // Here we convert the characters of the strings, "on" and "off" into a sequence of bytes and save that sequence into a byte array.                  byte[] onCommand = Encoding.UTF8.GetBytes("on");                byte[] offCommand = Encoding.UTF8.GetBytes("off");                // Send the on command to the onboard LED                serialPort1.Write(onCommand, 0, onCommand.Length);                // Wait for half a second before sending the next command. At slower baud rates you may need to increase the time between sending commands.                 Thread.Sleep(500);                // Send the off command to the onboard LED                serialPort1.Write(offCommand, 0, offCommand.Length);                Thread.Sleep(500);            }        } //end of Main()        static void RecievedData(object sender, SerialDataReceivedEventArgs e)        {            Debug.Print("Data incoming");            // Get the number of incoming bytes            int numberOfBytes = serialPort2.BytesToRead;            // Create a temporary Byte array to store the incoming data            byte[] tempData = new byte[numberOfBytes];            // There is one method for Read().            // Here we are passing as arguments our temporary data array, to be populate with the incoming data,            // an Offset of 0, meaning we grab the all the incoming data from the beginning. We could ignore the first 'x' number of             // incoming bytes by increasing the offset.             // The final argument is the count or number of bytes we are expecting to receiving from our incoming transmission.            serialPort2.Read(tempData, 0, numberOfBytes);            //Now we need to convert our incoming data into a readable string            string command = new string(Encoding.UTF8.GetChars(tempData));            // Here we do some minor error checking. In a more robust scenario you would create a data packet             // and do more intensive error correction.             if (command != null)            {                //Remove any extra empty space from the end of the string                command = command.Trim();            }            else            {                command = "";            }            // Pass our command string to the LED Controller            LEDController(command);        }//end of RecievedData()        static void LEDController(string command)        {            // Display received data in the debugger Output window.            Debug.Print("Incoming Command: '" + command + "'");            // Use a switch statement to define what action to take with the received command            switch (command)            {                case "on":                    // turn LED on                    led.Write(true);                    //Display LED state                    Debug.Print("LED is ON");                    break;                case "off":                    // turn LED off                    led.Write(false);                    //Display LED state                    Debug.Print("LED is OFF");                    break;                default:                    Debug.Print("Unrecognized command: '" + command + "'");                    break;            }        }// end of LEDController()    } //end of Program} //end of namespace

Edited by Gutworks, 01 March 2013 - 03:20 PM.


#6 Gutworks

Gutworks

    Advanced Member

  • Members
  • PipPipPip
  • 363 posts
  • LocationOttawa, Ontario

Posted 28 February 2013 - 07:07 PM

I also forgot to mention how to use the Object Browser. If you want to see what methods are available for any class you can easily right click on a method or class name and select "Go to Definition" or hit F12. You can also open up the Object Browser in the top menu, View > Object Browser, or hit Ctrl+W, J. This will show you a list of all the namespaces, classes. etc, that are included in your project. From there you can drill down through the various elements and discover all the goodies NETMF has to offer. 

 

Happy hunting, 

Steve






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.