private void BuildPacketTosend(object sender)
        {
            if (LeftPanelViewModel.GetInstance.ConnectButtonContent == "Disconnect")
            {
                Int32 _data = 0;
                if (!IsFloat)
                {
                    if (!Int32.TryParse(CommandValue, out _data))
                    {
                        return;
                    }
                }

                if (CommandValue != "")
                {
                    var tmp = new PacketFields
                    {
                        Data2Send = IsFloat ? CommandValue : _data.ToString(),
                        ID        = Convert.ToInt16(CommandId),
                        SubID     = Convert.ToInt16(CommandSubId),
                        IsSet     = true,
                        IsFloat   = IsFloat,
                    };
                    Task.Factory.StartNew(action: () => { Rs232Interface.GetInstance.SendToParser(tmp); });
                }
                ((DataViewModel)Commands.GetInstance.GenericCommandsList[new Tuple <int, int>(Convert.ToInt16(CommandId), Convert.ToInt16(CommandSubId))]).IsSelected = false;
                ((DataViewModel)Commands.GetInstance.GenericCommandsList[new Tuple <int, int>(Convert.ToInt16(CommandId), Convert.ToInt16(CommandSubId))]).Background = _background;
            }
            var _tb = sender as TextBox;

            _tb.MoveFocus(new TraversalRequest(FocusNavigationDirection.Next));
        }
Esempio n. 2
0
 static public void AssemblePacket(out PacketFields rxPacket, Int16 id, Int16 subId, bool isSet, bool isFloat, object data2Send)
 {
     if (id == 81 && subId == 1 && isSet == true)
     { /*int i = 0;*/
     }
     rxPacket.ID        = id;
     rxPacket.IsFloat   = isFloat;
     rxPacket.IsSet     = isSet;
     rxPacket.SubID     = subId;
     rxPacket.Data2Send = data2Send;
 }
 private void BuildPacketTosend()
 {
     if (LeftPanelViewModel.GetInstance.ConnectButtonContent == "Disconnect")
     {
         var tmp = new PacketFields
         {
             Data2Send = !IsChecked ? 1 : 0,
             ID        = CommandId,
             SubID     = CommandSubId,
             IsSet     = true,
             IsFloat   = false,
         };
         Task.Factory.StartNew(action: () => { Rs232Interface.GetInstance.SendToParser(tmp); });
     }
 }
Esempio n. 4
0
 private void SetCmd()
 {
     if (SetData != "" && ID != "" && Index != "")
     {
         var tmp = new PacketFields
         {
             Data2Send = Convert.ToInt32(SetData),
             ID        = Convert.ToInt16(ID),
             SubID     = Convert.ToInt16(Index),
             IsSet     = true,
             IsFloat   = !this.IntFloat,
         };
         Task.Factory.StartNew(action: () => { Rs232Interface.GetInstance.SendToParser(tmp); });
     }
 }
Esempio n. 5
0
 private void BuildPacketTosend()
 {
     Task.Factory.StartNew(action: () =>
     {
         var tmp = new PacketFields
         {
             Data2Send = Convert.ToInt16(SelectedIndex) + Convert.ToInt16(CommandValue),
             ID        = Convert.ToInt16(CommandId),
             SubID     = Convert.ToInt16(CommandSubId),
             IsSet     = true,
             IsFloat   = false
         };
         Rs232Interface.GetInstance.SendToParser(tmp);
     });
     IsOpened = false;
 }
 private void BuildPacketTosend(string val)
 {
     if (LeftPanelViewModel.GetInstance.ConnectButtonContent == "Disconnect")
     {
         Task.Factory.StartNew(action: () =>
         {
             var tmp = new PacketFields
             {
                 Data2Send = val,
                 ID        = Convert.ToInt16(CommandId),
                 SubID     = Convert.ToInt16(CommandSubId),
                 IsSet     = true,
                 IsFloat   = IsFloat
             };
             Rs232Interface.GetInstance.SendToParser(tmp);
         });
     }
 }
Esempio n. 7
0
 private void GetCmd()
 {
     DebugOperationPending = true;
     DebugViewModel.GetInstance.TxBuildOperation("", Convert.ToInt16(ID), Convert.ToInt16(Index), false, !this.IntFloat);
     try
     {
         var tmp = new PacketFields
         {
             Data2Send = 0,
             ID        = Convert.ToInt16(ID),
             SubID     = Convert.ToInt16(Index),
             IsSet     = false,
             IsFloat   = !this.IntFloat,
         };
         Task.Factory.StartNew(action: () => { Rs232Interface.GetInstance.SendToParser(tmp); });
     }
     catch (Exception)
     {
     }
 }
Esempio n. 8
0
 private void SetCmd()
 {
     if (SetData != "" && ID != "" && Index != "")
     {
         DebugOperationPending = true;
         DebugViewModel.GetInstance.TxBuildOperation(SetData, Convert.ToInt16(ID), Convert.ToInt16(Index), true, !this.IntFloat);
         try
         {
             var tmp = new PacketFields
             {
                 Data2Send = SetData,
                 ID        = Convert.ToInt16(ID),
                 SubID     = Convert.ToInt16(Index),
                 IsSet     = true,
                 IsFloat   = !this.IntFloat,
             };
             Task.Factory.StartNew(action: () => { Rs232Interface.GetInstance.SendToParser(tmp); });
         }
         catch { }
     }
 }
