#visa #dll #so #logging #ni-visa

visa-device-handler

a crate to handle NI-VISA connections and simplify its use

7 releases (2 stable)

new 1.1.0 Oct 21, 2024
1.0.0 Oct 2, 2024
0.6.3 Sep 8, 2024
0.5.1 Aug 29, 2024
0.2.0 Jul 30, 2024

#196 in Hardware support

Download history 231/week @ 2024-07-29 291/week @ 2024-08-05 20/week @ 2024-08-12 234/week @ 2024-08-26 452/week @ 2024-09-02 129/week @ 2024-09-09 56/week @ 2024-09-16 13/week @ 2024-09-23 163/week @ 2024-09-30 10/week @ 2024-10-07

245 downloads per month

MIT license

115KB
2K SLoC

Visa Device Handler

Based on the visa crate, this crate aims to provide a wrapper to allow multiple device connections and handling, and make the usage of NI-VISA easier to use.
The crate have mutex safe and non mutex safe mode.

The crate supports Windows, and sould support Linux and MacOS. but is being tested mainly on Windows.

Features

  • Core (core): The basic visa wrapper, simillar to the visa.h file.
  • Map (map): Adds the functionality of DeviceMap.
  • Mutex MAp (mutex_map): Adds the functionality of MutexDeviceMap.
  • All Complicated (all): Enables all features.

Example

Visa FFI

    let lib =
    let device_session = device.session;
    let cmd: &[u8] = "*IDN?\n".as_bytes();
    let mut ret_cnt = 0u32;
    let mut status = self.lib.viWrite(
        device_session,
        cmd.as_ptr(),
        u32::try_from(cmd.len()).map_err(|_| "u32 conversion error".to_string())?,
        &mut ret_cnt,
    );

Device Maps (Mutex and Non Mutex)


let sdm_result:SafeDeviceMap = SafeDeviceMap::init(None);
match sdm_result {
    Ok(mapper) => {
        mapper.connect_device("address_01".to_string());
        let data = mapper.query_from_device("name_01".to_string(),"cool funcation with args").unwrap();
        println!("got {} from the device",data);
        mapper.disconnect_device("name_01".to_string());
    }
    Err(e) => {/*print codes or anything */}
}

Tauri

The next Tauri project utilizes the crate as a peripheral for NI-VISA. https://github.com/LiorBuch/showcaser. this project uses React and Mantine as the UI, it's not failproof as it's just a POC.

Emulators

The next project creates an emulator of a visa device to be used with a TCP connection. As the project is not mine, i cant help much with its usage. One issue i spotted is that read operations always timeout, probably a missing termination character. Link to the project: https://github.com/bluehands/Open-SCPI-Protocol-Emulator/tree/main

Change Log 0.3.0

  • get_first_device now returns the device instead of printing.

  • get_first_device and find_all_devices now won't print unless debug boolean is true.

  • Fixed the error where the CString parses null terminators.

  • Added key error map in some functions.

    Change Log 0.3.1

Change Log 0.4.0

  • Fixed the disconnect issue.
  • Cleaned structure.

Change Log 0.5.0

  • All Device operations now use its address, more uniform approch since the address is always presented.
  • Linux is now enabled, yet not fully tested.
  • Added logger to the Map to save all the warnings and suppress them. (set to Debug by default).
  • status codes are now fully tested to give more accurate information.

Change Log 0.6.0

  • Fixed the problem where unable to use devices mapped since key include [\0] chars and address not.

  • Validated usage of TCP deviecs and emulators.

  • Added the option to define if a program should terminate by the Verbosity of the error, as some error codes can be warnings. defaults to Error level.

    Change Log 0.6.2

    • Updated the logger to V1.0.0, adds better log format.
    • Fixed the find all issue where it cant find more than one device without crashing.

    Change Log 0.6.3

    • Fixed the issue of buffer not cleaning when searching for devices.

Change Log 1.0.0

  • Changed SafeDeviceMap to MutexDeviceMap.
  • Added a non mutex variant of the map.

Change Log 1.1.0

  • Each map is now a feature to save space.
  • Crate now provide basic NI-VISA Library wrapper.
  • Dependencies update.
  • Each map can now close its RM and open a new one.

Dependencies

~0.9–12MB
~81K SLoC