public void TestOpenConnection()
        {
            Common.StartTest("Test opening connection");
            try
            {
                _cmdMessenger = Common.Connect(_systemSettings);
                AttachCommandCallBacks();
            }
            catch (Exception)
            {
                Common.TestNotOk("Exception during opening connection");
                Common.EndTest();
                return;
            }

            if (_systemSettings.Transport.IsConnected())
            {
                Common.TestOk("No issues during opening connection");
            }
            else
            {
                Common.TestNotOk("Not open after trying to open connection");
            }

            Common.EndTest();
        }
        // ------------------ M A I N  ----------------------

        // Setup function
        public void Setup()
        {
            // Create Serial Port object
            // Note that for some boards (e.g. Sparkfun Pro Micro) DtrEnable may need to be true.
            _serialTransport = new SerialTransport
            {
                CurrentSerialSettings = { PortName = "COM6", BaudRate = 115200, DtrEnable = false } // object initializer
            };

            // Initialize the command messenger with the Serial Port transport layer
            // Set if it is communicating with a 16- or 32-bit Arduino board
            _cmdMessenger = new CmdMessenger(_serialTransport, BoardType.Bit16);

            // 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
            _cmdMessenger.Connect();
        }
Example #3
0
        protected ConnectionManager(CmdMessenger cmdMessenger, int identifyCommandId = 0, string uniqueDeviceId = null)
        {
            if (cmdMessenger == null)
            {
                throw new ArgumentNullException("cmdMessenger", "Command Messenger is null.");
            }

            _cmdMessenger      = cmdMessenger;
            _identifyCommandId = identifyCommandId;
            _uniqueDeviceId    = uniqueDeviceId;

            WatchdogTimeout      = 3000;
            WatchdogRetryTimeout = 1500;
            WatchdogTries        = 3;
            WatchdogEnabled      = false;

            PersistentSettings = false;
            DeviceScanEnabled  = true;

            _worker      = new AsyncWorker(DoWork);
            _worker.Name = "ConnectionManager";

            if (!string.IsNullOrEmpty(uniqueDeviceId))
            {
                _cmdMessenger.Attach(identifyCommandId, OnIdentifyResponse);
            }
        }
