Esempio n. 1
0
        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);
        }
Esempio n. 2
0
        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);
            }
        }
Esempio n. 3
0
        public void Close()
        {
            if (this.DeviceHandle == 0)
            {
                throw new IOException("Device is already closed.");
            }
            var result = FCntl.close(this.DeviceHandle);

            if (result < 0)
            {
                throw new IOException(string.Format("Failed to close device - error {0}.", result));
            }
            this.DeviceHandle = 0;
            this.FreeTxRxBuffers();
        }
Esempio n. 4
0
        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();
        }
Esempio n. 5
0
        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();
        }
Esempio n. 6
0
        public void Close()
        {
            if (this.DeviceHandle == 0)
            {
                throw new System.IO.IOException("Device is already closed.");
            }
            var result = FCntl.close(this.DeviceHandle);

            if (result < 0)
            {
                throw new System.IO.IOException("Failed to close device.");
            }
            this.DeviceHandle = 0;
            this.FreeTxRxBuffers();
        }
Esempio n. 7
0
        private void Dispose(bool disposing)
        {
            // Check to see if Dispose has already been called.
            if (!this.disposed)
            {
                // If disposing equals true, dispose all managed
                // and unmanaged resources.
                if (disposing)
                {
                    // Dispose managed resources.
                    if (cancelTokenSource != null)
                    {
                        cancelTokenSource.Cancel();
                        if (this.pollTimeout >= 0)
                        {
                            // only wait for task to finish if poll timeout is not infinite
                            cancelTokenSource.Token.WaitHandle.WaitOne();
                        }
                        cancelTokenSource = null;
                    }
                    if (this.deviceHandle != 0)
                    {
                        try
                        {
                            FCntl.close(this.deviceHandle);
                        }
                        finally
                        {
                            this.deviceHandle = 0;
                        }
                    }
                    if (this.pin > 0)
                    {
                        setEdgeDetection(this.pin, EdgeDetectionMode.none);
                    }
                }

                // Note disposing has been done.
                disposed = true;
            }
        }
Esempio n. 8
0
        public static void decomp_NotifyCloseFile(object sender, NotifyEventArgs e)
        {
#if DO_OUTPUT
            Console.WriteLine("Close File Info\n" +
                              "  File name in cabinet = {0}", e.args.str1);
#endif
            string fname = destinationDirectory + e.args.str1;

            // TODO:  Most of this function probably should be encapsulated in the parent object.
            int err = 0;
            CabIO.FileClose(e.args.FileHandle, ref err, null);

            // set file date and time
            DateTime fileDateTime = FCntl.DateTimeFromDosDateTime(e.args.FileDate, e.args.FileTime);
            File.SetCreationTime(fname, fileDateTime);
            File.SetLastWriteTime(fname, fileDateTime);

            // get relevant file attributes and set attributes on the file
            FileAttributes fa = FCntl.FileAttributesFromFAttrs(e.args.FileAttributes);
            File.SetAttributes(fname, fa);

            e.Result = 1;
        }