Open Devlyn-Nelson opened 2 weeks ago
I should say I am willing to do work in order to fix this. I have a workaround currently working. there are 2 problems:
wrap_raw_error_in_unsafe
any status code greater than 0 is considered Success but 0xBFFF0011
is not a success condition.repr
for ErrorCode
fails to translate 0xBFFF0011
into a valid variant even though it is valid.Thanks for your response, I will check this problem ASAP.
On my PC, it returns the Error ErrorRsrcNfound
(error code 0xBFFF0011
) as expected, this problem might be related to your specific environment.
0xBFFF0011
is a negative number, so it should match the Error arm in the macro.
Here are codes that I tried.
use std::ffi::CString;
use visa_rs::{prelude::*, vs::ViStatus};
fn main() -> visa_rs::Result<()> {
let res = CString::new("TCPIP0::192.168.3.1::hislip0::INSTR")
.unwrap()
.into();
let r = DefaultRM::new()?.open(&res, AccessMode::NO_LOCK, TIMEOUT_IMMEDIATE);
if let Result::Err(e) = r {
eprintln!("Returned error in rust: `{}`", e);
eprintln!("Error code: `{:#0X}`", e.0 as ViStatus);
}
Ok(())
}
Output
Returned error in rust: `Insufficient location information or the device or resource is not present in the system.`
Error code: `0xBFFF0011`
Feel free to ask if you want more help.
When a device is not present in the system and I try to connect via TCP using
DefaultRM::new()?.open()
, visa-rs panics with a 0xBFFF0011 error which should just be returned as anvisa-rs::Error
because the function already returns a result contain that error type. The root cause of the panic is anunwrap
after atry_into
in thewrap_raw_error_in_unsafe
macro.