Open twonius opened 2 years ago
I'm trying to extend this so I can connect to multiple UART servers simultaneously.
I've already got the scan filtering for UART devices only and am passing the list of device labels to the TerminalFragement
But it looks like I'm overwriting the socket connection when I loop through the devices and create them in the service.
If i send a message I only get a reply from one of the devices. Is there an elegant way of doing this without just creating an array of services?
for(String d:deviceList) { try { BluetoothAdapter bluetoothAdapter = BluetoothAdapter.getDefaultAdapter(); BluetoothDevice device = bluetoothAdapter.getRemoteDevice(d); status("connecting..." + device); connected = Connected.Pending; SerialSocket socket = new SerialSocket(getActivity().getApplicationContext(), device); // need to make multiple connectons and retrieve address service.connect(socket); } catch (Exception e) { onSerialConnectError(e); } }
I recommend to create distinct service instances. Else you would have to enhance the service class to manage multiple sockets
I'm trying to extend this so I can connect to multiple UART servers simultaneously.
I've already got the scan filtering for UART devices only and am passing the list of device labels to the TerminalFragement
But it looks like I'm overwriting the socket connection when I loop through the devices and create them in the service.
If i send a message I only get a reply from one of the devices. Is there an elegant way of doing this without just creating an array of services?
for(String d:deviceList) { try { BluetoothAdapter bluetoothAdapter = BluetoothAdapter.getDefaultAdapter(); BluetoothDevice device = bluetoothAdapter.getRemoteDevice(d); status("connecting..." + device); connected = Connected.Pending; SerialSocket socket = new SerialSocket(getActivity().getApplicationContext(), device); // need to make multiple connectons and retrieve address service.connect(socket); } catch (Exception e) { onSerialConnectError(e); } }