无效的字符Arduino,蓝牙(HM10)和Xamarin.Forms

时间:2018-07-27 21:18:57

标签: xamarin xamarin.forms arduino bluetooth-lowenergy arduino-ide

尝试从我的Android Xamarin.Forms应用程序向Arduino Mega发送命令时遇到问题。当我从Play商店使用Bluetooth终端应用程序时,它可以工作,但我的代码无效。在Arduino终端中,我只是在平方,好像是波特率问题之类的。但是从我可以看到,波特率始终由设备决定,对于HM10,默认设置为9600。

我正在将此库用于蓝牙https://github.com/xabre/xamarin-bluetooth-le

Arduino Sketch(与bt终端应用程序配合使用)

void loop()
{
    // Read from the Bluetooth module and send to the Arduino Serial Monitor
    if (Serial3.available())
    {
        byte y = Serial3.read();
         //int x = (int)y;
        Serial.write(y);
    }


    // Read from the Serial Monitor and send to the Bluetooth module
    if (Serial.available())
    {
        c = Serial.read();

        // do not send line end characters to the HM-10
        if (c != 10 & c != 13)
        {
            Serial3.write(c);
        }

        // Echo the user input to the main window. 
        // If there is a new line print the ">" character.
        if (NL) { Serial.print("\r\n>"); NL = false; }
            Serial.write(c);
        if (c == 10) { NL = true; }
    }
}

然后在我的Xamarin.Forms应用中发送代码

    private async Task Button_ClickedAsync(object sender, EventArgs e)
    {
        if (_charataristice != null &&  _charataristice.CanWrite)
        {
            var data = Convert.ToByte(16);
            _charataristice.WriteType = CharacteristicWriteType.WithoutResponse;
            await _charataristice.WriteAsync(new[] { data });
        }

    }

我们将不胜感激,我尝试恢复的值是一个数字,应在一个字节内。

0 个答案:

没有答案