dwilches/Ardity

I/O operation aborted

Closed this issue · 3 comments

I am having issues when sending signals with some frequency. The program starts fine, but after a few seconds it suddenly gives an exception, and I hear disconnecting sound from windows (arduino disconnects). After that, I get an exception that port does not exist.

The error in unity:

Exception: The I/O operation has been aborted because of either a thread exit or an application request.
 StackTrace:   at System.IO.Ports.WinSerialStream.ReportIOError (System.String optional_arg) [0x00039] in <14e3453b740b4bd690e8d4e5a013a715>:0 
  at System.IO.Ports.WinSerialStream.Read (System.Byte[] buffer, System.Int32 offset, System.Int32 count) [0x0009d] in <14e3453b740b4bd690e8d4e5a013a715>:0 
  at System.IO.Ports.SerialPort.read_byte () [0x00007] in <14e3453b740b4bd690e8d4e5a013a715>:0 
  at System.IO.Ports.SerialPort.ReadTo (System.String value) [0x0003c] in <14e3453b740b4bd690e8d4e5a013a715>:0 
  at System.IO.Ports.SerialPort.ReadLine () [0x00000] in <14e3453b740b4bd690e8d4e5a013a715>:0 
  at (wrapper remoting-invoke-with-check) System.IO.Ports.SerialPort.ReadLine()
  at SerialThreadLines.ReadFromWire (System.IO.Ports.SerialPort serialPort) [0x00001] in C:\Users\Lord\source\diploma\blind-karting\Assets\Ardity\Scripts\Threads\SerialThreadLines.cs:39 
  at AbstractSerialThread.RunOnce () [0x0002e] in C:\Users\Lord\source\diploma\blind-karting\Assets\Ardity\Scripts\Threads\AbstractSerialThread.cs:249 
  at AbstractSerialThread.RunForever () [0x0000f] in C:\Users\Lord\source\diploma\blind-karting\Assets\Ardity\Scripts\Threads\AbstractSerialThread.cs:142 
UnityEngine.Debug:LogWarning(Object)
AbstractSerialThread:RunForever() (at Assets/Ardity/Scripts/Threads/AbstractSerialThread.cs:149)
System.Threading.ThreadHelper:ThreadStart()

Arduino snippet:


      void setup()
      {
        pinMode(3, OUTPUT);
        pinMode(5, OUTPUT);
        pinMode(9, OUTPUT);
        pinMode(10, OUTPUT);
      
        Serial.begin(9600);
      }
      void loop()
      {
        // Print a heartbeat
        if (millis() > last_time + heartbeat_freq)
        {
          Serial.println("Arduino is alive!!");
          last_time = millis();
        }
      
        if (Serial.available() > 0) {
          char *arr = new char[7];
          int i = 0;
          while (Serial.available() > 0) {
            arr[i] = Serial.read();
            ++i;
          }
          message = String(arr);
          int indexOfDelimeter = message.indexOf(' ');
          firstString = message.substring(0, indexOfDelimeter);
          secondString = message.substring(indexOfDelimeter + 1);
          
         updateMotorSpeed(firstString.toInt(),secondString.toInt());
        }
      }

C# where I send the messages:

            leftWeight = Mathf.Round(Map(leftWeight, 0f, 9f, 0f, 255f));
            rightWeight = Mathf.Round(Map(rightWeight, 0f, 9f, 0f, 255f));


            serialController.SendSerialMessage(leftWeight + " " + rightWeight);

Hello,

Did you find a solution to this?
I don't know what can be wrong as you mention it's only with some frequencies and that Arduino disconnects from Windows, so that means the disconnection is not related to Ardity nor Unity.
Try to see if using a thicker USB cable, or if a shorter one helps, some cables are better than others.

Regards.

Hello,

Did you find a solution to this?
I don't know what can be wrong as you mention it's only with some frequencies and that Arduino disconnects from Windows, so that means the disconnection is not related to Ardity nor Unity.
Try to see if using a thicker USB cable, or if a shorter one helps, some cables are better than others.

Regards.

Yeah, I have some experience with Arduino, and I wondered, maybe the reason is an overuse of cpu and/or ram resources. It seems that Arduino is lacking voltage, or just restarting, because of the overflow. Currently, I don't have time to test what is causing it, so I will close the issue. But as soon as I will return to this problem, I'll make sure to tell you what was wrong. Thanks for such a great library, really saved my diploma for university :)