473,781 Members | 2,718 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

c# code for interface between xbee meridian p micro controller devel

9 New Member
Does anyone have C# code for interface between xbee and meridian p micro controller development board?
Mar 31 '10
19 5253
sagar45
9 New Member
Expand|Select|Wrap|Line Numbers
  1. using System;
  2. using System.Threading;
  3. using Microsoft.SPOT.Hardware;
  4. using DeviceSolutions.SPOT.Hardware;
  5.  
  6. namespace GpioOutputPortSample
  7. {
  8.     public class Program
  9.     {
  10.         public static void Main()
  11.         {
  12.             OutputPort outputPort = new OutputPort(MeridianP.Pins.GPIO9, true);
  13.             while (true)
  14.  
  15.                // outputPort.Write = (true);
  16.  
  17.             {
  18.                 Thread.Sleep(500);
  19.                 outputPort.Write(!outputPort.Read()); //toggle port
  20.             }
  21.         }
  22.     }
i need to glow the GPIO pin 9 ...i have done all the connection but how can i debug the program and make the led glow ...

thanks
sagar
Apr 13 '10 #11
tlhintoq
3,525 Recognized Expert Specialist
TIP: When you first created your question you were asked to wrap your code with [code] tags.

It really does help a bunch. Look how much easier it is to read now that someone has done it for you. Its the button with a '#' on it. More on tags. They're cool. Check'em out.
Apr 13 '10 #12
tlhintoq
3,525 Recognized Expert Specialist
Developer page shows: MeridianP.Pins. LED
You are using: MeridianP.Pins. GPIO9
So one possibility is that GPIO9 is not designed to run an LED. It might be meant for communication not the voltage levels required of your LED.

Have you done the project the way the developer designed first, to make sure you have a proper understanding of it?

The developer did not try to flash the LED based on reading it's value, like you are trying. How about giving it a shot the way the developer did it before trying to get fancy?

Expand|Select|Wrap|Line Numbers
  1. //Thread.Sleep(500);
  2. //outputPort.Write(!outputPort.Read()); //toggle port
  3. outputPort.Write(true);
  4. Thread.Sleep(500);
  5. outputPort.Write(false);
  6. Thread.Sleep(500);
  7.  
The best advice I can give is to first do the project the way the developer designed it. Then start making modifications and experiments to push the limits of its capabilities.
Apr 13 '10 #13
sagar45
9 New Member
Hey thanks for the reply ....i would really present myself in a good way ....

the problem regarding my project is that i am writing my code for sending hello message in the controller for xbee ....i have another xbee module connected to the CPU(where this two modules can talk to each other by Xtcu software).when i write the code and debug i have problem get the out put ....i am using usb connection for the controller(meri dian P).

Expand|Select|Wrap|Line Numbers
  1. using System;
  2. using System.IO.Ports;
  3. using Microsoft.SPOT;
  4. using Microsoft.SPOT.Hardware;
  5. using System.Threading;
  6. namespace SerialPortWriteSample
  7. {
  8. public class Program
  9. {
  10. public static void Main()
  11. {
  12.      SerialPort serialPort = new SerialPort("COM1", 9600, Parity.None, 8, StopBits.None);
  13.      byte[] outBuffer = System.Text.Encoding.UTF8.GetBytes("Hello World!\r\n");
  14.      serialPort.Write(outBuffer, 0, outBuffer.Length);
  15.  
  16.      serialPort.Dispose();
  17.      Thread.Sleep(Timeout.Infinite);
  18. }
  19. }
  20. }
could u correct the code ...but this show no error when when i debug but an unhandle exception of system.argument Exception coored in microsoft.soft. hardware.serial port.dll..this the msg is cooming out ...

Thank you
sagar
Apr 15 '10 #14
tlhintoq
3,525 Recognized Expert Specialist
TIP: When you first created your question you were asked to wrap your code with [code] tags.

It really does help a bunch. Look how much easier it is to read now that someone has done it for you. Its the button with a '#' on it. More on tags. They're cool. Check'em out.
Apr 15 '10 #15
tlhintoq
3,525 Recognized Expert Specialist
i am using usb connection for the controller(meri dian P).
Then why are you doing all this to the serial port?
Expand|Select|Wrap|Line Numbers
  1. SerialPort serialPort = new SerialPort("COM1", 9600, Parity.None, 8, StopBits.None);
  2.      byte[] outBuffer = System.Text.Encoding.UTF8.GetBytes("Hello World!\r\n");
  3.      serialPort.Write(outBuffer, 0, outBuffer.Length);
  4.  
  5.      serialPort.Dispose();
  6.      Thread.Sleep(Timeout.Infinite);
problem regarding my project is that i am writing my code for sending hello message in the controller for xbee
This was an LED flashing project. Now you are trying to send "Hello World"? You've totally lost me. Are you trying to flash "Hello World" in Morse code?

This code doesn't look anything like your earlier code, which was very close to what the developer of the controller used in his example. Why the big change? Did you try any of the suggestions I made earlier?

1. Do the project exactly the way the developer designed it to be done and see if the board works.
2. Once that code works, make a backup of it.
3. Slowly make changes from a known-good condition.
4. Make backup copies of your code at each stage so you can roll back if you need to.
Apr 15 '10 #16
sagar45
9 New Member
sorry to say that i have made the LED to glow .....now i am looking for sending hello msg from meridian(contro ller) to xbee .....the problem when i debug it say.""""unhandl e exception system.argument exception""""". ...

Thank you

sagar
Apr 15 '10 #17
tlhintoq
3,525 Recognized Expert Specialist
When you get the exception, and program execution stops it does so at the offending line and highlights that line. What line number does it stop on?

Expand|Select|Wrap|Line Numbers
  1. SerialPort serialPort = new SerialPort("COM1", 9600, Parity.None, 8, StopBits.None);
  2.      byte[] outBuffer = System.Text.Encoding.UTF8.GetBytes("Hello World!\r\n");
  3.      serialPort.Write(outBuffer, 0, outBuffer.Length);
  4.  
  5.      serialPort.Dispose();
  6.      Thread.Sleep(Timeout.Infinite);
Apr 15 '10 #18
sagar45
9 New Member
SerialPort serialPort = new SerialPort("COM 1", 9600, Parity.None, 8, StopBits.None);
Apr 15 '10 #19
tlhintoq
3,525 Recognized Expert Specialist
You need to take the time to actually read about the controls you want to use.
The MSDN Page on SerialPort is here.
http://msdn.microsoft.com/en-us/libr...erialport.aspx

You are trying to send data out of a serial port you have never opened, and you are disposing of it without closing it.
Expand|Select|Wrap|Line Numbers
  1. SerialPort serialPort = new SerialPort("COM1", 9600, Parity.None, 8, StopBits.None);
  2.      byte[] outBuffer = System.Text.Encoding.UTF8.GetBytes("Hello World!\r\n");
  3. // You need to open the serial port
  4.      serialPort.Write(outBuffer, 0, outBuffer.Length);
  5. // Close the serial port
  6.      serialPort.Dispose();
There are two ways you can go about learning C#:
1) You can quickly glance at the function and start throwing a bunch of stuff at at and see what sticks. Then flail around for hours guessing and changing and guessing and changing and eventually throwing your hands up and ask for help.... or...
2) You can read the tutorials and do them as shown first, to get an education and understanding of how they work - *THEN* take the knowledge and apply it to your programming in a meaningful way.

