private void DeleteCommand_Click(object sender, RoutedEventArgs e)
        {
            if (CommandTable.SelectedItem == null)
            {
                return;
            }
            TransmitCommand tc = new TransmitCommand();

            tc = CommandTable.SelectedItem as TransmitCommand;
            if (tc == null)
            {
                return;
            }
            int temp = tc.ID;

            Test.Text = temp.ToString();
            using (var commandContext = new DataStoreContext())
            {
                commandContext.TransmitCommands.Load();
                var tempContext = commandContext.TransmitCommands.Local;
                tempContext.Remove(commandContext.TransmitCommands.Find(temp));
                commandContext.SaveChanges();
                CommandTable.DataContext = commandContext.TransmitCommands.Local;
            }
        }
Ejemplo n.º 2
0
        public override IResult Execute()
        {
            #region Code for sending command to remote system
            PacketElements CommandPacketElems = new PacketElements();
            CommandPacketElems.ActualCommand = Command;
            long HeaderValue = long.Parse(ConfigurationSettings.AppSettings["CommandHeader"]);
            CommandPacketElems.Header = HeaderValue;
            PackCommand CommandPckt = new PackCommand();
            CommandPckt.PacketElements = CommandPacketElems;
            TransmitCommand SendCmd = new TransmitCommand();
            SendCmd.DataPacket       = CommandPckt.CommandPack;
            SendCmd.RemoteSystemName = NetParams.RemoteSystemName;
            SendCmd.SendCommand();
            #endregion

            #region Code for receiving result from remote system
            ReceiveResult       ReceiveData    = new ReceiveResult();
            ResultPacketElement ResultElements = ReceiveData.GetResultPacket();
            IResult             Result         = new ExecutionResult();
            if (ResultElements.Header == int.Parse(ConfigurationSettings.AppSettings["ResultHeader"]))
            {
                Result = ResultElements.ActualResult;
            }
            else
            {
                throw(new ApplicationException("Corrupted Result"));
            }
            #endregion
            return(Result);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Transmits a command to the USB port
        /// </summary>
        /// <param name="commandType">the command to send</param>
        /// <param name="address">Optional</param>
        /// <param name="length">Optional </param>
        /// <param name="argument">Optional</param>
        private static void CommandPacketTransmit(TransmitCommand commandType, uint address = 0, int length = 0, uint argument = 0)
        {
            length /= 512; //Must take into account buffer size.

            var commandPacket = new List <byte>();

            commandPacket.AddRange(Encoding.ASCII.GetBytes("cmd"));
            commandPacket.Add((byte)commandType);
            if (BitConverter.IsLittleEndian)
            { //Convert to Big Endian
                commandPacket.AddRange(BitConverter.GetBytes(address).Reverse());
                commandPacket.AddRange(BitConverter.GetBytes(length).Reverse());
                commandPacket.AddRange(BitConverter.GetBytes(argument).Reverse());
            }
            else
            {
                commandPacket.AddRange(BitConverter.GetBytes(address));
                commandPacket.AddRange(BitConverter.GetBytes(length));
                commandPacket.AddRange(BitConverter.GetBytes(argument));
            }

            UsbInterface.Write(commandPacket.ToArray());
        }