...
Code Block |
---|
piTest -v RevPiLED |
At offset 119
Example with Python
Code Block | ||
---|---|---|
| ||
# ledswitch1.py f=open("/dev/piControl0","wb+",0) f.seek(119) f.write(b'1') f.seek(119) f.write(b'0') |
Read or write strings
The devices in PiCtory usually provide byte access to the data. You can test this example by using a Virtual Device 32 Bytes in PiCtory.
...
Info |
---|
We read out the offset of “Output_1” variable. This may vary on your configuration so be careful here. |
Code Block | ||
---|---|---|
| ||
pi@RevPi40302:~ $ piTest -v Output_1
variable name: Output_1
offset: 43
length: 8
bit: 0 |
Python example code
Code Block | ||
---|---|---|
| ||
def writeString(offset, myString):
f=open("/dev/piControl0","wb+",0)
f.seek(offset)
f.write(str.encode(myString))
def readString(offset, length):
f=open("/dev/piControl0","wb+",0)
f.seek(offset)
my_string_as_bytes = f.read(length)
return my_string_as_bytes.decode()
writeString(48,'Hello World')
readString(48,11)
' Hello World |
Verify it with piTest
Code Block |
---|
pi@RevPi40302:~ $ piTest -1 -r 48,11
72 101 108 108 111 32 87 111 114 108
100 |
RevPiModIO
Library developed from the RevPi community
Allows easy use of symbolic names from PiCtory
Installation not necessary already on the device
Documentation
...