コード例 #1
0
        private async Task <DeviceModelBase> Connect(SerialPortManager.SerialPortInfo port, CancellationToken ct)
        {
            DeviceModelBase    device  = null;
            SerialMavlinkLayer mavlink = new SerialMavlinkLayer(port.Device);

            Msg_configuration_control configCMD = new Msg_configuration_control();

            configCMD.command = (byte)CONFIG_COMMAND.CONFIG_COMMAND_GET_VERSION;
            Msg_data_transmission_handshake handshake = new Msg_data_transmission_handshake();

            PacketReceivedEventHandler pr = (o, e) =>
            {
                if (e.Message.GetType() == typeof(Msg_configuration_version2))
                {
                    Msg_configuration_version2 msg = e.Message as Msg_configuration_version2;
                    device = new AnySense(mavlink, msg.fw_version);
                }
                else if (e.Message.GetType() == typeof(Msg_configuration_version3))
                {
                    Msg_configuration_version3 msg = e.Message as Msg_configuration_version3;

                    switch (msg.hw_version)
                    {
                    case 1:
                        device = new AnySensePro(mavlink, msg.fw_version);
                        break;

                    default:
                        break;
                    }
                }
            };

            mavlink.PacketReceived += pr;

            do
            {
                ct.ThrowIfCancellationRequested();
                mavlink.SendMessage(configCMD);
                await Task.Delay(500, ct);
            } while (device == null);

            mavlink.PacketReceived -= pr;

            if (device == null)
            {
                try{
                    mavlink.Dispose();
                }
                catch { }
            }

            return(device);
        }
コード例 #2
0
 public AnySense(SerialMavlinkLayer mv, UInt32 version)
     : base(mv, version)
 {
     Firmware = string.Format("AnySense {0}.{1}.{2}", (byte)(version >> 16), (byte)(version >> 8), (byte)version);
 }