dmrconfig/src/serial.rs

34 lines
798 B
Rust

use std::ffi::{CStr};
use libc::{c_char};
extern {
fn find_path(vid: libc::c_int, pid: libc::c_int) -> *const c_char;
}
/// Connect to the specified device.
/// Initiate the programming session.
pub fn serial_init(vid: u32, pid: u32, trace_flag: bool) -> Option<String> {
let dev_path = unsafe { find_path(vid as i32, pid as i32) };
if dev_path.is_null() {
if trace_flag {
eprintln!("Cannot find USB device: {:#x}{:#x}", vid, pid);
}
return None;
}
let dev_path = unsafe { CStr::from_ptr(dev_path).to_str().unwrap().to_string() };
println!("Serial port: {}", dev_path);
Some(dev_path)
}
/*
/// Query and return the device identification string.
/// On error, return None.
//
pub fn serial_identify(dev_path: &str) -> Option<String> {
}
*/