예제 #1
0
 public GetVelocityRegulatorGainCommand(EltraDevice device)
     : base(device)
 {
     Name = "GetVelocityRegulatorGain";
 }
예제 #2
0
 public RelayVcs(AgentConnector connector, EltraDevice device)
     : base(connector, device)
 {
 }
예제 #3
0
        private async Task <bool> ExecuteCommand(EltraDevice device, ExecuteCommand executeCommand)
        {
            bool result = false;

            try
            {
                if (executeCommand != null && _executeCommandCache.CanExecute(executeCommand))
                {
                    var s = MsgLogger.BeginTimeMeasure();

                    var sourceChannelId = executeCommand.SourceChannelId;
                    var commandName     = executeCommand.Command?.Name;

                    var deviceCommand = device.FindCommand(commandName);

                    if (deviceCommand != null)
                    {
                        if (await DeviceControllerAdapter.SetCommandStatus(executeCommand, ExecCommandStatus.Executing))
                        {
                            try
                            {
                                MsgLogger.WriteDebug($"{GetType().Name} - ExecuteCommand", $"Clone Command '{commandName}'");

                                var clonedDeviceCommand = deviceCommand.Clone();

                                if (clonedDeviceCommand != null)
                                {
                                    MsgLogger.WriteDebug($"{GetType().Name} - ExecuteCommand", $"Sync Command '{commandName}'");

                                    clonedDeviceCommand.Sync(executeCommand.Command);

                                    MsgLogger.WriteDebug($"{GetType().Name} - ExecuteCommand", $"Execute Command '{commandName}', channel '{executeCommand.SourceChannelId}'");

                                    try
                                    {
                                        var start = MsgLogger.BeginTimeMeasure();

                                        result = clonedDeviceCommand.Execute(executeCommand.SourceChannelId, executeCommand.SourceLoginName);

                                        MsgLogger.EndTimeMeasure($"{GetType().Name} - ExecuteCommand", start, $"command '{executeCommand.Command.Name}' executed, result = {result}");
                                    }
                                    catch (Exception e)
                                    {
                                        MsgLogger.Exception($"{GetType().Name} - ExecuteCommand", e);
                                    }

                                    if (result)
                                    {
                                        var start = MsgLogger.BeginTimeMeasure();

                                        MsgLogger.WriteDebug($"{GetType().Name} - ExecuteCommand", $"Sync Response Command '{commandName}'");

                                        executeCommand.Command?.Sync(clonedDeviceCommand);

                                        MsgLogger.WriteDebug($"{GetType().Name} - ExecuteCommand", $"Push Response for Command '{commandName}'");

                                        executeCommand.SourceChannelId = Channel.Id;
                                        executeCommand.TargetChannelId = sourceChannelId;

                                        result = await DeviceControllerAdapter.PushCommand(executeCommand, ExecCommandStatus.Executed);

                                        if (result)
                                        {
                                            MsgLogger.WriteDebug($"{GetType().Name} - ExecuteCommand", $"Command '{commandName}' successfully processed!");
                                        }
                                        else
                                        {
                                            MsgLogger.WriteError($"{GetType().Name} - ExecuteCommand", $"Set command '{commandName}' status to exectuted failed!");
                                        }

                                        MsgLogger.EndTimeMeasure($"{GetType().Name} - ExecuteCommand", start, $"command '{executeCommand.Command.Name}' state synchronized, result = {result}");
                                    }
                                    else
                                    {
                                        var command = executeCommand.Command;

                                        MsgLogger.WriteError($"{GetType().Name} - ExecuteCommand",
                                                             command != null
                                                ? $"Command '{command.Name}' uuid '{executeCommand.CommandId}' execution failed!"
                                                : $"Command '?' uuid '{executeCommand.CommandId}' execution failed!");

                                        executeCommand.SourceChannelId = Channel.Id;
                                        executeCommand.TargetChannelId = sourceChannelId;

                                        await DeviceControllerAdapter.SetCommandStatus(executeCommand,
                                                                                       ExecCommandStatus.Failed);
                                    }
                                }
                                else
                                {
                                    await DeviceControllerAdapter.SetCommandStatus(executeCommand, ExecCommandStatus.Failed);

                                    MsgLogger.WriteError($"{GetType().Name} - ExecuteCommand", $"Command '{commandName}' cloning failed!");
                                }
                            }
                            catch (Exception e)
                            {
                                await DeviceControllerAdapter.SetCommandStatus(executeCommand,
                                                                               ExecCommandStatus.Failed);

                                MsgLogger.Exception($"{GetType().Name} - ExecuteCommand", e);
                            }
                        }
                        else
                        {
                            MsgLogger.WriteError($"{GetType().Name} - ExecuteCommand", $"Set Command '{commandName}' status to executing failed!");
                        }
                    }
                    else
                    {
                        MsgLogger.WriteError($"{GetType().Name} - ExecuteCommand", $"Command '{commandName}' not found!");
                    }

                    MsgLogger.EndTimeMeasure($"{GetType().Name} - ExecuteCommand", s, $"command '{executeCommand.Command?.Name}' executed, result = {result}");
                }
            }
            catch (Exception e)
            {
                result = false;
                MsgLogger.Exception($"{GetType().Name} - ExecuteCommand", e);
            }

            return(result);
        }
