Skip to content

Commit

Permalink
replace the call to serial.Serial with serial.serial_for_url (#386)
Browse files Browse the repository at this point in the history
* replace the call to Serial.serial with serial.serial_for_url, in order
to support loop:// and other url-types supported in pyserial (>3.0)

* documentation update

* initial test-addition

* fix the testsuite

* add conditional skip if PySerial is not found

* add pyserial as package avialable for the test environment

* change extra package installation

* Update CHNAGES file

* implement code-review changes
  • Loading branch information
LongnoseRob authored Jul 29, 2023
1 parent dc58253 commit 8016ec0
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 6 deletions.
1 change: 1 addition & 0 deletions CHANGES
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ PyVISA-py Changelog
0.7.1 (unreleased)
------------------

- addd URL-support to ASLR devices PR #386
- add support for GPIB secondary addresses
- fix missing sock.close() in rpc _connect()

Expand Down
5 changes: 3 additions & 2 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,10 @@ steps:
source $HOME/miniconda3/bin/activate
echo Activate environment
call conda activate test_
echo Install project
echo Install project and required dependencies
pip install git+https://github.com/pyvisa/pyvisa.git#egg=pyvisa
pip install -e .
pip install -e .[serial]
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)

0 comments on commit 8016ec0

Please sign in to comment.