update linux open port settings and readme

This commit is contained in:
Guangzong Chen 2021-10-09 19:56:16 -04:00
parent fdda601379
commit a052e6b3b8
No known key found for this signature in database
GPG Key ID: E3E141D720E7F9A3
3 changed files with 55 additions and 87 deletions

View File

@ -2,87 +2,45 @@
This is a serial tool for Linux and windows. This is a serial tool for Linux and windows.
## Motivation I am a embedded sorfware developer. USART is a very common communication protocal for communication and debug. I was using Moserial Terminal and Cutecom. But I found serveral problem in these tool. So I design this tool to help embedded software developer. This tool still work in progross. The function of this tool is limited for now.
I am a embedded sorfware developer. Usart is a very common communication protocal which used for debug.
I was using `Moserial Terminal` and `cutecom`. But I found serveral problem when I was using these tools.
So I write this tool to help embedded software developer. This tool may not have all function you need, it only design for personal use.
It will contain all function I need. If you requst some function and I think it is useful I will add it to TODO list.
The main thing in this tool is realiable. Tool will not crash, and get correct data from serial port. Display these data correctly and completance.
## Usage ## Usage
1. Only 1 input window. All function are provide by input command. This tool support following commands. `list`, `open`, `close`, `send`, `loop`, `loopend`, `clean`, `show`, `hide`, `set`.
Following command are support now. 1. `list`: List all avaliable port in log window
2. `open <port_name>`: Open port.
3. `close`: Close port.
4. `send <data>`: Send _data_ to port.
5. `loop <data>`: Send _data_ periodic. The period show in the status bar.
6. `loopend`: Stop send _data_ periodic.
7. `clear`: Clear log and receive data windows.
8. `show <window>`: Show log or hex window. The parameter, _window_, should be `log` or `hex`.
9. `hide <window>`" Inverse operation of `show`
### set commnad 10. `set <name> <value>`: Change port parameter.
Command `set` used for setup port configuration ### Set command
``` Supportted settings: `baudrate`, `databit`, `parity`, `stopbit`, `flowcontrol`, `period`.
set baudrate 115200 1. `baudrate`: Change baudrate. Support any value.
set databit 8 2. `databit`: Change databit. Support value: 5, 6, 7, 8.
set parity 0 // None 3. `parity`: Change parity. Support value: 0: None, 1: Odd, 2: Even.
set stopbit 1 4. `stopbit`" Change stopit. Support value: 1, 2.
``` 5. `flowcontrol`: Change flowcontrol. Support value: hard, soft, none.
6. `period`: Change loop send periodic. This will work after port is open. Minimum value: 10ms for Linux, 15 ms for Windows. Because operation system can not run programming in real time, this value is not accurate.
### open command
Command `open` used for open serialport
For Linux system, the port looks like `/dev/ttyUSB0`. We don't need type `/dev/tty`
Example for Linux System
```
open USB0
```
Example for Windows System
```
open COM0
```
### close command
command `close` used for close an opened serial port.
### list command
Command `list` used for list all avaliable port
### send command
Command `send` used for send message to port
```
send hello world // "hello world" will send to port
```
### clean command
Command `clean` used for clean ReceiveView and LogView
```
clean log
clean rec
```
## feature list ## Feature list
port function
- [x] open port - [x] open port
- [x] close port - [x] close port
- [x] send ascii to port - [x] send ascii to port
- [x] view recived data as hex
- [x] change port settings
- [x] send data periodic
- [ ] record output to file
- [ ] send hex to port - [ ] send hex to port
- [ ] save output to port - [ ] send hex periodic
- [ ] view recived data as hex
ui function
- [ ] show recived data as hex
- [ ] clean command

View File

