コード例 #1
0
ファイル: ProtocolDriver.cs プロジェクト: zhouwb168/CodeHub
        /// <summary>
        /// 初始化协议驱动
        /// </summary>
        /// <param name="cmdAsmType">带命令驱动的程序集类型</param>
        /// <param name="receiveFilter"></param>
        public virtual void InitDriver(Type cmdAsmType, IReceiveFilter receiveFilter)
        {
            ReceiveFilter = receiveFilter;

            this._Commands.Clear();
            System.Reflection.Assembly asm = cmdAsmType.Assembly;
            Type[] types = asm.GetTypes();
            foreach (Type t in types)
            {
                if (typeof(IProtocolCommand).IsAssignableFrom(t))
                {
                    if (t.Name != "IProtocolCommand" &&
                        t.Name != "ProtocolCommand" &&
                        !t.IsAbstract)
                    {
                        IProtocolCommand cmd = (IProtocolCommand)t.Assembly.CreateInstance(t.FullName);
                        if (cmd != null)
                        {
                            cmd.Setup(this);
                            _Commands.TryAdd(cmd.Name, cmd);
                        }
                    }
                }
            }
        }
コード例 #2
0
        public IProtocolPackage EncodeCommand(IProtocolCommand command, Dictionary <string, byte[]> paramBytes = null)
        {
            var package = new BytesProtocolPackage(command)
            {
                [StructureNames.CmdType] = { ComponentContent = command.CommandTypeCode },
                [StructureNames.CmdByte] = { ComponentContent = command.CommandCode }
            };


            foreach (var definition in command.CommandDefinitions)
            {
                package[definition.StructureName].ComponentContent = definition.ContentBytes;
            }

            if (paramBytes != null)
            {
                foreach (var paramByte in paramBytes)
                {
                    package[paramByte.Key].ComponentContent = paramByte.Value;
                }
            }

            var crcValue = Globals.GetUsmbcrc16(package.GetBytes(), (ushort)(package.PackageLenth - 3));

            package[StructureNames.CRCValue].ComponentContent = Globals.Uint16ToBytes(crcValue, false);

            package.Finalization();
            return(package);
        }
コード例 #3
0
        public ChannelProtocol(IProtocolCommand parent, int channelNumber) : base(parent)
        {
            ChannelNumber = channelNumber;
            PathParameter = channelNumber;

            BWLimit = new ProtocolCommand(this, "Bandwidth Limit", "BWL")
            {
                Options = StringOptions.BWLimit,
            };

            Coupling = new ProtocolCommand(this, "Coupling", "COUP")
            {
                Options = StringOptions.Coupling,
            };

            Display = new ProtocolCommand(this, "Display", "DISP")
            {
                Options = BooleanOptions.Boolean,
            };

            Invert = new ProtocolCommand(this, "Invert", "INV")
            {
                Options = BooleanOptions.Boolean,
            };

            Offset = new ProtocolCommand(this, "Offset", "OFFS")
            {
                Options = RealOptions.ChannelOffset_ScaleGreaterThan500m,
            };

            Range = new ProtocolCommand(this, "Range", "RANG")
            {
                Options = RealOptions.ChannelRange,
            };

            TCal = new ProtocolCommand(this, "TCal", "TCAL")
            {
                Options = RealOptions.ChannelTCal,
            };

            Scale = new ProtocolCommand(this, "Scale", "SCAL")
            {
                Options = RealOptions.ChannelScale,
            };

            Probe = new ProtocolCommand(this, "Probe", "PROB")
            {
                Options = StringOptions.ProbeRatio,
            };

            Units = new ProtocolCommand(this, "Units", "UNIT")
            {
                Options = StringOptions.Units,
            };

            Vernier = new ProtocolCommand(this, "Vernier", "VERN")
            {
                Options = BooleanOptions.Boolean,
            };
        }