Example #4
0
        // ------------------ MAIN  ----------------------

        // Setup function
        public void Setup(ControllerForm controllerForm)
        {
            // storing the controller form for later reference
            _controllerForm = controllerForm;
            
            // Create Serial Port object
            _serialTransport = new SerialTransport
            {
                CurrentSerialSettings = { PortName = "COM6", BaudRate = 115200 } // object initializer
            };

            // Initialize the command messenger with the Serial Port transport layer
            _cmdMessenger = new CmdMessenger(_serialTransport);

            // Tell CmdMessenger to "Invoke" commands on the thread running the WinForms UI
            _cmdMessenger.SetControlToInvokeOn(_controllerForm);

            // 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
            _cmdMessenger.StartListening();

            _controllerForm.SetLedState(true);
            _controllerForm.SetFrequency(2);
        }
        // ------------------ MAIN  ----------------------

        // Setup function
        public void Setup(ControllerForm controllerForm)
        {
            // storing the controller form for later reference
            _controllerForm = controllerForm;

            // Create Serial Port object
            // Note that for some boards (e.g. Sparkfun Pro Micro) DtrEnable may need to be true.
            _serialTransport = new SerialTransport
            {
                CurrentSerialSettings = { PortName = "COM6", BaudRate = 115200, DtrEnable = false } // object initializer
            };

            // Initialize the command messenger with the Serial Port transport layer
            // Set if it is communicating with a 16- or 32-bit Arduino board
            _cmdMessenger = new CmdMessenger(_serialTransport, BoardType.Bit16);

            // Tell CmdMessenger to "Invoke" commands on the thread running the WinForms UI
            _cmdMessenger.ControlToInvokeOn = _controllerForm;

            // 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
            _cmdMessenger.Connect();

            _controllerForm.SetLedState(true);
            _controllerForm.SetFrequency(2);
        }
        // Setup function
        public void Setup()
        {
            _transport = new SerialTransport {CurrentSerialSettings = {DtrEnable = false}};
            // some boards (e.g. Sparkfun Pro Micro) DtrEnable may need to be true.                        
            // We do not need to set serial port and baud rate: it will be found by the connection manager                                                           

            // Initialize the command messenger with the Serial Port transport layer
            // Set if it is communicating with a 16- or 32-bit Arduino board
            _cmdMessenger = new CmdMessenger(_transport, BoardType.Bit16)
            {
                PrintLfCr = false // Do not print newLine at end of command, to reduce data being sent
            };

            // The Connection manager is capable or storing connection settings, in order to reconnect more quickly  
            // the next time the application is run. You can determine yourself where and how to store the settings
            // by supplying a class, that implements ISerialConnectionStorer. For convenience, CmdMessenger provides
            //  simple binary file storage functionality
            var serialConnectionStorer = new SerialConnectionStorer("SerialConnectionManagerSettings.cfg");

            // We don't need to provide a handler for the Identify command - this is a job for Connection Manager.
            _connectionManager = new SerialConnectionManager(
                _transport as SerialTransport, 
                _cmdMessenger,
                (int) Command.Identify, 
                CommunicationIdentifier,
                serialConnectionStorer)
            {
                // Enable watchdog functionality.
                WatchdogEnabled = true,

                // Instead of scanning for the connected port, you can disable scanning and only try the port set in CurrentSerialSettings
                //DeviceScanEnabled = false
            };

            // Show all connection progress on command line             
            _connectionManager.Progress += (sender, eventArgs) =>
            {
                // If you want to reduce verbosity, you can only show events of level <=2 or ==1
                if (eventArgs.Level <= 3) Console.WriteLine(eventArgs.Description);
            };

            // If connection found, tell the arduino to turn the (internal) led on
            _connectionManager.ConnectionFound += (sender, eventArgs) =>
            {
                // Create command
                var command = new SendCommand((int)Command.TurnLedOn);
                // Send command
                _cmdMessenger.SendCommand(command);
            };

            //You can also do something when the connection is lost
            _connectionManager.ConnectionTimeout += (sender, eventArgs) =>
            {
                //Do something
            };

            // Finally - activate connection manager
            _connectionManager.StartConnectionManager();
        }
Example #7
0
        public static CmdMessenger Connect(systemSettings systemSettings)
        {
            CmdMessenger = new CmdMessenger(systemSettings.Transport, systemSettings.sendBufferMaxLength) {BoardType = systemSettings.BoardType};
            // Attach to NewLineReceived and NewLineSent for logging purposes
            LogCommands(true);

            CmdMessenger.StartListening();
            return CmdMessenger;
        }
Example #8
0
 /// <summary> send command queue constructor. </summary>
 /// <param name="disposeStack"> DisposeStack. </param>
 /// <param name="cmdMessenger"> The command messenger. </param>
 /// <param name="sender">Object that does the actual sending of the command</param>
 /// <param name="sendBufferMaxLength">Length of the send buffer</param>
 public SendCommandQueue(DisposeStack disposeStack, CmdMessenger cmdMessenger, Sender sender, int sendBufferMaxLength)
     : base(disposeStack, cmdMessenger)
 {
     MaxQueueLength       = 5000;
     QueueThread.Name     = "SendCommandQueue";
     _sender              = sender;
     _sendBufferMaxLength = sendBufferMaxLength;
     // _queueSpeed.Name = "SendCommandQueue";
 }
Example #9
0
 /// <summary> send command queue constructor. </summary>
 /// <param name="disposeStack"> DisposeStack. </param>
 /// <param name="cmdMessenger"> The command messenger. </param>
 /// <param name="sender">Object that does the actual sending of the command</param>
 /// <param name="sendBufferMaxLength">Length of the send buffer</param>
 public SendCommandQueue(DisposeStack disposeStack, CmdMessenger cmdMessenger, Sender sender, int sendBufferMaxLength)
     : base(disposeStack, cmdMessenger)
 {
     MaxQueueLength = 5000;
     QueueThread.Name = "SendCommandQueue";
     _sender = sender;
     _sendBufferMaxLength = sendBufferMaxLength;
     // _queueSpeed.Name = "SendCommandQueue";
 }
 public void SetUpConnection()
 {
     _cmdMessenger = Common.Connect(_systemSettings);
     AttachCommandCallBacks();
     if (!Common.Connected)
     {
         Common.TestNotOk("Not connected after opening connection");
     }            
 }
