Skip to content

Commit

Permalink
Remove TSP Command Calls When Getting Info (#35)
Browse files Browse the repository at this point in the history
We are unsure of whether the info command will be done when the
instrument is in a TSP command mode. In TTI, the instrument could be in
a SCPI mode. In which case the instrument needs to have the language
switched before attempting to run TSP commands.
  • Loading branch information
esarver authored Dec 20, 2024
1 parent dfcca32 commit e3f0afc
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 36 deletions.
10 changes: 9 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,13 @@ Check [Keep a Changelog](http://keepachangelog.com/) for recommendations on how
Security -- in case of vulnerabilities.
-->

## [0.19.1]

### Fixed

- Don't call tsp commands in `get-info` because the `*LANG` of the instrument
might be set to something besides `TSP`

## [0.19.0]

### Added
Expand Down Expand Up @@ -113,7 +120,8 @@ Check [Keep a Changelog](http://keepachangelog.com/) for recommendations on how
- Using `read_password` instead of `prompt_password` of rpassword crate (TSP-517)

<!--Version Comparison Links-->
[Unreleased]: https://github.com/tektronix/tsp-toolkit-kic-lib/compare/v0.19.0..HEAD
[Unreleased]: https://github.com/tektronix/tsp-toolkit-kic-lib/compare/v0.19.1..HEAD
[0.19.1]: https://github.com/tektronix/tsp-toolkit-kic-lib/releases/tag/v0.19.1
[0.19.0]: https://github.com/tektronix/tsp-toolkit-kic-lib/releases/tag/v0.19.0
[0.18.4]: https://github.com/tektronix/tsp-toolkit-kic-lib/releases/tag/v0.18.4
[0.18.3]: https://github.com/tektronix/tsp-toolkit-kic-lib/releases/tag/v0.18.3
Expand Down
60 changes: 30 additions & 30 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "tsp-toolkit-kic-lib"
description = "A library specifically enabling communication to the Keithley product-line of instruments"
version = "0.19.0"
version = "0.19.1"
authors = ["Keithley Instruments, LLC"]
edition = "2021"
repository = "https://github.com/tektronix/tsp-toolkit-kic-lib"
Expand Down
8 changes: 4 additions & 4 deletions src/instrument/info.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! Define the trait and datatypes necessary to describe an instrument.
use minidom::Element;
use tracing::{instrument, trace};
use tracing::{debug, instrument, trace};

use crate::{error::Result, InstrumentError};
use std::{
Expand All @@ -11,8 +11,6 @@ use std::{

use crate::interface::connection_addr::ConnectionAddr;

use super::clear_output_queue;

/// The information about an instrument.
#[allow(clippy::module_name_repetitions)]
#[derive(serde::Serialize, Debug, Default, Clone, PartialEq, Eq, Hash)]
Expand Down Expand Up @@ -40,11 +38,13 @@ pub struct InstrumentInfo {
#[allow(clippy::module_name_repetitions)]
#[instrument(skip(rw))]
pub fn get_info<T: Read + Write + ?Sized>(rw: &mut T) -> Result<InstrumentInfo> {
debug!("Sending abort");
rw.write_all(b"abort\n")?;
std::thread::sleep(Duration::from_millis(100));
debug!("Sending *CLS");
rw.write_all(b"*CLS\n")?;
std::thread::sleep(Duration::from_millis(100));
clear_output_queue(rw, 1000, Duration::from_millis(1))?;
debug!("Sending *IDN?");
rw.write_all(b"*IDN?\n")?;
let mut info: Option<InstrumentInfo> = None;
for _ in 0..100 {
Expand Down
6 changes: 6 additions & 0 deletions src/instrument/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ pub use language::{CmdLanguage, Language};
pub use login::{Login, State};
pub use reset::Reset;
pub use script::Script;
use tracing::debug;

/// A marker trait that defines the traits any [`Instrument`] needs to have.
pub trait Instrument:
Expand All @@ -30,6 +31,10 @@ pub trait Instrument:

/// Read from a 'rw' until we are sure we have cleared the output queue.
///
/// # Warning
/// This functions calls a TSP command and therefore should not be used before
/// we know whether the instrument is in TSP mode (only applicable for TTI)
///
/// # Errors
/// Whatever can errors can occur with [`std::io::Read`], [`std::io::Write`] or
/// [`tsp_toolkit_kic_lib::interface::NonBlock`].
Expand All @@ -40,6 +45,7 @@ pub fn clear_output_queue<T: Read + Write + ?Sized>(
) -> Result<()> {
let timestamp = chrono::Utc::now().to_string();

debug!("Sending print({timestamp})");
rw.write_all(format!("print(\"{timestamp}\")\n").as_bytes())?;

let mut accumulate = String::new();
Expand Down

0 comments on commit e3f0afc

Please sign in to comment.