ターミナルエミュレータライブラリを使用してターミナルを作成し、それを使用して、シリアルで入力されたデータをシリアルデバイスに送信します。ライブラリはここで見ることができます。
端末にデータを入力すると、奇妙な一連の文字が送受信されます。Unicode置換文字はシリアル経由で送信されると思いますが、シリアルデバイスはそれが何であるかを認識せず、〜0を返します。
「test」と書いたときにターミナルに表示されるスクリーンショット:
そして、送信された文字列と受信されたデータを示すログ。
EmulatorViewを作成します。これはターミナルビューです。ここでダイヤモンドについて言及しています。
private void sendText(CharSequence text) {
int n = text.length();
char c;
try {
for(int i = 0; i < n; i++) {
c = text.charAt(i);
if (Character.isHighSurrogate(c)) {
int codePoint;
if (++i < n) {
codePoint = Character.toCodePoint(c, text.charAt(i));
} else {
// Unicode Replacement Glyph, aka white question mark in black diamond.
codePoint = '\ufffd';
}
mapAndSend(codePoint);
} else {
mapAndSend(c);
}
}
} catch (IOException e) {
Log.e(TAG, "error writing ", e);
}
}
これを修正する方法はありますか?なぜこれが起こっているのかをライブラリクラスで誰かが見ることができますか?、Javaで�を参照して、必要に応じて解析することもできますか?(!str.contains( "�")私がそれを取るかどうかは言えません。
ターミナルに入力すると、これが実行されます。
public void write(byte[] bytes, int offset, int count) {
String str;
try {
str = new String(bytes, "UTF-8");
Log.d(TAG, "data received in write: " +str );
GraphicsTerminalActivity.sendOverSerial(str.getBytes("UTF-8"));
} catch (UnsupportedEncodingException e) {
Log.d(TAG, "exception" );
e.printStackTrace();
}
// appendToEmulator(bytes, 0, bytes.length);
return;
}
これは私がデータを送信するために呼び出すものです。sendData(Byte [] data)はライブラリメソッドです。
public static void sendOverSerial(byte[] data) {
String str;
try {
str = new String(data,"UTF-8");
if(mSelectedAdapter !=null && data !=null){
Log.d(TAG, "send over serial string==== " + str);
mSelectedAdapter.sendData(str.getBytes("UTF-8"));
}
} catch (UnsupportedEncodingException e) {
Log.d(TAG, "exception");
e.printStackTrace();
}
}
データが送信されると、ここで応答が受信されます。
public void onDataReceived(int id, byte[] data) {
try {
dataReceived = new String(data, "UTF-8");
} catch (UnsupportedEncodingException e) {
Log.d(TAG, "exception");
e.printStackTrace();
}
try {
dataReceivedByte = dataReceived.getBytes("UTF-8");
} catch (UnsupportedEncodingException e) {
Log.d(TAG, "exception");
e.printStackTrace();
}
statusBool = true;
Log.d(TAG, "in data received " + dataReceived);
((MyBAIsWrapper) bis).renew(data);
runOnUiThread(new Runnable(){
@Override
public void run() {
mSession.appendToEmulator(dataReceivedByte, 0, dataReceivedByte.length);
}});
viewHandler.post(updateView);
}
文字が書き込まれるライブラリクラスの関連セクション:
クラスの関連セクション:
private void sendText(CharSequence text) {
int n = text.length();
char c;
try {
for(int i = 0; i < n; i++) {
c = text.charAt(i);
if (Character.isHighSurrogate(c)) {
int codePoint;
if (++i < n) {
codePoint = Character.toCodePoint(c, text.charAt(i));
} else {
// Unicode Replacement Glyph, aka white question mark in black diamond.
codePoint = '\ufffd';
}
mapAndSend(codePoint);
} else {
mapAndSend(c);
}
}
} catch (IOException e) {
Log.e(TAG, "error writing ", e);
}
}
private void mapAndSend(int c) throws IOException {
int result = mKeyListener.mapControlChar(c);
if (result < TermKeyListener.KEYCODE_OFFSET) {
mTermSession.write(result);
} else {
mKeyListener.handleKeyCode(result - TermKeyListener.KEYCODE_OFFSET, getKeypadApplicationMode());
}
clearSpecialKeyStatus();
}