|
@@ -193,7 +193,7 @@ async fn run_mqtt_and_serial() -> Result<()> { |
|
|
println!("正在读取数据... (按 Ctrl+C 退出)"); |
|
|
println!("正在读取数据... (按 Ctrl+C 退出)"); |
|
|
|
|
|
|
|
|
// Read data continuously |
|
|
// Read data continuously |
|
|
let mut serial_buf: Vec<u8> = vec![0; 1000]; |
|
|
|
|
|
|
|
|
let mut serial_buf: Vec<u8> = vec![0; 1000000]; |
|
|
loop { |
|
|
loop { |
|
|
match port.read(serial_buf.as_mut_slice()) { |
|
|
match port.read(serial_buf.as_mut_slice()) { |
|
|
Ok(t) => { |
|
|
Ok(t) => { |
|
@@ -212,7 +212,7 @@ async fn run_mqtt_and_serial() -> Result<()> { |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
// 开始循环发送数据 |
|
|
// 开始循环发送数据 |
|
|
loop { |
|
|
|
|
|
|
|
|
// loop { |
|
|
// 序列化数据 |
|
|
// 序列化数据 |
|
|
let json_data = serde_json::to_string(&weight_data)?; |
|
|
let json_data = serde_json::to_string(&weight_data)?; |
|
|
println!("当前JSON数据: {}", json_data); |
|
|
println!("当前JSON数据: {}", json_data); |
|
@@ -228,8 +228,8 @@ async fn run_mqtt_and_serial() -> Result<()> { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// 等待3秒 |
|
|
// 等待3秒 |
|
|
thread::sleep(Duration::from_secs(3)); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
// thread::sleep(Duration::from_secs(1)); |
|
|
|
|
|
// } |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
Err(ref e) if e.kind() == io::ErrorKind::TimedOut => { |
|
|
Err(ref e) if e.kind() == io::ErrorKind::TimedOut => { |
|
|