Skip to content

Instantly share code, notes, and snippets.

@croxis
Created July 2, 2015 17:07
Show Gist options
  • Save croxis/9eb51ee32bf6b46963f8 to your computer and use it in GitHub Desktop.
Save croxis/9eb51ee32bf6b46963f8 to your computer and use it in GitHub Desktop.
Pyserial + panda3d example
from __future__ import print_function
from direct.showbase.ShowBase import ShowBase
import serial
ser = serial.Serial(1, 38400, timeout=0, parity=serial.PARITY_EVEN, rtscts=1)
buffer = ""
MyProgram(ShowBase):
__init__(self):
ShowBase.__init__(self)
self.accept("move-x", self.move_x)
def poller(self, task):
buffer += ser.read(100)
#Code for reading buffer goes here
commands = {}
#Interprit buffer into commands. Any incomplete instructions remain in buffer
#Commands dict looks like {"move-x": 3}
for command, ammount in commands.values():
self.messenger.send(command, [ammount])
return task.cont
def move_x(self, ammount):
print("Move x by", ammount)
if __name__ == "__main__":
app = MyProgram()
app.run()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment