Created
May 7, 2022 21:28
-
-
Save KorvinSzanto/83db81ab3198c2b4cee16ec4403fc998 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
[package] | |
name = "serial-test" | |
version = "0.1.0" | |
edition = "2021" | |
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | |
[dependencies] | |
serialport = "4.1.0" |
This file contains hidden or 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
use std::io::{self, Write}; | |
use std::time::Duration; | |
use serialport::{SerialPortType, available_ports}; | |
fn main() -> ! { | |
// Output ports: https://github.com/jessebraham/serialport-rs/blob/main/examples/list_ports.rs | |
match available_ports() { | |
Ok(ports) => { | |
match ports.len() { | |
0 => println!("No ports found."), | |
1 => println!("Found 1 port:"), | |
n => println!("Found {} ports:", n), | |
}; | |
for p in ports { | |
println!(" {}", p.port_name); | |
match p.port_type { | |
SerialPortType::UsbPort(info) => { | |
println!(" Type: USB"); | |
println!(" VID:{:04x} PID:{:04x}", info.vid, info.pid); | |
println!( | |
" Serial Number: {}", | |
info.serial_number.as_ref().map_or("", String::as_str) | |
); | |
println!( | |
" Manufacturer: {}", | |
info.manufacturer.as_ref().map_or("", String::as_str) | |
); | |
println!( | |
" Product: {}", | |
info.product.as_ref().map_or("", String::as_str) | |
); | |
} | |
SerialPortType::BluetoothPort => { | |
println!(" Type: Bluetooth"); | |
} | |
SerialPortType::PciPort => { | |
println!(" Type: PCI"); | |
} | |
SerialPortType::Unknown => { | |
println!(" Type: Unknown"); | |
} | |
} | |
} | |
} | |
Err(e) => { | |
eprintln!("{:?}", e); | |
eprintln!("Error listing serial ports"); | |
} | |
} | |
println!("\n-----------------------\n"); | |
// Connect to port | |
let port = serialport::new("/dev/ttyUSB0", 115_200) | |
.timeout(Duration::from_millis(10)) | |
.open(); | |
// Stream port output: https://github.com/jessebraham/serialport-rs/blob/main/examples/receive_data.rs | |
match port { | |
Ok(mut port) => { | |
let mut serial_buf: Vec<u8> = vec![0; 1000]; | |
println!("Receiving data on /dev/ttyUSB0 at 115200 baud:"); | |
loop { | |
match port.read(serial_buf.as_mut_slice()) { | |
Ok(t) => io::stdout().write_all(&serial_buf[..t]).unwrap(), | |
Err(ref e) if e.kind() == io::ErrorKind::TimedOut => (), | |
Err(e) => eprintln!("{:?}", e), | |
} | |
} | |
} | |
Err(e) => { | |
eprintln!("Failed to open \"/dev/ttyUSB0\". Error: {}", e); | |
::std::process::exit(1); | |
} | |
} | |
} |
This file contains hidden or 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
Found 1 port: | |
/dev/ttyUSB0 | |
Type: Unknown | |
----------------------- | |
Receiving data on /dev/ttyUSB0 at 115200 baud: | |
ets Jun 8 2016 00:22:57 | |
rst:0x1 (POWERON_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT) | |
configsip: 0, SPIWP:0x00 | |
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00 | |
mode:DIO, clock div:2 | |
load:0x3fff0008,len:8 | |
load:0x3fff0010,len:3480 | |
load:0x40078000,len:7804 | |
ho 0 tail 12 room 4 | |
load:0x40080000,len:252 | |
entry 0x40080034 | |
[0;32mI (46) boot: ESP-IDF v2.0-3-gbef9896 2nd stage bootloader[0m | |
[0;32mI (46) boot: compile time 05:59:45[0m | |
[0;32mI (46) boot: Enabling RNG early entropy source...[0m | |
[0;32mI (65) boot: SPI Speed : 40MHz[0m | |
[0;32mI (77) boot: SPI Mode : DIO[0m | |
[0;32mI (90) boot: SPI Flash Size : 4MB[0m | |
[0;32mI (102) boot: Partition Table:[0m | |
[0;32mI (113) boot: ## Label Usage Type ST Offset Length[0m | |
[0;32mI (136) boot: 0 phy_init RF data 01 01 0000f000 00001000[0m | |
[0;32mI (159) boot: 1 otadata OTA data 01 00 00010000 00002000[0m | |
[0;32mI (183) boot: 2 nvs WiFi data 01 02 00012000 0000e000[0m | |
[0;32mI (206) boot: 3 at_customize unknown 40 00 00020000 000e0000[0m | |
[0;32mI (229) boot: 4 ota_0 OTA app 00 10 00100000 00180000[0m | |
[0;32mI (252) boot: 5 ota_1 OTA app 00 11 00280000 00180000[0m | |
[0;32mI (276) boot: End of partition table[0m | |
[0;32mI (289) boot: Disabling RNG early entropy source...[0m | |
[0;32mI (306) boot: Loading app partition at offset 00100000[0m | |
[0;32mI (1481) boot: segment 0: paddr=0x00100018 vaddr=0x00000000 size=0x0ffe8 ( 65512) [0m | |
[0;32mI (1482) boot: segment 1: paddr=0x00110008 vaddr=0x3f400010 size=0x1c5f0 (116208) map[0m | |
[0;32mI (1498) boot: segment 2: paddr=0x0012c600 vaddr=0x3ffb0000 size=0x0215c ( 8540) load[0m | |
[0;32mI (1529) boot: segment 3: paddr=0x0012e764 vaddr=0x40080000 size=0x00400 ( 1024) load[0m | |
[0;32mI (1552) boot: segment 4: paddr=0x0012eb6c vaddr=0x40080400 size=0x1b028 (110632) load[0m | |
[0;32mI (1631) boot: segment 5: paddr=0x00149b9c vaddr=0x400c0000 size=0x00034 ( 52) load[0m | |
[0;32mI (1632) boot: segment 6: paddr=0x00149bd8 vaddr=0x00000000 size=0x06430 ( 25648) [0m | |
[0;32mI (1648) boot: segment 7: paddr=0x00150010 vaddr=0x400d0018 size=0x7a56c (501100) map[0m | |
[0;32mI (1676) heap_alloc_caps: Initializing. RAM available for dynamic allocation:[0m | |
[0;32mI (1698) heap_alloc_caps: At 3FFBA6B8 len 00025948 (150 KiB): DRAM[0m | |
[0;32mI (1719) heap_alloc_caps: At 3FFE8000 len 00018000 (96 KiB): D/IRAM[0m | |
[0;32mI (1741) heap_alloc_caps: At 4009B428 len 00004BD8 (18 KiB): IRAM[0m | |
[0;32mI (1761) cpu_start: Pro cpu up.[0m | |
[0;32mI (1773) cpu_start: Single core mode[0m | |
[0;32mI (1786) cpu_start: Pro cpu start user code[0m | |
[0;32mI (1847) cpu_start: Starting scheduler on PRO CPU.[0m | |
[0;32mI (2087) uart: queue free spaces: 10[0m | |
Bin version:0.10.0 | |
I (2088) wifi: wifi firmware version: c604573 | |
I (2088) wifi: config NVS flash: enabled | |
I (2089) wifi: config nano formating: disabled | |
I (2097) wifi: Init dynamic tx buffer num: 32 | |
I (2098) wifi: wifi driver task: 3ffc4eac, prio:23, stack:3584 | |
I (2103) wifi: Init static rx buffer num: 10 | |
I (2107) wifi: Init dynamic rx buffer num: 0 | |
I (2111) wifi: Init rx ampdu len mblock:7 | |
I (2115) wifi: Init lldesc rx ampdu entry mblock:4 | |
I (2120) wifi: wifi power manager task: 0x3ffca254 prio: 21 stack: 2560 | |
I (2126) wifi: wifi timer task: 3ffcb2d4, prio:22, stack:3584 | |
[0;31mE (2131) phy_init: PHY data partition validated[0m | |
[0;32mI (2154) phy: phy_version: 329, Feb 22 2017, 15:58:07, 0, 0[0m | |
I (2155) wifi: mode : softAP (0c:b8:15:c2:35:a5) | |
I (2158) wifi: mode : sta (0c:b8:15:c2:35:a4) + softAP (0c:b8:15:c2:35:a5) | |
I (2161) wifi: mode : softAP (0c:b8:15:c2:35:a5) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment