Processing, 类Serial用法介绍。
构造函数
Serial(parent)Serial(parent, baudRate)Serial(parent, portName)Serial(parent, portName, baudRate)Serial(parent, portName, baudRate, parity, dataBits, stopBits)
参数
parent通常使用"this"baudRate9600 是默认值portName端口名称(默认为 COM1)parity'N' 表示无,'E' 表示偶数,'O' 表示奇数,'M' 表示标记,'S' 表示空格('N' 是默认值)dataBits8 是默认值stopBits1.0、1.5 或 2.0(1.0 是默认值)
说明
使用串行通信协议发送和接收数据的类。
例子
// Example by Tom Igoe
import processing.serial.*;
// The serial port:
Serial myPort;
// List all the available serial ports:
printArray(Serial.list());
// Open the port you are using at the rate you want:
myPort = new Serial(this, Serial.list()[0], 9600);
// Send a capital A out the serial port:
myPort.write(65);
方法
- Serial.available()返回可用的字节数
- Serial.buffer()在调用
serialEvent()之前设置要缓冲的字节数 - Serial.bufferUntil()在调用
serialEvent()之前将特定字节设置为缓冲区 - Serial.clear()清空缓冲区,删除存储在那里的所有数据
- Serial.last()返回接收到的最后一个字节,如果没有可用则返回 -1
- Serial.lastChar()返回作为 char 接收的最后一个字节,如果没有可用,则返回 -1
- Serial.list()获取所有可用串行端口的列表
- Serial.read()返回缓冲区中等待的下一个字节的 0 到 255 之间的数字
- Serial.readBytes()从缓冲区或
null读取一组字节,如果没有可用的 - Serial.readBytesUntil()从端口读取到字节缓冲区,最多包含特定字符
- Serial.readChar()以 char 形式返回缓冲区中的下一个字节
- Serial.readString()如果没有可用的数据,则将缓冲区中的所有数据作为
String或null返回 - Serial.readStringUntil()
readBytesUntil()和readString()的组合 - Serial.serialEvent()数据可用时调用
- Serial.stop()停止此端口上的数据通信
- Serial.write()将
bytes、chars、ints、bytes[]、Strings写入串口
相关用法
- Processing Serial.readChar()用法及代码示例
- Processing Serial.read()用法及代码示例
- Processing Serial.available()用法及代码示例
- Processing Serial.lastChar()用法及代码示例
- Processing Serial.readStringUntil()用法及代码示例
- Processing Serial.readBytes()用法及代码示例
- Processing Serial.list()用法及代码示例
- Processing Serial.clear()用法及代码示例
- Processing Serial.buffer()用法及代码示例
- Processing Serial.readBytesUntil()用法及代码示例
- Processing Serial.bufferUntil()用法及代码示例
- Processing Serial.readString()用法及代码示例
- Processing Serial.stop()用法及代码示例
- Processing Serial.last()用法及代码示例
- Processing Serial.write()用法及代码示例
- Processing Serial.serialEvent()用法及代码示例
- Processing Server.disconnect()用法及代码示例
- Processing Server.write()用法及代码示例
- Processing Server.active()用法及代码示例
- Processing Server.stop()用法及代码示例
- Processing Server.available()用法及代码示例
- Processing Server用法及代码示例
- Processing SawOsc.pan()用法及代码示例
- Processing String用法及代码示例
- Processing StringList用法及代码示例
注:本文由纯净天空筛选整理自processing.org大神的英文原创作品 Serial。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。
