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.
## Motivation
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.
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.
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
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
```
set baudrate 115200
set databit 8
set parity 0 // None
set stopbit 1
```
### 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
```
Supportted settings: `baudrate`, `databit`, `parity`, `stopbit`, `flowcontrol`, `period`.
1. `baudrate`: Change baudrate. Support any value.
2. `databit`: Change databit. Support value: 5, 6, 7, 8.
3. `parity`: Change parity. Support value: 0: None, 1: Odd, 2: Even.
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.
## feature list
port function
## Feature list
- [x] open port
- [x] close 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
- [ ] save output to port
- [ ] view recived data as hex
ui function
- [ ] show recived data as hex
- [ ] clean command
- [ ] send hex periodic

View File

@ -15,9 +15,8 @@ use crate::port::*;
use gtk::prelude::TextViewExt;
use gtk::prelude::LabelExt;
use std::str;
use std::{str, env};
use std::time::Duration;
use std::num::ParseIntError;
fn main() {
let application = gtk::Application::new(
@ -126,8 +125,8 @@ fn build_ui(application: &gtk::Application) {
let tmp = ui_hex_scroll.vadjustment();
tmp.set_value(tmp.upper());
}
Message::UiCleanReceiveMsg => ui_receive_view.buffer().unwrap().set_text(""),
Message::UiCleanLog => ui_log_view.buffer().unwrap().set_text(""),
Message::UiClearReceiveMsg => ui_receive_view.buffer().unwrap().set_text(""),
Message::UiClearLog => ui_log_view.buffer().unwrap().set_text(""),
Message::UiShowLog => ui_log_window.show(),
Message::UiHideLog => ui_log_window.hide(),
Message::UiShowHex => ui_hex_window.show(),
@ -204,9 +203,9 @@ fn process_cmd(command: String, to_ui: glib::Sender<Message>, gui2main_tx: Sende
"loopend" => {
gui2main_tx.send(Message::MainCmdStopPeriod).unwrap();
}
"clean" => {
to_ui.send(Message::UiCleanReceiveMsg).unwrap();
to_ui.send(Message::UiCleanLog).unwrap();
"clear" => {
to_ui.send(Message::UiClearReceiveMsg).unwrap();
to_ui.send(Message::UiClearLog).unwrap();
}
"show" => {
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 {
if let Ok(msg) = rx.try_recv() {
match msg {
Message::UiCleanReceiveMsg => {}
Message::UiClearReceiveMsg => {}
Message::MainCmdOpen(arg) => {
if port_status_open {
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>();
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();
ui_upd.send(Message::UiUpdateStatusBarCom(default_com_port.clone())).unwrap();
match port_open(port_name, port_default_config) {
Ok(port) => {
port_status_open = true;

View File

@ -1,5 +1,4 @@
use std::sync::mpsc::{Sender, Receiver};
use std::env;
use serialport::{SerialPort, DataBits, Parity, FlowControl, StopBits};
use std::time::Duration;
@ -7,8 +6,8 @@ use std::time::Duration;
pub enum Message {
UiUpdateLog(String),
UiUpdateReceiveMsg(Vec<u8>),
UiCleanReceiveMsg,
UiCleanLog,
UiClearReceiveMsg,
UiClearLog,
UiShowLog,
UiHideLog,
UiShowHex,
@ -55,9 +54,8 @@ pub struct PortConfig {
}
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(prelude.to_owned() + &port, config.baud_rate)
let port_builder = serialport::new(port, config.baud_rate)
.data_bits(config.data_bits)
.parity(config.parity)
.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_send_msg = String::new();
let mut last_send = std::time::Instant::now();
to_main.send(Message::PortPeriodDuration(100));
to_main.send(Message::PortPeriodDuration(100)).unwrap();
loop {
if let Ok(msg) = from_main.try_recv() {
match msg {