/// <summary> /// Set the value of one bit in the process image. /// </summary> /// <param name="address">Address of the byte in the process image</param> /// <param name="bit">bit position (0-7)</param> /// <param name="value"></param> public void SetBitValue(ushort address, byte bit, bool value) { var bitValue = new SpiValue { Address = address, Bit = bit, Value = (byte)(value ? 1 : 0) }; if (!IsOpen) { return; } if (Interop.ioctl_value(_piControlHandle, Interop.KB_SET_VALUE, bitValue) < 0) { Trace.TraceError("PiControl.SetBitValue: Failed to write bit value."); } }
/// <summary> /// Get the value of one bit in the process image. /// </summary> /// <param name="address">Address of the byte in the process image</param> /// <param name="bit">bit position (0-7)</param> /// <returns>Bit value</returns> public bool GetBitValue(ushort address, byte bit) { var bitValue = new SpiValue { Address = address, Bit = bit }; if (!IsOpen) { return(false); } if (Interop.ioctl_value(_piControlHandle, Interop.KB_GET_VALUE, bitValue) < 0) { Trace.TraceError("PiControl.SetBitValue: Failed to read bit value."); return(false); } return(bitValue.Value != 0); }
internal static extern int ioctl_value(int file, uint cmd, SpiValue value);