Example #11
0
        public Action GoalTemperatureChanged;   // Action that is called when the goal temperature has changed

        // Setup function
        public void Setup(ChartForm chartForm)
        {           
            // getting the chart control on top of the chart form.
            _chartForm = chartForm;
            
            // Set up chart
            _chartForm.SetupChart();

            // Connect slider to GoalTemperatureChanged
            GoalTemperatureChanged += new Action(() => _chartForm.GoalTemperatureTrackBarScroll(null, null));

            // Create Serial Port object
            _serialTransport = new SerialTransport
            {
                CurrentSerialSettings = { PortName = "COM6", BaudRate = 115200 } // object initializer
            };

            // Initialize the command messenger with the Serial Port transport layer
            _cmdMessenger = new CmdMessenger(_serialTransport);

            // Tell CmdMessenger to "Invoke" commands on the thread running the WinForms UI
            _cmdMessenger.SetControlToInvokeOn(chartForm);

            // Set command strategy to continuously to remove all commands on the receive queue that 
            // are older than 1 sec. This makes sure that if data logging comes in faster that it can 
            // be plotted, the graph will not start lagging
            _cmdMessenger.AddReceiveCommandStrategy(new StaleGeneralStrategy(1000));            

            // 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
            _cmdMessenger.StartListening();

            // Send command to start sending data
            var command = new SendCommand((int)Command.StartLogging);

            // Send command
            _cmdMessenger.SendCommand(command);

            // Wait for a little bit and clear the receive queue
            Thread.Sleep(250);
            _cmdMessenger.ClearReceiveQueue();

            // Set initial goal temperature
            GoalTemperature = 25;            
        }
Example #12
0
        /// <summary> command queue constructor. </summary>
        /// <param name="disposeStack"> DisposeStack. </param>
        /// <param name="cmdMessenger"> The command messenger. </param>
        public CommandQueue(DisposeStack disposeStack, CmdMessenger cmdMessenger)
        {
            CmdMessenger = cmdMessenger;
            disposeStack.Push(this);

            // Create queue thread and wait for it to start
            QueueThread = new Thread(ProcessQueue) {Priority = ThreadPriority.Normal};
            QueueThread.Start();
            while (!QueueThread.IsAlive)
            {
                Thread.Sleep(TimeSpan.FromMilliseconds(50));
            }
        }
Example #13
0
        public static CmdMessenger Connect(systemSettings systemSettings)
        {
            if (CmdMessenger == null)
            {
                CmdMessenger = new CmdMessenger(systemSettings.Transport, systemSettings.sendBufferMaxLength,
                    systemSettings.BoardType);
            }

            // Attach to NewLineReceived and NewLineSent for logging purposes
            LogCommands(true);

            Connected = CmdMessenger.Connect();
            return CmdMessenger;
        }
Example #14
0
 public void SetUpConnection()
 {
     try
     {
         _cmdMessenger = Common.Connect(_systemSettings);
         AttachCommandCallBacks();
     }
     catch (Exception)
     {
     }
     if (!_systemSettings.Transport.IsConnected())
     {
     }
 }
Example #15
0
        /// <summary> command queue constructor. </summary>
        /// <param name="disposeStack"> DisposeStack. </param>
        /// <param name="cmdMessenger"> The command messenger. </param>
        public CommandQueue(DisposeStack disposeStack, CmdMessenger cmdMessenger)
        {
            CmdMessenger = cmdMessenger;
            disposeStack.Push(this);

            // Create queue thread and wait for it to start
            QueueThread = new Thread(ProcessQueue)
            {
                Priority = ThreadPriority.Normal
            };
            QueueThread.Start();
            while (!QueueThread.IsAlive && QueueThread.ThreadState != ThreadState.Running)
            {
                Thread.Sleep(TimeSpan.FromMilliseconds(25));
            }
        }
