<div align="center">
# `cat-dev-serial` #
A library used for interacting with [CAT-DEV](https://wiki.raregamingdump.ca/index.php?title=CAT-DEV)
(also sometimes referred to as the "cat-dev bridge") serial port. This is effectively a port of:
<https://github.com/de-vri-es/serial2-tokio-rs> at commit
`65ff229f65c27c57e261f94dc6cc9a761cce9b21`.
You can see the dual apache/bsd licenses for the original implementation at.:
<https://raw.githubusercontent.com/de-vri-es/serial2-tokio-rs/65ff229f65c27c57e261f94dc6cc9a761cce9b21/LICENSE-APACHE>
<https://raw.githubusercontent.com/de-vri-es/serial2-tokio-rs/65ff229f65c27c57e261f94dc6cc9a761cce9b21/LICENSE-BSD>
It has been updated to fit better into sprig's ecosystem (e.g. using `windows`
over `winapi`), and removing methods/etc. that would never work on a cat-dev.
</div>
## Stability ##
This crate is currently pre-1.0. We will do our best to minimize breaking
changes to the library, but there is still many parts of the cat-dev we have
not fully figured out. As such we're very hesitant to make any promises about
the stability of these APIs, or that we'll follow SEM-VER until we've at the
very least figured all of that out. If you are ever affected by this, or
concerned about this please reach out on our codeberg repository. We do want to
try, and make it as smooth as possible.
## Usage ##
Basic uses of this crate may look like the following:
***Listing all Serial Ports:***
```rust,no_run
use cat_dev_serial::SyncSerialPort;
use tracing::error;
let ports = match SyncSerialPort::available_ports() {
Ok(ports) => ports,
Err(cause) => {
error!(
?cause,
"failed to enumerate serial-ports",
);
std::process::exit(1);
}
};
if ports.is_empty() {
error!(
"os returned 0 serial ports being found"
);
std::process::exit(2);
}
for port in ports {
info!(
port = %port.display(),
"found a serial port",
);
}
```
***Reading Lines from a Serial Port:***
```rust,no_run
use cat_dev_serial::{AsyncSerialPort, SerialLines};
async fn async_lines() {
let serial = AsyncSerialPort::new("/dev/my-cool-serial-ports").expect("Failed to load serial port!");
let lines = SerialLines::new(serial);
while let Some(line) = lines.next_line().await? {
eprintln!("Got serial line:\n {line}");
}
}
```