Skip to content

Make bytes_in_buffer and flush() work - #219

Open
BT8298 wants to merge 4 commits into
pyvisa:mainfrom
BT8298:main
Open

Make bytes_in_buffer and flush() work#219
BT8298 wants to merge 4 commits into
pyvisa:mainfrom
BT8298:main

Conversation

@BT8298

@BT8298 BT8298 commented Jun 11, 2026

Copy link
Copy Markdown
Contributor

Made VI_ATTR_ASRL_AVAIL_NUM report the number of bytes in the internal receive buffer, not just the default of 0 all the time. Also implemented some of viFlush.

All tests pass.

Should fix #93.

Could be a stepping stone for #50 to actually clear the buffers like viClear, now that flush is available.

Worked around #82 by calling the new flush function after each test to clear the internal resource manager's buffer after every test. This is why I made the serial tests dependent on the flush buffer test.

PyVISA-sim would always return the default value of "0" for
VI_ATTR_ASRL_AVAIL_NUM. Now it reads the internal buffer attribute of
the device class. Similarly, flush clears the internal buffers
accordingly.
@codecov

codecov Bot commented Jun 11, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 97.91667% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 87.95%. Comparing base (9146c1a) to head (8d2ea0f).

Files with missing lines Patch % Lines
pyvisa_sim/highlevel.py 84.61% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #219      +/-   ##
==========================================
+ Coverage   86.78%   87.95%   +1.17%     
==========================================
  Files          19       19              
  Lines        1052     1146      +94     
  Branches      114      118       +4     
==========================================
+ Hits          913     1008      +95     
+ Misses        104      103       -1     
  Partials       35       35              
Flag Coverage Δ
unittests 87.95% <97.91%> (+1.17%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@MatthieuDartiailh

Copy link
Copy Markdown
Member

@BT8298 could you add some additional test to better test the added features (including error paths).

@BT8298

BT8298 commented Jun 12, 2026

Copy link
Copy Markdown
Contributor Author

Will add more tests when I have some time. Probably by Wednesday next week.

@BT8298
BT8298 force-pushed the main branch 2 times, most recently from 6f22c0f to 201ad25 Compare June 14, 2026 22:46
Add more tests for flush() method. Remove pytest-dependency; access
device buffers directly instead for tests. Buffer operations acting on
the VISA formatted I/O buffers should not be accepted, because
PyVISA-sim does not implement those buffers.
@BT8298

BT8298 commented Jun 14, 2026

Copy link
Copy Markdown
Contributor Author

What do you think of using of the device I/O buffers as the VISA low-level I/O buffers when doing buffer operations? Do you foresee it causing any issues?

@MatthieuDartiailh

Copy link
Copy Markdown
Member

To be honest I do not have a very clear mental model of how those differenr buffers work together.
But your suggestion is worth trying and checking if it emulates accurately real devices behavior.

@BT8298

BT8298 commented Jun 16, 2026

Copy link
Copy Markdown
Contributor Author

I don't personally own any serial instruments, so I won't be able to test on a real device soon. Elaborating on my previous comment:

From my understanding, PyVISA-sim does not implement the formatted read buffer nor the low-level receive buffer as seen in the figures on this NI-VISA page. However, we have access to the buffers on the (emulated) device itself, which is unique compared to a normal VISA library implementation. In this patch I'm using the device buffers as the low level receive buffer, which is a deviation from the VISA specification.

The question that still stands is whether this non-compliant treatment of the low level receive buffer could result in simulated instruments that use such code paths behaving differently from real instruments.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bytes_in_buffers does not work in simulation

2 participants