@ -15,9 +15,8 @@ use crate::port::*;
use gtk::prelude::TextViewExt; use gtk::prelude::TextViewExt;
use gtk::prelude::LabelExt; use gtk::prelude::LabelExt;
use std::str; use std::{str, env};
use std::time::Duration; use std::time::Duration;
use std::num::ParseIntError;
fn main() { fn main() {
let application = gtk::Application::new( let application = gtk::Application::new(
@ -126,8 +125,8 @@ fn build_ui(application: &gtk::Application) {
let tmp = ui_hex_scroll.vadjustment(); let tmp = ui_hex_scroll.vadjustment();
tmp.set_value(tmp.upper()); tmp.set_value(tmp.upper());
} }
Message::UiCleanReceiveMsg => ui_receive_view.buffer().unwrap().set_text(""), Message::UiClearReceiveMsg => ui_receive_view.buffer().unwrap().set_text(""),
Message::UiCleanLog => ui_log_view.buffer().unwrap().set_text(""), Message::UiClearLog => ui_log_view.buffer().unwrap().set_text(""),
Message::UiShowLog => ui_log_window.show(), Message::UiShowLog => ui_log_window.show(),
Message::UiHideLog => ui_log_window.hide(), Message::UiHideLog => ui_log_window.hide(),
Message::UiShowHex => ui_hex_window.show(), Message::UiShowHex => ui_hex_window.show(),
@ -204,9 +203,9 @@ fn process_cmd(command: String, to_ui: glib::Sender<Message>, gui2main_tx: Sende
"loopend" => { "loopend" => {
gui2main_tx.send(Message::MainCmdStopPeriod).unwrap(); gui2main_tx.send(Message::MainCmdStopPeriod).unwrap();
} }
"clean" => { "clear" => {
to_ui.send(Message::UiCleanReceiveMsg).unwrap(); to_ui.send(Message::UiClearReceiveMsg).unwrap();
to_ui.send(Message::UiCleanLog).unwrap(); to_ui.send(Message::UiClearLog).unwrap();
} }
"show" => { "show" => {
if command_split.len() == 1 { if command_split.len() == 1 {
@ -251,7 +250,7 @@ fn main_proc(to_main_tx: Sender<Message>, rx: Receiver<Message>, ui_upd: glib::S
loop { loop {
if let Ok(msg) = rx.try_recv() { if let Ok(msg) = rx.try_recv() {
match msg { match msg {
Message::UiCleanReceiveMsg => {} Message::UiClearReceiveMsg => {}
Message::MainCmdOpen(arg) => { Message::MainCmdOpen(arg) => {
if port_status_open { if port_status_open {
ui_upd.send(Message::UiUpdateLog("Port Already Open\n".to_string())).unwrap(); ui_upd.send(Message::UiUpdateLog("Port Already Open\n".to_string())).unwrap();
@ -260,9 +259,22 @@ fn main_proc(to_main_tx: Sender<Message>, rx: Receiver<Message>, ui_upd: glib::S
let (tmp_to_port, main2port_rx) = channel::<Message>(); let (tmp_to_port, main2port_rx) = channel::<Message>();
main2port_tx = tmp_to_port; main2port_tx = tmp_to_port;
let port_name = if arg.is_empty() { default_com_port.clone() } else { arg }; let port_name = if arg.is_empty() { default_com_port.clone() } else {
let mut tmp = arg.clone();
if env::consts::OS == "linux" {
let prelude = "/dev/tty";
if !arg.contains("/dev/tty"){
tmp = prelude.to_owned() + &arg;
}
}
tmp
};
default_com_port = port_name.clone(); default_com_port = port_name.clone();
ui_upd.send(Message::UiUpdateStatusBarCom(default_com_port.clone())).unwrap(); ui_upd.send(Message::UiUpdateStatusBarCom(default_com_port.clone())).unwrap();
match port_open(port_name, port_default_config) { match port_open(port_name, port_default_config) {
Ok(port) => { Ok(port) => {
port_status_open = true; port_status_open = true;

View File

@ -1,5 +1,4 @@
use std::sync::mpsc::{Sender, Receiver}; use std::sync::mpsc::{Sender, Receiver};
use std::env;
use serialport::{SerialPort, DataBits, Parity, FlowControl, StopBits}; use serialport::{SerialPort, DataBits, Parity, FlowControl, StopBits};
use std::time::Duration; use std::time::Duration;
@ -7,8 +6,8 @@ use std::time::Duration;
pub enum Message { pub enum Message {
UiUpdateLog(String), UiUpdateLog(String),
UiUpdateReceiveMsg(Vec<u8>), UiUpdateReceiveMsg(Vec<u8>),
UiCleanReceiveMsg, UiClearReceiveMsg,
UiCleanLog, UiClearLog,
UiShowLog, UiShowLog,
UiHideLog, UiHideLog,
UiShowHex, UiShowHex,
@ -55,9 +54,8 @@ pub struct PortConfig {
} }
pub fn port_open(port: String, config: PortConfig) -> Result<Box<dyn SerialPort>, Error> { pub fn port_open(port: String, config: PortConfig) -> Result<Box<dyn SerialPort>, Error> {
let mut prelude = "";
if env::consts::OS == "linux" { prelude = "/dev/tty"; } else if env::consts::OS == "windows" { prelude = "" } let port_builder = serialport::new(port, config.baud_rate)
let port_builder = serialport::new(prelude.to_owned() + &port, config.baud_rate)
.data_bits(config.data_bits) .data_bits(config.data_bits)
.parity(config.parity) .parity(config.parity)
.flow_control(config.flow_control) .flow_control(config.flow_control)
@ -78,7 +76,7 @@ pub fn port_proc(mut port: Box<dyn SerialPort>, to_main: Sender<Message>, from_m
let mut period_timeout = std::time::Duration::from_millis(100); let mut period_timeout = std::time::Duration::from_millis(100);
let mut period_send_msg = String::new(); let mut period_send_msg = String::new();
let mut last_send = std::time::Instant::now(); let mut last_send = std::time::Instant::now();
to_main.send(Message::PortPeriodDuration(100)); to_main.send(Message::PortPeriodDuration(100)).unwrap();
loop { loop {
if let Ok(msg) = from_main.try_recv() { if let Ok(msg) = from_main.try_recv() {
match msg { match msg {
@ -98,7 +96,7 @@ pub fn port_proc(mut port: Box<dyn SerialPort>, to_main: Sender<Message>, from_m
period_send = true; period_send = true;
period_send_msg = msg; period_send_msg = msg;
} }
Message::PortPeriodStop=> { Message::PortPeriodStop => {
period_send = false; period_send = false;
} }
Message::PortPeriodDuration(value) => { Message::PortPeriodDuration(value) => {
@ -116,7 +114,7 @@ pub fn port_proc(mut port: Box<dyn SerialPort>, to_main: Sender<Message>, from_m
} }
} }
} }
if period_send && (last_send.elapsed() > period_timeout){ if period_send && (last_send.elapsed() > period_timeout) {
last_send = std::time::Instant::now(); last_send = std::time::Instant::now();
match port.write(period_send_msg.as_bytes()) { match port.write(period_send_msg.as_bytes()) {
Err(e) => to_main.send(Message::PortError(format!("{}", e).to_string())).unwrap(), Err(e) => to_main.send(Message::PortError(format!("{}", e).to_string())).unwrap(),