Skip to content

Instantly share code, notes, and snippets.

@aep
Last active December 14, 2019 13:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aep/03db148e01796316018ca241f6825d88 to your computer and use it in GitHub Desktop.
Save aep/03db148e01796316018ca241f6825d88 to your computer and use it in GitHub Desktop.
dump T-962 temperature and ut181a temperature at the same time into a csv for matlab
[package]
name = "oven"
version = "0.1.0"
authors = ["Arvid E. Picciani <aep@exys.org>"]
edition = "2018"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
serialport = "3.3"
ut181a = "0.2.1"
hid = "0.4.1"
use serialport::prelude::*;
use std::io::BufReader;
use std::io::prelude::*;
use std::time::Duration;
use ut181a::{Dmm, Measurement};
use std::sync::{Arc, Mutex};
fn main() {
let mut settings: SerialPortSettings = Default::default();
settings.baud_rate = 115200;
settings.timeout = Duration::from_secs(10);
let dmmtemp = Arc::new(Mutex::new(0.0));
spawn_dmm(dmmtemp.clone());
let sp = serialport::open_with_settings("/dev/ttyUSB0", &settings).unwrap();
let mut reader = BufReader::new(sp);
let mut index = 0;
loop {
index += 1;
let mut buffer = String::new();
reader.read_line(&mut buffer).unwrap();
let line = buffer.split(",").collect::<Vec<&str>>();
if line.len() < 10 {
continue;
}
let tc_left : f32 = line[1].trim().parse().unwrap();
let tc_right : f32 = line[2].trim().parse().unwrap();
let tc_cold : f32 = line[9].trim().parse().unwrap();
println!("{}, {},{},{},{}", index, tc_left, tc_right, tc_cold, dmmtemp.lock().unwrap());
}
}
fn spawn_dmm(val: Arc<Mutex<f32>> ) {
std::thread::spawn(move ||{
let manager = hid::init().unwrap();
for device in manager.find(Some(0x10C4), Some(0xEA80)) {
let mut dmm = Dmm::new(device.open().unwrap()).unwrap();
dmm.monitor_on().unwrap();
loop {
if let Ok(Measurement::Normal(nm)) = dmm.get_measurement() {
*(val.lock().unwrap()) = nm.main.value;
}
}
};
});
}
C=csvread('/tmp/k1.csv');
T=C(:,1);
L=C(:,2);
R=C(:,3);
M=C(:,5);
plot(T,L,T,R,T,M)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment