protected override void EstablishContext()
        {
            controlDevice = A.Fake <ISpiControlDevice>();
            controlDevice
            .CallsTo(device => device.Control(A <uint> .Ignored, A <SpiTransferControlStructure[]> .Ignored))
            .Returns(IOCTL_PINVOKE_RESULT_CODE);

            connection = new NativeSpiConnection(controlDevice);

            // SPI control structure we expect to see during the P/Invoke call
            controlStructure = new SpiTransferControlStructure {
                BitsPerWord      = BITS_PER_WORD,
                Length           = 5,
                Delay            = DELAY,
                ChipSelectChange = 1,
                Speed            = SPEED_IN_HZ
            };

            buffer = A.Fake <ISpiTransferBuffer>();
            buffer
            .CallsTo(b => b.ControlStructure)
            .Returns(controlStructure);

            // setup fake collection to return our "prepared" fake buffer
            collection = A.Fake <ISpiTransferBufferCollection>();
            collection
            .CallsTo(c => c.Length)
            .Returns(1);
            collection
            .CallsTo(c => c.GetEnumerator())
            .ReturnsLazily(call => new List <ISpiTransferBuffer> {
                buffer
            }.GetEnumerator());
        }
        protected override void EstablishContext()
        {
            controlDeviceMock = new Mock <ISpiControlDevice>();
            controlDevice     = controlDeviceMock.Object;
            controlDeviceMock.Setup(x => x.Control(It.IsAny <uint>(), ref It.Ref <SpiTransferControlStructure> .IsAny)).Returns(IOCTL_PINVOKE_RESULT_CODE);

            connection = new NativeSpiConnection(controlDevice);

            // SPI control structure we expect to see during the P/Invoke call
            controlStructure = new SpiTransferControlStructure
            {
                BitsPerWord      = BITS_PER_WORD,
                Length           = 5,
                Delay            = DELAY,
                ChipSelectChange = 1,
                Speed            = SPEED_IN_HZ
            };

            bufferMock = new Mock <ISpiTransferBuffer>();
            buffer     = bufferMock.Object;
            bufferMock.Setup(x => x.ControlStructure).Returns(controlStructure);

            // setup fake collection to return our "prepared" fake buffer
            collectionMock = new Mock <ISpiTransferBufferCollection>();
            collection     = collectionMock.Object;
            collectionMock.Setup(x => x.Length).Returns(1);
            collectionMock.Setup(x => x.GetEnumerator()).Returns(new List <ISpiTransferBuffer> {
                buffer
            }.GetEnumerator());
        }
        protected override void EstablishContext()
        {
            // SPI control structure we expect to see during the P/Invoke call
            controlStructure = new SpiTransferControlStructure
            {
                BitsPerWord      = BITS_PER_WORD,
                Length           = 5,
                Delay            = DELAY,
                ChipSelectChange = 1,
                Speed            = SPEED_IN_HZ
            };

            controlDeviceMock = new Mock <ISpiControlDevice>();
            controlDevice     = controlDeviceMock.Object;
            controlDeviceMock.Setup(x => x.Control(It.IsAny <uint>(), ref It.Ref <SpiTransferControlStructure> .IsAny)).Returns(IOCTL_PINVOKE_RESULT_CODE);

            connection = new NativeSpiConnection(controlDevice);

            bufferMock = new Mock <ISpiTransferBuffer>();
            buffer     = bufferMock.Object;
            bufferMock.Setup(x => buffer.ControlStructure).Returns(controlStructure);
        }
        protected override void EstablishContext()
        {
            // SPI control structure we expect to see during the P/Invoke call
            controlStructure = new SpiTransferControlStructure
            {
                BitsPerWord      = BITS_PER_WORD,
                Length           = 5,
                Delay            = DELAY,
                ChipSelectChange = 1,
                Speed            = SPEED_IN_HZ
            };

            controlDevice = A.Fake <ISpiControlDevice>();
            A.CallTo(() => controlDevice.Control(A <uint> .Ignored, ref controlStructure))
            .WithAnyArguments()
            .Returns(IOCTL_PINVOKE_RESULT_CODE);

            connection = new NativeSpiConnection(controlDevice);

            buffer = A.Fake <ISpiTransferBuffer>();
            A.CallTo(() => buffer.ControlStructure)
            .Returns(controlStructure);
        }
Esempio n. 5
0
        /// <summary>
        /// The function manipulates the underlying device parameters of special files. In particular, many operating characteristics of character special files (e.g. terminals) may be controlled with ioctl requests.
        /// </summary>
        /// <param name="request">A device-dependent request code.</param>
        /// <param name="data">The data to be transmitted.</param>
        /// <returns>Usually, on success zero is returned. A few ioctls use the return value as an output parameter and return a nonnegative value on success. On error, -1 is returned, and errno is set appropriately.</returns>
        public int Control(UInt32 request, ref SpiTransferControlStructure data)
        {
            var result = ioctl(file.Descriptor, request, ref data);

            return(result);
        }
Esempio n. 6
0
 private static extern int ioctl(int descriptor, UInt32 request, ref SpiTransferControlStructure data);