using ACS.SPiiPlusNET; using Aurora; using Aurora.Api; using Aurora.Api.Devices; using Hermes; using System; using System.Security.Cryptography; using System.Threading; using System.Threading.Tasks; using System.Windows; using Axis = ACS.SPiiPlusNET.Axis; namespace AuroraACS { public class ACSDevice : Device { private const int BUFFER_MAX_NUM = 64; protected readonly Logger Log = new Logger("ACS"); // Get Total number of axes // Using Transaction function : return string text from controller, we need to convert to integer value private const string COMMAND_GETAXISCOUNT = "?SYSINFO(13)"; protected readonly Api _ACS; protected ACSDeviceConfig _Config; private int m_nTotalAxis = 0; private Axis[] m_arrAxisList = null; private readonly bool _IsSimulBySetting; protected bool[] BufferRunStatusArr; private CancellationTokenSource _cts; public ACSDevice(bool isSimulation, bool useTerminateUMD = false) { Type = DeviceType.Etc; _IsSimulBySetting = isSimulation; _ACS = new Api(); // Register Event _ACS.PHYSICALMOTIONEND += _ACS_PHYSICALMOTIONEND; _ACS.PROGRAMEND += _ACS_PROGRAMEND; if (useTerminateUMD) { TerminateUMD_Connection(); } } protected override int DoActivate(IDeviceConfig config) { if (IsActivated) return E1.OK; _Config = config as ACSDeviceConfig; IsSimul = _Config.IsSimul || _IsSimulBySetting; var socket = config.ConnConfig as SocketConnConfig; try { if (IsSimul) { _ACS.OpenCommSimulator(); } else { _ACS.OpenCommEthernetTCP(socket.Address.IpAddress, socket.Address.PortNumber); } } catch (Exception e) { Log.E("ACS Open Fail. Error : " + e.Message); return E1.NETWORK; } var strTemp = _ACS.Transaction(COMMAND_GETAXISCOUNT); if (strTemp == "") { Log.E("ACS Open fail"); return E1.NETWORK; } m_nTotalAxis = Convert.ToInt32(strTemp.Trim()); // When we are using multi axes command (ex) ToPointM, HaltM, ...), we need to allocate the array size more 1. // Because of the last delimeter (-1) BufferRunStatusArr = new bool[BUFFER_MAX_NUM]; m_arrAxisList = new Axis[m_nTotalAxis + 1]; for (int iAxis = 0; iAxis < m_nTotalAxis; iAxis++) { m_arrAxisList[iAxis] = (Axis)iAxis; } // Insert '-1' at the last m_arrAxisList[m_nTotalAxis] = Axis.ACSC_NONE; Log.I(string.Format("ACS Axis Count:{0:d}.", m_nTotalAxis)); SetEventProgramEnd(true); return E1.OK; } /// /// Terminate connections from SPiiPlus User Mode Driver /// - Maximum connections up to 10 in UMD /// private void TerminateUMD_Connection() { try { string terminateExceptionConnName = "ACS.Framework.exe"; ACSC_CONNECTION_DESC[] connectionList = _ACS.GetConnectionsList(); for (int index = 0; index < connectionList.Length; index++) { if (terminateExceptionConnName.CompareTo((string)connectionList[index].Application) != 0) _ACS.TerminateConnection(connectionList[index]); } } catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex.ToString()); } } protected override int DoDeactivate() { if (!IsActivated) return E1.OK; //AuroraE SetEventProgramEnd(false); try { if (IsSimul) { //_ACS.CloseSimulator(); } else { _ACS.CloseComm(); } } catch (ACSException ex) { Log.E(ex.Message); return E1.GENERIC; } catch (Exception e) { Log.E(e.Message); return E1.NETWORK; } return E1.OK; } public bool IsConnected => _ACS.IsConnected; #region Event private void SetEventMotionEnd() { //_ACS.PHYSICALMOTIONEND +=_ACS_PHYSICALMOTIONEND; _ACS.EnableEvent(Interrupts.ACSC_INTR_PHYSICAL_MOTION_END); Log.I("PHYSICAL_MOTION_END event enabled"); } private void SetEventProgramEnd(bool isSet) { //_ACS.PROGRAMEND += _ACS_PROGRAMEND; if (isSet) { _ACS.EnableEvent(Interrupts.ACSC_INTR_PROGRAM_END); Log.I("PROGRAM_END event enabled"); } else { _ACS.DisableEvent(Interrupts.ACSC_INTR_PROGRAM_END); Log.I("PROGRAM_END event disabled"); } } void _ACS_PHYSICALMOTIONEND(AxisMasks axis) { int bit = 0x01; int axisNo = 0; // Param value is bit number // Bit Number = Axis Number for (int i = 0; i < BUFFER_MAX_NUM; i++) { if ((int)axis == bit) { axisNo = i; break; } bit = bit << 1; } Log.I(String.Format(" - Axis {0}, Stopped", axisNo)); } void _ACS_PROGRAMEND(BufferMasks buffer) { ulong bit = 0x01; int bufferNo = 0; // Param value is bit number // Bit Number = Axis Number for (int i = 0; i < BUFFER_MAX_NUM; i++) { if ((ulong)buffer == bit) { bufferNo = i; break; } bit = bit << 1; } BufferRunStatusArr[bufferNo] = false; if (CallbackProgramEnd != null) { CallbackProgramEnd(bufferNo); CallbackProgramEnd = null; } Log.I(string.Format(" - Buffer {0}, Stoppped", bufferNo)); } #endregion #region Communication Termial - Using Transaction function public bool SendCMD(string strCMD) { if (!IsActivated) return false; return !string.IsNullOrEmpty(_ACS.Transaction(strCMD)); } #endregion Action CallbackProgramEnd = null; #region Run/Stop Buffer Program public bool RunBuffer(ProgramBuffer bufferNo, string strLabel = "", Action programEnd = null) { if (!IsActivated || IsSimul) return false; try { BufferRunStatusArr[(int)bufferNo] = true; if (strLabel != "") { // Run buffer program from label position _ACS.RunBuffer(bufferNo, strLabel); CallbackProgramEnd = programEnd; } else { // Run buffer program from first line _ACS.RunBuffer(bufferNo, null); } return true; } catch (Exception ex) { Log.E(ex.Message); return false; } } public bool IsBufferRunning(int buffNo) => BufferRunStatusArr[buffNo]; #region Move to absolute position public int MoveABS(Axis eAxisNo, double dPos) { try { _ACS.ToPoint(0, eAxisNo, dPos); // '0' - Absolute position, Axis number, Target position } catch (Exception ex) { Log.E(ex.Message); return E1.ARGUMENT; } return E1.OK; } #endregion public int MoveMABS(ACSMotor[] motors, double[] dPos) { Axis[] temp = new Axis[3]; temp[0] = motors[0].AxisNo; temp[1] = motors[1].AxisNo; temp[2] = (Axis)(-1); try { _ACS.ToPointM(0, temp, dPos); // '0' - Absolute position, Axis number, Target position } catch (Exception ex) { Log.E(ex.Message); return -1; } return 0; } #region Move to relative position (from current position) public int MoveINC(Axis eAxisNo, double dPos) { try { _ACS.ToPoint(MotionFlags.ACSC_AMF_RELATIVE, eAxisNo, dPos); // Flat,Axis number,Move distance } catch (Exception ex) { Log.E(ex.Message); return E1.ARGUMENT; } return E1.OK; } #endregion #region Motor Enable / Disable public bool SetMotorEnable(Axis eAxisNo, bool isEnable) { try { if (isEnable) { // Enable selected axis _ACS.Enable(eAxisNo); } else { _ACS.Disable(eAxisNo); } // If you want to enable several axes, // // Ex) Eanble three axes (0, 1, 6) // // int[] AxisList = new int[] { 0, 1, 6, -1 }; !!!! Important !! Must insert '-1' at the last // _ACS.EnableM(AxisList); } catch (Exception ex) { Log.E(ex.Message); return false; } return true; } public void SetMotorDisableAll() { try { // Disable all of axes _ACS.DisableAll(); } catch (Exception ex) { Log.E(ex.Message); } } #endregion public void StopBuffer(ProgramBuffer bufferNo) { if (IsActivated == false) return; // Stop program _ACS.StopBuffer(bufferNo); Thread.Sleep(10); BufferRunStatusArr[(int)bufferNo] = false; } public void StopBuffer(params int[] buffNoList) { foreach (var buffNo in buffNoList) { StopBuffer((ProgramBuffer)buffNo); } } #endregion public double ReadMotorPosition(Axis eAxisNo) { try { if (IsActivated == false) return 0; return _ACS.GetFPosition(eAxisNo); } catch (Exception e) { Log.E(e.Message); return 0; } } public void ControllerReboot(int timeout) { _ACS.ControllerReboot(timeout); } public bool SetCurrentPosition(Axis eAxisNo, double pos) { try { _ACS.SetFPosition(eAxisNo, pos); return true; } catch (Exception e) { Log.E(e.Message); return false; } } public bool ReadInposition(Axis eAxisNo) { var state = _ACS.GetMotorState(eAxisNo); if ((state & MotorStates.ACSC_MST_INPOS) != 0) { return true; } return false; } internal double ReadRPosition(Axis axisNo) { if (!IsActivated) { return 0; } return _ACS.GetRPosition(axisNo); } public string GetMotorAlarmDesc(int errorCode) { return _ACS.GetErrorString(errorCode); } public int GetMotorAlarmCode(Axis eAxisNo) { if (!IsActivated) { return E1.GENERIC; } // Retrieves the reason for motor disabling return _ACS.GetMotorError(eAxisNo); } public SafetyControlMasks GetFault(Axis eAxisNo) { if (!IsActivated) { return SafetyControlMasks.ACSC_NONE; } return _ACS.GetFault(eAxisNo); } public void ClearAlam(Axis eAxisNo) { _ACS.FaultClear(eAxisNo); } #region JOG Command public int Jog(Axis eAxisNo, GlobalDirection direction) { try { if (!IsActivated) return E1.GENERIC; if (direction == GlobalDirection.ACSC_NEGATIVE_DIRECTION) { _ACS.Jog(0, eAxisNo, (double)GlobalDirection.ACSC_NEGATIVE_DIRECTION); } else { _ACS.Jog(0, eAxisNo, (double)GlobalDirection.ACSC_POSITIVE_DIRECTION); } return E1.OK; } catch (Exception ex) { Log.E(ex.Message); return E1.GENERIC; } } public int Jog(Axis eAxisNo, double velocity) { try { if (!IsActivated) return E1.GENERIC; _ACS.Jog(MotionFlags.ACSC_AMF_VELOCITY, eAxisNo, velocity); return E1.OK; } catch (Exception e) { Log.E(e.Message); return E1.ARGUMENT; } } // Stop JOG motion public void stopJogMove(Axis eAxisNo) { SetHalt(eAxisNo); } #endregion public bool setAcceleration(Axis eAxisNo, double dVel) { if (!IsActivated) return false; _ACS.SetAcceleration(eAxisNo, dVel); if (dVel == _ACS.GetAcceleration(eAxisNo)) return true; else return false; } public bool SetAccelerationImm(Axis eAxisNo, double dVel) { if (!IsActivated) return false; _ACS.SetAccelerationImm(eAxisNo, dVel); return true; } public double GetAcceleration(Axis eAxisNo) { if (!IsActivated) return -1.0; return _ACS.GetAcceleration(eAxisNo); } public bool SetDeceleration(Axis eAxisNo, double dVel) { if (!IsActivated) return false; _ACS.SetDeceleration(eAxisNo, dVel); if (dVel == _ACS.GetDeceleration(eAxisNo)) return true; else return false; } public bool SetDecelerationImm(Axis eAxisNo, double dVel) { if (!IsActivated) return false; _ACS.SetDecelerationImm(eAxisNo, dVel); return true; } public double GetDeceleration(Axis eAxisNo) { if (!IsActivated) return -1.0; return _ACS.GetDeceleration(eAxisNo); } public bool SetKillDeceleration(Axis eAxisNo, double dVel) { if (!IsActivated) return false; _ACS.SetKillDeceleration(eAxisNo, dVel); if (dVel == _ACS.GetKillDeceleration(eAxisNo)) return true; else return false; } public double GetKillDeceleration(Axis eAxisNo) { if (!IsActivated) return -1.0; return _ACS.GetKillDeceleration(eAxisNo); } #region Stop motion using deceleration (halt command) public void SetHalt(params Axis[] eAxisNos) { try { foreach (var axisNo in eAxisNos) { _ACS.Halt(axisNo); } } catch (Exception ex) { Log.E(ex.Message); } } public void SetHalt(params int[] eAxisNos) { try { foreach (var axisNo in eAxisNos) { _ACS.Halt((Axis)axisNo); } } catch (Exception ex) { Log.E(ex.Message); } } public void SetHaltAll() { if (!IsActivated) return; try { // There is no halt all command, so you need to user HaltM function // // ex) You want to stop 0, 2, 5 axis // int[] m_arrAxisList = new int[] { 0, 2, 5, -1 }; // if (m_arrAxisList != null) _ACS.HaltM(m_arrAxisList); } catch (Exception ex) { Log.E(ex.Message); } } public void SetKill(Axis eAxisNo) { try { _ACS.Kill(eAxisNo); } catch (Exception ex) { Log.E(ex.Message); } } #endregion public bool setJerk(Axis eAxisNo, double dVel) { if (!IsActivated) return false; _ACS.SetJerk(eAxisNo, dVel); if (dVel == _ACS.GetJerk(eAxisNo)) return true; else return false; } public bool SetJerkImm(Axis eAxisNo, double dVel) { if (!IsActivated) return false; _ACS.SetJerkImm(eAxisNo, dVel); return true; } public double GetJerk(Axis eAxisNo) { if (!IsActivated) return -1.0; return _ACS.GetJerk(eAxisNo); } public void LoadBuffersFromFile(string strPath) { if (!IsActivated || IsSimul) return; _ACS.LoadBuffersFromFile(strPath); //_ACS.RunBuffer((ProgramBuffer)10, null); } #region Read / Write Buffer public int ReadVariableInt(string VariableName) { // [Coverity] CID #10056: (#1 of 1): null 리턴 값 역참조 (NULL_RETURNS) // public int ReadVariableInt(string VariableName) => (int)ReadVariable(VariableName); //2.unbox_null: null 객체 this.ReadVariable(VariableName, (ACS.SPiiPlusNET.ProgramBuffer) - 1, -1, -1, -1, -1) 언박싱. //returned_null: ReadVariable이(가) NULL을 반환합니다(6회 중 null회 검사).[상세정보 표시] if (IsSimul) return 1; var result = ReadVariable(VariableName); if (/*result != null && */result is int intValue) { return intValue; } Log.E($"ReadVariable {VariableName} Error : " + result); return 0; } /// /// Get int or an element of one int array. /// /// /// /// /// public bool ReadVariableInt(string VariableName, out int val, int index = -1) { val = 0; if (!IsActivated /*|| IsSimul*/) { return false; } object temp = ReadVariable(VariableName, ProgramBuffer.ACSC_NONE, index, index); if (temp is int) { val = (int)temp; return true; } return false; } //public int ReadVariableInt(string VariableName) // => (int)ReadVariable(VariableName); public bool ReadVariableIntArr(string VariableName, out int[] val, ProgramBuffer nBuf = ProgramBuffer.ACSC_NONE, int from1 = -1, int to1 = -1) { val = null; if (!IsActivated) { return false; } object temp = ReadVariable(VariableName, nBuf, from1, to1); if (temp is int[] ret && ret != null) { val = ret; return true; } return false; } public bool ReadVariableIntArrRef(string VariableName, ref int[] val, ProgramBuffer nBuf = ProgramBuffer.ACSC_NONE, int from1 = -1, int to1 = -1) { if (!IsActivated) { return false; } object temp = ReadVariable(VariableName, nBuf, from1, to1); if (temp is int[] ret && ret != null) { val = ret; return true; } return false; } public bool ReadVariableReal(string VariableName, out double val, int index = -1) { val = 0; if (!IsActivated) { return false; } object temp = ReadVariable(VariableName, ProgramBuffer.ACSC_NONE, index, index); if (temp is double ret) { val = ret; return true; } return false; } public bool ReadVariableRealArr(string VariableName, out double[] val, ProgramBuffer nBuf = ProgramBuffer.ACSC_NONE, int from1 = -1, int to1 = -1) { val = null; if (!IsActivated) { return false; } object temp = ReadVariable(VariableName, nBuf, from1, to1); if (temp is double[] ret && ret != null) { val = ret; return true; } return false; } public bool ReadVariableRealMatrix(string VariableName, out double[,] val, ProgramBuffer nBuf = ProgramBuffer.ACSC_NONE, int from1 = -1, int to1 = -1, int from2 = -1, int to2 = -1) { val = null; if (!IsActivated) { return false; } object temp = ReadVariable(VariableName, nBuf, from1, to1, from2, to2); if (temp is double[,]) { val = (double[,])temp; return true; } return false; } public bool ReadVariableIntMatrix(string VariableName, out int[,] val, ProgramBuffer nBuf = ProgramBuffer.ACSC_NONE, int from1 = -1, int to1 = -1, int from2 = -1, int to2 = -1) { val = null; if (!IsActivated /*|| IsSimul*/) { return false; } object temp = ReadVariable(VariableName, nBuf, from1, to1, from2, to2); if (temp is int[,]) { val = (int[,])temp; return true; } return false; } public object ReadVariable(string VariableName, ProgramBuffer nBuf = ProgramBuffer.ACSC_NONE, int from1 = -1, int to1 = -1, int from2 = -1, int to2 = -1) { try { if (!IsActivated /*|| IsSimul*/) { return null; } else { return _ACS.ReadVariable(VariableName, nBuf, from1, to1, from2, to2); } } catch (Exception exc) { if (!IsSimul) { Log.E($"ReadVariable {VariableName} Exception : " + exc.Message); return null; } return null; } } private bool WriteVariableInt(string VariableName, int Value) { _ACS.WriteVariable(Value, VariableName); if ((int)_ACS.ReadVariable(VariableName) == Value) return true; else return false; } public bool WriteVariableInt(string VariableName, int val, int idx = -1) { if (IsSimul) return true; if (!IsActivated) return false; return WriteVariable(VariableName, val, ProgramBuffer.ACSC_NONE, idx, idx); //if (ReadVariableInt(VariableName, out int temp, idx) && temp == val) // return true; //else // return false; } public bool WriteVariableIntArr(string VariableName, int[] val, ProgramBuffer nBuf = ProgramBuffer.ACSC_NONE, int from1 = -1, int to1 = -1) { if (IsSimul) return true; if (!IsActivated) return false; var res = WriteVariable(VariableName, val, nBuf, from1, to1); //var res1 = ReadVariableIntArr(VariableName, out int[] temp, nBuf, from1, to1); //var res2 = val.Equals(temp); if (res) return true; else return false; } public bool WriteRealVariable(string VariableName, object val) { if (IsSimul) return true; if (!IsActivated) return false; Log.V($"ACS variable[{VariableName}] : {val}"); return WriteVariable(VariableName, val); //if (ReadVariableReal(VariableName, out double temp) && val.Equals(temp)) // return true; //else // return false; } public bool WriteRealVariableArr(string VariableName, double[] val, ProgramBuffer nBuf = ProgramBuffer.ACSC_NONE, int from1 = -1, int to1 = -1) { if (!IsActivated) return false; return WriteVariable(VariableName, val, nBuf, from1, to1); } public bool WriteRealMatrixVariable(string VariableName, double[,] matrix, ProgramBuffer nBuf = ProgramBuffer.ACSC_NONE, int from1 = -1, int to1 = -1, int from2 = -1, int to2 = -1) { if (!IsActivated) return false; return WriteVariable(VariableName, matrix, nBuf, from1, to1, from2, to2); } public bool WriteIntMatrixVariable(string VariableName, int[,] matrix, ProgramBuffer nBuf = ProgramBuffer.ACSC_NONE, int from1 = -1, int to1 = -1, int from2 = -1, int to2 = -1) { if (!IsActivated) return false; return WriteVariable(VariableName, matrix, nBuf, from1, to1, from2, to2); } public bool WriteVariable(string VariableName, object Value, ProgramBuffer nBuf = ProgramBuffer.ACSC_NONE, int from1 = -1, int to1 = -1, int from2 = -1, int to2 = -1) { try { if (!IsActivated) return false; _ACS.WriteVariable(Value, VariableName, nBuf, from1, to1, from2, to2); Thread.Sleep(10); } catch (Exception exc) { Log.E($"WriteVariable {VariableName} Exception : " + exc.Message); return false; } return true; } #endregion public MotorStates GetMotorState(Axis axisNo) { if (!IsActivated) return MotorStates.ACSC_NONE; return _ACS.GetMotorState(axisNo); } public bool SetVelocity(Axis eAxisNo, double dVel) { if (!IsActivated) return false; _ACS.SetVelocity(eAxisNo, dVel); if (dVel == _ACS.GetVelocity(eAxisNo)) return true; else return false; } public bool SetVelocityImm(Axis eAxisNo, double dVel) { if (!IsActivated) return false; _ACS.SetVelocityImm(eAxisNo, dVel); return true; } public double GetVelocity(Axis eAxisNo) { if (!IsActivated) return -1.0; return _ACS.GetVelocity(eAxisNo); } public double GetFeedbackVelocity(Axis eAxis) { if (!IsActivated) { return 0; } double dVelocity = _ACS.GetFVelocity(eAxis); return dVelocity; } public void SetZeroPosition(Axis eAxisNo) { try { if (IsBufferRunning((int)eAxisNo)) { Log.FuncW($"Run buffer fail. Buffer({(int)eAxisNo}) is running!!!"); StopBuffer((int)eAxisNo); } // Change current poisition as you want // SetFPosition(Axis number, new position) _ACS.SetFPosition(eAxisNo, 0); } catch (Exception ex) { Log.E(ex.Message); } } public void readACSAxisCurrentPositionAll(ref double[] dPosition) { for (int i = 0; i < dPosition.Length; i++) { dPosition[i] = ReadMotorPosition((Axis)i); } } public void readACSAxisCurrentOverloadAll(ref double[] dOverload) { } public double GetAxisCurrentOverload(Axis eAxisNo) { if(ReadVariableReal("RMS", out double val, (int) eAxisNo) == true) { return val; } else { return 0.0; } } public bool checkMoveComp(Axis eAxis) { return true; //_ACS. } public bool clearInterfaceSignalAll() { //m_UMAC.AbsCompleteTable(eUMACZone.VisionA, false); //m_UMAC.AbsRequestTable(eUMACZone.VisionA, false); //m_UMAC.LoadingRequest(eUMACZone.VisionA, false); //m_UMAC.LoadingComplete(eUMACZone.VisionA, false); return true; //_ACS. } public double GetMotorSoftLimit(Axis eAxis, bool bPlusLimit) { try { double dLimitPos = double.NaN; if (bPlusLimit) { dLimitPos = (double)_ACS.ReadVariable("SRLIMIT", ProgramBuffer.ACSC_NONE, (int)eAxis, (int)eAxis) - 0.1; } else { dLimitPos = (double)_ACS.ReadVariable("SLLIMIT", ProgramBuffer.ACSC_NONE, (int)eAxis, (int)eAxis) + 0.1; } return dLimitPos; } catch (Exception ex) { Log.E($"Error : {ex.Message}"); return double.NaN; } } public bool IsHPLimit(Axis eAxis) { if (!IsActivated) { return false; } SafetyControlMasks eFaultState = _ACS.GetFault(eAxis); if ((eFaultState & SafetyControlMasks.ACSC_SAFETY_RL) != 0) { return true; } else { return false; } } public bool IsHNLimit(Axis eAxis) { if (!IsActivated) { return false; } SafetyControlMasks eFaultState = _ACS.GetFault(eAxis); if ((eFaultState & SafetyControlMasks.ACSC_SAFETY_LL) != 0) { return true; } else { return false; } } public bool IsSPLimit(Axis eAxis) { if (!IsActivated) { return false; } SafetyControlMasks eFaultState = _ACS.GetFault(eAxis); if ((eFaultState & SafetyControlMasks.ACSC_SAFETY_SRL) != 0) { return true; } else { return false; } } public bool IsSNLimit(Axis eAxis) { if (!IsActivated) { return false; } SafetyControlMasks eFaultState = _ACS.GetFault(eAxis); if ((eFaultState & SafetyControlMasks.ACSC_SAFETY_SLL) != 0) { return true; } else { return false; } } #region DIO public int GetInput(int port, int bit) { try { if (!IsActivated) return -1; int res = _ACS.GetInput(port, bit); return res; } catch (Exception exc) { Log.E(exc.Message); return -1; } } public int GetInputPort(int port) { try { if (!IsActivated) return -1; int res = _ACS.GetInputPort(port); return res; } catch (Exception exc) { Log.E(exc.Message); return -1; } } public int GetOutput(int port, int bit) { try { if (!IsActivated) return -1; int res = _ACS.GetOutput(port, bit); return res; } catch (Exception exc) { Log.E(exc.Message); return -1; } } public int GetOutputPort(int port) { try { if (!IsActivated) return -1; int res = _ACS.GetOutputPort(port); return res; } catch (Exception exc) { Log.E(exc.Message); return -1; } } public bool SetOutput(int port, int bit, int value) { try { if (!IsActivated) return false; _ACS.SetOutput(port, bit, value); return true; } catch(Exception exc) { Log.E(exc.Message); return false; } } public ACSC_WAITBLOCK SetOutputAsync(int port, int bit, int value) { try { if (!IsActivated) return new ACSC_WAITBLOCK() { Event = IntPtr.Zero, Ret = -1 }; return _ACS.SetOutputAsync(port, bit, value); } catch (Exception exc) { Log.E(exc.Message); return new ACSC_WAITBLOCK() { Event = IntPtr.Zero, Ret = -1 }; } } public bool SetOutputPort(int port, int value) { try { if (!IsActivated) return false; _ACS.SetOutputPort(port, value); return true; } catch (Exception exc) { Log.E(exc.Message); return false; } } public object GetResult(ACSC_WAITBLOCK waitBlock, int timeout) { try { if (!IsActivated) return null; return _ACS.GetResult(waitBlock, timeout); } catch (Exception exc) { Log.E(exc.Message); return null; } } public double GetAnalogInputNT(int port) { try { if (!IsActivated) return double.NaN; double res = _ACS.GetAnalogInputNT(port); return res; } catch (Exception exc) { Log.E(exc.Message); return double.NaN; } } public double GetAnalogOutputNT(int port) { try { if (!IsActivated) return double.NaN; double res = _ACS.GetAnalogOutputNT(port); return res; } catch (Exception exc) { Log.E(exc.Message); return double.NaN; } } public bool SetAnalogOutputNT(int port, double value) { try { if (!IsActivated) return false; _ACS.SetAnalogOutputNT(port, value); return true; } catch (Exception exc) { Log.E(exc.Message); return false; } } public int GetExtInput(int port, int bit) { try { if (!IsActivated) return -1; int res = _ACS.GetExtInput(port, bit); return res; } catch (Exception exc) { Log.E(exc.Message); return -1; } } public int GetExtInputPort(int port) { try { if (!IsActivated) return -1; int res = _ACS.GetExtInputPort(port); return res; } catch (Exception exc) { Log.E(exc.Message); return -1; } } public int GetExtOutput(int port, int bit) { try { if (!IsActivated) return -1; int res = _ACS.GetExtOutput(port, bit); return res; } catch (Exception exc) { Log.E(exc.Message); return -1; } } public int GetExtOutputPort(int port) { try { if (!IsActivated) return -1; int res = _ACS.GetExtOutputPort(port); return res; } catch (Exception exc) { Log.E(exc.Message); return -1; } } public bool SetExtOutput(int port, int bit, int value) { try { if (!IsActivated) return false; _ACS.SetExtOutput(port, bit, value); return true; } catch (Exception exc) { Log.E(exc.Message); return false; } } public bool SetExtOutputPort(int port, int value) { try { if (!IsActivated) return false; _ACS.SetExtOutputPort(port, value); return true; } catch (Exception exc) { Log.E(exc.Message); return false; } } #endregion } }