/// <summary> /// 夹件|松件信号 /// </summary> /// <param name="number"></param> /// <param name="enable"></param> public IDevice Clamp(int number, bool enable = true) { eSwitchOption clamp; switch (number) { case 0: clamp = eSwitchOption.Clamp0; Bit.Clr(_status, eSwitchState.Unclamped0); break; case 1: clamp = eSwitchOption.Clamp1; Bit.Clr(_status, eSwitchState.Unclamped0); break; case 2: clamp = eSwitchOption.Clamp2; break; case 3: clamp = eSwitchOption.Clamp3; break; case 4: clamp = eSwitchOption.Clamp4; break; case 5: clamp = eSwitchOption.Clamp5; break; default: return(this); } byte[] result; lock (_port) { _option = enable ? Bit.Set(_option, clamp) : Bit.Clr(_option, clamp); _port.Write(_serialize.Serialize(new WriteRandomCommand(eElementCode.M, 2 * 16, (ushort)_option))) .Read(out result); } #if DEBUG var res = _serialize.Deserialize <WriteRandomResult>(result); Logger.LogInfo($"Switch:{clamp.ToString()} {enable}, code:{res.Code.ToString()}"); #endif return(this); }
public SwitchDevice(IPort port, ISerialize serialize) : base(port, serialize) { _port.Write(_serialize.Serialize(new ReadRandomCommand(eElementCode.M, 2 * 16))) .Read(out byte[] result); var res = _serialize.Deserialize <ReadRandomResult>(result); if (res.Code == ePlcResultCode.OK) { _option = (eSwitchOption)res.WordData; } _isOnline = true; Update(); }
/// <summary> /// 急停 /// </summary> /// <returns></returns> public IDevice EStop(bool enable) { byte[] result; lock (_port) { _option = enable ? Bit.Set(_option, eSwitchOption.EStop) : Bit.Clr(_option, eSwitchOption.EStop); _port.Write(_serialize.Serialize(new WriteRandomCommand(eElementCode.M, 2 * 16, (ushort)_option))) .Read(out result); } #if DEBUG var res = _serialize.Deserialize <WriteRandomResult>(result); Logger.LogInfo($"Switch:estop {enable}, code:{res.Code.ToString()}"); #endif return(this); }
/// <summary> /// 旋转 /// </summary> /// <returns></returns> public IDevice Rotate(bool enable = true) { byte[] result; lock (_port) { Bit.Clr(_status, eSwitchState.Rotate); _option = enable ? Bit.Set(_option, eSwitchOption.Rotate) : Bit.Clr(_option, eSwitchOption.Rotate); _port.Write(_serialize.Serialize(new WriteRandomCommand(eElementCode.M, 2 * 16, (ushort)_option))) .Read(out result); //_option = Bit.Clr(_option, eSwitchOption.Rotate); //_port.Write(_serialize.Serialize(new WriteRandomCommand(eElementCode.M, 2 * 16, (ushort)_option))); //_option = enable ? Bit.Set(_option, eSwitchOption.Rotate); //_port.Write(_serialize.Serialize(new WriteRandomCommand(eElementCode.M, 2 * 16, (ushort)_option))); //_port.Read(out result); } #if DEBUG var res = _serialize.Deserialize <WriteRandomResult>(result); Logger.LogInfo($"Switch:rotate, code:{res.Code.ToString()}"); #endif return(this); }