void Start()
 {
     arduinoSerial = new ArduinoSerial();
     arduinoSerial.ConnectToArduino(baudRate: 9600);
     AnnounceScene(SceneManager.GetActiveScene());
     SceneManager.sceneLoaded += SceneManager_sceneLoaded;
 }
Exemplo n.º 2
0
 public void Disconnect()
 {
     Arduino?.Disconnect();
     Arduino = null;
     _thread?.Abort();
     _thread?.Join(100);
     _thread = null;
 }
 private void Cleanup()
 {
     if (arduinoSerial != null)
     {
         arduinoSerial.ClosePort();
         arduinoSerial = null;
     }
 }
Exemplo n.º 4
0
 public void Start(string portName)
 {
     _arduino = new ArduinoSerial(portName);
     _arduino.BytesReceived += Receive;
     _arduino.Start();
     _thread = new Thread(Loop);
     _thread.IsBackground = true;
     _thread.Start();
 }
Exemplo n.º 5
0
    void Start()
    {
        serial = ArduinoSerial.Instance;
        bool success = serial.Open(portNum, ArduinoSerial.Baudrate.B_115200);

        if (!success)
        {
            return;
        }
        serial.OnDataReceived += SerialCallBack;
    }
Exemplo n.º 6
0
    private void Start()
    {
        _serial = ArduinoSerial.Instance;
        bool success = _serial.Open(null, ArduinoSerial.Baudrate.B_115200);

        if (!success)
        {
            return;
        }
        _serial.OnDataReceived += OnDataReceived;
    }
Exemplo n.º 7
0
 public void Connect(string portName)
 {
     Disconnect();
     Arduino                = new ArduinoSerial(portName);
     Arduino.BytesSent     += (port, bytes) => BytesSent?.Invoke(port, bytes);
     Arduino.BytesReceived += (port, bytes) => BytesReceived?.Invoke(port, bytes);
     Arduino.Connect(false);
     _thread = new Thread(Loop);
     _thread.IsBackground = true;
     _thread.Start();
 }
Exemplo n.º 8
0
        public ConnectResult TryConnect(string portName, bool sayhello)
        {
            if (portName == "")
            {
                return(ConnectResult.InvalidArgument);
            }
            Disconnect();
            EventWaitHandle ewh    = new EventWaitHandle(false, EventResetMode.AutoReset);
            ConnectResult   result = ConnectResult.None;

            Arduino                = new ArduinoSerial(portName);
            Arduino.BytesSent     += (port, bytes) => BytesSent?.Invoke(port, bytes);
            Arduino.BytesReceived += (port, bytes) => BytesReceived?.Invoke(port, bytes);
            ArduinoSerial.StatusChangedHandler statuschanged = status =>
            {
                lock (ewh)
                {
                    if (result != ConnectResult.None)
                    {
                        return;
                    }
                    if (status == ArduinoSerial.Status.Connected || status == ArduinoSerial.Status.ConnectedUnsafe)
                    {
                        result = ConnectResult.Success;
                        ewh.Set();
                    }
                    if (status == ArduinoSerial.Status.Error)
                    {
                        result = ConnectResult.Error;
                        ewh.Set();
                    }
                }
            };
            Arduino.StatusChanged += statuschanged;
            Arduino.Connect(sayhello);
            if (!ewh.WaitOne(300) && sayhello)
            {
                Arduino.Disconnect();
                Arduino = null;
                return(ConnectResult.Timeout);
            }
            if (result != ConnectResult.Success)
            {
                Arduino.Disconnect();
                Arduino = null;
                return(result);
            }
            Arduino.StatusChanged -= statuschanged;
            _thread = new Thread(Loop);
            _thread.IsBackground = true;
            _thread.Start();
            return(ConnectResult.Success);
        }
 void Start()
 {
     arduinoSerial = new ArduinoSerial();
     arduinoSerial.ConnectToArduino(baudRate: 115200);
 }
 void Start()
 {
     arduinoSerial = new ArduinoSerial();
     arduinoSerial.ConnectToArduino(baudRate: 115200, pName: portName);
     startRot = go.transform.rotation;
 }
Exemplo n.º 11
0
 // Use this for initialization
 void Start()
 {
     arduinoInfo = FindObjectOfType <ArduinoSerial>();
     setCom();
     arduinoInfo.comienzaThread();
 }
Exemplo n.º 12
0
 void Start()
 {
     serial = ArduinoSerial.Instance;
     serial.OnDataReceived += OnSerialReceived;
     serial.Open(null, ArduinoSerial.Baudrate.B_9600);
 }