Esempio n. 1
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 += () => _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;
        }
Esempio n. 2
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;
        }
Esempio n. 3
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;            
        }
        // ------------------ 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);
        }
Esempio n. 5
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);
        }
Esempio n. 6
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);
        }
Esempio n. 7
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);
        }
Esempio n. 8
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);
        }
Esempio n. 9
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)
        {
            // Choose which transport mode you want to use:
            // 1. Serial port. This can be a real serial port but is usually a virtual serial port over USB.
            //                 It can also be a virtual serial port over Bluetooth, but the direct bluetooth works better
            // 2. Bluetooth    This bypasses the Bluetooth virtual serial port, but communicates over the RFCOMM layer
            var transportMode = TransportMode.Serial;

            // 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);

            // Set up transport
            if (transportMode == TransportMode.Bluetooth)
            {
                _transport = new BluetoothTransport();
            }
            // We do not need to set the device: it will be found by the connection manager
            else
            {
                _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
            _cmdMessenger = new CmdMessenger(_transport)
            {
                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;

            // Set up connection manager
            if (transportMode == TransportMode.Bluetooth)
            {
                _connectionManager = new BluetoothConnectionManager((_transport as BluetoothTransport), _cmdMessenger, (int)Command.RequestId, (int)Command.SendId);
            }
            else
            {
                _connectionManager = new SerialConnectionManager((_transport as SerialTransport), _cmdMessenger, (int)Command.RequestId, (int)Command.SendId);
            }

            // Tell the Connection manager to "Invoke" commands on the thread running the WinForms UI
            _connectionManager.SetControlToInvokeOn(chartForm);

            // Event when the connection manager finds a connection
            _connectionManager.ConnectionFound += ConnectionFound;

            // Event when the connection manager watchdog notices that the connection is gone
            _connectionManager.ConnectionTimeout += ConnectionTimeout;

            // Event notifying on scanning process
            _connectionManager.Progress += LogProgress;

            // Initialize the application
            InitializeTemperatureControl();

            // Start scanning for ports/devices
            _connectionManager.StartScan();
        }
        // 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;
        }
        // Setup function
        public void Setup(ChartForm chartForm)
        {
            // Choose which transport mode you want to use:
            // 1. Serial port. This can be a real serial port but is usually a virtual serial port over USB. 
            //                 It can also be a virtual serial port over Bluetooth, but the direct bluetooth works better
            // 2. Bluetooth    This bypasses the Bluetooth virtual serial port, and instead communicates over the RFCOMM layer                 
            var transportMode = TransportMode.Serial;
            //var transportMode = TransportMode.Bluetooth;
            
            // 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);

            // Set up transport 
            if (transportMode == TransportMode.Bluetooth)
                _transport = new BluetoothTransport();
                    // We do not need to set the device: it will be found by the connection manager
            else
                _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 one of the two transport layers
            // Set if it is communicating with a 16- or 32-bit Arduino board
            _cmdMessenger = new CmdMessenger(_transport, BoardType.Bit32)
            {
                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.ControlToInvokeOn = 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;                       

            // Set up connection manager, corresponding to the transportMode
            if (transportMode == TransportMode.Bluetooth)
                _connectionManager = new BluetoothConnectionManager((_transport as BluetoothTransport), _cmdMessenger, (int)Command.Identify, UniqueDeviceId);
            else
                _connectionManager = new SerialConnectionManager   ((_transport as SerialTransport),    _cmdMessenger, (int)Command.Identify, UniqueDeviceId);

            // Enable watchdog functionality.
            _connectionManager.WatchdogEnabled = true;

            // Event when the connection manager finds a connection
            _connectionManager.ConnectionFound += ConnectionFound;

            // Event when the connection manager watchdog notices that the connection is gone
            _connectionManager.ConnectionTimeout += ConnectionTimeout;
            
            // Event notifying on scanning process
            _connectionManager.Progress += LogProgress;

            // Initialize the application
            InitializeTemperatureControl(); 

            // Start scanning for ports/devices
            _connectionManager.StartConnectionManager();           
        }