Esempio n. 9
0
        private void GetCmd()
        {
            var data = new DebugObjViewModel
            {
                ID       = ID,
                Index    = Index,
                IntFloat = IntFloat,
                GetData  = "",
                SetData  = "",
            };

            Commands.GetInstance.DebugCommandsList.Remove(new Tuple <int, int>(Commands.GetInstance.DebugCommandsList.ElementAt(0).Key.Item1, Commands.GetInstance.DebugCommandsList.ElementAt(0).Key.Item2));
            Commands.GetInstance.DebugCommandsList.Add(new Tuple <int, int>(Convert.ToInt16(ID), Convert.ToInt16(Index)), data);
            try
            {
                //Rs232Interface.GetInstance.SendToParser(new PacketFields
                //{
                //    Data2Send = 0,
                //    ID = Convert.ToInt16(ID),
                //    SubID = Convert.ToInt16(Index),
                //    IsSet = false,
                //    IsFloat = !this.IntFloat
                //});
                var tmp = new PacketFields
                {
                    Data2Send = 0,
                    ID        = Convert.ToInt16(ID),
                    SubID     = Convert.ToInt16(Index),
                    IsSet     = false,
                    IsFloat   = !this.IntFloat,
                };
                Task.Factory.StartNew(action: () => { Rs232Interface.GetInstance.SendToParser(tmp); });
            }
            catch (Exception)
            {
            }
        }
Esempio n. 10
0
        private void BuildPacketTosend()
        {
            if (LeftPanelViewModel.GetInstance.ConnectButtonContent == "Disconnect")
            {
                Debug.WriteLine("Enter to Send");

                RefreshManger.DataPressed = false;
                if (Commands.GetInstance.DataViewCommandsList.ContainsKey(new Tuple <int, int>(Convert.ToInt16(CommandId), Convert.ToInt16(CommandSubId))))
                {
                    Commands.GetInstance.DataViewCommandsList[new Tuple <int, int>(Convert.ToInt16(CommandId), Convert.ToInt16(CommandSubId))].IsSelected          = false;
                    Commands.GetInstance.DataViewCommandsList[new Tuple <int, int>(Convert.ToInt16(CommandId), Convert.ToInt16(CommandSubId))].BackgroundStd       = new SolidColorBrush(Colors.White);
                    Commands.GetInstance.DataViewCommandsList[new Tuple <int, int>(Convert.ToInt16(CommandId), Convert.ToInt16(CommandSubId))].BackgroundSmallFont = new SolidColorBrush(Colors.Gray);
                    this.ReadOnly      = true;
                    this.EnableTextBox = false;
                }
                if (CommandValue != "")
                {
                    //bool _escPressed = true;
                    var tmp = new PacketFields
                    {
                        Data2Send = CommandValue,
                        ID        = Convert.ToInt16(CommandId),
                        SubID     = Convert.ToInt16(CommandSubId),
                        IsSet     = true,
                        IsFloat   = IsFloat,
                    };
                    Task.Factory.StartNew(action: () => { Rs232Interface.GetInstance.SendToParser(tmp); });
                    //_escPressed = false;
                    MouseLeaveCommandFunc();
                    //_escPressed = true;
                }
                else
                {
                    MouseLeaveCommandFunc();
                }
            }
        }
        public void ParseData(string packetStr)
        {
            Debug.WriteLine("New packet:\t string:" + packetStr);

            for (int i = 0; i < packetStr.Length; i++)
            {
                //Simple state-machine
                if (packetStr[i] == 'T')
                {
                    incomingPacket = new Packet {
                        RawString = packetStr
                    };
                    currentField = PacketFields.Type;
                }

                else if (packetStr[i] == 'N')
                {
                    currentField = PacketFields.NodeID;
                }
                else if (packetStr[i] == 'I')
                {
                    if (incomingPacket.PacketType == PacketTypes.Command || incomingPacket.PacketType == PacketTypes.Command_Reply)
                    {
                        currentField = PacketFields.CommandID;
                    }
                    else if (incomingPacket.PacketType == PacketTypes.Data_Array_Request || incomingPacket.PacketType == PacketTypes.Data_Int || incomingPacket.PacketType == PacketTypes.Data_Request)
                    {
                        currentField = PacketFields.SensorID;
                    }
                }
                else if (packetStr[i] == 'P')
                {
                    currentField = PacketFields.Payload;
                }
                else if (packetStr[i] == 'Q')
                {
                    currentField = PacketFields.Parity;
                }
                else
                {
                    switch (currentField)
                    {
                    case PacketFields.Type:
                        incomingPacket.PacketType = (PacketTypes)packetStr.Substring(i, 2).FromHexStringToInt();
                        i++;
                        break;

                    case PacketFields.NodeID:
                        incomingPacket.NodeID = packetStr.Substring(i, 2).FromHexStringToInt();
                        i++;
                        break;

                    case PacketFields.SensorID:
                        incomingPacket.SensorID = packetStr.Substring(i, 2).FromHexStringToInt();
                        i++;
                        break;

                    case PacketFields.CommandID:
                        incomingPacket.CommandID = (Commands)packetStr.Substring(i, 2).FromHexStringToInt();
                        i++;
                        break;

                    case PacketFields.Payload:
                        incomingPacket.Payload = packetStr.Substring(i, 2).FromHexStringToInt();
                        i++;
                        break;

                    case PacketFields.Parity:
                        incomingPacket.Parity = packetStr.Substring(i, 2).FromHexStringToInt();
                        i = packetStr.Length;                                                          //we're done with this packet

                        if (SerialMessageReceived != null && ComputeParity() == incomingPacket.Parity) //&& parity klopt
                        {
                            SerialMessageReceived(this, new SerialArduinoMessageEventArgs(incomingPacket));
                        }
                        else
                        {
                            Debug.WriteLine("Parity failed");
                        }
                        break;

                    default:
                        throw new ArgumentOutOfRangeException();
                    }
                }
            }
        }
