processing.py串行库的文档说明

3

Processing.py的串口库有文档吗?

我已经从Java Serial库文档中猜测了一些语法。这是我目前所拥有的:

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

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

1
根据这个例子,看起来Python仍然接受this作为函数参数。如果我将this添加为串行连接行的第一个参数,我会得到一个新的错误:processing.app.SketchException: java.lang.UnsatisfiedLinkError: jssc.SerialNativeInterface.openPort(Ljava/lang/String;Z)J - ericksonla
在Python模式中提供的this关键字是为了与Processing Java库兼容而使用的,它几乎在每个库中都被使用 :) - villares
1个回答

3

关于您最初的问题 - 据我所知,没有针对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)

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接