using Aurora.Api; using Aurora.Api.DataType; using Aurora.Api.Devices; using Hermes; using System; using System.Collections.Generic; using System.ComponentModel; using System.IO.Ports; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Input; using static AuroraHeightSensor.HeightSensor; namespace AuroraHeightSensor.Keyence { // Keyence LK-G85 public partial class HeightSensorLKG85 : SerialConn, IHeightSensor { //private HeightSensorConfig _Config; public HeightSensorLKG85(string deviceId, bool isSimul = false) : base(deviceId, isSimul) { } //public int Connect(IConnConfig config) public int Activate(IConnConfig config) { if (IsPortOpen()) { return E1.OK; } return Open(config as SerialConnConfig); } //public int Disconnect() public int Deactivate() { return Close(); } public bool CheckConnected() { return IsConnected(); } public int MeasureAll(out List SensorValue) { SensorValue = null; return E1.OK; } public int Measure(eChannel channel, out double value) { value = 0; if (ReadZPosition(out double value1, out double value2) != E1.OK) { return E2.INTERNAL_ERROR; } if (channel == eChannel.CH0) { value = value1; } else { value = value2; } return E1.OK; } public int SetZero(eChannel channel, bool isSet = true) { return Reset(channel, isSet); } public virtual int CheckAlive() { if (IsConnected()) { return E1.OK; } return E1.NETWORK; } // BOOL CHeightSensorControl::ReadZPosition( int iCH, double &dVal1, double &dVal2 ) private int ReadZPosition(out double value1, out double value2) { value1 = -9999; value2 = -9999; if (!IsPortOpen()) { Log.E("Serial Port is NOT Open!"); return E1.NETWORK; } if (CMD_MeasureControl_GetMeasureValueDual(ref value1, ref value2) == false) { return E1.GENERIC; } return E1.OK; } // BOOL CHeightSensorControl::Reset( int iCH ) private int Reset(eChannel channel, bool isSet = true) { if (!IsPortOpen()) { Log.E("Serial Port is NOT Open!"); return E1.NETWORK; } if (CMD_MeasureControl_SetAutoZero((int)channel, isSet) == false) { return E1.GENERIC; } return E1.OK; } public int SetLed(bool isOn) { throw new NotImplementedException(); } public int StartStopAutoTransmit(bool isOn, ICommand callback) { //throw new NotImplementedException(); return E1.OK; } public int SetZeroShift(eChannel channel) { return E1.OK; } public int SetZeroShiftReset(eChannel channel) { return E1.OK; } public int Reset(eChannel channel) { return E1.OK; } } }