Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Documentation for serial library in processing.py

Is there some documentation for Processing.py's Serial library?

I've been able to guess some of the syntax from the Java Serial library doc. Here's what I have so far:

add_library('serial')

def setup():
    #setup the serial port
    print Serial.list()
    portIndex = 4
    LF = 10
    print " Connecting to ", Serial.list()[portIndex]
    myPort = Serial(Serial.list()[portIndex], 9600)
    myPort.bufferUntil(LF)

def draw():
    pass

def serialEvent(evt):
    inString = evt.readString()
    print inString

I get the following error:

processing.app.SketchException: TypeError: processing.serial.Serial(): 1st arg can't be coerced to processing.core.PApplet

The Java syntax for creating a Serial instance has "this" as the first argument which I assume refers to a Sketch (PApplet) object. How do I reference that in processing.py?

like image 819
ericksonla Avatar asked Jun 04 '26 14:06

ericksonla


1 Answers

Re: your original question - AFAIK here is no documentation for the libraries that is specific to Python mode. We're expected to refer to the vanilla reference pages for the library and/or the code itself.

Re: the error resulting from your code - As you point out in the comments, adding this as the first argument to the Serial() instantiation should do the trick. The following works nicely on my machine:

add_library('serial')

def setup():
    #setup the serial port
    print Serial.list()
    portIndex = 0
    LF = 10
    print " Connecting to ", Serial.list()[portIndex]
    myPort = Serial(this, Serial.list()[portIndex], 9600)
    myPort.bufferUntil(LF)
like image 145
mbaytas Avatar answered Jun 06 '26 05:06

mbaytas



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!