@@ -2,6 +2,7 @@ import 'dart:async';
22import 'dart:convert' ;
33import 'dart:typed_data' ;
44import 'package:flutter_serial_communication/flutter_serial_communication.dart' ;
5+ import 'package:flutter_serial_communication/models/device_info.dart' ;
56import 'package:flutter_bluetooth_classic_serial/flutter_bluetooth_classic.dart' ;
67import 'package:permission_handler/permission_handler.dart' ;
78import '../../models/node_frame.dart' ;
@@ -162,7 +163,7 @@ class SerialCapability extends CapabilityHandler {
162163 'transport' : 'usb' ,
163164 'devices' : devices
164165 .map ((d) => {
165- 'name' : d.deviceName ?? d.productName ?? 'Unknown USB Device' ,
166+ 'name' : d.deviceName.isNotEmpty ? d.deviceName : (d. productName.isNotEmpty ? d.productName : 'Unknown USB Device' ) ,
166167 'deviceId' : d.deviceId,
167168 'vendorId' : d.vendorId,
168169 'productId' : d.productId,
@@ -248,7 +249,7 @@ class SerialCapability extends CapabilityHandler {
248249
249250 final connId = 'usb_${device .deviceId }' ;
250251 _usbConnectionId = connId;
251- _usbDeviceName = device.deviceName ?? device.productName ?? 'USB Device' ;
252+ _usbDeviceName = device.deviceName.isNotEmpty ? device.deviceName : (device. productName.isNotEmpty ? device.productName : 'USB Device' ) ;
252253 _usbBuffer = _ReadBuffer ();
253254
254255 _usbDataSub? .cancel ();
@@ -302,16 +303,7 @@ class SerialCapability extends CapabilityHandler {
302303
303304 _btDataSub? .cancel ();
304305 _btDataSub = _btSerial.onDataReceived.listen ((event) {
305- if (event is List <int >) {
306- _btBuffer? .add (event);
307- } else {
308- try {
309- final data = (event as dynamic ).data;
310- if (data is List <int >) {
311- _btBuffer? .add (data);
312- }
313- } catch (_) {}
314- }
306+ _btBuffer? .add (event.data);
315307 });
316308
317309 return NodeFrame .response ('' , payload: {
0 commit comments