2.0.14
This commit is contained in:
@@ -30,23 +30,42 @@ public class IOCommanderModule:IVisionBuilderModule
|
||||
{
|
||||
_ioCommander = _factory.Create();
|
||||
_ioCommander.OnPinChanged += OnPinChanged;
|
||||
BroadcastInitialPinStates();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Log.Warning("IOCommander did non load: {e}",e);
|
||||
_ioCommander= null;
|
||||
}
|
||||
|
||||
|
||||
|
||||
if (_settings.ShowDebugView)_debugViewService.ShowDebugView();
|
||||
|
||||
|
||||
}
|
||||
private void BroadcastInitialPinStates()
|
||||
{
|
||||
if (_ioCommander == null) return;
|
||||
Task.Run(async () =>
|
||||
{
|
||||
// Wait for the first poll cycle to populate PinState
|
||||
for (int attempt = 0; attempt < 10 && _ioCommander?.PinState == null; attempt++)
|
||||
{
|
||||
await Task.Delay(200);
|
||||
}
|
||||
if (_ioCommander?.PinState == null) return;
|
||||
for (int i = 0; i < _ioCommander.PinState.Length; i++)
|
||||
{
|
||||
OnPinChanged(i + 1, _ioCommander.PinState[i]);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
ConcurrentDictionary<int, bool> _pinStates = new ConcurrentDictionary<int, bool>();
|
||||
public event Action<int, bool>? OnPinChangedEvent = delegate { };
|
||||
private void OnPinChanged(int arg1, bool arg2)
|
||||
{
|
||||
_pinStates.TryAdd(arg1, arg2);
|
||||
_pinStates[arg1] = arg2;
|
||||
_debugViewService.SetInputPinStatus(arg1, arg2);
|
||||
OnPinChangedEvent?.Invoke(arg1, arg2);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user