當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


Processing Serial.readStringUntil()用法及代碼示例

Processing, 類Serial中的readStringUntil()用法介紹。

用法

  • serial.readStringUntil(inByte)

參數

  • serial (Serial) Serial 類型的任何變量
  • inByte (int) 指定用於標記數據結束的字符

返回

  • String

說明

readBytesUntil()readString() 的組合。如果找不到您要查找的內容,則返回 null

例子

// Example by Tom Igoe

import processing.serial.*;

int lf = 10;    // Linefeed in ASCII
String myString = null;
Serial myPort;  // The serial port

void setup() {
  // 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);
  myPort.clear();
  // Throw out the first reading, in case we started reading 
  // in the middle of a string from the sender.
  myString = myPort.readStringUntil(lf);
  myString = null;
}

void draw() {
  while (myPort.available() > 0) {
    myString = myPort.readStringUntil(lf);
    if (myString != null) {
      println(myString);
    }
  }
}

相關用法


注:本文由純淨天空篩選整理自processing.org大神的英文原創作品 Serial.readStringUntil()。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。