本文介绍了如何从阿尔杜伊诺的Xbee发送数据,并从C#收到的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Arduino的XBee ,我有一个Sparkfun的XBee USB探险家。我想在我的C#程序发送来自Ardunio的XBee数据(温度传感器)和接收它。

I have an Arduino XBee shield and I have a Sparkfun XBee USB explorer. I would like to send data (temperature sensor) that comes from the Ardunio XBee and receive it in my C# programme.

现在,让我们说,我想送45,100到我的C#程序。

For now, let's say I want to send 45, 100 to my C# programme.

我没有收到来自的XBee屏蔽任何数据。我失去了与code什么?

I don't receive any data that comes from the XBee shield. Am I missing anything with the code?

下面code是Arduino的盾牌的XBee发件人:

The below code is the sender from the Arduino XBee shield:

SoftwareSerial mySerial(4,5);
void setup()
{
    mySerial.begin(9600);
}


void loop()
{
    if (mySerial.available() > 0)
    {
        mySerial.write(45);
        mySerial.write(',');
        mySerial.write(100);
        mySerial.write('\n');
    }
}

接收器code在C#中的USB的XBee探险:

Receiver code for the USB XBee explorer in C#:

SerialPort port = new SerialPort();

public Form1()
{
    try
        {
            port.PortName = "COM8";
            port.BaudRate = 9600;
            port.DataBits = 8;
            port.Parity = Parity.None;
            port.StopBits = StopBits.One;
            port.Open();
            Console.WriteLine("Opened");
        }
        catch(Exception ex)
        {
            Console.WriteLine("Sorry! " + ex);
        }

        // Handler for receiving data
        port.DataReceived += serialPort1_DataReceived;
    }

    private void serialPort1_DataReceived(object sender, System.IO.Ports.SerialDataReceivedEventArgs e)
    {
        if (port.IsOpen == true)
        {
            string RxString = port.ReadLine();
            Console.WriteLine(RxString);
        }
    }

本的XBee配置:

The XBee configuration:


  • 一的XBee是:协调AT模式 - 连接到USB Sparkfun浏览器

  • 另外的XBee是:路由器AT模式 - 连接到Arduino的盾牌

由于tomlogic回答我的问题在堆栈溢出问题的 的XBee同时双向通信(发送器和接收器) 的。

As tomlogic answered my question in Stack Overflow question XBee two-way communication (sender and receiver) at the same time.

推荐答案

我得到了它的工作。这个问题是由我的空隙环()方法。该mySerial应该像

I got it working. The problem was from my void loop() method. The mySerial should be like

mySerial.println(temperature);


  • 但是,你必须检查mySerial RX,TX引脚,他们是正确的

  • 这篇关于如何从阿尔杜伊诺的Xbee发送数据,并从C#收到的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-16 01:27