Thanks, Norman. This is what I came up with substituting the proper GPIO calls in. Not sure about the use the memory block though. At least it compiles but won’t be able to test until tomorrow (probably).
[code]Private Function readCelsius() As double
dim v as Uint16
GPIO.DigitalWrite(10, GPIO.LOW)
// wait 1 msec
GPIO.Delay(1)
dim m as new MemoryBlock(8)
dim iResult as integer = GPIO.SPIDataRW(0, m, 8)
if iResult = -1 then
//Result failed
return -1
end
v = m.Int8Value(0)
v = Bitwise.ShiftLeft(v, 8)
m = new MemoryBlock(8)
iResult = GPIO.SPIDataRW(0, m, 8)
if iResult = -1 then
//Result failed
return -1
end
dim v2 as integer
v2 = m.Int8Value(0)
v = BitWise.BitOr(v, v2)
GPIO.DigitalWrite(10, GPIO.HIGH)
if bitwise.BitAnd(v, &h4) > 0 then
// uh oh, no thermocouple attached!
return -1
end if
v = BitWise.ShiftRight(v, 3)
return v*0.25
End Function
[/code]
SPIDataRW is defined in the GPIO library as:
[code]Protected Function SPIDataRW(channel As Integer, data As CString, len As Integer) As Integer
// int wiringPiSPIDataRW (int channel, unsigned char *data, int len) ;
// This performs a simultaneous write/read transaction over the selected SPI bus.
// Data that was in your buffer is overwritten by data returned from the SPI bus.
//
// Thats all there is in the helper library. It is possible to do simple
// read and writes over the SPI bus using the standard read() and write() system
// calls though write() may be better to use for sending data to chains of
// shift registers, or those LED strings where you send RGB triplets of data.
// Devices such as A/D and D/A converters usually need to perform a concurrent
// write/read transaction to work.
// http://wiringpi.com/reference/spi-library/
#If TargetARM And TargetLinux Then
Soft Declare Function wpWiringPiSPIDataRW Lib “libwiringPi.so” Alias “wiringPiSPIDataRW” (channel As Integer, data As CString, len As Integer) As Integer
Return wpWiringPiSPIDataRW(channel, data, len)
#Endif
End Function
[/code]
Thanks for the help!