teratail header banner
teratail header banner
質問するログイン新規登録

回答編集履歴

3

うまく動かないことがあるようなので、その旨追記した。

2019/08/29 04:20

投稿

murakami-kurio
murakami-kurio

スコア15

answer CHANGED
@@ -4,7 +4,14 @@
4
4
  j2xxを使っています。
5
5
 
6
6
  みなさま、いろいろありがとうございました。
7
+ ###追記(2019.Aug.29)
8
+ 大量に(あるいは高速に)データを受け取ると、
9
+ Handlerまでデータが届かない、という症状が出ております。
10
+ readDataまで、データは来ているようなのですが...。
11
+ タイマーを追加し、マイコンの手法で読んでみたいと思います。
7
12
 
13
+ 追記、ここまで。
14
+
8
15
  ###追記(2019.July.25)
9
16
  受信が安定しないようなので、次のように変えました。
10
17
  [オープン・リード・ライト・クローズで見るAndroid FTDI公式 ドライバ](https://ksksue.hatenadiary.org/entry/20130402/1364922862)

2

安定して動かなかった旨、修正し追記しました。

2019/08/29 04:20

投稿

murakami-kurio
murakami-kurio

スコア15

answer CHANGED
@@ -5,6 +5,23 @@
5
5
 
6
6
  みなさま、いろいろありがとうございました。
7
7
 
8
+ ###追記(2019.July.25)
9
+ 受信が安定しないようなので、次のように変えました。
10
+ [オープン・リード・ライト・クローズで見るAndroid FTDI公式 ドライバ](https://ksksue.hatenadiary.org/entry/20130402/1364922862)
11
+ ```java
12
+ ftDev.read(readData, iavailable);
13
+ // String mData = new String(readData);
14
+ // cannot use System.arraycopy
15
+ for(i=0; i<iavailable; i++) {
16
+ readDataToText[i] = (char)readData[i];
17
+ }
18
+ Message msg = mHandler.obtainMessage();
19
+ // msg.obj = mData;
20
+ msg.obj = String.copyValueOf(readDataToText,0,iavailable);
21
+ mHandler.sendMessage(msg);
22
+ ```
23
+ 追記ここまで。
24
+
8
25
  MainActivity.java
9
26
  ```java
10
27
  package xx.xx.xxxx.myusbhost;
@@ -117,27 +134,6 @@
117
134
  }
118
135
 
119
136
  /* 20190703
120
- @Override
121
- public boolean onCreateOptionsMenu(Menu menu) {
122
- // Inflate the menu; this adds items to the action bar if it is present.
123
- getMenuInflater().inflate(R.menu.menu_main, menu);
124
- return true;
125
- }
126
-
127
- @Override
128
- public boolean onOptionsItemSelected(MenuItem item) {
129
- // Handle action bar item clicks here. The action bar will
130
- // automatically handle clicks on the Home/Up button, so long
131
- // as you specify a parent activity in AndroidManifest.xml.
132
- int id = item.getItemId();
133
-
134
- //noinspection SimplifiableIfStatement
135
- if (id == R.id.action_settings) {
136
- return true;
137
- }
138
-
139
- return super.onOptionsItemSelected(item);
140
- }
141
137
  */
142
138
  public void SendMessage(String msg) {
143
139
 

1

足りなかった、ソースを加えた。

2019/07/25 04:29

投稿

murakami-kurio
murakami-kurio

スコア15

answer CHANGED
@@ -280,6 +280,38 @@
280
280
  </android.support.constraint.ConstraintLayout>
281
281
  ```
282
282
 
283
+ AndroidManifest.xml
284
+ ```xml
285
+ <?xml version="1.0" encoding="utf-8"?>
286
+ <manifest xmlns:android="http://schemas.android.com/apk/res/android"
287
+ package="xx.xx.xxxx.myusbhost">
283
288
 
289
+ <application
290
+ android:allowBackup="true"
291
+ android:icon="@mipmap/ic_launcher"
292
+ android:label="@string/app_name"
293
+ android:roundIcon="@mipmap/ic_launcher_round"
294
+ android:supportsRtl="true"
295
+ android:theme="@style/AppTheme">
296
+ <activity android:name=".MainActivity">
297
+ <intent-filter>
298
+ <action android:name="android.intent.action.MAIN" />
299
+ <action android:name="android.intent.action.VIEW"/>
300
+
301
+ <category android:name="android.intent.category.LAUNCHER" />
302
+ </intent-filter>
303
+ <intent-filter>
304
+ <action android:name="android.hardware.usb.action.USB_DEVICE_ATTACHED" />
305
+ </intent-filter>
306
+
307
+ <meta-data android:name="android.hardware.usb.action.USB_DEVICE_ATTACHED"
308
+ android:resource="@xml/device_filter" />
309
+
310
+ </activity>
311
+ </application>
312
+
313
+ </manifest>
284
314
  ```
315
+
316
+ device_filter.xml
285
- ```
317
+ は、質問と同じ。