コード例 #1
0
        // ------------------ 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);
        }
コード例 #2
0
        // ------------------ 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();
        }
コード例 #3
0
        /// <summary>
        /// Connection manager for serial port connection
        /// </summary>
        public SerialConnectionManager(SerialTransport serialTransport, CmdMessenger cmdMessenger, int watchdogCommandId = 0, string uniqueDeviceId = null, ISerialConnectionStorer serialConnectionStorer = null)
            : base(cmdMessenger, watchdogCommandId, uniqueDeviceId)
        {
            if (serialTransport == null)
                throw new ArgumentNullException("serialTransport", "Transport is null.");

            _serialTransport = serialTransport;
            _serialConnectionStorer = serialConnectionStorer;
            PersistentSettings = (_serialConnectionStorer != null);

            DeviceScanBaudRateSelection = true;

            UpdateAvailablePorts();

            _serialConnectionManagerSettings = new SerialConnectionManagerSettings();
            ReadSettings();
        }
コード例 #4
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
            // 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 = 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.Connect();

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

            // Send command
            _cmdMessenger.SendCommand(command);
        }
コード例 #5
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();                                
        }
コード例 #6
0
        public override void Setup()
        {
            var version = typeof(Program).Assembly.GetName().Version;

            // Set console title
            Console.Title = "PetduinoConnect v" + version;

            // Display header
            Console.WriteLine(@"                                                                           ");
            Console.WriteLine(@"  ########  ######## ######## ########  ##     ## #### ##    ##  #######   ");
            Console.WriteLine(@"  ##     ## ##          ##    ##     ## ##     ##  ##  ####  ## ##     ##  ");
            Console.WriteLine(@"  ########  ######      ##    ##     ## ##     ##  ##  ## ## ## ##     ##  ");
            Console.WriteLine(@"  ##        ##          ##    ##     ## ##     ##  ##  ##  #### ##     ##  ");
            Console.WriteLine(@"  ##        ########    ##    ########   #######  #### ##    ##  #######   ");
            Console.WriteLine(@"                                                                           ");
            Console.WriteLine(@"                      PetduinoConnect Version " + version + "              ");
            Console.WriteLine(@"                       Copyright "+ DateTime.Today.Year +" @Circuitbeard   ");
            Console.WriteLine(@"                                                                           ");
            Console.WriteLine(@"                                                                           ");

            // Force enum serialization to be in camelcase
            JsonConvert.DefaultSettings = () => new JsonSerializerSettings {
                Converters = {
                    new StringEnumConverter {
                        CamelCaseText = true
                    }
                }
            };

            // Setup serial
            _serialTransport = new SerialTransport
            {
                CurrentSerialSettings = {
                    PortName = Config.Instance.Serial.Port,
                    BaudRate = Config.Instance.Serial.BuadRate,
                    DataBits = Config.Instance.Serial.DataBits,
                    StopBits = Config.Instance.Serial.StopBits,
                    Parity = Config.Instance.Serial.Parity,
                    DtrEnable = Config.Instance.Serial.DtrEnable,
                    Timeout = Config.Instance.General.Timeout
                }
            };

            // Setup command messenger
            _cmdMessenger = new CmdMessenger(_serialTransport, BoardType.Bit16);

            // Setup handlers
            _cmdMessenger.Attach(OnUnknownCommand);

            foreach (var val in Enum.GetValues(typeof(EventType)))
            {
                _cmdMessenger.Attach((int)val, OnEventCommand);
            }

            // Setup dweet client
            _dweetClient = new DweetClient(Config.Instance.Dweet.Thing,
                Config.Instance.General.Timeout);
        }
コード例 #7
0
        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 = "COM15", BaudRate = 115200 } // 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
            _cmdMessenger.Connect();

            _receivedItemsCount = 0;
            _receivedBytesCount = 0;

            // Clear queues 
            _cmdMessenger.ClearReceiveQueue();
            _cmdMessenger.ClearSendQueue();

            Thread.Sleep(100);

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

            // Now wait until all values have arrived
            while (!_receivePlainTextFloatSeriesFinished)
            {
                Thread.Sleep(100);
            }


            // Clear queues 
            _cmdMessenger.ClearReceiveQueue();
            _cmdMessenger.ClearSendQueue();

            _receivedItemsCount = 0;
            _receivedBytesCount = 0;
            // Send command requesting a series of 100 float values send in binary form
            var commandBinary = new SendCommand((int)Command.RequestBinaryFloatSeries);
            commandBinary.AddBinArgument((UInt16)SeriesLength);
            commandBinary.AddBinArgument((float)SeriesBase); 
            
            // Send command 
            _cmdMessenger.SendCommand(commandBinary);

            // Now wait until all values have arrived
            while (!_receiveBinaryFloatSeriesFinished)
            {
                Thread.Sleep(100);
            }
        }
コード例 #8
-1
        // 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;
            }                    
        }