Example #16
0
        public override void Setup()
        {
            // Create Serial Port object
            serialTransport = new SerialTransport();
            serialTransport.CurrentSerialSettings.PortName = Config.SerialCOMPort;
            serialTransport.CurrentSerialSettings.BaudRate = Config.SerialBaudRate;
            serialTransport.CurrentSerialSettings.DtrEnable = Config.SerialDtrEnable;     // For some boards (e.g. Sparkfun Pro Micro) DtrEnable may need to be true.

            // Initialize the command messenger with the Serial Port transport layer
            cmdMessenger = new CmdMessenger(serialTransport);

            // Tell CmdMessenger if it is communicating with a 16 or 32 bit Arduino board
            cmdMessenger.BoardType = Config.SerialBoardType;

            // Start listening
            cmdMessenger.StartListening();
        }
Example #17
0
        // ------------------ MAIN  ----------------------
        // Setup function
        public void Setup(ChartForm chartForm)
        {
            // getting the chart control on top of the chart form.
            _chartForm = chartForm;

            // Set up chart
            _chartForm.SetupChart();

            // Create Serial Port object
            // Note that for some boards (e.g. Sparkfun Pro Micro) DtrEnable may need to be true.
            _serialTransport = new SerialTransport
            {
                CurrentSerialSettings = { PortName = "COM6", BaudRate = 115200, DtrEnable = false } // object initializer
            };

            // Initialize the command messenger with the Serial Port transport layer
            _cmdMessenger = new CmdMessenger(_serialTransport)
            {
                BoardType = BoardType.Bit16 // Set if it is communicating with a 16- or 32-bit Arduino board
            };

            // Tell CmdMessenger to "Invoke" commands on the thread running the WinForms UI
            _cmdMessenger.SetControlToInvokeOn(chartForm);

            // Set Received command strategy that removes commands that are older than 1 sec
            _cmdMessenger.AddReceiveCommandStrategy(new StaleGeneralStrategy(1000));

            // 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
            _cmdMessenger.StartListening();

            // Send command to start sending data
            var command = new SendCommand((int)Command.StartLogging);

            // Send command
            _cmdMessenger.SendCommand(command);
        }
Example #18
0
        // Setup function
        public void Setup()
        {
            _ledState = false;

            // Create Serial Port object
            _serialTransport = new SerialTransport();
            _serialTransport.CurrentSerialSettings.PortName = "COM6";     // Set com port
            _serialTransport.CurrentSerialSettings.BaudRate = 115200;     // Set baud rate

            // Initialize the command messenger with the Serial Port transport layer
            _cmdMessenger = new CmdMessenger(_serialTransport);
            
            // Attach the callbacks to the Command Messenger
            AttachCommandCallBacks();
            
            // Start listening
            _cmdMessenger.StartListening();                                
        }
Example #19
0
        // Setup function
        public void Setup()
        {
            _ledState = false;

            // Create Serial Port object
            _serialTransport = new SerialTransport();
            _serialTransport.CurrentSerialSettings.PortName = "COM6";    // Set com port
            _serialTransport.CurrentSerialSettings.BaudRate = 115200;     // Set baud rate
            _serialTransport.CurrentSerialSettings.DtrEnable = false;     // For some boards (e.g. Sparkfun Pro Micro) DtrEnable may need to be true.
            
            // Initialize the command messenger with the Serial Port transport layer
            _cmdMessenger = new CmdMessenger(_serialTransport, BoardType.Bit16);

            // Attach the callbacks to the Command Messenger
            AttachCommandCallBacks();
            
            // Start listening
            _cmdMessenger.Connect();                                
        }
