コード例 #1
0
ファイル: SerialComm.cs プロジェクト: anashandaru/MIFASOL
        public SerialComm(Form1 form)
        {
            _form = form;

            // Create Serial Port object
            _serialTransport = new SerialTransport
            {
                CurrentSerialSettings = { PortName = "COM3", BaudRate = 115200, DtrEnable = true } // 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);



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

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

            IsTriggered  = false;
            Channels     = new List <Channels>();
            _traceBuffer = new List <float>();
            _traces      = new List <ISeismicTrace>();
        }
コード例 #2
0
        private void WaitAndClear()
        {
            var requestResetCommand     = new SendCommand(_command["RequestReset"], _command["RequestResetAcknowledge"], 1000);
            var requestResetAcknowledge = _cmdMessenger.SendCommand(requestResetCommand, SendQueue.ClearQueue, ReceiveQueue.ClearQueue);

            Common.WriteLine(!requestResetAcknowledge.Ok ? "No Wait OK received" : "Wait received");
            // Wait another second to see if
            Thread.Sleep(1000);
            // Clear queues again to be very sure
            _cmdMessenger.ClearReceiveQueue();
            _cmdMessenger.ClearSendQueue();
        }
コード例 #3
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);
            }
        }