Creates SPI connection on given device number.
shared Open(
deviceNumber
as UInt8,
bitExchangeSize
as UInt8,
speed
as UInt32,
mode
as SPI.Modes,
useLock
as Boolean)
as SPI.Connection
Parameters
- deviceNumber
- The device number to open.
- bitExchangeSize
- The bit exchange size.
- speed
- The speed to set.
- mode
- The connection mode.
- useLock
- Set to true if wanting to use locks, else false. (Locks probably will never make sense for Xojo users given the lack of true threads).
Returns
- SPI.Connection
- Newly created connection or exception is thrown.
Remarks
This function can throw SPIException.
In the example bellow we just connected wire between MOSI and MISO so that we get what we send echoed back to us to test.
try
var sp as SPI.Connection = SPI.Connection.Open(0, 8, 1000000, SPI.Modes.SPI_MODE_0, false)
var bytes(5) as UInt8
bytes(0) = 1
bytes(1) = 2
bytes(2) = 3
bytes(3) = 4
bytes(4) = 5
bytes(5) = 6
var result() as UInt8 = sp.WriteAndRead(bytes, false)
for i as Integer = 0 to result.LastIndex
MessageBox(result(i).ToString())
next
catch ex as SPIException
MessageBox(ex.Message)
end try
See Also
Connection Class