Exemplo n.º 1
0
        public void SendDevicePropertyMessage(string type, string name, string argument)
        {
            DeviceProperty_10 deviceProperty = null;

            //if (Enum.TryParse(type, out DeviceProperty_10.Types.DevicePropertyType device_property_type))
            if (Enum.TryParse(type, true, out DeviceProperty_10.Types.DevicePropertyType device_property_type))
            {
                if (Enum.TryParse(name, true, out DeviceProperty_10.Types.DevicePropertyName device_property_name))
                {
                    deviceProperty          = new DeviceProperty_10();
                    deviceProperty.Type     = device_property_type;
                    deviceProperty.Name     = device_property_name;
                    deviceProperty.Argument = argument;
                }
            }

            if (deviceProperty != null)
            {
                LynxaMessageInfo lynxaMessageInfo = new LynxaMessageInfo();
                lynxaMessageInfo.deviceUid     = 0xFFFFFFFF;
                lynxaMessageInfo.messageId     = 10;
                lynxaMessageInfo.payloadBuffer = deviceProperty.ToByteArray();
                lynxaMessageInfo.payloadSize   = Convert.ToUInt16(lynxaMessageInfo.payloadBuffer.Length);

                byte[] output = MessageHandler.ConstructPacket(lynxaMessageInfo);
                _serialPort.Write(output, 0, output.Length);
            }
        }
Exemplo n.º 2
0
        public void Read()
        {
            while (_serialPort.IsOpen)
            {
                try
                {
                    int data = _serialPort.ReadByte();
                    if (data != -1)
                    {
                        LynxaMessageInfo lynxa_message_info = _myMessageHandler.ParsePacket((byte)data);
                        if (lynxa_message_info != null)
                        {
                            LynxaMessageId lynxa_message_id = (LynxaMessageId)lynxa_message_info.messageId;
                            switch (lynxa_message_id)
                            {
                            case LynxaMessageId.DeviceProperty10Id:
                                DeviceProperty_10 deviceProperty_10 = DeviceProperty_10.Parser.ParseFrom(lynxa_message_info.payloadBuffer);
                                LynxaPacketReceivedEvent?.Invoke(this, deviceProperty_10);
                                break;

                            case LynxaMessageId.GnggaMessage100Id:
                                GnggaMessage_100 nmeaRecord_100 = GnggaMessage_100.Parser.ParseFrom(lynxa_message_info.payloadBuffer);
                                LynxaPacketReceivedEvent?.Invoke(this, nmeaRecord_100);
                                break;

                            case LynxaMessageId.WifiStationList102Id:
                                WifiStationList_102 wifiStationList_102 = WifiStationList_102.Parser.ParseFrom(lynxa_message_info.payloadBuffer);
                                LynxaPacketReceivedEvent?.Invoke(this, wifiStationList_102);
                                break;

                            case LynxaMessageId.ModemParameters103Id:
                                ModemParameters_103 modemParameters_103 = ModemParameters_103.Parser.ParseFrom(lynxa_message_info.payloadBuffer);
                                LynxaPacketReceivedEvent?.Invoke(this, modemParameters_103);
                                break;
                            }
                        }
                    }
                }
                catch (TimeoutException te)
                {
                    //comes here if there was a timeout
                }
            }
        }