Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

I/O operation aborted #49

Closed
LordNani opened this issue May 20, 2021 · 3 comments
Closed

I/O operation aborted #49

LordNani opened this issue May 20, 2021 · 3 comments

Comments

@LordNani
Copy link

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);
@LordNani
Copy link
Author

image

@dwilches
Copy link
Owner

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.

@LordNani
Copy link
Author

LordNani commented Jun 2, 2021

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 :)

@LordNani LordNani closed this as completed Jun 2, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants