Esempio n. 1
0
        /// <summary>
        /// Sets up a conntection to a specified serial port.
        /// </summary>
        /// <param name="Dtr">If <c>true</c> use dtr for transmition.</param>
        public static bool Setup(bool Dtr = false)
        {
            if (SerialPortName != null)
            {
                if (_cmdMessenger != null)
                {
                    _cmdMessenger.Disconnect();
                    _cmdMessenger.Dispose();
                }
                if (ConnectionWatchdog != null)
                {
                    ConnectionWatchdog.Dispose();
                }

                _cmdMessenger = new CmdMessenger(new SerialTransport()
                {
                    CurrentSerialSettings =
                    {
                        PortName  = SerialPortName,
                        BaudRate  =         115200,
                        DataBits  =              8,
                        Parity    = Parity.None,
                        DtrEnable = Dtr
                    }
                }, 512, BoardType.Bit32);

                // Attach the callbacks to the Command Messenger
                AttachCommandCallBacks();

                // Attach to NewLinesReceived for logging purposes
                _cmdMessenger.NewLineReceived += NewLineReceived;

                // Attach to NewLineSent for logging purposes
                _cmdMessenger.NewLineSent += NewLineSent;

                // Start listening
                IsConnected = _cmdMessenger.Connect();
                if (!IsConnected)
                {
                    SerialPortName = string.Empty;
                }
                else
                {
                    ConnectionWatchdog = new System.Threading.Timer(new System.Threading.TimerCallback(ConnectionWatchdogCallback), null, 0, 1000);
                }
                return(IsConnected);
            }
            return(false);
        }
Esempio n. 2
0
 // Exit function
 public void Exit()
 {
     _connectionManager.Dispose();
     _cmdMessenger.Disconnect();
     _cmdMessenger.Dispose();
     _transport.Dispose();
 }
Esempio n. 3
0
 public static void Disconnect()
 {
     LogCommands(false);
     CmdMessenger.Disconnect();
     Connected = false;
     //CmdMessenger.Dispose();
 }
        public bool SearchAndConnectToArduino()
        {
            for (var i = 0; i <= 20; i++)
            {
                _serialTransport = new SerialTransport
                {
                    CurrentSerialSettings = { PortName = "COM" + i.ToString(), BaudRate = 115200 }
                };
                _cmdMessenger = new CmdMessenger(_serialTransport)
                {
                    BoardType = BoardType.Bit16
                };
                AttachCommandCallBacks();
                _cmdMessenger.Connect();

                var commandCheck = new SendCommand((int)Command.pCheckArduino);
                _cmdMessenger.SendCommand(commandCheck);
                Thread.Sleep(100);//wait 100 ms for the response
                if (_arduinoFound)
                {
                    return(true);
                }
                //else
                _cmdMessenger.Disconnect();
                _cmdMessenger.Dispose();
                _serialTransport.Dispose();
            }
            return(false);
        }
Esempio n. 5
0
        // Exit function
        public void Exit()
        {
            // Stop listening
            _cmdMessenger.Disconnect();

            // Dispose Command Messenger
            _cmdMessenger.Dispose();

            // Dispose Serial Port object
            _serialTransport.Dispose();
        }
 public void Stop()
 {
     if (_cmdMessenger != null)
     {
         _cmdMessenger.Disconnect();
         _cmdMessenger.Dispose();
     }
     if (_serialTransport != null)
     {
         _serialTransport.Dispose();
     }
 }
Esempio n. 7
0
        // Exit function
        public void Exit()
        {
            // Stop listening
            _cmdMessenger.Disconnect();

            // Dispose Command Messenger
            _cmdMessenger.Dispose();

            // Dispose Serial Port object
            _serialTransport.Dispose();

            // Pause before stop
            Console.WriteLine("Press any key to stop...");
            Console.ReadKey();
        }
Esempio n. 8
0
        // Exit function
        public void Exit()
        {
            // Stop listening
            _cmdMessenger.Disconnect();

            // Dispose Command Messenger
            _cmdMessenger.Dispose();

            // Dispose Serial Port object
            _serialTransport.Dispose();
            Properties.Settings.Default.initRed     = _controllerForm._RedValue;
            Properties.Settings.Default.initGreen   = _controllerForm._GreenValue;
            Properties.Settings.Default.initBlue    = _controllerForm._BlueValue;
            Properties.Settings.Default.initGlitter = _controllerForm.glitter;
            Properties.Settings.Default.Save();
        }
Esempio n. 9
0
        // Exit function
        public void Exit()
        {
            if (_cmdMessenger != null)
            {
                // Stop listening
                _cmdMessenger.Disconnect();

                // Dispose Command Messenger
                _cmdMessenger.Dispose();
            }
            // Dispose Serial Port object
            // Dispose Serial Port object
            if (_serialTransport != null)
            {
                _serialTransport.Dispose();
            }
        }
        // Exit function
        public void Exit()
        {
            // Disconnect ConnectionManager
            _connectionManager.Progress          -= LogProgress;
            _connectionManager.ConnectionTimeout -= ConnectionTimeout;
            _connectionManager.ConnectionFound   -= ConnectionFound;

            // Dispose ConnectionManager
            _connectionManager.Dispose();

            // Disconnect Command Messenger
            _cmdMessenger.Disconnect();

            // Dispose Command Messenger
            _cmdMessenger.Dispose();

            // Dispose transport layer
            _transport.Dispose();
        }
Esempio n. 11
0
 public void Dispose()
 {
     _messenger.Disconnect();
     _messenger.Dispose();
     _transport.Dispose();
 }
Esempio n. 12
0
 public bool Disconnect()
 {
     return(_cmdMessenger.Disconnect());
 }
Esempio n. 13
0
 protected void Disconnect()
 {
     // Stop listening
     _cmdMessenger.Disconnect();
 }
Esempio n. 14
0
 public void Exit()
 {
     _cmdMessenger.Disconnect();
     _cmdMessenger.Dispose();
     _serialTransport.Dispose();
 }
Esempio n. 15
0
 private void Close()
 {
     cmdMessenger.Disconnect();
     cmdMessenger.Dispose();
     cmdMessenger = null;
 }