動作環境
Processing 3.1.1 on Windows 8.1 pro(64bit)
ControlP5 v2.2.6
状況
http://qiita.com/7of9/items/1edf5a109eea9b711058
を実装中にはまった点を整理。
以下のjavaプログラムで0x0Aが<LF>
として扱われなかったために、通信先が<LF>
を拾えなかった。
txt = tx + 0x0A;
myPort.write(txt);
確認
ideoneで確認した。
/* package whatever; // don't place package name! */
import java.util.*;
import java.lang.*;
import java.io.*;
/* Name of the class has to be "Main" only if the class is public. */
class Ideone
{
public static void main (String[] args) throws java.lang.Exception
{
String str1 = "AAA" + "\n";
System.out.print(str1);
String str2 = "BBB" + 0x0A;
System.out.print(str2);
System.out.println("END");
}
}
結果
Success time: 0.1 memory: 320512 signal:0
AAA
BBB10END
String方に対して+ 0x0A
は10という数値を文字列に変換した上でString文字列に足されるようだ。
文字列連結演算子 +が働いているのでふるまいとしては正しいのだろう。
<LF>
を足したい場合は+ "\n"
にしないといけない。
演算子"+"使用時にはまりそうな点
@shiracamus さんのコメントを参照ください。