J'essaie de communiquer avec un microcontrôleur programmable Bluetooth. L'appareil Bluetooth sur le microcontrôleur communique (spécifiquement) sur le numéro de port COM série Bluetooth 4.Android: Communication Bluetooth série (Com Port) avec Android Phone
QUESTION: Comment puis-je obtenir l'application Android pour lire les données de ce port COM (numéro 4)?
Je sais que l'UUID est un ID unique bien connu, qui fonctionne pour cet appareil, mais je ne pense pas que cela ait quelque chose à voir avec la spécification du port COM.
static final UUID myUUID = UUID.fromString("00001101-0000-1000-8000-00805F9B34FB");
btSocket = btDevice.createRfcommSocketToServiceRecord(myUUID);
btSocket.connect();
valid.append(btDevice.getName() + "\n" + btDevice.getAddress());
north.append("Socket Connected");
InputStream mmInStream = btSocket.getInputStream();
OutputStream mmOutStream = btSocket.getOutputStream();
byte[] buffer = new byte[10];
int bytes;
StringBuffer str = new StringBuffer();
while (true) {
try {
mmOutStream.write("a".getBytes());
//Reads a # of bytes until the end of stream is reached
bytes = mmInStream.read(buffer);
//Transform to string
str.append(buffer.toString()+"\t"); //Clear the buffer
Log.e("DATA", "THE DATA: "+ str.toString());
south.setText(str.toString());
str.delete(0,str.length());
} catch (IOException e) {
break;
} }}