Esempio n. 12
0
 public abstract void ParseOutputData(PacketFields PacketIn);
Esempio n. 13
0
 public void SendToParser(PacketFields messege)
 {
     RxtoParser?.Invoke(this, new Rs232InterfaceEventArgs(messege)); // then go to "void parseOutdata(object sender, Rs232InterfaceEventArgs e)"
 }
Esempio n. 14
0
 public Rs232InterfaceEventArgs(PacketFields packetRx)
 {
     LeftPanelViewModel.GetInstance.LedStatusTx = RoundBoolLed.PASSED;
     PacketRx = packetRx;     // Send Packet
 }
Esempio n. 15
0
 public PacketData()
 {
     commonFields = new PacketFields();
     c2sFields = new PacketFields();
     s2cFields = new PacketFields();
 }
        public void ParseData(string packetStr)
        {
            Debug.WriteLine("New packet:\t string:" + packetStr);

            for (int i = 0; i < packetStr.Length; i++)
            {
                //Simple state-machine
                if (packetStr[i] == 'T')
                {
                    incomingPacket = new Packet { RawString = packetStr };
                    currentField = PacketFields.Type;
                }

                else if (packetStr[i] == 'N')
                    currentField = PacketFields.NodeID;
                else if (packetStr[i] == 'I')
                {
                    if (incomingPacket.PacketType == PacketTypes.Command || incomingPacket.PacketType == PacketTypes.Command_Reply)
                        currentField = PacketFields.CommandID;
                    else if (incomingPacket.PacketType == PacketTypes.Data_Array_Request || incomingPacket.PacketType == PacketTypes.Data_Int || incomingPacket.PacketType == PacketTypes.Data_Request)
                    {
                        currentField = PacketFields.SensorID;
                    }
                }
                else if (packetStr[i] == 'P')
                    currentField = PacketFields.Payload;
                else if (packetStr[i] == 'Q')
                    currentField = PacketFields.Parity;
                else
                {
                    switch (currentField)
                    {
                        case PacketFields.Type:
                            incomingPacket.PacketType = (PacketTypes)packetStr.Substring(i, 2).FromHexStringToInt();
                            i++;
                            break;
                        case PacketFields.NodeID:
                            incomingPacket.NodeID = packetStr.Substring(i, 2).FromHexStringToInt();
                            i++;
                            break;
                        case PacketFields.SensorID:
                            incomingPacket.SensorID = packetStr.Substring(i, 2).FromHexStringToInt();
                            i++;
                            break;
                        case PacketFields.CommandID:
                            incomingPacket.CommandID = (Commands)packetStr.Substring(i, 2).FromHexStringToInt();
                            i++;
                            break;
                        case PacketFields.Payload:
                            incomingPacket.Payload = packetStr.Substring(i, 2).FromHexStringToInt();
                            i++;
                            break;
                        case PacketFields.Parity:
                            incomingPacket.Parity = packetStr.Substring(i, 2).FromHexStringToInt();
                            i = packetStr.Length; //we're done with this packet

                            if (SerialMessageReceived != null && ComputeParity() == incomingPacket.Parity) //&& parity klopt
                                SerialMessageReceived(this, new SerialArduinoMessageEventArgs(incomingPacket));
                            else
                            {
                                Debug.WriteLine("Parity failed");
                            }
                            break;
                        default:
                            throw new ArgumentOutOfRangeException();
                    }
                }

            }
        }
 public void SendToParser(PacketFields messege)
 {
     RxtoParser?.Invoke(this, new Rs232InterfaceEventArgs(messege));
     //Debug.WriteLine("{0} {1}[{2}]={3} {4}.", messege.IsSet ? "Set" : "Get", messege.ID, messege.SubID, messege.Data2Send, messege.IsFloat ? "F" : "I");
 }
Esempio n. 18
0
 public Rs232InterfaceEventArgs(PacketFields packetRx)
 {
     LeftPanelViewModel.GetInstance.led = LeftPanelViewModel.TX_LED;
     PacketRx = packetRx;     // Send Packet
 }