私はプロジェクトに取り組んでおり、この Web サイトを参照として使用して、Netduino を PC と通信させています。
このBluetoothトランシーバーを購入しました。元の投稿で使用されているものの更新版のようです。彼のウェブサイトで 1.06 対 1.04。
Bluetooth の TXD を Pin0、RXD を Pin1、VCC を 5V に設定しました。
これは、Netduino での私のコードです。
static SerialPort Bluetooth;
public static void Main()
{
Bluetooth = new SerialPort(SerialPorts.COM1, 9600, Parity.None, 8, StopBits.One);
Bluetooth.DataReceived += new SerialDataReceivedEventHandler(Bluetooth_DataReceived);
Bluetooth.Open();
Thread.Sleep(Timeout.Infinite);
}
static void Bluetooth_DataReceived(object sender, SerialDataReceivedEventArgs e)
{
byte[] bytes = new byte[1];
while(Bluetooth.BytesToRead > 0)
{
Bluetooth.Read(bytes, 0, bytes.Length);
Debug.Print(bytes[0].ToString());
}
}
これは私のラップトップ上のコードです: (これは WPF アプリケーションです)
SerialPort serialBT;
private void Connect()
{
// COM7 is the outgoing port that corresponds to the Bluetooth transceiver
serialBT = new SerialPort("COM7", 9600, Parity.None, 8, StopBits.One);
serialBT.Open();
serialBT.Write(new byte[] { 23, 24, 25, 26 }, 0, 4);
Debug.Print("Values sent");
}
Netduino で、23、24、25、および 26 のバイト配列を送信すると (テスト目的のみ)、DataReceived イベントが発生します。ただし、受信してデバッグ ウィンドウに表示される値は、本来あるべき 23、24、25、および 26 ではなく、6、0、0、および 248 です。
私が送信する他の値も、同じように不思議なことにまったく異なる値に変換されます。
Bluetooth トランシーバーの適切な COM 設定を 3 倍にチェックしましたが、それらは正しい設定です。オリジナルの Arduino は TXD が Pin1 で RXD が Pin0 であると想定しているので、TXD ピンと RXD ピンを入れ替えましたが、Netduino でデータが受信されません。