3

Processing.py 的串行库有一些文档吗?

我已经能够从 Java 串行库文档中猜出一些语法。这是我到目前为止所拥有的:

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

我收到以下错误:

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

创建 Serial 实例的 Java 语法将“this”作为第一个参数,我假设它指的是 Sketch (PApplet) 对象。我如何在 processing.py 中引用它?

4

1 回答 1

3

回复:您最初的问题 - AFAIK 这里没有特定于 Python 模式的库的文档。我们应该参考和/或代码本身的原始参考页面。

回复:您的代码导致的错误 -正如您在评论中指出的那样,添加作为实例化this的第一个参数应该可以解决问题。Serial()以下在我的机器上运行良好:

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)
于 2016-09-26T11:07:07.180 回答