Ejemplo n.º 1
0
        /// <summary>
        /// Sleeps for the given amount of microseconds.
        /// Waits of 100 microseconds or less use busy waits.
        /// Returns the real elapsed microseconds.
        /// </summary>
        /// <param name="microsecs">The micro seconds.</param>
        /// <returns>Returns the real elapsed microseconds.</returns>
        public long SleepMicros(long microsecs)
        {
            if (microsecs <= 0)
            {
                return(0L);
            }

            if (microsecs <= uint.MaxValue)
            {
                return(Threads.GpioDelay(Convert.ToUInt32(microsecs)));
            }

            var componentSeconds   = microsecs / SecondsToMicrosFactor;
            var componentMicrosecs = microsecs % SecondsToMicrosFactor;

            if (componentSeconds <= int.MaxValue && componentMicrosecs <= int.MaxValue)
            {
                BoardException.ValidateResult(
                    Threads.GpioSleep(
                        TimeType.Relative,
                        Convert.ToInt32(componentSeconds),
                        Convert.ToInt32(componentMicrosecs)));

                return(microsecs);
            }

            Threads.TimeSleep(componentSeconds + (componentMicrosecs / (double)SecondsToMicrosFactor));
            return(microsecs);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Writes the specified buffer to the transmit pin as a free-form wave.
        /// </summary>
        /// <param name="buffer">The buffer.</param>
        public void Write(byte[] buffer)
        {
            Waves.GpioWaveClear();
            BoardException.ValidateResult(
                Waves.GpioWaveAddSerial(
                    (UserGpio)_transmitPin.PinNumber,
                    Convert.ToUInt32(BaudRate),
                    Convert.ToUInt32(DataBits),
                    Convert.ToUInt32(StopBits),
                    0,
                    Convert.ToUInt32(buffer.Length),
                    buffer));

            var waveId = BoardException.ValidateResult(
                Waves.GpioWaveCreate());

            Waves.GpioWaveTxSend(Convert.ToUInt32(waveId), WaveMode.OneShotSync);

            // Wait for the wave to finish sending
            while (Waves.GpioWaveTxBusy() > 0)
            {
                Board.Timing.Sleep(1);
            }

            Waves.GpioWaveDelete(Convert.ToUInt32(waveId));
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Retrieves a list of files matching the given pattern. See <see cref="FileListUnmanaged" />.
        /// </summary>
        /// <param name="pathPattern">The path pattern.</param>
        /// <returns>A list of matching files.</returns>
        public static string[] FileList(string pathPattern)
        {
            var  buffer        = new byte[1024 * 128]; // 128kb of file paths
            var  result        = BoardException.ValidateResult(FileListUnmanaged(pathPattern, buffer, (uint)buffer.Length));
            var  encoding      = Encoding.GetEncoding(0);
            var  fileList      = new List <string>();
            var  lastZeroIndex = -1;
            var  runLength     = 0;
            byte byteValue;

            // Split the bytes into 0-terminated strings
            for (var byteIndex = 0; byteIndex < result; byteIndex++)
            {
                byteValue = buffer[byteIndex];
                if (byteValue == 0 || byteIndex >= result - 1)
                {
                    if (runLength > 0)
                    {
                        fileList.Add(encoding.GetString(buffer, lastZeroIndex + 1, runLength));
                    }

                    runLength     = 0;
                    lastZeroIndex = byteIndex;
                    continue;
                }

                runLength++;
            }

            return(fileList.ToArray());
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Reads data from the specified address.
        /// </summary>
        /// <param name="address">The address.</param>
        /// <param name="count">The count. Recommended 32 as maximum.</param>
        /// <returns>The byte array that was read.</returns>
        public byte[] Read(byte address, int count)
        {
            var data = new byte[7];

            data[0] = 0x04;                  // Set Address
            data[1] = address;               // Address Literal
            data[2] = 0x02;                  // Start Condition
            data[3] = 0x06;                  // Write Command
            data[4] = Convert.ToByte(count); // data length;
            data[5] = 0x03;                  // Stop condition
            data[6] = 0x00;                  // End command;

            var output   = new byte[count];
            var outCount = BoardException.ValidateResult(
                I2c.BbI2CZip(Handle, data, Convert.ToUInt32(data.Length), output, Convert.ToUInt32(output.Length)));

            if (output.Length == outCount)
            {
                return(output);
            }

            var result = new byte[outCount];

            Buffer.BlockCopy(output, 0, result, 0, outCount);
            return(result);
        }
Ejemplo n.º 5
0
        private bool _isDisposed; // To detect redundant calls

        /// <summary>
        /// Initializes a new instance of the <see cref="SoftI2cBus"/> class.
        /// </summary>
        /// <param name="dataPin">The data pin.</param>
        /// <param name="clockPin">The clock pin.</param>
        /// <param name="baudRate">The baud rate.</param>
        internal SoftI2cBus(GpioPin dataPin, GpioPin clockPin, int baudRate)
        {
            BoardException.ValidateResult(I2c.BbI2COpen((UserGpio)dataPin.PinNumber, (UserGpio)clockPin.PinNumber, Convert.ToUInt32(baudRate)));
            Handle   = (UserGpio)dataPin.PinNumber;
            DataPin  = dataPin;
            ClockPin = clockPin;
            BaudRate = baudRate;
        }
Ejemplo n.º 6
0
 /// <summary>
 /// Starts the hardware clock on this pin.
 /// All pins sharing the clock channel and running in clock mode will get theis new frequency.
 /// The frequency must be 0 (off) or 4689-250,000,000 (250M) Hz.
 /// </summary>
 /// <param name="frequency">The frequency. 0 (off) or 4689-250000000 (250M).</param>
 public void Start(int frequency)
 {
     if (ClockChannel < 0)
     {
         return;
     }
     BoardException.ValidateResult(Pwm.GpioHardwareClock(Pin.PinGpio, Convert.ToUInt32(frequency)));
 }
Ejemplo n.º 7
0
 /// <summary>
 /// Stops the hardware clock on this pin.
 /// </summary>
 public void Stop()
 {
     if (ClockChannel < 0)
     {
         return;
     }
     BoardException.ValidateResult(Pwm.GpioHardwareClock(Pin.PinGpio, 0));
 }
Ejemplo n.º 8
0
        /// <summary>
        /// Reads from a file handle up to count bytes.
        /// </summary>
        /// <param name="handle">The handle.</param>
        /// <param name="count">The count.</param>
        /// <returns>The array of bytes read.</returns>
        public static byte[] FileRead(UIntPtr handle, int count)
        {
            var buffer       = new byte[count];
            var result       = BoardException.ValidateResult(FileRead(handle, buffer, (uint)count));
            var outputBuffer = new byte[result];

            Buffer.BlockCopy(buffer, 0, outputBuffer, 0, result);
            return(outputBuffer);
        }
        /// <summary>
        /// Stops the hardware ISR callbacks.
        /// </summary>
        public void Stop()
        {
            ValidateAvailable();

            lock (SyncLock)
            {
                BoardException.ValidateResult(
                    IO.GpioSetIsrFunc(Pin.PinGpio, 0, 0, null));
                Callback = null;
            }
        }
Ejemplo n.º 10
0
        /// <summary>
        /// Applies a glitch filter to alert triggering.
        /// Prevents reporting signals that are not steady for at least the given number of microseconds.
        /// </summary>
        /// <param name="steadyMicroseconds">The steady microseconds.</param>
        public void ApplyGlitchFilter(int steadyMicroseconds)
        {
            ValidateAvailable();

            lock (SyncLock)
            {
                BoardException.ValidateResult(
                    IO.GpioGlitchFilter((UserGpio)Pin.PinNumber, Convert.ToUInt32(steadyMicroseconds)));

                m_GlitchFilterSteadyMicros = steadyMicroseconds;
            }
        }
Ejemplo n.º 11
0
        /// <summary>
        /// Applies a noise filter to alert triggering.
        /// Level changes on the GPIO are ignored until a level which has
        /// been stable for <paramref name="steadyMicroseconds"/> microseconds is detected.  Level changes
        /// on the GPIO are then reported for <paramref name="activeMicroseconds"/> microseconds after
        /// which the process repeats.
        /// </summary>
        /// <param name="steadyMicroseconds">The steady microseconds.</param>
        /// <param name="activeMicroseconds">The active microseconds.</param>
        public void ApplyNoiseFilter(int steadyMicroseconds, int activeMicroseconds)
        {
            ValidateAvailable();

            lock (SyncLock)
            {
                BoardException.ValidateResult(
                    IO.GpioNoiseFilter((UserGpio)Pin.PinNumber, Convert.ToUInt32(steadyMicroseconds), Convert.ToUInt32(activeMicroseconds)));

                m_NoiseFilterSteadyMicros = steadyMicroseconds;
                m_NoiseFilterActiveMicros = activeMicroseconds;
            }
        }
Ejemplo n.º 12
0
        /// <summary>
        /// Clears the alert callback and stops reporting changes.
        /// </summary>
        /// <exception cref="NotSupportedException">IsUserGpio is false.</exception>
        public void Stop()
        {
            ValidateAvailable();

            lock (SyncLock)
            {
                // TODO: For some reason passing NULL to cancel the alert makes everything hang!
                // This looks like a bug in the pigpio library.
                BoardException.ValidateResult(
                    IO.GpioSetAlertFunc((UserGpio)Pin.PinNumber, (g, l, t) => { }));
                Callback = null;
            }
        }
Ejemplo n.º 13
0
        /// <summary>
        /// Wrapper for the native <see cref="GpioSerialReadUnmanaged"/>.
        /// </summary>
        /// <param name="userGpio">The user gpio.</param>
        /// <param name="readLength">Length of the read.</param>
        /// <returns>The array containing the bytes that were read.</returns>
        public static byte[] GpioSerialRead(UserGpio userGpio, int readLength)
        {
            var buffer = new byte[readLength];
            var result = BoardException.ValidateResult(GpioSerialReadUnmanaged(userGpio, buffer, (uint)readLength));

            if (result == buffer.Length)
            {
                return(buffer);
            }

            var outputBuffer = new byte[result];

            Buffer.BlockCopy(buffer, 0, outputBuffer, 0, result);
            return(outputBuffer);
        }
Ejemplo n.º 14
0
        /// <summary>
        /// This function transfers count bytes of data from txBuf to the SPI
        /// device associated with the handle. Simultaneously count bytes of
        /// data are read from the device and placed in rxBuf.
        ///
        /// PI_BAD_HANDLE, PI_BAD_SPI_COUNT, or PI_SPI_XFER_FAILED.
        /// </summary>
        /// <param name="handle">&gt;=0, as returned by a call to <see cref="SpiOpen"/></param>
        /// <param name="transmitBuffer">the data bytes to write</param>
        /// <returns>Returns the number of bytes transferred if OK, otherwise PI_BAD_HANDLE, PI_BAD_SPI_COUNT, or PI_SPI_XFER_FAILED.</returns>
        public static byte[] SpiXfer(UIntPtr handle, byte[] transmitBuffer)
        {
            var receiveBuffer = new byte[transmitBuffer.Length];
            var result        = BoardException.ValidateResult(SpiXferUnmanaged(handle, transmitBuffer, receiveBuffer, Convert.ToUInt32(receiveBuffer.Length)));

            if (result == receiveBuffer.Length)
            {
                return(receiveBuffer);
            }

            var output = new byte[result];

            Buffer.BlockCopy(receiveBuffer, 0, output, 0, result);
            return(output);
        }
Ejemplo n.º 15
0
        /// <summary>
        /// This function reads count bytes of data from the SPI
        /// device associated with the handle.
        ///
        /// PI_BAD_HANDLE, PI_BAD_SPI_COUNT, or PI_SPI_XFER_FAILED.
        /// </summary>
        /// <param name="handle">&gt;=0, as returned by a call to <see cref="SpiOpen"/></param>
        /// <param name="count">The max number of bytes to read</param>
        /// <returns>Returns the number of bytes transferred if OK, otherwise PI_BAD_HANDLE, PI_BAD_SPI_COUNT, or PI_SPI_XFER_FAILED.</returns>
        public static byte[] SpiRead(UIntPtr handle, int count)
        {
            var buffer = new byte[count];
            var result = BoardException.ValidateResult(SpiReadUnmanaged(handle, buffer, Convert.ToUInt32(count)));

            if (result == buffer.Length)
            {
                return(buffer);
            }

            var output = new byte[result];

            Buffer.BlockCopy(buffer, 0, output, 0, result);
            return(output);
        }
Ejemplo n.º 16
0
        /// <summary>
        /// This reads a block of up to 32 bytes from the specified register of
        /// the device associated with handle.
        ///
        /// The amount of returned data is set by the device.
        ///
        /// Block read. SMBus 2.0 5.5.7.
        /// </summary>
        /// <remarks>
        /// S Addr Wr [A] i2cReg [A]
        ///    S Addr Rd [A] [Count] A [buf0] A [buf1] A ... A [bufn] NA P.
        /// </remarks>
        /// <param name="handle">&gt;=0, as returned by a call to <see cref="I2cOpen"/>.</param>
        /// <param name="register">0-255, the register to read.</param>
        /// <returns>Returns the number of bytes read (&gt;=0) if OK, otherwise PI_BAD_HANDLE, PI_BAD_PARAM, or PI_I2C_READ_FAILED.</returns>
        public static byte[] I2cReadBlockData(UIntPtr handle, byte register)
        {
            var buffer = new byte[32];
            var count  = BoardException.ValidateResult(I2cReadBlockDataUnmanaged(handle, register, buffer));

            if (count == buffer.Length)
            {
                return(buffer);
            }

            var output = new byte[count];

            Buffer.BlockCopy(buffer, 0, output, 0, output.Length);
            return(output);
        }
Ejemplo n.º 17
0
        /// <summary>
        /// Begins rendering the waveform pulses.
        /// Do not forget to set the pin direction/mode as an output pin.
        /// The wave is automatically prepared if it has not been prepared before.
        /// </summary>
        /// <param name="mode">The mode.</param>
        public void Send(WaveMode mode)
        {
            if (IsDisposed)
            {
                throw new ObjectDisposedException(DisposedErrorMessage);
            }
            if (IsPrepared == false)
            {
                Prepare();
            }

            if (IsPrepared)
            {
                BoardException.ValidateResult(Waves.GpioWaveTxSend(Convert.ToUInt32(WaveId), mode));
            }
        }
Ejemplo n.º 18
0
        /// <summary>
        /// Initializes a new instance of the <see cref="SoftSerialPort"/> class.
        /// </summary>
        /// <param name="receivePin">The receive pin.</param>
        /// <param name="transmitPin">The transmit pin.</param>
        /// <param name="baudRate">The baud rate.</param>
        /// <param name="dataBits">The data bits.</param>
        /// <param name="invert">if set to <c>true</c> [invert].</param>
        internal SoftSerialPort(GpioPin receivePin, GpioPin transmitPin, UartRate baudRate, int dataBits, bool invert)
        {
            BoardException.ValidateResult(
                Serial.GpioSerialReadOpen((UserGpio)receivePin.PinNumber, Convert.ToUInt32(baudRate), Convert.ToUInt32(dataBits)));

            Handle   = (UserGpio)receivePin.PinNumber;
            DataBits = dataBits;
            BaudRate = (int)baudRate;

            if (invert)
            {
                Serial.GpioSerialReadInvert(Handle, true);
                Invert = true;
            }

            _transmitPin = transmitPin;
        }
Ejemplo n.º 19
0
        /// <summary>
        /// Initializes a new instance of the <see cref="SoftSpiChannel"/> class.
        /// </summary>
        /// <param name="csPin">The cs pin.</param>
        /// <param name="misoPin">The miso pin.</param>
        /// <param name="mosiPin">The mosi pin.</param>
        /// <param name="clockPin">The clock pin.</param>
        /// <param name="baudRate">The baud rate.</param>
        /// <param name="flags">The flags.</param>
        internal SoftSpiChannel(GpioPin csPin, GpioPin misoPin, GpioPin mosiPin, GpioPin clockPin, int baudRate, SoftSpiFlags flags)
        {
            BoardException.ValidateResult(Spi.BbSPIOpen(
                                              (UserGpio)csPin.PinNumber,
                                              (UserGpio)misoPin.PinNumber,
                                              (UserGpio)mosiPin.PinNumber,
                                              (UserGpio)clockPin.PinNumber,
                                              Convert.ToUInt32(baudRate),
                                              flags));

            Handle        = (UserGpio)csPin.PinNumber;
            ChipSelectPin = csPin;
            MosiPin       = mosiPin;
            MisoPin       = misoPin;
            ClockPin      = clockPin;
            BaudRate      = baudRate;
            Flags         = flags;
        }
Ejemplo n.º 20
0
        /// <summary>
        /// Prepares the waveform to be rendered by DMA.
        /// </summary>
        /// <exception cref="ObjectDisposedException">When the wave has been disposed.</exception>
        public void Prepare()
        {
            lock (SyncLock)
            {
                if (IsPrepared)
                {
                    return;
                }
                if (_isDisposed)
                {
                    throw new ObjectDisposedException(DisposedErrorMessage);
                }

                BoardException.ValidateResult(
                    Waves.GpioWaveAddGeneric(Convert.ToUInt32(m_Pulses.Count), m_Pulses.ToArray()));
                WaveId = BoardException.ValidateResult(
                    Waves.GpioWaveCreate());
            }
        }
Ejemplo n.º 21
0
        /// <summary>
        /// Transfers the specified transmit buffer and returns the read bytes in a new buffer.
        /// </summary>
        /// <param name="transmitBuffer">The transmit buffer.</param>
        /// <returns>The received bytes as a result of writing to the ring buffer.</returns>
        public byte[] Transfer(byte[] transmitBuffer)
        {
            if (_isDisposed)
            {
                throw new ObjectDisposedException(nameof(SoftSpiChannel));
            }

            var receiveBuffer = new byte[transmitBuffer.Length];
            var result        = BoardException.ValidateResult(Spi.BbSPIXfer(Handle, transmitBuffer, receiveBuffer, Convert.ToUInt32(receiveBuffer.Length)));

            if (result == receiveBuffer.Length)
            {
                return(receiveBuffer);
            }

            var output = new byte[result];

            Buffer.BlockCopy(receiveBuffer, 0, output, 0, result);
            return(output);
        }
        /// <summary>
        /// Starts the hardware ISR callbacks.
        /// </summary>
        /// <param name="callback">The callback.</param>
        /// <param name="edgeDetection">The edge detection.</param>
        /// <param name="timeoutMilliseconds">The timeout milliseconds.</param>
        /// <exception cref="ArgumentNullException">callback - Use Stop first.</exception>
        /// <exception cref="ArgumentException">A callback is already registered. Clear the current callback before registering a new one. - callback</exception>
        public void Start(PiGpioIsrDelegate callback, EdgeDetection edgeDetection, int timeoutMilliseconds)
        {
            ValidateAvailable();

            if (callback == null)
                throw new ArgumentNullException(nameof(callback), $"The callback cannot be null. Use the '{nameof(Stop)}' method instead.");

            lock (SyncLock)
            {
                if (Callback != null)
                    throw new ArgumentException("A callback is already registered. Clear the current callback before registering a new one.", nameof(callback));

                BoardException.ValidateResult(
                    IO.GpioSetIsrFunc(Pin.PinGpio, edgeDetection, timeoutMilliseconds, callback));

                m_EdgeDetection = edgeDetection;
                m_TimeoutMilliseconds = timeoutMilliseconds;
                Callback = callback;
            }
        }
Ejemplo n.º 23
0
        /// <summary>
        /// Writes data to the specified address.
        /// </summary>
        /// <param name="address">The address.</param>
        /// <param name="buffer">The buffer. Recommended 32 bytes max.</param>
        public void Write(byte address, byte[] buffer)
        {
            var data = new byte[7 + buffer.Length];

            data[0] = 0x04;                        // Set Address
            data[1] = address;                     // Address Literal
            data[2] = 0x02;                        // Start Condition
            data[3] = 0x07;                        // Write Command
            data[4] = Convert.ToByte(data.Length); // data length;
            data[data.Length - 2] = 0x03;          // Stop condition
            data[data.Length - 1] = 0x00;          // End command;

            // copy buffer data to command
            Buffer.BlockCopy(buffer, 0, data, 5, data.Length);

            var output = new byte[32];

            BoardException.ValidateResult(
                I2c.BbI2CZip(Handle, data, Convert.ToUInt32(data.Length), output, Convert.ToUInt32(output.Length)));
        }
Ejemplo n.º 24
0
        /// <summary>
        /// Start the alert callbacks.
        /// </summary>
        /// <param name="callback">The callback.</param>
        /// <exception cref="NotSupportedException">IsUserGpio is false.</exception>
        /// <exception cref="ArgumentNullException">callback - ClearAlertCallback.</exception>
        /// <exception cref="ArgumentException">A callback is already registered. Clear the current callback before registering a new one. - callback.</exception>
        public void Start(PiGpioAlertDelegate callback)
        {
            ValidateAvailable();

            if (callback == null)
            {
                throw new ArgumentNullException(nameof(callback), $"The callback cannot be null. Use the '{nameof(Stop)}' method instead.");
            }

            lock (SyncLock)
            {
                if (Callback != null)
                {
                    throw new ArgumentException("A callback is already registered. Clear the current callback before registering a new one.", nameof(callback));
                }

                BoardException.ValidateResult(
                    IO.GpioSetAlertFunc((UserGpio)Pin.PinNumber, callback));
                Callback = callback;
            }
        }
Ejemplo n.º 25
0
        /// <summary>
        /// This function requests a free notification handle.
        ///
        /// It differs from <see cref="GpioNotifyOpen"/> in that the pipe size may be
        /// specified, whereas <see cref="GpioNotifyOpen"/> uses the default pipe size.
        ///
        /// See <see cref="GpioNotifyOpen"/> for further details.
        /// </summary>
        /// <param name="bufferSize">The pipe size of the the buffer.</param>
        /// <returns>The result code. 0 for success. See the <see cref="ResultCode"/> enumeration.</returns>
        public static UIntPtr GpioNotifyOpenWithSize(int bufferSize)
        {
            var result = BoardException.ValidateResult(GpioNotifyOpenWithSizeUnmanaged(bufferSize));

            return(new UIntPtr((uint)result));
        }
Ejemplo n.º 26
0
        /// <summary>
        /// This function requests a free notification handle.
        ///
        /// A notification is a method for being notified of GPIO state changes
        /// via a pipe or socket.
        ///
        /// Pipe notifications for handle x will be available at the pipe
        /// named /dev/pigpiox (where x is the handle number).  E.g. if the
        /// function returns 15 then the notifications must be read
        /// from /dev/pigpio15.
        ///
        /// Socket notifications are returned to the socket which requested the
        /// handle.
        ///
        /// </summary>
        /// <example>
        /// <code>
        /// h = gpioNotifyOpen();
        ///
        /// if (h &gt;= 0)
        /// {
        ///    sprintf(str, "/dev/pigpio%d", h);
        ///
        ///    fd = open(str, O_RDONLY);
        ///
        ///    if (fd &gt;= 0)
        ///    {
        ///       // Okay.
        ///    }
        ///    else
        ///    {
        ///       // Error.
        ///    }
        /// }
        /// else
        /// {
        ///    // Error.
        /// }
        /// </code>
        /// </example>
        /// <returns>Returns a handle greater than or equal to zero if OK, otherwise PI_NO_HANDLE.</returns>
        public static UIntPtr GpioNotifyOpen()
        {
            var result = BoardException.ValidateResult(GpioNotifyOpenUnmanaged());

            return(new UIntPtr((uint)result));
        }
Ejemplo n.º 27
0
        /// <summary>
        /// This function returns the pad drive strength in mA.
        ///
        /// Pad @ GPIO
        /// 0   @ 0-27
        /// 1   @ 28-45
        /// 2   @ 46-53.
        ///
        /// </summary>
        /// <example>
        /// <code>
        /// strength = gpioGetPad(1); // get pad 1 strength
        /// </code>
        /// </example>
        /// <param name="pad">0-2, the pad to get.</param>
        /// <returns>Returns the pad drive strength if OK, otherwise PI_BAD_PAD.</returns>
        public static GpioPadStrength GpioGetPad(GpioPadId pad)
        {
            var result = BoardException.ValidateResult(GpioGetPadUnmanaged(pad));

            return((GpioPadStrength)result);
        }
Ejemplo n.º 28
0
        /// <summary>
        /// Reads the value of the GPIO.
        /// </summary>
        /// <param name="gpio">The gpio.</param>
        /// <returns>The digital value.</returns>
        public static bool GpioRead(SystemGpio gpio)
        {
            var result = BoardException.ValidateResult(GpioReadUnmanaged(gpio));

            return((DigitalValue)result == DigitalValue.True);
        }
Ejemplo n.º 29
0
 /// <summary>
 /// Seeks within a file.
 /// </summary>
 /// <param name="handle">The handle.</param>
 /// <param name="seekOffset">The seek offset.</param>
 /// <param name="seekFrom">The seek from.</param>
 /// <returns>The new byte position within the file.</returns>
 public static int FileSeek(UIntPtr handle, int seekOffset, SeekMode seekFrom) => BoardException.ValidateResult(FileSeekUnmanaged(handle, seekOffset, seekFrom));
Ejemplo n.º 30
0
        /// <summary>
        /// A wrapper function for <see cref="FileOpenUnmanaged"/>.
        /// </summary>
        /// <param name="filePath">The file path.</param>
        /// <param name="mode">The mode.</param>
        /// <returns>A file handle.</returns>
        /// <exception cref="System.IO.IOException">When the file fails to open.</exception>
        public static UIntPtr FileOpen(string filePath, FileModeFlags mode)
        {
            var result = BoardException.ValidateResult(FileOpenUnmanaged(filePath, (uint)mode));

            return(new UIntPtr((uint)result));
        }