Filter empty serial ports and scroll the printer list.
Co-authored-by: Cursor <cursoragent@cursor.com>
@@ -278,7 +278,9 @@ Printers may appear as:
278
278
279
279
- **USB printer-class** devices (direct bulk OUT)
280
280
- **Windows spooler** queues (Windows)
281
- **Serial / USB-serial** ports (`COMx`, `/dev/ttyUSB0`, …)
281
- **USB-serial** ports with a device attached (`COMx`, `/dev/ttyUSB0`, `/dev/ttyACM0`, …)
282
283
Empty motherboard serial ports (common on Linux as `/dev/ttyS*`) are hidden. Use **Enter port or queue manually** if you need one of those.
282
284
283
285
**Linux serial:** join the `dialout` group.
284
286
@@ -278,7 +278,9 @@ Printers may appear as:278
278
279
- **USB printer-class** devices (direct bulk OUT)279
- **USB printer-class** devices (direct bulk OUT)280
- **Windows spooler** queues (Windows)280
- **Windows spooler** queues (Windows)281
- **Serial / USB-serial** ports (`COMx`, `/dev/ttyUSB0`, …)281
- **USB-serial** ports with a device attached (`COMx`, `/dev/ttyUSB0`, `/dev/ttyACM0`, …)282
283
Empty motherboard serial ports (common on Linux as `/dev/ttyS*`) are hidden. Use **Enter port or queue manually** if you need one of those.282
284
283
**Linux serial:** join the `dialout` group.285
**Linux serial:** join the `dialout` group.284
286
@@ -79,7 +79,7 @@ pub trait PrinterTransport {
79
79
80
80
1. USB printer-class devices (`usb_direct`)
81
81
2. Windows spooler queues (Windows)
82
3. Serial ports (`serialport::available_ports()`, with VID/PID labels when available)
82
3. USB-serial ports only (`SerialPortType::UsbPort` — skips empty PCI/`ttyS*` ports common on Linux)
83
83
84
84
### Serial baud rates
85
85
@@ -100,8 +100,9 @@ pub trait PrinterTransport {
100
100
## Print dialog (UI)
101
101
102
102
- One field per unique `${Parameter}`.
103
- Printer list: USB, spooler, and serial (Refresh button).
104
- Optional manual serial port name.
103
- Printer list: USB printer-class, Windows spooler (Windows), and connected USB-serial devices (Refresh button). Empty motherboard serial ports are omitted; use manual entry for those.
104
- The printer list scrolls when long so Cancel / Print stay reachable.
105
- Optional manual serial port / queue name.
105
106
- While open, the main Design UI is disabled (including editor autocomplete).
106
107
- Errors shown inline (parse, open, write, barcode validation).
107
108
@@ -79,7 +79,7 @@ pub trait PrinterTransport {79
79
80
1. USB printer-class devices (`usb_direct`)80
1. USB printer-class devices (`usb_direct`)81
2. Windows spooler queues (Windows)81
2. Windows spooler queues (Windows)82
3. Serial ports (`serialport::available_ports()`, with VID/PID labels when available)82
3. USB-serial ports only (`SerialPortType::UsbPort` — skips empty PCI/`ttyS*` ports common on Linux)83
83
84
### Serial baud rates84
### Serial baud rates85
85
@@ -100,8 +100,9 @@ pub trait PrinterTransport {100
## Print dialog (UI)100
## Print dialog (UI)101
101
102
- One field per unique `${Parameter}`.102
- One field per unique `${Parameter}`.103
- Printer list: USB, spooler, and serial (Refresh button).103
- Printer list: USB printer-class, Windows spooler (Windows), and connected USB-serial devices (Refresh button). Empty motherboard serial ports are omitted; use manual entry for those.104
- Optional manual serial port name.104
- The printer list scrolls when long so Cancel / Print stay reachable.105
- Optional manual serial port / queue name.105
- While open, the main Design UI is disabled (including editor autocomplete).106
- While open, the main Design UI is disabled (including editor autocomplete).106
- Errors shown inline (parse, open, write, barcode validation).107
- Errors shown inline (parse, open, write, barcode validation).107
108
@@ -99,24 +99,22 @@ pub fn list_usb_serial_printers() -> Result<Vec<PrinterDevice>, serialport::Erro
99
99
fn list_serial_devices() -> Result<Vec<PrinterDevice>, serialport::Error> {
100
100
let mut devices = Vec::new();
101
101
for port in serialport::available_ports()? {
102
let label = match &port.port_type {
103
SerialPortType::UsbPort(info) => {
104
let product = info
105
.product
106
.as_deref()
107
.or(info.serial_number.as_deref())
108
.unwrap_or("USB device");
109
format!(
110
"{} — {product} (serial {}:{})",
111
port.port_name,
112
fmt_vid_pid(info.vid),
113
fmt_vid_pid(info.pid)
114
)
115
}
116
SerialPortType::BluetoothPort => format!("{} — Bluetooth", port.port_name),
117
SerialPortType::PciPort => format!("{} — PCI", port.port_name),
118
SerialPortType::Unknown => format!("{} — Serial", port.port_name),
102
// Only USB-attached serial devices: Linux often lists dozens of empty
103
// /dev/ttyS* (PCI/Unknown) that are not connected to anything.
104
let SerialPortType::UsbPort(info) = &port.port_type else {
105
continue;
119
106
};
107
let product = info
108
.product
109
.as_deref()
110
.or(info.serial_number.as_deref())
111
.unwrap_or("USB device");
112
let label = format!(
113
"{} — {product} (serial {}:{})",
114
port.port_name,
115
fmt_vid_pid(info.vid),
116
fmt_vid_pid(info.pid)
117
);
120
118
devices.push(PrinterDevice {
121
119
id: format!("serial:{}", port.port_name),
122
120
display_name: label,
@@ -127,6 +125,11 @@ fn list_serial_devices() -> Result<Vec<PrinterDevice>, serialport::Error> {
127
125
Ok(devices)
128
126
}
129
127
128
/// True when a serial port type is a connected USB device (possible POS printer).
129
pub fn is_usb_serial_candidate(port_type: &SerialPortType) -> bool {
130
matches!(port_type, SerialPortType::UsbPort(_))
131
}
132
130
133
pub fn open_printer(target: &PrinterTarget) -> Result<Box<dyn PrinterTransport>, PrintError> {
131
134
match target {
132
135
PrinterTarget::Serial(port) => Ok(Box::new(SerialTransport::open(port)?)),
@@ -227,6 +230,7 @@ impl PrinterTransport for MockTransport {
227
230
#[cfg(test)]
228
231
mod tests {
229
232
use super::*;
233
use serialport::UsbPortInfo;
230
234
231
235
#[test]
232
236
fn mock_transport_records_bytes() {
@@ -240,4 +244,23 @@ mod tests {
240
244
let list = list_printers();
241
245
assert!(list.is_ok());
242
246
}
247
248
#[test]
249
fn non_usb_serial_ports_are_not_candidates() {
250
assert!(!is_usb_serial_candidate(&SerialPortType::PciPort));
251
assert!(!is_usb_serial_candidate(&SerialPortType::BluetoothPort));
252
assert!(!is_usb_serial_candidate(&SerialPortType::Unknown));
253
}
254
255
#[test]
256
fn usb_serial_port_is_candidate() {
257
let usb = SerialPortType::UsbPort(UsbPortInfo {
258
vid: 0x0416,
259
pid: 0x5011,
260
serial_number: None,
261
manufacturer: None,
262
product: Some("POS-58".into()),
263
});
264
assert!(is_usb_serial_candidate(&usb));
265
}
243
266
}
@@ -99,24 +99,22 @@ pub fn list_usb_serial_printers() -> Result<Vec<PrinterDevice>, serialport::Erro99
fn list_serial_devices() -> Result<Vec<PrinterDevice>, serialport::Error> {
99
fn list_serial_devices() -> Result<Vec<PrinterDevice>, serialport::Error> {
100
let mut devices = Vec::new();
100
let mut devices = Vec::new();
101
for port in serialport::available_ports()? {
101
for port in serialport::available_ports()? {
102
let label = match &port.port_type {
102
// Only USB-attached serial devices: Linux often lists dozens of empty
103
SerialPortType::UsbPort(info) => {
103
// /dev/ttyS* (PCI/Unknown) that are not connected to anything.
104
let product = info
104
let SerialPortType::UsbPort(info) = &port.port_type else {
105
.product
105
continue;
106
.as_deref()
107
.or(info.serial_number.as_deref())
108
.unwrap_or("USB device");
109
format!(
110
"{} — {product} (serial {}:{})",
111
port.port_name,
112
fmt_vid_pid(info.vid),
113
fmt_vid_pid(info.pid)
114
)
115
}
116
SerialPortType::BluetoothPort => format!("{} — Bluetooth", port.port_name),
117
SerialPortType::PciPort => format!("{} — PCI", port.port_name),
118
SerialPortType::Unknown => format!("{} — Serial", port.port_name),
119
};
106
};
107
let product = info
108
.product
109
.as_deref()
110
.or(info.serial_number.as_deref())
111
.unwrap_or("USB device");
112
let label = format!(
113
"{} — {product} (serial {}:{})",
114
port.port_name,
115
fmt_vid_pid(info.vid),
116
fmt_vid_pid(info.pid)
117
);
120
devices.push(PrinterDevice {
118
devices.push(PrinterDevice {
121
id: format!("serial:{}", port.port_name),
119
id: format!("serial:{}", port.port_name),
122
display_name: label,
120
display_name: label,
@@ -127,6 +125,11 @@ fn list_serial_devices() -> Result<Vec<PrinterDevice>, serialport::Error> {127
Ok(devices)
125
Ok(devices)
128
}
126
}
129
127
128
/// True when a serial port type is a connected USB device (possible POS printer).
129
pub fn is_usb_serial_candidate(port_type: &SerialPortType) -> bool {
130
matches!(port_type, SerialPortType::UsbPort(_))
131
}
132
130
pub fn open_printer(target: &PrinterTarget) -> Result<Box<dyn PrinterTransport>, PrintError> {
133
pub fn open_printer(target: &PrinterTarget) -> Result<Box<dyn PrinterTransport>, PrintError> {
131
match target {
134
match target {
132
PrinterTarget::Serial(port) => Ok(Box::new(SerialTransport::open(port)?)),
135
PrinterTarget::Serial(port) => Ok(Box::new(SerialTransport::open(port)?)),
@@ -227,6 +230,7 @@ impl PrinterTransport for MockTransport {227
#[cfg(test)]
230
#[cfg(test)]
228
mod tests {
231
mod tests {
229
use super::*;
232
use super::*;
233
use serialport::UsbPortInfo;
230
234
231
#[test]
235
#[test]
232
fn mock_transport_records_bytes() {
236
fn mock_transport_records_bytes() {
@@ -240,4 +244,23 @@ mod tests {240
let list = list_printers();
244
let list = list_printers();
241
assert!(list.is_ok());
245
assert!(list.is_ok());
242
}
246
}
247
248
#[test]
249
fn non_usb_serial_ports_are_not_candidates() {
250
assert!(!is_usb_serial_candidate(&SerialPortType::PciPort));
251
assert!(!is_usb_serial_candidate(&SerialPortType::BluetoothPort));
252
assert!(!is_usb_serial_candidate(&SerialPortType::Unknown));
253
}
254
255
#[test]
256
fn usb_serial_port_is_candidate() {
257
let usb = SerialPortType::UsbPort(UsbPortInfo {
258
vid: 0x0416,
259
pid: 0x5011,
260
serial_number: None,
261
manufacturer: None,
262
product: Some("POS-58".into()),
263
});
264
assert!(is_usb_serial_candidate(&usb));
265
}
243
}
266
}
@@ -269,9 +269,21 @@ impl PrintDialog {
269
269
"No printers found. Connect a USB POS printer, refresh, or enter a port/queue manually.",
270
270
);
271
271
} else {
272
for (i, printer) in self.printers.iter().enumerate() {
273
ui.selectable_value(&mut self.selected_printer, Some(i), &printer.display_name);
274
}
272
// Keep Cancel/Print reachable when many devices are listed.
273
let list_height = (self.printers.len() as f32 * 22.0).clamp(44.0, 180.0);
274
egui::ScrollArea::vertical()
275
.id_salt("print_dialog_printer_list")
276
.max_height(list_height)
277
.auto_shrink([false, true])
278
.show(ui, |ui| {
279
for (i, printer) in self.printers.iter().enumerate() {
280
ui.selectable_value(
281
&mut self.selected_printer,
282
Some(i),
283
&printer.display_name,
284
);
285
}
286
});
275
287
}
276
288
277
289
if let Some(err) = &self.error {
@@ -269,9 +269,21 @@ impl PrintDialog {269
"No printers found. Connect a USB POS printer, refresh, or enter a port/queue manually.",
269
"No printers found. Connect a USB POS printer, refresh, or enter a port/queue manually.",
270
);
270
);
271
} else {
271
} else {
272
for (i, printer) in self.printers.iter().enumerate() {
272
// Keep Cancel/Print reachable when many devices are listed.
273
ui.selectable_value(&mut self.selected_printer, Some(i), &printer.display_name);
273
let list_height = (self.printers.len() as f32 * 22.0).clamp(44.0, 180.0);
274
}
274
egui::ScrollArea::vertical()
275
.id_salt("print_dialog_printer_list")
276
.max_height(list_height)
277
.auto_shrink([false, true])
278
.show(ui, |ui| {
279
for (i, printer) in self.printers.iter().enumerate() {
280
ui.selectable_value(
281
&mut self.selected_printer,
282
Some(i),
283
&printer.display_name,
284
);
285
}
286
});
275
}
287
}
276
288
277
if let Some(err) = &self.error {
289
if let Some(err) = &self.error {