Example #20
0
        // ------------------ MAIN  ----------------------

        // Setup function
        public void Setup(ChartForm chartForm)
        {
           
            // getting the chart control on top of the chart form.
            _chartForm = chartForm;
            
            // Set up chart
            _chartForm.SetupChart();

            // Create Serial Port object
            _serialTransport = new SerialTransport
            {
                CurrentSerialSettings = { PortName = "COM6", BaudRate = 115200 } // object initializer
            };

            // Initialize the command messenger with the Serial Port transport layer
            _cmdMessenger = new CmdMessenger(_serialTransport);

            // Tell CmdMessenger to "Invoke" commands on the thread running the WinForms UI
            _cmdMessenger.SetControlToInvokeOn(chartForm);

            // Set Received command strategy that removes commands that are older than 1 sec
            _cmdMessenger.AddReceiveCommandStrategy(new StaleGeneralStrategy(1000));

            // 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
            _cmdMessenger.StartListening();

            // Send command to start sending data
            var command = new SendCommand((int)Command.StartLogging);

            // Send command
            _cmdMessenger.SendCommand(command);
        }
Example #21
0
        // Setup function
        public void Setup()
        {
            // Create Serial Port object
            _serialTransport = new SerialTransport();
            _serialTransport.CurrentSerialSettings.PortName = ConfigurationManager.AppSettings["COMPort"];    // Set com port
            _serialTransport.CurrentSerialSettings.BaudRate = int.Parse(ConfigurationManager.AppSettings["BaudRate"]);     // Set baud rate
            _serialTransport.CurrentSerialSettings.DtrEnable = false;     // For some boards (e.g. Sparkfun Pro Micro) DtrEnable may need to be true.

            // Initialize the command messenger with the Serial Port transport layer
            _cmdMessenger = new CmdMessenger(_serialTransport);

            // Tell CmdMessenger if it is communicating with a 16 or 32 bit Arduino board
            _cmdMessenger.BoardType = BoardType.Bit16;

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

            // Start listening
            _cmdMessenger.StartListening();
        }
Example #22
0
        public Commander(String portname, int baudrate, BoardType boardtype)
        {
            Transport = new SerialTransport
            {
                CurrentSerialSettings =
                { 
                    PortName = portname, 
                    BaudRate = baudrate, 
                    DtrEnable = false
                }
            };

            Messenger = new CmdMessenger(Transport)
            {
                BoardType = boardtype
            };

            AttachCommandCallBacks();
            Messenger.StartListening();
        }
 public void SetUpConnection()
 {
     try
     {
         _cmdMessenger = Common.Connect(_systemSettings);
         AttachCommandCallBacks();
         if (!Common.Connected)
         {
             Common.TestNotOk("Not connected after opening connection");
         }               
     }
     catch (Exception)
     {
         Common.TestNotOk("CmdMessenger application could not be created");
         Common.EndTestSet();
     }
     if (!_systemSettings.Transport.IsConnected())
     {
         Common.TestOk("No issues during opening connection");
     }
 }
        private const float SeriesBase = 1111111.111111F;       // Base of values to return: SeriesBase * (0..SeriesLength-1)

        // ------------------ M A I N  ----------------------

        // Setup function
        public void Setup()
        {
            // Create Serial Port object
            _serialTransport = new SerialTransport
            {
                CurrentSerialSettings = { PortName = "COM6", BaudRate = 115200 } // object initializer
            };

            // Initialize the command messenger with the Serial Port transport layer
            _cmdMessenger = new CmdMessenger(_serialTransport);

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

            // Start listening
            _cmdMessenger.StartListening();

            _receivedPlainTextCount = 0;
            
            // Send command requesting a series of 100 float values send in plain text
            var commandPlainText = new SendCommand((int)Command.RequestPlainTextFloatSeries);
            commandPlainText.AddArgument(SeriesLength);
            commandPlainText.AddArgument(SeriesBase);
            // Send command 
            _cmdMessenger.SendCommand(commandPlainText);

            // Now wait until all values have arrived
            while (!_receivePlainTextFloatSeriesFinished) {}

            // Send command requesting a series of 100 float values send in plain text
            var commandBinary = new SendCommand((int)Command.RequestBinaryFloatSeries);
            commandBinary.AddBinArgument((UInt16)SeriesLength);
            commandBinary.AddBinArgument((Single)SeriesBase); 
            
            // Send command 
            _cmdMessenger.SendCommand(commandBinary);

            // Now wait until all values have arrived
            while (!_receiveBinaryFloatSeriesFinished) { }
        }