You also need to start wrapping functions in Try/Catch blocks. You can't just let applications fail: You need to *expect* them to fail and make an effort to recover gracefully.


I can make some general suggestions that apply to good coding practice.
  • Assume that everything is broken, or at least not ideal.
  • Presume that the user is going to provide data in a format or manner that you just didn't expect. If you use a textbox for a number, the user will type "One".
  • Assume that hardware breaks in the middle of what you are doing, so you have to recover.
  • Take a few extra lines of code to get standards like the boot drive, the number thousands seperator etc. Don't assume that you have a C: drive or that a comma is the separator because not everyone is in America.
  • Check that files/folders exist, even if you just did a call to make it: You may not have permissions.
  • Don't assume the harddrive has room for what you are doing: They do fill up. Usually right in the middle of you writing to your log file.
  • Get used to placing breakpoints and walking through the code line by line. Double check EVERYTHING on every line. Keep the "Locals" and "Autos" windows open so you can see your values.
    • Put a breakpoint on the first line of the method causing trouble.
    • When the code stops there, walk through line by line with F-10.
    • Check the values of your assumptions (looking at the Locals and Automatic variable windows as well as hovering the mouse over the variables in the code (hothelp will popup).
  • Stop. Breath. Relax. Then reason out the problem. Cut it down by sections or halves. "The value was good here, then at this method it wasn't. Where did it go between 'A' and 'B'?"
  • Range check and validate values. Confirm that you didn't get a zero when you are only set to accept 1-10. Confirm your objects and values aren't null. Initialize them to a known default if possible. If a selection can be from 0-10, then initialize to -1: Now you have something to check for.

Example:
Expand|Select|Wrap|Line Numbers
  1. Graphics g = Graphics.FromImage(m_Undo);
Presumes that m_Undo must be good (not null)(actually exists)(not in use)(you have permissions)(do esn't time out when accessed). If that assumption fails so does the program, because you can't make anything from a file if the file is null. Get used to validating data and assumptions in your code if you want it to be robust. For example:
Expand|Select|Wrap|Line Numbers
  1. if (m_Undo != null)
  2. {
  3.    bool bSuccess = false;
  4.    // Do your thing here, for example:
  5.    if (myObject != null) bSuccess = true;
  6.    // or
  7.    if (denominator > 0) bSuccess = true;
  8.    // or
  9.    if (MyFunctionReturn != Failed) bSuccess = true;
  10.    // Hurray, your thing worked!
  11.  
  12.    if (bSuccess)
  13.    {
  14.       // Then do this other thing if it worked
  15.    }
  16.    else
  17.    {
  18.       // Then do the failure recovery part / user failure message
  19.    }
  20.  
  21.    return bSuccess; // If you want the calling method to know if it worked.
  22. }
Apr 17 '10 #20

Sign in to post your reply or Sign up for a free account.

Similar topics

1
1320
by: Sean | last post by:
Hi all! I am developing an apps following the OOP principles and I would like to know how should I implement a controller class in order to call the others classes involved in the Business and Data Access Layers ... Thanks in advance for any help on this! Sean.
13
6217
by: webzila | last post by:
Hello, I have to write a program for an 8051 micro-controller using micro-C to monitor Switch 1 and if the switch in pushed the message "switch 1 pushed" should be displayed in the LCD. Also the microcontroller should display in the LCD the value of the voltage applied to the input of the ADC. The above procedure should only execute once the user has entered "1234" using a keypad that is attached to the 8051 microprocessor.
4
8261
by: fahadarif | last post by:
I have one xbee module used as cordinator (host side). This side is connected to PC. And this cordinator needs to communicate to other end-devices. These end-devices are battery powered and not connected to any PC. Now, I want the end-devices to send their Identity (may be any text or MY address) on power up wirelessly to the host. This host should receive this information from end-devices and send back an ACK signal to end-devices. And...
0
3081
by: shobhon | last post by:
Can anyone please tell how to setup xbee series 2 . i have set up one xbee with co-ordinator and ther other one with end device. Now i have i have opened one of the ADC port setup sample rate.. but it is not tranmitting anything unlike series one when i open ADC and sample rate it starts trasmites data stright away.. (using xctu) i have also tested with connecting the port with a analog voltage again series 1 works but series 2 does not. Does...
1
3877
by: Chakshika | last post by:
Hello, We are doing a wireless sensor network project using Xbee modules as our University Final year project. We have bought some Xbee Series 2 modules and Two XBIB-U-DEV (and XBIB-R-DEV) development kits ( USB and RS 232) The was a small software came with them in a CD. Its called as X-CTU. It only has a range test. We couldn't programm motes as we wish through that development kit.Is there any IDE to do that? Any software? We are confused...
0
2429
by: mlkushan | last post by:
hi, I have imported Xbee modules (XB24-BWIT-004) and Xbee starter pro development kit. It has XBIB-U-DEV and XBIB-R-Dev development kits with 10 Xbee motes and two Xbee pro motes. So I have configured the codewarrior development environment in my PC (Windows XP) and also I have configured the TOSSIM environment with Cygwin (on the same platform). So I need to know, how I should start to program the Xbee motes using nesC programming language....
4
4136
by: Pancakes | last post by:
Hello all, this is my first post in these forums, so bear with me if I've broken a few rules here or there. Anyhow, I would like to ask if anyone if familiar with the XBee Pro, here, and documentation is available here. The documents don't match the product exactly, the links from the product page ended up to the documents page I supplied. The difference between the models are just the effective range (I think), and the models are...
1
3455
by: boredo212 | last post by:
I have ordered the XBEE Starter kit and was able to use XCTU to get the two modules to communicate through the two dev boards (USB and RS-232). Now I would like to take it to the next step by writing a program that will send a string to the xbee module and have the xbee broadcast it. Eventually, this would have to connect to a mysql database. Could somebody point me in the right directions. I am clueless as how to start this off. I am...
16
17177
by: KDaly | last post by:
Hey guys, I was kind of hoping that someone could help me out with a project I am working on for school... We are desigining a robot that someone will approach, and the robot will ask the user if they would like to go to room A, B, or C. (keep in mind all the rooms are in a striagh hallway with no turns). We have decided to put Xbee modules at each room and an additional xbee module on the robot. In front of each room, we would like to...
21
12749
by: ritusingh2008 | last post by:
Hello, I have transmitted an APi frame fron one xbee radio to other.I am able to receive it in 2nd xbee radios.I can see it xbee terminal.If i want to find the RSSI value for it how can i calculate it. Can anyone please explain it detail? Thanks
0
9639
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9474
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10143
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9939
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7486
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6729
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5375
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4040
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3633
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.