I have a project that requires a Raspberry Pi 3 to read 4 USB inputs coming from 4 microcontrollers (SAMD21G mini breakout boards in particular). They are connected directly via USB. Raspberry Pi 3 is running Windows IOT core.
I have used microsoft's Serial Sample app with success on reading up to 3 inputs simultaneously.
The problem is everytime i try 4 USB inputs, the raspberry pi hangs and disconnects from remote debugging, then I have to restart the Pi so i can do remote debugging again.
Below is a snippet of the code where the problem occurs.
everything stops at the line: "serialPort4 = await SerialDevice.FromIdAsync(entry4.Id);"
I've already tried the program on a PC and it works fine. Has anyone encountered this issue? any help would be appreciated :)
private async void comPortInput_Click_1(object sender, RoutedEventArgs e)
{
var selection = ConnectDevices.SelectedItems;
if (selection.Count <= 0)
{
status.Text = "Select a device and connect";
return;
}
DeviceInformation entry1 = (DeviceInformation)selection[0];
DeviceInformation entry2 = (DeviceInformation)selection[1];
DeviceInformation entry3 = (DeviceInformation)selection[2];
DeviceInformation entry4 = (DeviceInformation)selection[3];
try
{
serialPort1 = await SerialDevice.FromIdAsync(entry1.Id);
serialPort2 = await SerialDevice.FromIdAsync(entry2.Id);
serialPort3 = await SerialDevice.FromIdAsync(entry3.Id);
serialPort4 = await SerialDevice.FromIdAsync(entry4.Id);
if (serialPort1 == null || serialPort2 == null || serialPort3 == null || serialPort4 == null)
{
status.Text = "null";
return;
}
// Disable the 'Connect' button
comPortInput.IsEnabled = false;
// Configure serial settings
serialPort1.WriteTimeout = TimeSpan.FromMilliseconds(3);
serialPort1.ReadTimeout = TimeSpan.FromMilliseconds(3);
serialPort1.BaudRate =9600; //57600
serialPort1.Parity = SerialParity.None;
serialPort1.StopBits = SerialStopBitCount.One;
serialPort1.DataBits = 8;
serialPort1.Handshake = SerialHandshake.None;
serialPort2.WriteTimeout = TimeSpan.FromMilliseconds(3);
serialPort2.ReadTimeout = TimeSpan.FromMilliseconds(3);
serialPort2.BaudRate = 9600; //57600
serialPort2.Parity = SerialParity.None;
serialPort2.StopBits = SerialStopBitCount.One;
serialPort2.DataBits = 8;
serialPort2.Handshake = SerialHandshake.None;
serialPort3.WriteTimeout = TimeSpan.FromMilliseconds(3);
serialPort3.ReadTimeout = TimeSpan.FromMilliseconds(3);
serialPort3.BaudRate = 9600; //57600
serialPort3.Parity = SerialParity.None;
serialPort3.StopBits = SerialStopBitCount.One;
serialPort3.DataBits = 8;
serialPort3.Handshake = SerialHandshake.None;
serialPort4.WriteTimeout = TimeSpan.FromMilliseconds(3);
serialPort4.ReadTimeout = TimeSpan.FromMilliseconds(3);
serialPort4.BaudRate = 9600; //57600
serialPort4.Parity = SerialParity.None;
serialPort4.StopBits = SerialStopBitCount.One;
serialPort4.DataBits = 8;
serialPort4.Handshake = SerialHandshake.None;
// Create cancellation token object to close I/O operations when closing the device
ReadCancellationTokenSource = new CancellationTokenSource();
if (serialPort1 != null || serialPort2 != null || serialPort3 != null || serialPort4 != null) //|| serialPort4 != null
{
// Create the DataWriter object and attach to OutputStream
dataWriteObject1 = new DataWriter(serialPort1.OutputStream);
dataWriteObject2 = new DataWriter(serialPort2.OutputStream);
dataWriteObject3 = new DataWriter(serialPort3.OutputStream);
dataWriteObject4 = new DataWriter(serialPort4.OutputStream);
//Launch the WriteAsync task to perform the write
await WriteAsync();
}
else
{
status.Text = "Select a device and connect";
}
Listen();
}
catch (Exception ex)
{
status.Text = ex.Message;
comPortInput.IsEnabled = true;
//sendTextButton.IsEnabled = false;
}
}