Skip to content

Commit

Permalink
Add example of receiving ArtNet and fix formatting in readme
Browse files Browse the repository at this point in the history
  • Loading branch information
Timoteus Ruotsalainen committed Nov 11, 2024
1 parent f8b6cad commit 985ec70
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,12 @@ Contains the [ArtCommand](struct.ArtCommand.html) enum which holds the entire Ar

You can run the example program using

```shell
cargo build --example simple_sender
cargo run --example simple_sender
```

Here is an example of sending dmx. You can find more examples in the [examples directory](https://github.com/Trangar/artnet_protocol/tree/master/examples)
```rust
use artnet_protocol::*;
use std::net::{ToSocketAddrs, UdpSocket};
Expand Down
24 changes: 24 additions & 0 deletions examples/receive_artnet.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
use artnet_protocol::*;
use std::net::{ToSocketAddrs, UdpSocket};

Check warning on line 2 in examples/receive_artnet.rs

View workflow job for this annotation

GitHub Actions / Test Suite

unused import: `ToSocketAddrs`

fn main() {
let socket = UdpSocket::bind(("0.0.0.0", 6454)).unwrap();

loop {
let mut buffer = [0u8; 1024];
let (length, addr) = socket.recv_from(&mut buffer).unwrap();

Check warning on line 9 in examples/receive_artnet.rs

View workflow job for this annotation

GitHub Actions / Test Suite

unused variable: `addr`
let command = ArtCommand::from_buffer(&buffer[..length]).unwrap();

println!("Received {:?}", command);
match command {
ArtCommand::Output(output) => {
println!(
"port {:?} data: {:?}",
u16::from(output.port_address),
output.data
)
}
_ => {}
}
}
}

0 comments on commit 985ec70

Please sign in to comment.