Example #25
0
        protected ConnectionManager(CmdMessenger cmdMessenger, int challengeCommandId, int responseCommandId)
        {
            WatchdogTimeOut      = 2000;
            WatchdogRetryTimeOut = 1000;
            MaxWatchdogTries     = 3;

            if (cmdMessenger == null)
            {
                return;
            }

            ControlToInvokeOn = null;
            CmdMessenger      = cmdMessenger;
            _scanThread       = new BackgroundWorker {
                WorkerSupportsCancellation = true, WorkerReportsProgress = false
            };
            _scanThread.DoWork += ScanThreadDoWork;
            _challengeCommandId = challengeCommandId;
            _responseCommandId  = responseCommandId;

            CmdMessenger.Attach((int)responseCommandId, OnResponseCommandId);
        }
        // ------------------ M A I N  ----------------------

        // Setup function
        public void Setup()
        {
            // Create Serial Port object
            _serialTransport = new SerialTransport
            {
                CurrentSerialSettings = { PortName = "COM6", BaudRate = 115200 } // object initializer
            };

            // Initialize the command messenger with the Serial Port transport layer
            _cmdMessenger = new CmdMessenger(_serialTransport);

            // 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
            _cmdMessenger.StartListening();
        }
Example #27
0
        // ------------------ MAIN  ----------------------
        // Setup function
        public void Setup(ChartForm chartForm)
        {
            // getting the chart control on top of the chart form.
            _chartForm = chartForm;

            // Set up chart
            _chartForm.SetupChart();

            // Create Serial Port object
            _serialPortManager = new SerialPortManager
            {
                CurrentSerialSettings = { PortName = "COM6", BaudRate = 115200 } // object initializer
            };

            _cmdMessenger = new CmdMessenger(_serialPortManager);

            // Tell CmdMessenger to "Invoke" commands on the thread running the WinForms UI
            _cmdMessenger.SetControlToInvokeOn(chartForm);

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

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

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

            // Start listening
            _cmdMessenger.StartListening();

            // Send command to start sending data
            var command = new SendCommand((int)Command.StartLogging);

            // Send command
            _cmdMessenger.SendCommand(command);
        }
        // Setup function
        public void Setup(ChartForm chartForm)
        {
            // getting the chart control on top of the chart form.
            _chartForm = chartForm;

            // Set up chart
            _chartForm.SetupChart();

            // Connect slider to GoalTemperatureChanged
            GoalTemperatureChanged += () => _chartForm.GoalTemperatureTrackBarScroll(null, null);

            // Create Serial Port object
            // Note that for some boards (e.g. Sparkfun Pro Micro) DtrEnable may need to be true.
            _serialTransport = new SerialTransport
            {
                CurrentSerialSettings = { PortName = "COM6", BaudRate = 115200, DtrEnable = false } // object initializer
            };

            // Initialize the command messenger with the Serial Port transport layer
            _cmdMessenger = new CmdMessenger(_serialTransport)
            {
                BoardType = BoardType.Bit16, // Set if it is communicating with a 16- or 32-bit Arduino board
                PrintLfCr = false            // Do not print newLine at end of command, to reduce data being sent
            };

            // Tell CmdMessenger to "Invoke" commands on the thread running the WinForms UI
            _cmdMessenger.SetControlToInvokeOn(chartForm);

            // Set command strategy to continuously to remove all commands on the receive queue that
            // are older than 1 sec. This makes sure that if data logging comes in faster that it can
            // be plotted, the graph will not start lagging
            _cmdMessenger.AddReceiveCommandStrategy(new StaleGeneralStrategy(1000));

            // 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
            _cmdMessenger.StartListening();

            // Send command to start sending data
            var command = new SendCommand((int)Command.StartLogging);

            // Send command
            _cmdMessenger.SendCommand(command);

            // Wait for a little bit and clear the receive queue
            Thread.Sleep(250);
            _cmdMessenger.ClearReceiveQueue();

            // Set initial goal temperature
            GoalTemperature = 25;
        }
