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

replace the call to serial.Serial with serial.serial_for_url #386

Merged
merged 9 commits into from
Jul 29, 2023
3 changes: 3 additions & 0 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,12 @@ steps:
source $HOME/miniconda3/bin/activate
echo Activate environment
call conda activate test_
echo Install support packages
pip install pyserial
echo Install project
pip install git+https://github.com/pyvisa/pyvisa.git#egg=pyvisa
pip install -e .
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could do pip install -e .[serial] instead with a comment explining why we install this extra.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you would prefer it that way, I will change it.


displayName: "Install dependencies"

- script: |
Expand Down
10 changes: 10 additions & 0 deletions docs/source/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,16 @@ Currently Pyvisa-py support the following resources:
- USB INSTR
- USB RAW

Note:
ASRL INSTR supports also URL Handlers like

- loop:// --> ASLRloop://::INSTR
- socket:// --> ASRLsocket://::INSTR

These entries will not be listed during the device discovery `rm.list_resources()`.
For further details see https://pyserial.readthedocs.io/en/latest/url_handlers.html


You can report a problem or ask for features in the `issue tracker`_.
Or get the code in GitHub_.

Expand Down
6 changes: 2 additions & 4 deletions pyvisa_py/serial.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,8 @@ def get_low_level_info(cls) -> str:
return "via PySerial (%s)" % ver

def after_parsing(self) -> None:
cls = serial.Serial

self.interface = cls(
port=("COM" if IS_WIN else "") + self.parsed.board,
self.interface = serial.serial_for_url(
("COM" if IS_WIN else "") + self.parsed.board,
timeout=self.timeout,
write_timeout=self.timeout,
)
Expand Down
43 changes: 43 additions & 0 deletions pyvisa_py/testsuite/test_serial.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
"""Test creating a resource manager using PyVISA-Py as a backend.


:copyright: 2014-2023 by PyVISA-py Authors, see AUTHORS for more details.
:license: MIT, see LICENSE for more details.

"""
import pytest
from pyvisa import ResourceManager
from pyvisa.testsuite import BaseTestCase


class TestSerial(BaseTestCase):
"""Test generic property of PyVisaLibrary."""

serial = pytest.importorskip("serial", reason="PySerial not installed")

def test_serial(self):
"""Test loop://"""
msg = b"Test01234567890"

available = ["loop://"]
expected = []
exp_missing = []
missing = {}

rm = ResourceManager("@py")
try:
dut = rm.open_resource("ASRLloop://::INSTR")
print("opened")
dut.timeout = 3000
dut.read_termination = "\r\n"
dut.write_termination = "\r\n"
dut.write(str(msg))
ret_val = dut.read()
if str(msg) == ret_val:
expected = ["loop://"]

except Exception:
exp_missing = ["loop://"]

assert sorted(available) == sorted(expected)
assert sorted(missing) == sorted(exp_missing)
Loading