3

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?

ericksonla
  • 1,247
  • 3
  • 18
  • 34
  • 1
    Based on [this example](https://github.com/jdf/processing.py/blob/16a134c52876086f8a44c1b181bfb0c5bd06efd7/mode/examples/Contributed%20Libraries%20in%20Python/OpenCV/BackgroundSubtraction/BackgroundSubtraction.pyde), it looks like Python still accepts `this` as a a function argument. If I add `this` as the first argument to the serial connection line I get a new error: `processing.app.SketchException: java.lang.UnsatisfiedLinkError: jssc.SerialNativeInterface.openPort(Ljava/lang/String;Z)J` – ericksonla Feb 27 '15 at 14:44
  • `this` keyword if provided in Python mode for compatibility with the Processing Java libraries, it is used on almost every library :) – villares Oct 13 '20 at 20:07

1 Answers1

3

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)
mbaytas
  • 2,676
  • 7
  • 26
  • 37