예제 #4
0
 public XddParameterBase(EltraDevice device, XmlNode source)
     : base(device, source)
 {
 }
예제 #5
0
 public StructuredParameter(EltraDevice device, XmlNode source)
     : base(device, source)
 {
 }
예제 #6
0
 public SetSensorTypeCommand(EltraDevice device)
     : base(device)
 {
     Name = "SetSensorType";
 }
예제 #7
0
 public XddDeviceVersion(EltraDevice device)
 {
     _device = device;
 }
 public GetPositionMarkerParameterCommand(EltraDevice device)
     : base(device)
 {
     Name = "GetPositionMarkerParameter";
 }
 public ActivatePositionCompareCommand(EltraDevice device)
     : base(device)
 {
     Name = "ActivatePositionCompare";
 }
예제 #10
0
 /// <summary>
 /// MasterVcs
 /// </summary>
 /// <param name="masterAgent"></param>
 /// <param name="device"></param>
 /// <param name="updateInterval"></param>
 /// <param name="timeout"></param>
 public MasterVcs(SyncCloudAgent masterAgent, EltraDevice device, uint updateInterval, uint timeout)
     : base(masterAgent.Url, device.ChannelId, masterAgent.Identity, updateInterval, timeout)
 {
     Device = device;
 }
예제 #11
0
 public XddProfileBody(EltraDevice device)
 {
     _device = device;
 }
 public GetPositionRegulatorFeedForwardCommand(EltraDevice device)
     : base(device)
 {
     Name = "GetPositionRegulatorFeedForward";
 }
예제 #13
0
 public Epos4ObjectDictionary(EltraDevice device)
     : base(device)
 {
 }
 public SetPositionRegulatorGainCommand(EltraDevice device)
     : base(device)
 {
     Name = "SetPositionRegulatorGain";
 }
예제 #15
0
 public ShowChannelDataDlgCommand(EltraDevice device)
     : base(device)
 {
     Name = "ShowChannelDataDlg";
 }
 public GetStepDirectionParameterCommand(EltraDevice device)
     : base(device)
 {
     Name = "GetStepDirectionParameter";
 }
예제 #17
0
 public XddApplicationProcess(EltraDevice device, XddDeviceManager deviceManager)
 {
     _device        = device;
     _deviceManager = deviceManager;
 }
예제 #18
0
 public VirtualCommandSet CreateVcs(AgentConnector agent, EltraDevice device)
 {
     return(new RelayVcs(agent, device));
 }
예제 #19
0
 public SetEcMotorParameterCommand(EltraDevice device)
     : base(device)
 {
     Name = "SetEcMotorParameter";
 }
예제 #20
0
 public EnableAnalogCurrentSetpointCommand(EltraDevice device)
     : base(device)
 {
     Name = "EnableAnalogCurrentSetpoint";
 }
예제 #21
0
 public GetIpmBufferParameterCommand(EltraDevice device)
     : base(device)
 {
     Name = "GetIpmBufferParameter";
 }
