Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

A quick and easy introduction to how to use the RevPi with the Python programming language.

...

...

Info

We read out the offset of “Output_1” variable. This may vary on your configuration, so be careful here.

Code Block
languagebash
pi@RevPi40302:~ $ piTest -v Output_1
variable name: Output_1
       offset: 43
       length: 8
          bit: 0

...

Code Block
languagepy
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(4843,'Hello World')
readString(4843,11)
' Hello World

Verify

...

the contents of the process image with piTest

Code Block
languagebash
pi@RevPi40302:~ $ piTest -1 -r 4843,11
 72 101 108 108 111  32  87 111 114 108
100
pi@RevPi40302:~ $ piTest -1 -r 43,11,h
48 65 6c 6c 6f 20 57 6f 72 6c 64

RevPiModIO

  • Library developed from the RevPi community

  • Allows easy use of symbolic names from PiCtory

  • Installation not necessary, already on the device

  • Documentation

...

Code Block
languagepy
import revpimodio2
rpi = revpimodio2.RevPiModIO(autorefresh=True)
rpi.io.RevPiLED.value = 1
rpi.io.RevPiLED.value = 0
rpi.cleanup()

 Python I/O Bit Mirror

Code Block
languagepy
import revpimodio2
import time
rpi = revpimodio2.RevPiModIO(autorefresh=True)
while True:
    rpi.io.O_1.value = rpi.io.I_1.value
    time.sleep(0.02)
revpi.cleanup()

Video Tutorials

Also have , take a look at our video tutorials about Python

Also have Besides, take a look at the following video tutorials

...

Filter by label (Content by label)
kb-how-to-article
showLabelsfalse
max5
spacescom.atlassian.confluence.content.render.xhtml.model.resource.identifiers.SpaceResourceIdentifier@968
showSpacefalse
sortmodified
typeshowSpacepagefalse
reversetruelabels
typepage
cqllabel = "kb-how-to-article" and type = "page" and space = "KS"
labelskb-how-to-article
Page Properties
hiddentrue

Verwandte Vorgänge

Jira Legacy
serverId6a616e0c-dd66-30e3-95b5-0fa763638e21
keySUP-1136