Skip to content

Commit

Permalink
Merge pull request pymodbus-dev#622 from riptideio/dev
Browse files Browse the repository at this point in the history
v2.5.1
  • Loading branch information
dhoomakethu authored Apr 1, 2021
2 parents 84424bb + c7a582b commit d212d17
Show file tree
Hide file tree
Showing 16 changed files with 226 additions and 102 deletions.
70 changes: 59 additions & 11 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ jobs:
name: ${{ matrix.task.name }} - ${{ matrix.os.name }} ${{ matrix.python.name }} ${{ matrix.arch.name }}
runs-on: ${{ matrix.os.runs-on }}
container: ${{ matrix.os.container[matrix.python.docker] }}
# present runtime seems to be about 1 minute 30 seconds
timeout-minutes: 10
strategy:
fail-fast: false
matrix:
Expand All @@ -30,7 +32,6 @@ jobs:
os:
- name: Linux
runs-on: ubuntu-latest
python_platform: linux
matrix: linux
container:
2.7: docker://python:2.7-buster
Expand All @@ -40,55 +41,67 @@ jobs:
3.9: docker://python:3.9-buster
pypy2: docker://pypy:2-jessie
pypy3: docker://pypy:3-stretch
# - name: Windows
# runs-on: windows-latest
# python_platform: win32
# matrix: windows
# - name: macOS
# runs-on: macos-latest
# python_platform: darwin
# matrix: macos
- name: macOS
runs-on: macos-latest
matrix: macos
- name: Windows
runs-on: windows-latest
matrix: windows
openssl:
x86: win32
x64: win64
python:
- name: CPython 2.7
tox: py27
action: 2.7
docker: 2.7
matrix: 2.7
implementation: cpython
- name: PyPy 2.7
tox: pypy27
action: pypy-2.7
docker: pypy2.7
matrix: 2.7
implementation: pypy
openssl_msvc_version: 2019
- name: CPython 3.6
tox: py36
action: 3.6
docker: 3.6
matrix: 3.6
implementation: cpython
- name: CPython 3.7
tox: py37
action: 3.7
docker: 3.7
matrix: 3.7
implementation: cpython
- name: CPython 3.8
tox: py38
action: 3.8
docker: 3.8
matrix: 3.8
implementation: cpython
- name: CPython 3.9
tox: py39
action: 3.9
docker: 3.9
matrix: 3.9
implementation: cpython
- name: PyPy 3.6
tox: pypy36
action: pypy-3.6
docker: pypy3.6
matrix: 3.6
implementation: pypy
openssl_msvc_version: 2019
- name: PyPy 3.7
tox: pypy37
action: pypy-3.7
docker: pypy3.7
matrix: 3.7
implementation: pypy
openssl_msvc_version: 2019
arch:
- name: x86
action: x86
Expand All @@ -105,6 +118,12 @@ jobs:
matrix: macos
arch:
matrix: x86
- os:
matrix: windows
python:
implementation: pypy
arch:
matrix: x64
env:
# Should match name above
JOB_NAME: ${{ matrix.task.name }} - ${{ matrix.os.name }} ${{ matrix.python.name }} ${{ matrix.arch.name }}
Expand All @@ -129,7 +148,37 @@ jobs:
pip install --upgrade pip setuptools wheel
pip install --upgrade tox
- uses: twisted/[email protected]
- name: Add PyPy Externals
if: ${{ matrix.os.matrix == 'windows' && matrix.python.implementation == 'pypy'}}
env:
PYPY_EXTERNALS_PATH: ${{ github.workspace }}/pypy_externals
shell: bash
run: |
echo $PYPY_EXTERNALS_PATH
mkdir --parents $(dirname $PYPY_EXTERNALS_PATH)
hg clone https://foss.heptapod.net/pypy/externals/ $PYPY_EXTERNALS_PATH
dir $PYPY_EXTERNALS_PATH
cd $PYPY_EXTERNALS_PATH && hg update win32_14x
echo "INCLUDE=$PYPY_EXTERNALS_PATH/include;$INCLUDE" >> $GITHUB_ENV
echo "LIB=$PYPY_EXTERNALS_PATH/lib;$LIB" >> $GITHUB_ENV
# echo "CL=${{ matrix.PYTHON.CL_FLAGS }}" >> $GITHUB_ENV
- name: Add Brew
if: ${{ matrix.os.matrix == 'macos' && matrix.python.implementation == 'pypy'}}
shell: bash
run: |
brew install [email protected] rust
echo "LDFLAGS=-L$(brew --prefix [email protected])/lib" >> $GITHUB_ENV
echo "CFLAGS=-I$(brew --prefix [email protected])/include" >> $GITHUB_ENV
- name: rustup
if: ${{ matrix.os.matrix == 'windows' && matrix.python.implementation == 'pypy'}}
shell: bash
run: |
rustup target add i686-pc-windows-msvc
- name: Test
env:
# When compiling Cryptography for PyPy on Windows there is a cleanup
# failure. This is CI, it doesn't matter.
PIP_NO_CLEAN: 1
run: |
tox -vv -e ${{ matrix.python.tox }}
- name: Coverage Processing
Expand Down Expand Up @@ -161,7 +210,6 @@ jobs:
os:
- name: Linux
runs-on: ubuntu-latest
python_platform: linux
matrix: linux
container:
3.8: docker://python:3.8-buster
Expand Down Expand Up @@ -195,6 +243,7 @@ jobs:
# Should match JOB_NAME below
name: ${{ matrix.task.name }} - ${{ matrix.os.name }} ${{ matrix.python.name }} ${{ matrix.arch.name }}
runs-on: ${{ matrix.os.runs-on }}
if: always()
needs:
- test
container: ${{ matrix.os.container[matrix.python.docker] }}
Expand All @@ -208,7 +257,6 @@ jobs:
os:
- name: Linux
runs-on: ubuntu-latest
python_platform: linux
matrix: linux
container:
3.8: docker://python:3.8-buster
Expand Down
7 changes: 7 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
version 2.5.1
----------------------------------------------------------
* Bug fix TCP Repl server.
* Support multiple UID's with REPL server.
* Support serial for URL (sync serial client)
* Bug fix/enhancements, close socket connections only on empty or invalid response

