238 lines
8.3 KiB
C#
238 lines
8.3 KiB
C#
using System;
|
|
using DTS.DASLib.Command.SLICE;
|
|
using DTS.Common.ICommunication;
|
|
using DTS.Common.Utilities.Logging;
|
|
using DTS.Common.Interface.Connection;
|
|
using DTS.Common.Enums.DASFactory;
|
|
using DTS.Common.Interface.DASFactory;
|
|
|
|
namespace DTS.DASLib.Service
|
|
{
|
|
public partial class Slice<T> : Communication<T>,
|
|
IDASCommunication,
|
|
IConfigurationActions,
|
|
IDiagnosticsActions,
|
|
ITriggerCheckActions,
|
|
IRealTimeActions,
|
|
IArmActions,
|
|
IDownloadActions where T : IConnection, new()
|
|
{
|
|
#region Trigger check
|
|
void ITriggerCheckActions.PreStartTriggerCheck(ServiceCallback callback, object userData)
|
|
{
|
|
var info = new SliceServiceAsyncInfo(callback, userData);
|
|
LaunchAsyncWorker("Slice.PreStartTriggerCheck", AsyncPreStartTriggerCheck, info);
|
|
}
|
|
|
|
/// <summary>
|
|
/// complete any prep work before starting trigger check that needs to be done
|
|
/// </summary>
|
|
protected virtual void AsyncPreStartTriggerCheck(object asyncInfo)
|
|
{
|
|
if (!(asyncInfo is SliceServiceAsyncInfo info)) { return; }
|
|
try
|
|
{
|
|
if (SupportsStartInversion())
|
|
{
|
|
var ssaPolarity = new SetSystemAttribute(this);
|
|
ssaPolarity.SetValue(AttributeTypes.SystemAttributes.StartRecordPolarity, (byte)(InvertStart ? 1 : 0), true);
|
|
ssaPolarity.SyncExecute();
|
|
}
|
|
if (SupportsTriggerInversion())
|
|
{
|
|
var ssaPolarity = new SetSystemAttribute(this);
|
|
ssaPolarity.SetValue(AttributeTypes.SystemAttributes.TriggerPolarity, (byte)(InvertTrigger ? 1 : 0), true);
|
|
ssaPolarity.SyncExecute();
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
APILogger.Log($"AsyncPreStartTriggerCheck failed, {ex.Message}");
|
|
}
|
|
info.Success();
|
|
}
|
|
void ITriggerCheckActions.PostStartTriggerCheck(ServiceCallback callback, object userData)
|
|
{
|
|
var info = new SliceServiceAsyncInfo(callback, userData);
|
|
info.Success();
|
|
}
|
|
void ITriggerCheckActions.StartTriggerCheck(ServiceCallback callback, object userData)
|
|
{
|
|
var info = new SliceServiceAsyncInfo(callback, userData);
|
|
LaunchAsyncWorker("Slice.StartTriggerCheck", AsyncStartTriggerCheck, info);
|
|
}
|
|
protected virtual void AsyncStartTriggerCheck(object asyncInfo)
|
|
{
|
|
if (!(asyncInfo is SliceServiceAsyncInfo info)) { return; }
|
|
try
|
|
{
|
|
try
|
|
{
|
|
var ihl = new InitializeHardwareLines(this) { LogCommands = true };
|
|
try
|
|
{
|
|
if (IsCommandSupported(DFConstantsAndEnums.ProtocolLimitedCommands.InitHardwareInputLines))
|
|
{
|
|
ihl.SyncExecute();
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
InitializeHardwareLines.Log(ex, ihl);
|
|
}
|
|
if (ihl.TriggerInputShorted)
|
|
{
|
|
info.Error("TriggerInputShorted");
|
|
return;
|
|
}
|
|
if (ihl.StartRecordShorted)
|
|
{
|
|
info.Error("StartInputShorted");
|
|
return;
|
|
}
|
|
|
|
}
|
|
catch (CanceledException)
|
|
{
|
|
info.Cancel();
|
|
return;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
info.Error(ex.Message, ex);
|
|
return;
|
|
}
|
|
info.Success();
|
|
}
|
|
catch (CanceledException)
|
|
{
|
|
info.Cancel();
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
info.Error(ex.Message, ex);
|
|
}
|
|
}
|
|
void ITriggerCheckActions.DoStartCheck(ServiceCallback callback, object userData)
|
|
{
|
|
var info = new SliceServiceAsyncInfo(callback, userData);
|
|
|
|
LaunchAsyncWorker("Slice.DoStartCheck", AsyncDoStartCheck, info);
|
|
}
|
|
void ITriggerCheckActions.DoTriggerCheck(ServiceCallback callback, object userData)
|
|
{
|
|
SliceServiceAsyncInfo info = null;
|
|
if (null != callback)
|
|
{
|
|
info = new SliceServiceAsyncInfo(callback, userData);
|
|
}
|
|
|
|
LaunchAsyncWorker("Slice.DoTriggerCheck", AsyncDoTriggerCheck, info);
|
|
}
|
|
|
|
void ITriggerCheckActions.DoTriggerCheckSync()
|
|
{
|
|
var ihl = new InitializeHardwareLines(this) { LogCommands = false };
|
|
try
|
|
{
|
|
if (IsCommandSupported(DFConstantsAndEnums.ProtocolLimitedCommands.InitHardwareInputLines))
|
|
{
|
|
ihl.SyncExecute();
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
InitializeHardwareLines.Log(ex, ihl);
|
|
}
|
|
|
|
var status = new ArmStatus
|
|
{
|
|
IsTriggered = ihl.TriggerInputShorted,
|
|
IsArmed = !ihl.TriggerInputShorted,
|
|
IsTriggerShorted = ihl.TriggerInputShorted,
|
|
IsStartShorted = ihl.StartRecordShorted
|
|
};
|
|
SetDASArmStatus(status, true);
|
|
}
|
|
private void AsyncDoTriggerCheck(object asyncInfo)
|
|
{
|
|
SliceServiceAsyncInfo info = null;
|
|
|
|
if (asyncInfo is SliceServiceAsyncInfo)
|
|
{
|
|
info = (SliceServiceAsyncInfo)asyncInfo;
|
|
}
|
|
try
|
|
{
|
|
((ITriggerCheckActions)this).DoTriggerCheckSync();
|
|
info?.Success();
|
|
}
|
|
catch (CanceledException)
|
|
{
|
|
info?.Cancel();
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
info?.Error(ex.Message, ex);
|
|
}
|
|
}
|
|
private void AsyncDoStartCheck(object asyncInfo)
|
|
{
|
|
if (!(asyncInfo is SliceServiceAsyncInfo info)) { return; }
|
|
try
|
|
{
|
|
var ihl = new InitializeHardwareLines(this) { LogCommands = false };
|
|
try
|
|
{
|
|
if (IsCommandSupported(DFConstantsAndEnums.ProtocolLimitedCommands.InitHardwareInputLines))
|
|
{
|
|
ihl.SyncExecute();
|
|
}
|
|
}
|
|
catch (Exception ex) { InitializeHardwareLines.Log(ex, ihl); }
|
|
|
|
var status = new ArmStatus
|
|
{
|
|
IsArmed = !ihl.TriggerInputShorted,
|
|
IsRecording = ihl.StartRecordShorted
|
|
};
|
|
SetDASArmStatus(status, true);
|
|
info.Success();
|
|
}
|
|
catch (CanceledException)
|
|
{
|
|
info.Cancel();
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
info.Error(ex.Message, ex);
|
|
}
|
|
}
|
|
void ITriggerCheckActions.CancelTriggerCheck(ServiceCallback callback, object userData)
|
|
{
|
|
var info = new SliceServiceAsyncInfo(callback, userData);
|
|
|
|
LaunchAsyncWorker("Slice.CancelTriggerCheck", AsyncCancelTriggerCheck, info);
|
|
}
|
|
|
|
private void AsyncCancelTriggerCheck(object asyncInfo)
|
|
{
|
|
if (!(asyncInfo is SliceServiceAsyncInfo info)) { return; }
|
|
try
|
|
{
|
|
info.Success();
|
|
}
|
|
catch (CanceledException)
|
|
{
|
|
info.Cancel();
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
info.Error(ex.Message, ex);
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
}
|
|
}
|