Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to check state in configure? #86

Open
Afate2023 opened this issue Dec 24, 2024 · 0 comments
Open

How to check state in configure? #86

Afate2023 opened this issue Dec 24, 2024 · 0 comments

Comments

@Afate2023
Copy link

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("");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant