Add methods to set serial parameters and control lines in UsbSerialPort
Signed-off-by: Tony <tonylu@tony-cloud.com>
This commit is contained in:
@@ -32,6 +32,50 @@ class UsbSerialPort {
|
||||
return written ?? 0;
|
||||
}
|
||||
|
||||
/// Updates serial line parameters for an already-open port.
|
||||
Future<void> setParameters({
|
||||
required int baudRate,
|
||||
int dataBits = 8,
|
||||
UsbSerialParity parity = UsbSerialParity.none,
|
||||
UsbSerialStopBits stopBits = UsbSerialStopBits.one,
|
||||
}) async {
|
||||
await _methods.invokeMethod<void>('setParameters', {
|
||||
'portId': _portId,
|
||||
'baudRate': baudRate,
|
||||
'dataBits': dataBits,
|
||||
'parity': parity.index,
|
||||
'stopBits': FlutterUsbSerial._stopBitsIndex(stopBits),
|
||||
});
|
||||
}
|
||||
|
||||
/// Sets the DTR modem control line.
|
||||
Future<void> setDTR(bool value) async {
|
||||
await _methods.invokeMethod<void>('setDTR', {
|
||||
'portId': _portId,
|
||||
'value': value,
|
||||
});
|
||||
}
|
||||
|
||||
/// Sets the RTS modem control line.
|
||||
Future<void> setRTS(bool value) async {
|
||||
await _methods.invokeMethod<void>('setRTS', {
|
||||
'portId': _portId,
|
||||
'value': value,
|
||||
});
|
||||
}
|
||||
|
||||
/// Purges USB serial driver buffers when the driver supports it.
|
||||
Future<void> purgeHwBuffers({
|
||||
bool purgeWriteBuffers = true,
|
||||
bool purgeReadBuffers = true,
|
||||
}) async {
|
||||
await _methods.invokeMethod<void>('purgeHwBuffers', {
|
||||
'portId': _portId,
|
||||
'purgeWriteBuffers': purgeWriteBuffers,
|
||||
'purgeReadBuffers': purgeReadBuffers,
|
||||
});
|
||||
}
|
||||
|
||||
/// Close the port and release native resources.
|
||||
Future<void> close() async {
|
||||
await _methods.invokeMethod<void>('close', {'portId': _portId});
|
||||
|
||||
Reference in New Issue
Block a user