When i try the built-in Serial Port I/O Test with the following script I get message saying "DISCONNECTED". FYI, I've connected my RPi and Arduino via USB
var portname = "/dev/ttyACM0";
Action<string>
HandleStringReceived = (string message) => {
// this will be called every time a message is received from serial port
Program.Notify("SerialPort String", message);
};
Action<byte[]>
HandleMessageReceived = (byte[] message) => {
// this will be called every time a message is received from serial port
Program.Notify("SerialPort Bytes", BitConverter.ToString(message));
};
Action<bool>
HandleStatusChanged = (bool connected) => {
// this will be called every time the connection status changes
Program.Notify("SerialPort Status", connected ? "CONNECTED!" : "DISCONNECTED!");
};
// open the serial port channel and register handlers
SerialPort
.WithName( portname )
.OnStatusChanged( HandleStatusChanged )
.OnMessageReceived( HandleMessageReceived )
.OnStringReceived( HandleStringReceived )
.Connect( 9600 ); // change baud rate if needed
while (Program.IsEnabled)
{
// send a test message through serial port every 10 seconds
//
byte[] message = { 0x00, 0x00, 0x00, 0x00, 0x00 };
SerialPort.SendMessage(message);
//
Pause(5);
SerialPort.SendMessage("Hello Things!");
//
Pause(10);
}