Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit054f561

Browse files
committed
Add an example application to list available interfaces
Add a new example that shows how to list available SocketCAN interfaces.Signed-off-by: Gerard Marull-Paretas <gerard@teslabs.com>
1 parent40e201d commit054f561

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

‎examples/enumerate.rs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// socketcan/examples/enumerate.rs
2+
//
3+
// Example application for listing available SocketCAN interfaces
4+
//
5+
// This file is part of the Rust 'socketcan-rs' library.
6+
//
7+
// Licensed under the MIT license:
8+
// <LICENSE or http://opensource.org/licenses/MIT>
9+
// This file may not be copied, modified, or distributed except according
10+
// to those terms.
11+
12+
//! An example that lists available SocketCAN interfaces.
13+
14+
use socketcan::available_interfaces;
15+
16+
fnmain(){
17+
matchavailable_interfaces(){
18+
Ok(interfaces) =>{
19+
match interfaces.len(){
20+
0 =>println!("No CAN interfaces found."),
21+
1 =>println!("Found 1 CAN interface:"),
22+
n =>println!("Found {} CAN interfaces:", n),
23+
};
24+
25+
for ifacein interfaces{
26+
println!("{}", iface);
27+
}
28+
}
29+
Err(e) =>{
30+
eprintln!("{:?}", e);
31+
eprintln!("Error listing CAN interfaces")
32+
}
33+
}
34+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp