私は最近、純粋な Java での「シリアル通信」用のパッケージであるJava Communication APIに出くわしました。javax
シリアル通信という言葉は以前からよく耳にしていましたが、「シリアル通信」が何を意味するのか、何を意味するのか、よくわかっていません。
ウィキペディアによると:
電気通信およびコンピュータ サイエンスでは、シリアル通信は、通信チャネルまたはコンピュータ バスを介して、一度に 1 ビットずつ順番にデータを送信するプロセスです。
OK...Java Communication API を使用すると、一度に 1 ビットずつデータを読み書きできます。しかし、それはどういう意味ですか?!? 自分でそれを行うことはできませんか (疑似コードはこちら)?:
String str = "I want to send this bit by bit.";
byte[] strAsBytes = str.getBytes();
byte[] bits = new byte[strAsBytes.length * 8]; // For each byte we need 8 bits.
for(int i = 0; i < strAsBytes.length; i++) {
for(int j = 0; j < 8; j++) {
// Something like this (again this is just pseudo-code).
// Regardless, populate all elements in the bits array with the
// bit in the position of the current byte.
bits[i*j + j] = getBit(strAsBytes[i], j);
}
}
// Sends the array of bits over a network, maybe using Netty and TCP,
// or something. Sends each bit one by one.
networkManager.sendBitByBit(bits);
// Retrieves the value of a bit at any position in a byte (theByte).
public byte getBit(byte theByte, int position) {
return (theByte) & (0x01 << pos) ;
}
「シリアル通信」という言葉には、「1 ビットずつ送信する」以上の意味があるように感じます。マシンのシリアルポートから読み書きするために使用できるということですか? 他に何か?!?
私は、「シリアル通信」というより広い用語とは何か、およびそれを使用してどのようなことができるかについて、平易な英語の素人の説明を探していると思います。そして、それを Java Communications API のコンテキストに入れます。また、API を使用して達成できることの例を 1 つまたは 2 つ用意していただければ幸いです。