Example #29
0
        // Setup function
        public void Setup()
        {
            _ledState = false;

            // Create Serial Port object
            _serialPortManager = new SerialPortManager
                {
                    CurrentSerialSettings = {PortName = "COM6", BaudRate = 115200} // object initializer
                };
            _cmdMessenger = new CmdMessenger(_serialPortManager);

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

            // Start listening
            _cmdMessenger.StartListening();
        }
Example #30
0
        // Setup function
        public void Setup()
        {
            _ledState = false;

            // Create Serial Port object
            _serialPortManager = new SerialPortManager();
            _serialPortManager.CurrentSerialSettings.PortName = "COM6";     // Set com port
            _serialPortManager.CurrentSerialSettings.BaudRate = 115200;     // Set baud rate
            _cmdMessenger = new CmdMessenger(_serialPortManager);

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

            // Start listening
            _cmdMessenger.StartListening();
        }
Example #31
0
 public void SetUpConnection()
 {
     _cmdMessenger = Common.Connect(_systemSettings);
     AttachCommandCallBacks();
 }
Example #32
0
        // Setup function
        public void Setup()
        {
            _ledState = false;

            // Create Serial Port object
            // Note that for some boards (e.g. Sparkfun Pro Micro) DtrEnable may need to be true.
            _serialTransport = new SerialTransport
            {
                CurrentSerialSettings = { PortName = "COM6", BaudRate = 115200, DtrEnable = false } // object initializer
            };

            // Initialize the command messenger with the Serial Port transport layer
            _cmdMessenger = new CmdMessenger(_serialTransport)
                {
                    BoardType = BoardType.Bit16 // Set if it is communicating with a 16- or 32-bit Arduino board
                };

            // Tell CmdMessenger if it is communicating with a 16 or 32 bit Arduino board

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

            // Start listening
            _cmdMessenger.StartListening();
        }
        public void Initialize()
        {
            Debug.WriteLine("***********************************START*************************");

            _transport = new SerialTransport { CurrentSerialSettings = { DtrEnable = false } };

            _cmdMessenger = new CmdMessenger(_transport, BoardType.Bit16) { PrintLfCr = false };
            _cmdMessenger.NewLineReceived += _cmdMessenger_NewLineReceived;
            _cmdMessenger.NewLineSent += _cmdMessenger_NewLineSent;

            AttachCallbacks();
            _connectionManager = new SerialConnectionManager((_transport as SerialTransport), _cmdMessenger, (int)Command.Watchdog, UniqueDeviceID);

            _connectionManager.WatchdogEnabled = true;
            _connectionManager.WatchdogTimeout = WatchdogTimeout;
            _connectionManager.WatchdogRetryTimeout = WatchdogRetryTimeout;

            _connectionManager.ConnectionFound += _connectionManager_ConnectionFound;
            _connectionManager.ConnectionTimeout += _connectionManager_ConnectionTimeout;
            OnConnecting();
            _connectionManager.StartConnectionManager();
        }
        // Setup function
        public void Setup()
        {
            _ledState = false;

            // Create Serial Port transport object
            // Note that for some boards (e.g. Sparkfun Pro Micro) DtrEnable may need to be true.
            _serialTransport = new SerialTransport
            {
                CurrentSerialSettings = { PortName = "COM6", BaudRate = 115200, DtrEnable = false } // object initializer
            };

            // Initialize the command messenger with the Serial Port transport layer
            // Set if it is communicating with a 16- or 32-bit Arduino board
            _cmdMessenger = new CmdMessenger(_serialTransport, BoardType.Bit16);

            // Attach the callbacks to the Command Messenger
            AttachCommandCallBacks();
            
            // Start listening
            var status =_cmdMessenger.Connect();
            if (!status)
            {
                Console.WriteLine("No connection could be made");
                return;
            }                    
        }