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.

leke_lion

Member Since 26 Feb 2013
Offline Last Active Apr 30 2013 12:12 AM
-----

Topics I've Started

Netduino serial data eventhandler

29 April 2013 - 01:33 AM

Hi,  

 

Can anyone help troubleshoot this code? I'm building a wireless temperature sensor, and reading the values from the receiver end of a xbee into the digital input of a netduino. I found some examples on reading hex values and looping through a byte array online and essentially integrated them into this. Specifically, I'm getting an error about delegate not matching overload. It's the bold and underlined part of the code. Any help is greatly appreciated! Also, if there's a more efficient way to read the hex values coming through the COM2 port then please explain how. THANKS!

 

error:

"no overload for 'serialPort_DataReceived' matches delegate 'SerialDataReceivedEventHandler'"

 

 

...................................................................................
using System;
using System.Threading;
 
using Microsoft.SPOT;
using Microsoft.SPOT.Hardware;
 
using SecretLabs.NETMF.Hardware;
using SecretLabs.NETMF.Hardware.Netduino;
 
using System.IO.Ports;
using System.Text;
using LXIT.Hardware;
 
namespace NetduinoApplication1
{
    public class Program
    {
        static SerialPort serialPort;
        const int Max_Command_Length = 3;
        static byte[] commandString = new Byte[Max_Command_Length];
        static int commandStringIndex = 0;
         
       
        public static void Main()
        {
            // Create buffer for data from xbee
            serialPort = new SerialPort("COM2",9600);
            serialPort.Open();
            serialPort.DataReceived += new SerialDataReceivedEventHandler(serialPort_DataReceived);
            Thread.Sleep(Timeout.Infinite);
 
            // Create instance for a SparkFun SerLCD 16x2
            SerLCD smallLcd = new SerLCD(SerialPorts.COM1);
 
            // Now start playing with these LCD's 
            smallLcd.ClearDisplay();
            smallLcd.SetCursorPosition(1, 6);
            smallLcd.Write("Helmet");
            smallLcd.SetCursorPosition(2, 6);
            smallLcd.Write("Temps");
            // Wait 2 seconds
            Thread.Sleep(2000);
        }
 
        static void serialPort_DataReceived(object sender, SerialErrorReceivedEventArgs e)
        {
            int numberOfBytesReceived = serialPort.BytesToRead;
            byte[] serialBuffer = new byte[numberOfBytesReceived];
            serialPort.Read(serialBuffer, 0, numberOfBytesReceived);
            loop();  
        }
 
        static void loop()
        {
            SerLCD smallLcd = new SerLCD(SerialPorts.COM1);
         
            if (serialPort.DataBits == 0x7E)
            {
                for (int i = 1; i < 19; i++)
                {
                    byte discardByte = (byte)serialPort.DataBits;
                }
 
                int firstBit = serialPort.DataBits;
                int secondBit = serialPort.DataBits;
 
                int reading = secondBit + (firstBit * 256);
                double Temp = (reading / 1023) * 1.23;
                Temp = (Temp - 0.5) / 0.01;
 
                while (true)
                {
                    string newTemp = Temp.ToString();
                    Thread.Sleep(500);
                    // waits for 500 milliseconds
 
                    // Clear screen
                    smallLcd.ClearDisplay();
                    smallLcd.Write("Player Temp:");
                    smallLcd.SetCursorPosition(2, 6);
                    smallLcd.Write(newTemp + "*C");
 
                    //wait 2 seconds
                    Thread.Sleep(2000);
                }
 
                // Wait 2 seconds
                //Thread.Sleep(2000);
 
                // Turn the LCD back on
                //smallLcd.SetDisplay(SerLCD.Status.On);
            }
            else
            { }
 
        }
    }
}
 

Xbee to LCD using Netduino

26 February 2013 - 03:34 AM

Hi, 

 

I am looking for a reference/starting point on how to read data from an Xbee using a Netduino in C#  code. Any feedback is greatly appreciated!


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.