Bluetooth serial port drops final command (Mac OS)

HomeForumsMonoBrick Communication LibraryBluetooth serial port drops final command (Mac OS)

Viewing 1 post (of 1 total)
  • Author
    Posts
  • #4931
    Author Image
    bl-nero
    Participant

    Consider this simple program:

    using System;
    using System.Threading;
    using MonoBrick.EV3;
    
    namespace MonoBrickTest {
      class MainClass {
        public static void Main(string[] args) {
          string portName = args.Length > 0 ? args[0] : "usb";
          var ev3 = new Brick<Sensor, Sensor, Sensor, IRSensor>(portName);
          ev3.Connection.Open();
          ev3.MotorB.On(1);
          Thread.Sleep(200);  // (1)
          ev3.MotorB.Off();
          // Thread.Sleep(2000);  // (2)
          ev3.Connection.Close();  // optional
        }
      }
    }
    

    When I use USB, it’s fine. However, if I decide to connect through Bluetooth to my EV3, it sometimes (very frequently) drops the Off() command and keeps the motor turned on. If I get rid of statement (1), the “off” command is always skipped. However, it’s enough to uncomment (2) to stop this behavior.

    I have a theory that the serial port doesn’t flush itself properly before closing, so I decided to dig further – I dumped both commands into binary files from inside the Bluetooth.Send() method, and sent them manually to the serial port device using the “cat” command. I confirmed that I can send them one by one to make the motor start and stop, and that sending them both at once didn’t leave the motor turned on – so the commands are 100% correct, and it’s most probably the connection handling that gets messed up.

    Did anyone else come across this problem? I can see a mysterious Thread.Sleep() in the Bluetooth class in the Open() method; could this be for similar reasons?

    For the reference, here’s what mono –version says:

    Mono JIT compiler version 3.10.0 ((detached/e204655 Mon Oct 13 08:50:28 EDT 2014)
    Copyright (C) 2002-2014 Novell, Inc, Xamarin Inc and Contributors. www.mono-project.com
    	TLS:           normal
    	SIGSEGV:       altstack
    	Notification:  kqueue
    	Architecture:  x86
    	Disabled:      none
    	Misc:          softdebug
    	LLVM:          yes(3.4svn-mono-(detached/e656cac)
    	GC:            sgen

    I’m using Mac OS 10.9.5.

    And here’s the brick info:

    Brick HW: V0.60
    Brick FW: V1.06H
    • This topic was modified 10 years ago by Author Imagebl-nero.
    • This topic was modified 10 years ago by Author Imagebl-nero.
    • This topic was modified 10 years ago by Author Imagebl-nero.
Viewing 1 post (of 1 total)

You must be logged in to reply to this topic.

Posted in

Make a donation