Skip to content

Commit

Permalink
Show error if example is run without support files. (#2189)
Browse files Browse the repository at this point in the history
  • Loading branch information
janiversen committed Jun 18, 2024
1 parent 5cd3ae5 commit 50814a7
Show file tree
Hide file tree
Showing 11 changed files with 101 additions and 12 deletions.
10 changes: 9 additions & 1 deletion examples/client_async.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,16 @@
"""
import asyncio
import logging
import sys

import helper

try:
import helper
except ImportError:
print("*** ERROR --> THIS EXAMPLE needs the example directory, please see \n\
https://pymodbus.readthedocs.io/en/latest/source/examples.html\n\
for more information.")
sys.exit(-1)

import pymodbus.client as modbusClient
from pymodbus import ModbusException
Expand Down
9 changes: 8 additions & 1 deletion examples/client_async_calls.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,16 @@
"""
import asyncio
import logging
import sys

import client_async

try:
import client_async
except ImportError:
print("*** ERROR --> THIS EXAMPLE needs the example directory, please see \n\
https://pymodbus.readthedocs.io/en/latest/source/examples.html\n\
for more information.")
sys.exit(-1)

_logger = logging.getLogger(__file__)
_logger.setLevel("DEBUG")
Expand Down
11 changes: 10 additions & 1 deletion examples/client_calls.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,17 @@
./server_async.py
"""
import logging
import sys


try:
import client_sync
except ImportError:
print("*** ERROR --> THIS EXAMPLE needs the example directory, please see \n\
https://pymodbus.readthedocs.io/en/latest/source/examples.html\n\
for more information.")
sys.exit(-1)

import client_sync


_logger = logging.getLogger(__file__)
Expand Down
10 changes: 9 additions & 1 deletion examples/client_payload.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,17 @@
Works out of the box together with payload_server.py
"""
import asyncio
import sys
from collections import OrderedDict

import client_async

try:
import client_async
except ImportError:
print("*** ERROR --> THIS EXAMPLE needs the example directory, please see \n\
https://pymodbus.readthedocs.io/en/latest/source/examples.html\n\
for more information.")
sys.exit(-1)

from pymodbus.constants import Endian
from pymodbus.payload import BinaryPayloadBuilder, BinaryPayloadDecoder
Expand Down
10 changes: 9 additions & 1 deletion examples/client_sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,16 @@
"""
import logging
import sys

import helper

try:
import helper
except ImportError:
print("*** ERROR --> THIS EXAMPLE needs the example directory, please see \n\
https://pymodbus.readthedocs.io/en/latest/source/examples.html\n\
for more information.")
sys.exit(-1)

import pymodbus.client as modbusClient
from pymodbus import ModbusException
Expand Down
10 changes: 9 additions & 1 deletion examples/modbus_forwarder.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,16 @@
"""
import asyncio
import logging
import sys

import helper

try:
import helper
except ImportError:
print("*** ERROR --> THIS EXAMPLE needs the example directory, please see \n\
https://pymodbus.readthedocs.io/en/latest/source/examples.html\n\
for more information.")
sys.exit(-1)

from pymodbus.client import ModbusTcpClient
from pymodbus.datastore import ModbusServerContext
Expand Down
10 changes: 9 additions & 1 deletion examples/server_async.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,16 @@
"""
import asyncio
import logging
import sys

import helper

try:
import helper
except ImportError:
print("*** ERROR --> THIS EXAMPLE needs the example directory, please see \n\
https://pymodbus.readthedocs.io/en/latest/source/examples.html\n\
for more information.")
sys.exit(-1)

from pymodbus import __version__ as pymodbus_version
from pymodbus.datastore import (
Expand Down
10 changes: 9 additions & 1 deletion examples/server_callback.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,16 @@
"""
import asyncio
import logging
import sys

import server_async

try:
import server_async
except ImportError:
print("*** ERROR --> THIS EXAMPLE needs the example directory, please see \n\
https://pymodbus.readthedocs.io/en/latest/source/examples.html\n\
for more information.")
sys.exit(-1)

from pymodbus.datastore import (
ModbusSequentialDataBlock,
Expand Down
11 changes: 10 additions & 1 deletion examples/server_payload.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,17 @@
"""
import asyncio
import logging
import sys


try:
import server_async
except ImportError:
print("*** ERROR --> THIS EXAMPLE needs the example directory, please see \n\
https://pymodbus.readthedocs.io/en/latest/source/examples.html\n\
for more information.")
sys.exit(-1)

import server_async

from pymodbus.constants import Endian
from pymodbus.datastore import (
Expand Down
12 changes: 10 additions & 2 deletions examples/server_sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,17 @@
a lot slower.
"""
import logging
import sys

import helper
import server_async

try:
import helper
import server_async
except ImportError:
print("*** ERROR --> THIS EXAMPLE needs the example directory, please see \n\
https://pymodbus.readthedocs.io/en/latest/source/examples.html\n\
for more information.")
sys.exit(-1)

# --------------------------------------------------------------------------- #
# import the various client implementations
Expand Down
10 changes: 9 additions & 1 deletion examples/server_updating.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,16 @@
"""
import asyncio
import logging
import sys

import server_async

try:
import server_async
except ImportError:
print("*** ERROR --> THIS EXAMPLE needs the example directory, please see \n\
https://pymodbus.readthedocs.io/en/latest/source/examples.html\n\
for more information.")
sys.exit(-1)

from pymodbus.datastore import (
ModbusSequentialDataBlock,
Expand Down

0 comments on commit 50814a7

Please sign in to comment.