-
Notifications
You must be signed in to change notification settings - Fork 63
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
adds README and LICENSE for serial-unix
- Loading branch information
1 parent
7f9ec8f
commit 1275bb4
Showing
3 changed files
with
66 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../LICENSE |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# Unix Serial Ports | ||
|
||
The `serial-unix` crate provides a serial port implementation for Unix operating systems. | ||
|
||
* [Documentation](http://dcuddeback.github.io/serial-rs/serial_unix/) | ||
|
||
## Compatibility | ||
|
||
The `serial-unix` crate is compatible with any Unix operating system that implements the termios | ||
API. The following platforms are confirmed to be compatible: | ||
|
||
* Linux (x86_64, armv6l) | ||
* OS X (x86_64) | ||
* FreeBSD (amd64) | ||
* OpenBSD (amd64) | ||
|
||
## Usage | ||
|
||
In general, one shouldn't need to use the `serial-unix` library directly. The implementation | ||
provided by `serial-unix` is also exposed through a cross-platform API in the [`serial` | ||
crate](../serial/). | ||
|
||
The serial port type defined in `serial-unix` works with any Unix TTY device. In addition to | ||
implementing the standard serial port traits, it also implements `std::os::unix::io::AsRawFd`, which | ||
can be used for integrating with other I/O libraries. See [`examples/poll.rs`](examples/poll.rs) for | ||
an example of using `AsRawFd` for event-driven I/O. | ||
|
||
## License | ||
|
||
Copyright © 2015 David Cuddeback | ||
|
||
Distributed under the [MIT License](LICENSE). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
extern crate serial_unix; | ||
extern crate libc; | ||
|
||
use std::io; | ||
use std::path::Path; | ||
|
||
use std::io::prelude::*; | ||
use std::os::unix::prelude::*; | ||
|
||
fn main() { | ||
let mut port = serial_unix::TTYPort::open(Path::new("/dev/ttyUSB0")).unwrap(); | ||
|
||
let mut fds = vec![libc::pollfd { | ||
fd: port.as_raw_fd(), | ||
events: libc::POLLIN, | ||
revents: 0, | ||
}]; | ||
|
||
loop { | ||
let retval = unsafe { libc::poll(fds.as_mut_ptr(), fds.len() as libc::nfds_t, 100) }; | ||
|
||
if retval < 0 { | ||
panic!("{:?}", io::Error::last_os_error()); | ||
} | ||
|
||
if retval > 0 && fds[0].revents & libc::POLLIN != 0 { | ||
let mut buffer = Vec::<u8>::new(); | ||
port.read_to_end(&mut buffer).unwrap(); | ||
|
||
println!("{:?}", buffer); | ||
} | ||
} | ||
} |