コード例 #4
0
        public TimebaseProtocol(IProtocolCommand parent) : base(parent)
        {
            Delay = new TimebaseDelayCommands(this);

            Offset = new ProtocolCommand(this, "Offset", "OFFS")
            {
                Path = ":MAIN:OFFS",
                // depends on whether scope is in slow sweep mode
                // Normal    : (-0.5 x MemDepth / SampleRate) to 1s
                // Slow sweep: (-MemDepth/SampleRate) to (1s + 0.5 x MemDepth/SampleRate)
                // Highest memdepth is 24000000
                // MemDepth = SampleRate x WaveformLength
                // WaveformLength = Scale x number of scales
                // number of scales for DS1000Z is 12
                Options = new RealOptions(-12, 12)
            };

            Scale = new ProtocolCommand(this, "Scale", "SCAL")
            {
                Path = ":MAIN:SCAL",
                // YT mode  : 5ns/div to 50s/div in 1,2,5 steps
                // Roll mode: 200ms/div to 50s/div in 1,2,5 steps
                Options = TimebaseScaleOptions.YT,
            };

            Mode = new ProtocolCommand(this, "Mode", "MODE")
            {
                Options = new StringOptions
                {
                    new StringOption("Main", "MAIN"),
                    new StringOption("XY", "XY"),
                    new StringOption("Roll", "ROLL"),
                }
            };
        }
コード例 #5
0
        public StringProtocolPackage(IProtocolCommand command)
        {
            Protocol = command.Protocol;

            Command = command;

            foreach (var structure in Protocol.ProtocolStructures)
            {
                var component = new PackageComponent <string>()
                {
                    ComponentName    = structure.StructureName,
                    DataType         = structure.DataType,
                    ComponentIndex   = structure.StructureIndex,
                    ComponentContent = Encoding.ASCII.GetString(structure.DefaultBytes)
                };

                this[structure.StructureName] = component;
            }

            foreach (var commandData in command.CommandDatas)
            {
                var component = new PackageComponent <string>()
                {
                    ComponentName  = commandData.DataName,
                    DataType       = commandData.DataConvertType,
                    ComponentIndex = commandData.DataIndex
                };

                AppendData(component);
            }
        }
コード例 #6
0
        public TriggerWindowsCommands(IProtocolCommand parent) : base(parent)
        {
            Source = new TriggerSourceChannelCommand(this);

            Slope = new TriggerSlopeCommand(this);

            Time = new TriggerTimeCommand(this)
            {
                Options = new RealOptions(8 * SI.n, 10)
            };

            Position = new ProtocolCommand(this)
            {
                Name    = "POSition",
                Term    = "POS",
                Options = new StringOptions()
                {
                    new StringOption("EXIT", "EXIT"),
                    new StringOption("ENTER", "ENTER"),
                    new StringOption("TIMe", "TIM"),
                }
            };

            ALevel = new TriggerLevelCommand(this);

            BLevel = new TriggerLevelCommand(this);
        }
コード例 #7
0
 public TriggerNEdgeCommands(IProtocolCommand parent) : base(parent)
 {
     Source = new TriggerSourceCommand(this);
     Slope  = new TriggerSlopeCommand(this)
     {
         Options = new StringOptions {
             new StringOption("POSitive", "POS"),
             new StringOption("NEGative", "NEG"),
         }
     };
     Idle = new TriggerTimeCommand(this)
     {
         Name    = "IDLE",
         Term    = "IDLE",
         Options = new RealOptions
         {
             new RealOption(16 * SI.n, 10)
         }
     };
     Edge = new ProtocolCommand(this)
     {
         Name    = "EDGE",
         Term    = "EDGE",
         Options = new IntegerOptions {
             new IntegerOption(1, 65535)
         }
     };
     Level = new TriggerLevelCommand(this);
 }
コード例 #8
0
ファイル: ProtocolDriver.cs プロジェクト: zhouwb168/CodeHub
        public void DriverCommand <T1, T2>(string cmdName, T1 t1, T2 t2)
        {
            IProtocolCommand cmd = GetProcotolCommand(cmdName);

            if (cmd != null)
            {
                cmd.ExcuteCommand <T1, T2>(t1, t2);
            }
        }
コード例 #9
0
 public TriggerEdgeCommands(IProtocolCommand parent) : base(parent)
 {
     Source = new TriggerSourceCommand(this)
     {
         Description = "The trigger source in edge trigger",
     };
     Slope = new TriggerSlopeCommand(this);
     Level = new TriggerLevelCommand(this);
 }
コード例 #10
0
ファイル: ProtocolDriver.cs プロジェクト: zhouwb168/CodeHub
        /// <summary>
        /// 驱动命令
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="cmdName"></param>
        /// <param name="t"></param>
        public void DriverCommand <T>(string cmdName, T t)
        {
            IProtocolCommand cmd = GetProcotolCommand(cmdName);

            if (cmd != null)
            {
                cmd.ExcuteCommand <T>(t);
            }
        }
コード例 #11
0
ファイル: ProtocolDriver.cs プロジェクト: zhouwb168/CodeHub
        /// <summary>
        ///
        /// </summary>
        /// <typeparam name="T1"></typeparam>
        /// <typeparam name="T2"></typeparam>
        /// <param name="code"></param>
        /// <param name="cmdName"></param>
        /// <param name="t1"></param>
        /// <param name="t2"></param>
        /// <returns></returns>
        public byte[] DriverPackage <T1, T2>(string code, string cmdName, T1 t1, T2 t2)
        {
            IProtocolCommand cmd = GetProcotolCommand(cmdName);

            if (cmd != null)
            {
                return(cmd.Package <T1, T2>(code, t1, t2));
            }
            else
            {
                return(null);
            }
        }
コード例 #12
0
        public TriggerTimeoutCommands(IProtocolCommand parent) : base(parent)
        {
            Source = new TriggerSourceCommand(this);

            Slope = new TriggerSlopeCommand(this);

            Time = new ProtocolCommand(this)
            {
                Name    = "TIMe",
                Term    = "TIM",
                Options = new RealOptions(16 * SI.n, 10),
            };
        }
コード例 #13
0
        /// <summary>
        /// 打包数据
        /// </summary>
        /// <param name="addr"></param>
        /// <param name="cmdName"></param>
        /// <param name="obj"></param>
        /// <returns></returns>
        public byte[] DriverPackage(int addr, string cmdName, object obj)
        {
            IProtocolCommand cmd = GetProcotolCommand(cmdName);

            if (cmd != null)
            {
                return(cmd.Package(addr, obj));
            }
            else
            {
                return(null);
            }
        }
コード例 #14
0
        /// <summary>
        /// 解析数据
        /// </summary>
        /// <param name="cmdName"></param>
        /// <param name="data"></param>
        /// <param name="obj"></param>
        /// <returns></returns>
        public object DriverAnalysis(string cmdName, byte[] data, object obj)
        {
            IProtocolCommand cmd = GetProcotolCommand(cmdName);

            if (cmd != null)
            {
                return(cmd.Analysis(data, obj));
            }
            else
            {
                return(null);
            }
        }
コード例 #15
0
ファイル: ProtocolDriver.cs プロジェクト: zhouwb168/CodeHub
        /// <summary>
        ///
        /// </summary>
        /// <typeparam name="T1"></typeparam>
        /// <typeparam name="T2"></typeparam>
        /// <param name="cmdName"></param>
        /// <param name="data"></param>
        /// <param name="t1"></param>
        /// <param name="t2"></param>
        /// <returns></returns>
        public dynamic DriverAnalysis <T1, T2>(string cmdName, byte[] data, T1 t1, T2 t2)
        {
            IProtocolCommand cmd = GetProcotolCommand(cmdName);

            if (cmd != null)
            {
                return(cmd.Analysis <T1, T2>(data, t1, t2));
            }
            else
            {
                return(null);
            }
        }
コード例 #16
0
        public TriggerSHoldCommands(IProtocolCommand parent) : base(parent)
        {
            DataSource = new TriggerSourceChannelCommand(this);

            ClockSource = new TriggerSourceChannelCommand(this);

            Slope = new TriggerSlopeCommand(this)
            {
                Options = new StringOptions
                {
                    new StringOption("POSitive", "POS"),
                    new StringOption("NEGative", "NEG"),
                }
            };

            Pattern = new TriggerPatternCommands(this)
            {
                Options = new StringOptions()
                {
                    new StringOption("H", "H"),
                    new StringOption("L", "L"),
                }
            };

            Type = new ProtocolCommand(this)
            {
                Name    = "TYP",
                Term    = "TYP",
                Options = new StringOptions
                {
                    new StringOption("SETup", "SET"),
                    new StringOption("HOLd", "HOL"),
                    new StringOption("SETHOLd", "SETHOL"),
                }
            };

            SetupTime = new TriggerTimeCommand(this)
            {
                Name    = "SHOLd",
                Term    = "SHOL",
                Options = new RealOptions(8 * SI.n, 1),
            };

            HoldTime = new TriggerTimeCommand(this)
            {
                Name    = "HTIMe",
                Term    = "HTIM",
                Options = new RealOptions(8 * SI.n, 1),
            };
        }
