Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Async operations #19

Open
TsuITOAR opened this issue Sep 5, 2023 · 3 comments
Open

Async operations #19

TsuITOAR opened this issue Sep 5, 2023 · 3 comments
Labels
enhancement New feature or request help wanted Extra attention is needed

Comments

@TsuITOAR
Copy link
Owner

TsuITOAR commented Sep 5, 2023

This crate wraps two async operations, async_read and async_write, they rely on Callback added to EventIoCompletion event that VISA is listening to.

There are several aspects that need to be aware of and should be improved:

  • Under some circumstances that are unclear, the callback would not be called even the IO is completed, this happens occasionally by running tests in this repo on my machine.
  • If there are other callback installed by user, and the callback return SuccessNchain internally to VISA, althought it should not be possible only use safe API provided, not for the unsafe functions. So the SuccessNchain (VI_SUCCESS_NCHAIN) will tell VISA not to invoke other callbacks installed, which will cause a permanent wait.
  • The Future contains the ref of the buf passed to these two async functions, so they are not Sync and Send.
    • Seems that it is common for async io to hold reference to buffer

The cause of the first problem is not clear, it might be related with running multiple VISA program synchronously, use cargo t --jobs 1 can usually pass all tests, without it, a function of the tests will not quit sometimes. Another is associated with the Waker mechanism of Rust future system.

They might be solved by adding another Waker that wakes the futures after some time no matter what.
I'm not familiar with low level async programing design and not sure if there are better solutions, any help would be grateful.

@TsuITOAR TsuITOAR added enhancement New feature or request help wanted Extra attention is needed labels Sep 5, 2023
@dr-kernel
Copy link

Something that's not entirely clear from your readme is whether the NI_VISA library is required, or will libvisa work as well?

I ask this because when trying to use async_write using libvisa and i get:

  = note: /build/private/cargo-target/release/deps/libvisa_rs-de0f39bbca939597.rlib(visa_rs-de0f39bbca939597.visa_rs.bcfb2d0a6785fd0b-cgu.02.rcgu.o): In function `visa_rs::async_
io::AsyncIoHandler::new':
          visa_rs.bcfb2d0a6785fd0b-cgu.02:(.text._ZN7visa_rs8async_io14AsyncIoHandler3new17h212d79d7ae1c5689E+0x221): undefined reference to `viInstallHandler'
          /build/private/cargo-target/release/deps/libvisa_rs-de0f39bbca939597.rlib(visa_rs-de0f39bbca939597.visa_rs.bcfb2d0a6785fd0b-cgu.02.rcgu.o): In function `<visa_rs::async
_io::AsyncIoHandler as core::ops::drop::Drop>::drop':
          visa_rs.bcfb2d0a6785fd0b-cgu.02:(.text._ZN75_$LT$visa_rs..async_io..AsyncIoHandler$u20$as$u20$core..ops..drop..Drop$GT$4drop17h84ef7ecf876e51e3E+0xe4): undefined reference to `viTerminate'
          visa_rs.bcfb2d0a6785fd0b-cgu.02:(.text._ZN75_$LT$visa_rs..async_io..AsyncIoHandler$u20$as$u20$core..ops..drop..Drop$GT$4drop17h84ef7ecf876e51e3E+0x1dc): undefined reference to `viUninstallHandler'
          /build/private/cargo-target/release/deps/libvisa_rs-de0f39bbca939597.rlib(visa_rs-de0f39bbca939597.visa_rs.bcfb2d0a6785fd0b-cgu.05.rcgu.o): In function `visa_rs::instru
ment::Instrument::visa_write_async':
          visa_rs.bcfb2d0a6785fd0b-cgu.05:(.text._ZN7visa_rs10instrument10Instrument16visa_write_async17h4a91cc3f7856106eE+0x24): undefined reference to `viWriteAsync'
          collect2: error: ld returned 1 exit status

Appreciate you're feedback on this.
~Dustin

@TsuITOAR
Copy link
Owner Author

TsuITOAR commented Nov 8, 2023

Something that's not entirely clear from your readme is whether the NI_VISA library is required, or will libvisa work as well?

I ask this because when trying to use async_write using libvisa and i get:

  = note: /build/private/cargo-target/release/deps/libvisa_rs-de0f39bbca939597.rlib(visa_rs-de0f39bbca939597.visa_rs.bcfb2d0a6785fd0b-cgu.02.rcgu.o): In function `visa_rs::async_
io::AsyncIoHandler::new':
          visa_rs.bcfb2d0a6785fd0b-cgu.02:(.text._ZN7visa_rs8async_io14AsyncIoHandler3new17h212d79d7ae1c5689E+0x221): undefined reference to `viInstallHandler'
          /build/private/cargo-target/release/deps/libvisa_rs-de0f39bbca939597.rlib(visa_rs-de0f39bbca939597.visa_rs.bcfb2d0a6785fd0b-cgu.02.rcgu.o): In function `<visa_rs::async
_io::AsyncIoHandler as core::ops::drop::Drop>::drop':
          visa_rs.bcfb2d0a6785fd0b-cgu.02:(.text._ZN75_$LT$visa_rs..async_io..AsyncIoHandler$u20$as$u20$core..ops..drop..Drop$GT$4drop17h84ef7ecf876e51e3E+0xe4): undefined reference to `viTerminate'
          visa_rs.bcfb2d0a6785fd0b-cgu.02:(.text._ZN75_$LT$visa_rs..async_io..AsyncIoHandler$u20$as$u20$core..ops..drop..Drop$GT$4drop17h84ef7ecf876e51e3E+0x1dc): undefined reference to `viUninstallHandler'
          /build/private/cargo-target/release/deps/libvisa_rs-de0f39bbca939597.rlib(visa_rs-de0f39bbca939597.visa_rs.bcfb2d0a6785fd0b-cgu.05.rcgu.o): In function `visa_rs::instru
ment::Instrument::visa_write_async':
          visa_rs.bcfb2d0a6785fd0b-cgu.05:(.text._ZN7visa_rs10instrument10Instrument16visa_write_async17h4a91cc3f7856106eE+0x24): undefined reference to `viWriteAsync'
          collect2: error: ld returned 1 exit status

Appreciate you're feedback on this. ~Dustin

Hi, in principle any visa library should work if it follows the specifications.
It seems that libvisa uses the specification distributed in 06-18-2012, while I generate the prebindings in visa-sys based on distribution in 10-30-2020, maybe that's the problem. You can try rebinding by setting env var INCLUDE_PATH_VAR and open its bindgen feature (check the build.rs of visa-sys).

EDIT: NI-visa use the visa version 5.8 while libvisa using 5.1, there should be no version problem since NI VISA works fine.

BTW, do all methods fail or just this one?

@dr-kernel
Copy link

dr-kernel commented Nov 8, 2023

I have only tried async_write and write_all (from the example). write_all compiles and links correctly.
I should also note that I have to create a symlink of libvisa -> libvisa64 for linking to work since that name is hard coded, it would be nice if this was a env_var or flag as part of the build.
I have found rsvisa, i could also try and see if that provides the bindings.

Interestingly those functions do exist in the visa.h file that the source (libvisa-dev) provides. I'm curious why those methods don't end up in the compiled .so.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants