diff --git a/ni-syscfg/Cargo.toml b/ni-syscfg/Cargo.toml index a62724d..ccad3f4 100644 --- a/ni-syscfg/Cargo.toml +++ b/ni-syscfg/Cargo.toml @@ -15,4 +15,8 @@ homepage = "https://github.com/WiresmithTech/ni-syscfg-rs" ni-syscfg-sys = { path = "../ni-syscfg-sys", version="20.5" } thiserror = "1" num-derive = "0.3" -num-traits = "0.2" \ No newline at end of file +num-traits = "0.2" + +[[bin]] +name = "ni-syscfg" +path = "bin/ni-syscfg.rs" \ No newline at end of file diff --git a/ni-syscfg/bin/ni-syscfg.rs b/ni-syscfg/bin/ni-syscfg.rs new file mode 100644 index 0000000..4344b16 --- /dev/null +++ b/ni-syscfg/bin/ni-syscfg.rs @@ -0,0 +1,19 @@ +use std::path::PathBuf; + +use ni_syscfg::SessionConfig; + +fn main() { + let session = SessionConfig::new() + .target("192.168.10.102") + .username("admin") + .unwrap() + .password("labview") + .unwrap() + .connect() + .expect("Session failed"); + session + .get_software_image(&PathBuf::from( + r"C:\Users\JamesMcNally\Documents\Delete\TestImage", + )) + .unwrap(); +} diff --git a/ni-syscfg/src/lib.rs b/ni-syscfg/src/lib.rs index 4bd024c..97cfbc3 100644 --- a/ni-syscfg/src/lib.rs +++ b/ni-syscfg/src/lib.rs @@ -5,6 +5,8 @@ mod hardware_filter; mod parameters; mod resources; mod session; +mod software; +pub(crate) mod types; pub use experts::ExpertType; pub use hardware_filter::{FilterMode, HardwareFilter}; diff --git a/ni-syscfg/src/software.rs b/ni-syscfg/src/software.rs new file mode 100644 index 0000000..1c55816 --- /dev/null +++ b/ni-syscfg/src/software.rs @@ -0,0 +1,65 @@ +//! Module for managing software on NI systems. +//! + +use std::ffi::CString; +use std::os::raw::c_char; +use std::path::Path; + +use ni_syscfg_sys::{NISysCfgCreateSystemImageAsFolder, NISysCfgSetSystemImageFromFolder2}; + +use crate::error::{api_status, Result}; +use crate::types::FfiBoolean; +use crate::Session; + +type Uuid = String; + +struct ImageInfo { + name: String, + id: Uuid, +} + +impl Session { + pub fn get_software_image(&self, image: &Path) -> Result<()> { + let handle = self.handle(); + let path = CString::new(image.as_os_str().to_string_lossy().as_ref())?; + let title = std::ptr::null(); + let id = std::ptr::null(); + let version = std::ptr::null(); + let description = std::ptr::null(); + + unsafe { + api_status(NISysCfgCreateSystemImageAsFolder( + *handle, + title, + id, + version, + description, + FfiBoolean::True as i32, + path.as_ptr(), + std::ptr::null(), + 0, + std::ptr::null_mut(), + FfiBoolean::False as i32, + ))?; + } + Ok(()) + } + pub fn set_software_image(&self, image: &Path) -> Result<()> { + let handle = self.handle(); + let path = CString::new(image.as_os_str().to_string_lossy().as_ref())?; + + unsafe { + api_status(NISysCfgSetSystemImageFromFolder2( + *handle, + FfiBoolean::True as i32, + path.as_ptr(), + std::ptr::null(), + 0, + std::ptr::null_mut(), + FfiBoolean::False as i32, + 2, + ))?; + } + Ok(()) + } +} diff --git a/ni-syscfg/src/types.rs b/ni-syscfg/src/types.rs new file mode 100644 index 0000000..8868c1a --- /dev/null +++ b/ni-syscfg/src/types.rs @@ -0,0 +1,11 @@ +//! Wrappers for a few utility types. +//! + +use ni_syscfg_sys::{NISysCfgBool_NISysCfgBoolFalse, NISysCfgBool_NISysCfgBoolTrue}; + +/// Wraps the constant values for true and false elements. +#[repr(i32)] +pub enum FfiBoolean { + True = NISysCfgBool_NISysCfgBoolTrue, + False = NISysCfgBool_NISysCfgBoolFalse, +}