예제 #22
0
 public ReadDataBufferCommand(EltraDevice device)
     : base(device)
 {
     Name = "ReadDataBuffer";
 }
예제 #23
0
 public StopIpmTrajectoryCommand(EltraDevice device)
     : base(device)
 {
     Name = "StopIpmTrajectory";
 }
예제 #24
0
 public GetVersionCommand(EltraDevice device)
     : base(device)
 {
     Name = "GetVersion";
 }
예제 #25
0
 public GetFreeIpmBufferSizeCommand(EltraDevice device)
     : base(device)
 {
     Name = "GetFreeIpmBufferSize";
 }
 public DisableAnalogPositionSetpointCommand(EltraDevice device)
     : base(device)
 {
     Name = "DisableAnalogPositionSetpoint";
 }
예제 #27
0
 public GetHomingStateCommand(EltraDevice device)
     : base(device)
 {
     Name = "GetHomingState";
 }
예제 #28
0
        public async Task <bool> PlayWithDevice(EltraDevice device)
        {
            bool result = false;

            Console.WriteLine($"device = {device.Name}, node id = {device.NodeId}, version = {device.Version}, serial number = {device.Identification.SerialNumber:X8}");

            //0x3000, 0x00 is address of the counter parameter in object dictionary
            var counterParameter     = device.SearchParameter(0x3000, 0x00) as Parameter;
            var controlWordParameter = device.SearchParameter(0x6040, 0x00) as Parameter;
            var cp = await device.GetParameter(0x3000, 0x00) as Parameter;

            if (counterParameter != null && controlWordParameter != null)
            {
                const ushort readyFlag    = 1;
                const ushort sleepingFlag = 0;

                //let's get the current value stored in local object dictionary (can be outdated)
                controlWordParameter.GetValue(out ushort controlWord);

                // force parameter update, ok, now we are sure that the value is synchronized with master object dictionary
                await controlWordParameter.ReadValue();

                //control word is defined as UINT16 - RW, let's modify value of this parameter in local object dictionary
                controlWordParameter.SetValue(readyFlag);

                //synchronize value with master object dictionary
                await controlWordParameter.Write();

                // this method is reliable, but to keep the local object dictionary up-to-date not quiete effective
                // (object dictionary can contain more than 100 parameters)
                // your agent usually, doesn't need the current value information about all parameters
                // to limit the read requests, you can specify explicite the parameters you are interested in
                Console.WriteLine($"register parameter 0x{counterParameter.Index:X4}:0x{counterParameter.SubIndex:X2} for updates");

                //we would like to be informed each time the parameter is changed
                counterParameter.ParameterChanged += OnParameterChanged;

                // to activate this feature, call RegisterUpdate
                // priority is transfered to the master and is up to master to decide what low, high or medium priority is
                counterParameter.AutoUpdate(ParameterUpdatePriority.High);
                //from now on, our local object dictionary will be actualized each time the {counterParameter} is changed by remote party

                // execute command on the remote master device,
                // our dummy master has 2 simple methods, start and stop counting
                // let's start counting and observe how our counter parameter {counterParameter} is changing ...
                // on the end, we will stop counting, to give our master some peace ...
                var sampleCommands = new SampleCommands(device);

                await sampleCommands.PlayWithDeviceCommands();

                //we don't need the notifications at this point
                counterParameter?.StopUpdate(ParameterUpdatePriority.High);

                //remove events handling
                counterParameter.ParameterChanged -= OnParameterChanged;

                //in case our parameter is supporting <backup> flag, we can grab some historic data
                await PlayWithParameterStatistics(device);

                //reset control word parameter value
                controlWordParameter.SetValue(sleepingFlag);

                result = true;
            }

            return(result);
        }
예제 #29
0
        public async Task <bool> IsDeviceRegistered(EltraDevice device)
        {
            var status = await DeviceControllerAdapter.GetDeviceStatus(device);

            return(status == DeviceStatus.Registered || status == DeviceStatus.Ready);
        }
 public EnableAnalogVelocitySetpointCommand(EltraDevice device)
     : base(device)
 {
     Name = "EnableAnalogVelocitySetpoint";
 }