/// <summary> /// Initializes a new instance of the <see cref="SpiTransferBuffer"/> class. /// </summary> /// <param name="lengthInBytes">Size of data that shall be transmitted.</param> /// <param name="transferMode">Specifies read and/or write mode.</param> public SpiTransferBuffer(int lengthInBytes, SpiTransferMode transferMode) { if (transferMode == 0) { throw new ArgumentException("An appropriate transfer mode must be specified (read/write)", "transferMode"); } mode = transferMode; if ((TransferMode & SpiTransferMode.Write) == SpiTransferMode.Write) { txBuf = new ManagedMemory(lengthInBytes); } if ((TransferMode & SpiTransferMode.Read) == SpiTransferMode.Read) { rxBuf = new ManagedMemory(lengthInBytes); } var txPtr = ReferenceEquals(Tx, null) ? 0 : unchecked ((UInt64)Tx.Pointer.ToInt64()); var rxPtr = ReferenceEquals(Rx, null) ? 0 : unchecked ((UInt64)Rx.Pointer.ToInt64()); control.Length = unchecked ((uint)lengthInBytes); control.Tx = txPtr; control.Rx = rxPtr; }
/// <summary> /// Initializes a new instance of the <see cref="SpiTransferBuffer" /> class. /// </summary> /// <param name="lengthInBytes">Size of data that shall be transmitted.</param> /// <param name="transferMode">Specifies read and/or write mode.</param> public SpiTransferBuffer(int lengthInBytes, SpiTransferMode transferMode) { if (transferMode == 0) { throw new ArgumentException("An appropriate transfer mode must be specified (read/write)", nameof(transferMode)); } this.mode = transferMode; if ((this.TransferMode & SpiTransferMode.Write) == SpiTransferMode.Write) { this.txBuf = new ManagedMemory(lengthInBytes); } if ((this.TransferMode & SpiTransferMode.Read) == SpiTransferMode.Read) { this.rxBuf = new ManagedMemory(lengthInBytes); } var txPtr = this.Tx is null ? 0 : unchecked ((ulong)this.Tx.Pointer.ToInt64()); var rxPtr = this.Rx is null ? 0 : unchecked ((ulong)this.Rx.Pointer.ToInt64()); this.control.Length = unchecked ((uint)lengthInBytes); this.control.Tx = txPtr; this.control.Rx = rxPtr; }
/// <summary> /// Creates a transfer buffer of the given <see paramref="sizeInBytes"/> and copies the connection settings to it. /// </summary> /// <param name="sizeInBytes">Memory size in bytes.</param> /// <param name="transferMode">The transfer mode.</param> /// <returns>The requested transfer buffer.</returns> public ISpiTransferBuffer CreateTransferBuffer(int sizeInBytes, SpiTransferMode transferMode) { return(new SpiTransferBuffer(sizeInBytes, transferMode) { BitsPerWord = bitsPerWord, Delay = delay, Speed = maxSpeed }); }
/// <summary> /// Initializes a new instance of the <see cref="SpiTransferBufferCollection"/> class. /// </summary> /// <param name="numberOfMessages">Number of tranfer messages</param> /// <param name="messageLengthInBytes">Message size in bytes</param> /// <param name="transferMode">Transfer mode</param> public SpiTransferBufferCollection(int numberOfMessages, int messageLengthInBytes, SpiTransferMode transferMode) { if (numberOfMessages <= 0) { throw new ArgumentOutOfRangeException("numberOfMessages", numberOfMessages, string.Format(CultureInfo.InvariantCulture, "{0} is not a valid number of messages", numberOfMessages)); } transferBuffers = new ISpiTransferBuffer[numberOfMessages]; for (var i = 0; i < numberOfMessages; i++) { transferBuffers[i] = new SpiTransferBuffer(messageLengthInBytes, transferMode); } }
/// <summary> /// Creates transfer buffers for <paramref name="numberOfMessages"/>. /// </summary> /// <param name="numberOfMessages">The number of messages to send.</param> /// <param name="messageSizeInBytes">Message size in bytes.</param> /// <param name="transferMode">The transfer mode.</param> /// <returns>The requested transfer buffer collection.</returns> public ISpiTransferBufferCollection CreateTransferBufferCollection(int numberOfMessages, int messageSizeInBytes, SpiTransferMode transferMode) { var collection = new SpiTransferBufferCollection(numberOfMessages, messageSizeInBytes, transferMode); foreach (var transferBuffer in collection) { transferBuffer.BitsPerWord = bitsPerWord; transferBuffer.Delay = delay; transferBuffer.Speed = maxSpeed; } return(collection); }
/// <summary> /// Creates transfer buffers for <paramref name="numberOfMessages"/>. /// </summary> /// <param name="numberOfMessages">The number of messages to send.</param> /// <param name="messageSizeInBytes">Message size in bytes.</param> /// <param name="transferMode">The transfer mode.</param> /// <returns>The requested transfer buffer collection.</returns> public ISpiTransferBufferCollection CreateTransferBufferCollection(int numberOfMessages, int messageSizeInBytes, SpiTransferMode transferMode) { var collection = new SpiTransferBufferCollection(numberOfMessages, messageSizeInBytes, transferMode); foreach (var transferBuffer in collection) { transferBuffer.BitsPerWord = bitsPerWord; transferBuffer.Delay = delay; transferBuffer.Speed = maxSpeed; } return collection; }
/// <summary> /// Creates a transfer buffer of the given <see paramref="sizeInBytes"/> and copies the connection settings to it. /// </summary> /// <param name="sizeInBytes">Memory size in bytes.</param> /// <param name="transferMode">The transfer mode.</param> /// <returns>The requested transfer buffer.</returns> public ISpiTransferBuffer CreateTransferBuffer(int sizeInBytes, SpiTransferMode transferMode) { return new SpiTransferBuffer(sizeInBytes, transferMode) { BitsPerWord = bitsPerWord, Delay = delay, Speed = maxSpeed }; }
/// <summary> /// Initializes a new instance of the <see cref="SpiTransferBuffer"/> class. /// </summary> /// <param name="lengthInBytes">Size of data that shall be transmitted.</param> /// <param name="transferMode">Specifies read and/or write mode.</param> public SpiTransferBuffer(int lengthInBytes, SpiTransferMode transferMode) { if (transferMode == 0) { throw new ArgumentException("An appropriate transfer mode must be specified (read/write)", "transferMode"); } mode = transferMode; if ((TransferMode & SpiTransferMode.Write) == SpiTransferMode.Write) { txBuf = new ManagedMemory(lengthInBytes); } if ((TransferMode & SpiTransferMode.Read) == SpiTransferMode.Read) { rxBuf = new ManagedMemory(lengthInBytes); } var txPtr = ReferenceEquals(Tx, null) ? 0 : unchecked((UInt64) Tx.Pointer.ToInt64()); var rxPtr = ReferenceEquals(Rx, null) ? 0 : unchecked((UInt64) Rx.Pointer.ToInt64()); control.Length = unchecked((uint)lengthInBytes); control.Tx = txPtr; control.Rx = rxPtr; }