private void openEdgeDetectionFileHandle() { // close Handle if open if (this.deviceHandle != 0) { try { FCntl.close(this.deviceHandle); } finally { this.deviceHandle = 0; } } // open Handle readonly var result = FCntl.open(this.deviceName, FCntl.O_RDONLY); if (result < 0) { throw new IOException(string.Format("Failed to open device - error {0}.", result)); } this.deviceHandle = result; // clear pending interrupts readBufs(this.deviceHandle); }
private void setEdgeDetection(byte pin, EdgeDetectionMode edge) { if (edge == EdgeDetectionMode.none) { // open file handle to gpio export var fd = FCntl.open("/sys/class/gpio/unexport", FCntl.O_WRONLY); if (fd < 0) { throw new IOException(string.Format("Failed to open gpio class - error {0}.", fd)); } // write pin number to export gpio pin // (don't check for errors because it raises if already unexported..) var buf = System.Text.UTF8Encoding.UTF8.GetBytes(pin.ToString() + Environment.NewLine); UniStd.write(fd, buf, Convert.ToUInt32(buf.Length)); FCntl.close(fd); } else { // open file handle to gpio export var fd = FCntl.open("/sys/class/gpio/export", FCntl.O_WRONLY); if (fd < 0) { throw new IOException(string.Format("Failed to open gpio class - error {0}.", fd)); } // write pin number to export gpio pin // (don't check for errors because it raises if already exported..) var buf = System.Text.UTF8Encoding.UTF8.GetBytes(pin.ToString() + Environment.NewLine); UniStd.write(fd, buf, Convert.ToUInt32(buf.Length)); FCntl.close(fd); // wait short delay for export to complete System.Threading.Thread.Sleep(50); // open file handle to gpio direction fd = FCntl.open(String.Format("/sys/class/gpio/gpio{0}/direction", pin), FCntl.O_WRONLY); if (fd < 0) { throw new IOException(string.Format("Failed to open gpio direction - error {0}.", fd)); } // write pin number to export gpio direction buf = System.Text.UTF8Encoding.UTF8.GetBytes("in" + Environment.NewLine); UniStd.write(fd, buf, Convert.ToUInt32(buf.Length)); FCntl.close(fd); // open file handle to gpio edge fd = FCntl.open(String.Format("/sys/class/gpio/gpio{0}/edge", pin), FCntl.O_WRONLY); if (fd < 0) { throw new IOException(string.Format("Failed to open gpio edge - error {0}.", fd)); } // write pin number to export gpio direction buf = System.Text.UTF8Encoding.UTF8.GetBytes(edge.ToString() + Environment.NewLine); UniStd.write(fd, buf, Convert.ToUInt32(buf.Length)); FCntl.close(fd); } }
public void Open(int flags) { if (this.DeviceHandle != 0) { throw new IOException("Device is already open."); } var result = FCntl.open(this.DeviceName, flags); if (result < 0) { throw new IOException(string.Format("Failed to open device - error {0}.", result)); } this.DeviceHandle = result; this.InitTxRxBuffers(); }
public void Open(uint mode) { if (this.DeviceHandle != 0) { throw new System.IO.IOException("Device is already open."); } var result = FCntl.open(this.DeviceName, FCntl.O_RDWR); if (result < 0) { throw new System.IO.IOException("Failed to open device."); } this.DeviceHandle = result; this.InitTxRxBuffers(); }