version 2.5.0
----------------------------------------------------------
* Support response types `stray` and `empty` in repl server.
Expand Down
2 changes: 1 addition & 1 deletion pymodbus/client/sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -649,7 +649,7 @@ def connect(self):
if self.socket:
return True
try:
self.socket = serial.Serial(port=self.port,
self.socket = serial.serial_for_url(self.port,
timeout=self.timeout,
bytesize=self.bytesize,
stopbits=self.stopbits,
Expand Down
3 changes: 2 additions & 1 deletion pymodbus/repl/server/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ def server(ctx, host, web_port, broadcast_support, repl, verbose):
case_sensitive=False),
help="Modbus framer to use")
@click.option("--modbus-port", default="5020", help="Modbus port")
@click.option("--modbus-unit-id", default=[1], multiple=True, help="Modbus unit id")
@click.option("--modbus-unit-id", default=[1], type=int,
multiple=True, help="Modbus unit id")
@click.option("--modbus-config", type=click.Path(exists=True),
help="Path to additional modbus server config")
@click.option("-r", "--randomize", default=0, help="Randomize every `r` reads."
Expand Down
15 changes: 8 additions & 7 deletions pymodbus/server/reactive/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,18 +135,19 @@ async def start_modbus_server(self, app):
:return:
"""
try:
if isinstance(self._modbus_server, ModbusSerialServer):
if hasattr(asyncio, "create_task"):
if hasattr(asyncio, "create_task"):
if isinstance(self._modbus_server, ModbusSerialServer):
app["modbus_serial_server"] = asyncio.create_task(
self._modbus_server.start())
app["modbus_server"] = asyncio.create_task(
self._modbus_server.serve_forever())
else:
app["modbus_server"] = asyncio.create_task(
self._modbus_server.serve_forever())
else:
if isinstance(self._modbus_server, ModbusSerialServer):
app["modbus_serial_server"] = asyncio.ensure_future(
self._modbus_server.start()
)
app["modbus_server"] = asyncio.ensure_future(
self._modbus_server.serve_forever())
app["modbus_server"] = asyncio.ensure_future(
self._modbus_server.serve_forever())

logger.info("Modbus server started")
except Exception as e:
Expand Down
13 changes: 7 additions & 6 deletions pymodbus/server/sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -327,16 +327,17 @@ def __init__(self, context, framer=None, identity=None,
self.control = ModbusControlBlock()
self.address = address or ("", Defaults.Port)
self.handler = handler or ModbusConnectedRequestHandler
self.ignore_missing_slaves = kwargs.get('ignore_missing_slaves',
self.ignore_missing_slaves = kwargs.pop('ignore_missing_slaves',
Defaults.IgnoreMissingSlaves)
self.broadcast_enable = kwargs.get('broadcast_enable',
self.broadcast_enable = kwargs.pop('broadcast_enable',
Defaults.broadcast_enable)

if isinstance(identity, ModbusDeviceIdentification):
self.control.Identity.update(identity)

socketserver.ThreadingTCPServer.__init__(self, self.address,
self.handler)
self.handler,
**kwargs)

def process_request(self, request, client):
""" Callback for connecting a new client thread
Expand Down Expand Up @@ -456,16 +457,16 @@ def __init__(self, context, framer=None, identity=None, address=None,
self.control = ModbusControlBlock()
self.address = address or ("", Defaults.Port)
self.handler = handler or ModbusDisconnectedRequestHandler
self.ignore_missing_slaves = kwargs.get('ignore_missing_slaves',
self.ignore_missing_slaves = kwargs.pop('ignore_missing_slaves',
Defaults.IgnoreMissingSlaves)
self.broadcast_enable = kwargs.get('broadcast_enable',
self.broadcast_enable = kwargs.pop('broadcast_enable',
Defaults.broadcast_enable)

if isinstance(identity, ModbusDeviceIdentification):
self.control.Identity.update(identity)

socketserver.ThreadingUDPServer.__init__(self,
self.address, self.handler)
self.address, self.handler, **kwargs)
# self._BaseServer__shutdown_request = True

def process_request(self, request, client):
Expand Down
5 changes: 3 additions & 2 deletions pymodbus/transaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,19 +217,20 @@ def execute(self, request):
"/Unable to decode response")
response = ModbusIOException(last_exception,
request.function_code)
self.client.close()
if hasattr(self.client, "state"):
_logger.debug("Changing transaction state from "
"'PROCESSING REPLY' to "
"'TRANSACTION_COMPLETE'")
self.client.state = (
ModbusTransactionState.TRANSACTION_COMPLETE)
self.client.close()

return response
except ModbusIOException as ex:
# Handle decode errors in processIncomingPacket method
_logger.exception(ex)
self.client.close()
self.client.state = ModbusTransactionState.TRANSACTION_COMPLETE
self.client.close()
return ex

def _retry_transaction(self, retries, reason,
Expand Down
2 changes: 1 addition & 1 deletion pymodbus/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def __str__(self):
return '[%s, version %s]' % (self.package, self.short())


version = Version('pymodbus', 2, 5, 0)
version = Version('pymodbus', 2, 5, 1, "rc1")

version.__name__ = 'pymodbus' # fix epydoc error

Expand Down
7 changes: 6 additions & 1 deletion requirements-tests.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ sqlalchemy>=1.1.15
#wsgiref>=0.1.2
verboselogs >= 1.5
tornado==4.5.3
Twisted[serial]>=20.3.0
# using platform_python_implementation rather than
# implementation_name for Python 2 support
Twisted[conch,serial]>=20.3.0; platform_python_implementation != "PyPy" or sys_platform != "win32"
# pywin32 isn't supported on pypy
# https://github.com/mhammond/pywin32/issues/1289
Twisted[conch]>=20.3.0; platform_python_implementation == "PyPy" and sys_platform == "win32"
zope.interface>=4.4.0
asynctest>=0.10.0
8 changes: 6 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,12 @@
'sphinx_rtd_theme',
'humanfriendly'],
'twisted': [
'twisted[serial] >= 20.3.0',
'pyasn1 >= 0.1.4',
# using platform_python_implementation rather than
# implementation_name for Python 2 support
'Twisted[conch,serial]>=20.3.0; platform_python_implementation != "PyPy" or sys_platform != "win32"',
# pywin32 isn't supported on pypy
# https://github.com/mhammond/pywin32/issues/1289
'Twisted[conch]>=20.3.0; platform_python_implementation == "PyPy" and sys_platform == "win32"',
],
'tornado': [
'tornado == 4.5.3'
Expand Down
Loading

0 comments on commit d212d17

Please sign in to comment.