Exemple #1
0
        void mSerialPortInterface_MessageReceived(object sender, SerialMessageReceivedEventArgs e)
        {
            mInterface = (SerialPortInterface)sender;
            mPortValid = true;

            UInt16 u16dat = BitConverter.ToUInt16(e.Message.Data, 0);
            Int16  i16dat = BitConverter.ToInt16(e.Message.Data, 0);

            if (e.Message.Command == Command.SET_ID)
            {
                IsConnected = true;
                if (Connected != null)
                {
                    Connected(this, null);
                }
            }
        }
Exemple #2
0
        void messageReceived(object sender, SerialMessageReceivedEventArgs e)
        {
            mInterface = (SerialPortInterface)sender;
            if (e.Message.ID != (byte)mBoardID)
            {
                return;
            }

            //byte[] swapped = new byte[]{e.Message.Data[1] ,e.Message.Data[0]};
            UInt16 u16dat = BitConverter.ToUInt16(e.Message.Data, 0);
            Int16  i16dat = BitConverter.ToInt16(e.Message.Data, 0);

            switch (e.Message.Command)
            {
            case Command.BTN:
                Buttons[0].Set(!isBitSet(u16dat, 0));
                Buttons[1].Set(!isBitSet(u16dat, 1));
                Buttons[2].Set(!isBitSet(u16dat, 2));
                Buttons[3].Set(!isBitSet(u16dat, 3));
                break;

            case Command.RT_BTN:
                Encoders[0].Button.Set(!isBitSet(u16dat, 0));
                Encoders[1].Button.Set(!isBitSet(u16dat, 1));
                Encoders[2].Button.Set(!isBitSet(u16dat, 2));
                Encoders[3].Button.Set(!isBitSet(u16dat, 3));
                break;

            case Command.RT_DELTA1:
                Encoders[0].Delta = i16dat;
                break;

            case Command.RT_DELTA2:
                Encoders[1].Delta = i16dat;
                break;

            case Command.RT_DELTA3:
                Encoders[2].Delta = i16dat;
                break;

            case Command.RT_DELTA4:
                Encoders[3].Delta = i16dat;
                break;

            case Command.TEMP:
                Temperature = ((double)i16dat) / 10.0;
                if (TemperatureChanged != null)
                {
                    TemperatureChanged(this, Temperature);
                }
                break;

            case Command.ANA:
                Analog = u16dat;
                if (AnalogChanged != null)
                {
                    AnalogChanged(this, Analog);
                }
                break;

            default:
                // Do nothing
                break;
            }
        }