I am using an arduino to test a HID controller on Ubuntu using Serial.IO.Ports and the default arduino serial setup at the moment, once its working I plan on increasing the baud rate. I am reading it on /dev/ttyUSB0 or USB1 depending on the port its plugged into. The arduino in question is a Ruggeduino Uno, it uses a different chip for serial communication from the standard uno r3 but it should work the same. This code works on Windows but get stuck on the first read (Line 131) on Ubuntu. I had to cut out the Windows stuff to shorten it to fit hoping I didn't break anything but it looks good.
Sorry about the code its kind of a mess (I SEE IT IN MY NIGHTMARES NOW).
using System.IO.Ports;class Program{ static void Main(string[] args) { Console.WriteLine("Begin Setup"); bool cerialSet = false; string cerial = ""; string read; bool realPort = false; SerialPort cerialPort = new SerialPort("/dev/ttyUSB0", 9600, Parity.None,8, StopBits.One); while (cerialSet != true) { try { if (realPort) { try { cerialPort.Open(); // Write data to the serial port //cerialPort.Write("3"); cerialPort.Write("respond"); // Read data from the serial port read = cerialPort.ReadLine();; if (read == "PedalTester" || read == "PedalTester\n" || read == "PedalTester\r" || read == "PedalTester " || read == "PedalTester \n" || read == "PedalTester \r") { cerialSet = true; } else { Console.WriteLine("Serial Port entered is not valid \n Assign Serial Port For Tester:"); } cerialPort.Close(); } catch { Console.WriteLine("Serial Port entered is not available \n Assign Serial Port For Tester:"); } } else { Console.WriteLine("Serial Port entered is not a real Port \n Assign Serial Port For Tester:"); } } catch (UnauthorizedAccessException) { Console.WriteLine($"Serial port {cerial} is not available."); } catch { Console.WriteLine("Serial Port entered is not available \n Assign Serial Port For Tester:"); } } }}
The code should read the response from the arduin "PedalTester" to confirm it is the correct device then move onto checking the HID deviec being tested and progress into the test loop.
Currently it is getting stuck waiting for the Arduino to respond PedalTester. Sometimes it work if you break before it and step through the code but will freeze later in the a or b testing loops.
I have drive SerialPortStream and LibSerial neither worked. I added user to Dialout and disabled the manager thing with no changes.