Make bytes_in_buffer and flush() work - #219
Conversation
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 Report❌ Patch coverage is
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
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
@BT8298 could you add some additional test to better test the added features (including error paths). |
|
Will add more tests when I have some time. Probably by Wednesday next week. |
6f22c0f to
201ad25
Compare
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.
|
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? |
|
To be honest I do not have a very clear mental model of how those differenr buffers work together. |
|
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. |
Made
VI_ATTR_ASRL_AVAIL_NUMreport the number of bytes in the internal receive buffer, not just the default of 0 all the time. Also implemented some ofviFlush.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.