コード例 #17
0
 public TriggerSlopeCommands(IProtocolCommand parent) : base(parent)
 {
     Source = new ProtocolCommand(this)
     {
         Name    = "SOURce",
         Term    = "SOUR",
         Options = new StringOptions
         {
             new StringOption("CH1", "CHAN1"),
             new StringOption("CH2", "CHAN2"),
             new StringOption("CH3", "CHAN3"),
             new StringOption("CH4", "CHAN4"),
         }
     };
 }
コード例 #18
0
        public TriggerDelayCommands(IProtocolCommand parent) : base(parent)
        {
            SourceA = new TriggerSourceChannelCommand(this)
            {
                Name = "SourceA",
                Term = "SA",
            };

            SlopeA = new TriggerSlopeCommand(this)
            {
                Name = "SLOPeA",
                Term = "SLOPA",
            };

            SourceB = new TriggerSourceChannelCommand(this)
            {
                Name = "SourceB",
                Term = "SB",
            };

            SlopeB = new TriggerSlopeCommand(this)
            {
                Name = "SLOPeB",
                Term = "SLOPB",
            };

            Type = new TriggerTypeCommand(this);

            TUpper = new TriggerTimeCommand(this)
            {
                Name    = "TUPPer",
                Term    = "TUPP",
                Options = new RealOptions()
                {
                    new RealOption(16 * SI.n, 10)
                }
            };

            TLower = new TriggerTimeCommand(this)
            {
                Name    = "TLOWer",
                Term    = "TLOW",
                Options = new RealOptions()
                {
                    new RealOption(8 * SI.n, 10)
                }
            };
        }
コード例 #19
0
 public TriggerPatternCommands(IProtocolCommand parent) : base(parent)
 {
     Pattern = new ProtocolCommand(this)
     {
         Name    = "PATTern",
         Term    = "PATT",
         Options = new StringOptions
         {
             new StringOption("H", "H"),
             new StringOption("L", "L"),
             new StringOption("X", "X"),
             new StringOption("R", "R"),
             new StringOption("F", "F"),
         }
     };
     Level = new TriggerLevelCommand(this);
 }
コード例 #20
0
        public ScopeCommand(IProtocolVM viewModel, IProtocolCommand protocolCommand, string defaultResponse)
        {
            //ViewModel = viewModel;
            ProtocolCommand = protocolCommand;

            if (protocolCommand.IsSettable)
            {
                var canSet = this.WhenValueChanged(x => x.IsEnabled)
                             .Where(x => x == true);
                SetCommand = ReactiveCommand.CreateFromTask(SendCommandAsync, canSet);
                SetCommand.ThrownExceptions.SubscribeOnUI().Subscribe(async ex => await DisplayException(ex, "Couldn't set"));
                Increment = ReactiveCommand.Create(IncrementValue);
                Increment.ThrownExceptions.SubscribeOnUI().Subscribe(async ex => await DisplayException(ex, "Couldn't increment"));
                Decrement = ReactiveCommand.Create(DecrementValue);
                Decrement.ThrownExceptions.SubscribeOnUI().Subscribe(async ex => await DisplayException(ex, "Couldn't decrement"));
            }
            else
            {
                // set command is used to send the command without a value or response
                SetCommand = ReactiveCommand.CreateFromTask(SendCommandAsync);
            }

            if (protocolCommand.IsQueryable)
            {
                if (App.Mock)
                {
                    DefaultResponse = defaultResponse;
                }
                GetCommand = ReactiveCommand.CreateFromTask(SendQueryAsync);
                GetCommand.ThrownExceptions.SubscribeOnUI().Subscribe(async ex => await DisplayException(ex, "Couldn't query"));
            }
            else
            {
                if (App.Mock)
                {
                    DefaultResponse = null;
                }
                IsEnabled = true;
            }
        }
コード例 #21
0
        /// <summary>
        /// 初始化驱动
        /// </summary>
        public virtual void InitDriver(IRunDevice runDevice)
        {
            this._Commands.Clear();
            Assembly asm = runDevice.GetType().Assembly;

            Type[] types = asm.GetTypes();
            foreach (Type t in types)
            {
                if (typeof(IProtocolCommand).IsAssignableFrom(t))
                {
                    if (t.Name != "IProtocolCommand" && t.Name != "ProtocolCommand")
                    {
                        IProtocolCommand cmd = (IProtocolCommand)t.Assembly.CreateInstance(t.FullName);
                        if (cmd != null)
                        {
                            cmd.Setup(this);
                            _Commands.TryAdd(cmd.Name, cmd);
                        }
                    }
                }
            }
        }
コード例 #22
0
        public TimebaseDelayCommands(IProtocolCommand parent) : base(parent)
        {
            Enable = new TimebaseEnableCommand(this);

            Offset = new ProtocolCommand(this, "Offset", "OFFS")
            {
                // LeftTime = 6x MainScale - MainOffset
                // RightTime = 6x MainScale - MainOffset
                // DelayRange = 12x DelayScale
                Options = new RealOptions(-12, 12)
            };

            Scale = new ProtocolCommand(this, "Scale", "SCAL")
            {
                // max scale: MainScale
                // min scale: 50 / (SampleRate x AmplificationFactor)
                // Amplification factor is (10 x the sum of):
                //    Number of enabled analog channels
                //    Number of analog channels set as trigger sources
                //    Number of enabled digital channel groups (D0 to D7 is one, D8 to D15 is the other)
                // TODO: This needs more work, I'm just guessing here
                Options = new RealOptions(10 * SI.n, 50)
            };
        }
コード例 #23
0
 public IProtocolPackage EncodeCommand(IProtocolCommand command, Dictionary <string, byte[]> paramBytes = null)
 {
     throw new NotImplementedException();
 }
コード例 #24
0
 public ProtocolSimpleCommand(IProtocolCommand parent, string name, string term)
     : base(parent, name, term)
 {
 }
コード例 #25
0
 public ProtocolCommand(IProtocolCommand parent, object pathParameter)
 {
     Parent        = parent;
     PathParameter = pathParameter;
 }
コード例 #26
0
 public ProtocolCommand(IProtocolCommand parent, string name, string term)
 {
     Parent = parent;
     Name   = name;
     Term   = term;
 }
コード例 #27
0
 public ProtocolCommand(IProtocolCommand parent)
 {
     Parent = parent;
 }
コード例 #28
0
ファイル: ProtocolCommand.cs プロジェクト: Wrath7/testrepo
        public static byte[] Serialize(IProtocolCommand command)
        {
            StringBuilder Sb = new StringBuilder();
            Sb.Append(command.Command + "`" + command.From + "`" + command.To + "`" + command.Id.ToString() + "`");

            foreach (object o in command.Parameters)
            {
                Sb.Append(o.ToString() + "`");
            }

            string commandStr = Sb.ToString(0, Sb.Length - 1);

            System.Text.ASCIIEncoding encoding = new ASCIIEncoding();
            return encoding.GetBytes(commandStr);
        }
コード例 #29
0
 public TriggerWhenCommand(IProtocolCommand parent) : base(parent)
 {
 }
コード例 #30
0
 public TriggerRuntCommands(IProtocolCommand parent) : base(parent)
 {
     Source = new TriggerSourceCommand(this);
 }
コード例 #31
0
        private void Send(IProtocolCommand cmd, ConnectionState state)
        {
            Logger.WriteLine("Sending Command from: " + state.RemoteEndPoint.ToString() + " - " + cmd.Command, Logger.Severity.Debug, state.LOGNAME);

            byte[] dataToSend = ProtocolCommand.Serialize(cmd);

            bool status = state.Write(dataToSend, 0, dataToSend.Length);

            if (!status)
            {
                state.EndConnection();
            }
        }
コード例 #32
0
        public override IProtocolCommand Send(IProtocolCommand cmd)
        {
            IProtocolCommand receiveCmd = _client.Send(ProtocolCommand.Serialize(cmd));

            return receiveCmd;
        }
コード例 #33
0
 /// <summary>
 /// 协议编码
 /// </summary>
 /// <param name="command">指定的指令</param>
 /// <param name="paramBytes"></param>
 /// <returns>协议字节流</returns>
 public static byte[] EncodeProtocol(IProtocolCommand command, Dictionary <string, byte[]> paramBytes = null)
 => UnityFactory.Resolve <ICommandCoder>(command.Protocol.ProtocolModule).EncodeCommand(command, paramBytes).GetBytes();