Skip to content

How to check state in configure? #86

@Afate2023

Description

@Afate2023

My esi file have mailbox sdo write from SAFE-OP state to OP like twincat start-up.
So I need to create start-up config by slave info.
I create callback dictionary to start in configure function (in your state region) like your created po2socallback.
But I found no use,so I log slave state by EcMaster.getState(slaveindex),and found all slave state are Pre-op.
Is it a problem with the way I use it?

public void Configure(SlaveInfo rootSlave = null)
{
    var networkInterface = NetworkInterface
        .GetAllNetworkInterfaces()
        .Where(nic => nic.Name == _settings.InterfaceName)
        .FirstOrDefault();
    
    if (networkInterface?.OperationalStatus != OperationalStatus.Up)
        throw new Exception($"Network interface '{_settings.InterfaceName}' is not linked. Aborting action.");
    #region "PreOp"
    var slaves = rootSlave.Descendants().ToList();
    
    LogSlaveStates(slaves);
    var actualSlave = EcUtilities.ScanDevices(this.Context, _settings.InterfaceName, null);
    
    
    //StartInitCmd(slaves,DeviceTypeMailboxCoEInitCmdTransition.PS);
    //StartInitCmd(slaves, DeviceTypeMailboxCoEInitCmdTransition.SO);
    
    var actualSlaves = actualSlave.Descendants().ToList();
    
    if (rootSlave == null)
    {
        rootSlave = actualSlave;
    
        rootSlave.Descendants().ToList().ForEach(current =>
        {
            EcUtilities.CreateDynamicData(_settings.EsiDirectoryPath, current);
        });
    }
    //LogSlaveStates(slaves);
    this.ValidateSlaves(slaves, actualSlaves);
    
    this.ConfigureSlaves(slaves);
    this.ConfigureIoMap(slaves);
    this.ConfigureDc();
    this.ConfigureSync01(slaves);
    LogSlaveStates(slaves);
    #endregion
    
    #region "SafeOp"
    EcUtilities.CheckErrorCode(this.Context, EcHL.CheckSafeOpState(this.Context), nameof(EcHL.CheckSafeOpState));
    
    LogSlaveStates(slaves);
    #endregion
    
    #region "Op"
    
    EcUtilities.CheckErrorCode(this.Context, EcHL.RequestCommonState(this.Context, (UInt16)SlaveState.Operational), nameof(EcHL.RequestCommonState));
    
    LogSlaveStates(slaves);
    
    #endregion
    
    if (_watchdogTask == null)
        _watchdogTask = Task.Run(() => this.WatchdogRoutine(), _cts.Token);
    
    LogSlaveStates(slaves);
}
public void LogSlaveStates(List<SlaveInfo> slaves)
{
    foreach (var slave in slaves)
    {
        var slaveIndex = (ushort)(Convert.ToUInt16(slaves.ToList().IndexOf(slave)) + 1);
        Debug.Write($"GetState {slaveIndex}:{GetState(slaveIndex).ToString()};");
    }
    Debug.WriteLine("");
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions