Skip to content

Commit

Permalink
try #2
Browse files Browse the repository at this point in the history
  • Loading branch information
janiversen committed Oct 20, 2022
1 parent 6d1eec5 commit 9356d6b
Show file tree
Hide file tree
Showing 56 changed files with 109 additions and 139 deletions.
2 changes: 1 addition & 1 deletion examples/client_async.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@
The corresponding server must be started before e.g. as:
python3 server_sync.py
"""
import os
import asyncio
import logging
import os

# --------------------------------------------------------------------------- #
# import the various client implementations
Expand Down
2 changes: 1 addition & 1 deletion examples/client_async_basic_calls.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
import asyncio
import logging

from examples.helper import get_commandline
from examples.client_async import run_async_client, setup_async_client
from examples.helper import get_commandline


_logger = logging.getLogger()
Expand Down
4 changes: 2 additions & 2 deletions examples/client_async_extended_calls.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,8 @@
import asyncio
import logging

from examples.helper import get_commandline
from examples.client_async import run_async_client, setup_async_client

from examples.helper import get_commandline
from pymodbus.diag_message import (
ChangeAsciiInputDelimiterRequest,
ClearCountersRequest,
Expand All @@ -54,6 +53,7 @@
ReportSlaveIdRequest,
)


_logger = logging.getLogger()

UNIT = 0x01
Expand Down
2 changes: 1 addition & 1 deletion examples/client_payload.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
Works out of the box together with payload_server.py
"""
from collections import OrderedDict
import logging
from collections import OrderedDict

from pymodbus.client import ModbusTcpClient as ModbusClient
from pymodbus.constants import Endian
Expand Down
2 changes: 1 addition & 1 deletion examples/client_sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
The corresponding server must be started before e.g. as:
python3 server_sync.py
"""
import os
import logging
import os

# --------------------------------------------------------------------------- #
# import the various client implementations
Expand Down
2 changes: 1 addition & 1 deletion examples/client_sync_basic_calls.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
"""
import logging

from examples.helper import get_commandline
from examples.client_sync import run_sync_client, setup_sync_client
from examples.helper import get_commandline


_logger = logging.getLogger()
Expand Down
3 changes: 1 addition & 2 deletions examples/client_sync_extended_calls.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,8 @@
"""
import logging

from examples.helper import get_commandline
from examples.client_sync import run_sync_client, setup_sync_client

from examples.helper import get_commandline
from pymodbus.diag_message import (
ChangeAsciiInputDelimiterRequest,
ClearCountersRequest,
Expand Down
8 changes: 4 additions & 4 deletions examples/common/custom_synchronous_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,6 @@ def decode(self, data):
"""
import logging

from .custom_message import ( # pylint: disable=relative-beyond-top-level
CustomModbusRequest,
)

from pymodbus.datastore import (
ModbusSequentialDataBlock,
ModbusServerContext,
Expand All @@ -70,6 +66,10 @@ def decode(self, data):
from pymodbus.server import StartTcpServer
from pymodbus.version import version

from .custom_message import ( # pylint: disable=relative-beyond-top-level
CustomModbusRequest,
)


# --------------------------------------------------------------------------- #
# configure the service logging
Expand Down
10 changes: 6 additions & 4 deletions examples/common/performance.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,23 @@
The following is an quick performance check of the synchronous
modbus client.
"""
from concurrent.futures import ThreadPoolExecutor as eWorker, as_completed

# --------------------------------------------------------------------------- #
# import the necessary modules
# --------------------------------------------------------------------------- #
import logging
import os
from threading import Lock, Thread as tWorker
from concurrent.futures import ThreadPoolExecutor as eWorker
from concurrent.futures import as_completed
from threading import Lock
from threading import Thread as tWorker
from time import time

from pymodbus.client import ModbusTcpClient


try:
from multiprocessing import Process as mWorker, log_to_stderr
from multiprocessing import Process as mWorker
from multiprocessing import log_to_stderr
except ImportError:
log_to_stderr = logging.getLogger

Expand Down
14 changes: 6 additions & 8 deletions examples/contrib/concurrent_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,20 @@
a high level of concurrency by using worker threads/processes to handle
writing/reading from one or more client handles at once.
"""
from collections import namedtuple
from concurrent.futures import Future
import itertools

# -------------------------------------------------------------------------- #
# import system libraries
# -------------------------------------------------------------------------- #
import logging
import multiprocessing
from multiprocessing import (
Event as mEvent,
Process as mProcess,
Queue as mQueue,
)
from queue import Queue as qQueue
import threading
from collections import namedtuple
from concurrent.futures import Future
from multiprocessing import Event as mEvent
from multiprocessing import Process as mProcess
from multiprocessing import Queue as mQueue
from queue import Queue as qQueue
from threading import Event, Thread

# -------------------------------------------------------------------------- #
Expand Down
2 changes: 1 addition & 1 deletion examples/contrib/message_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import logging
from optparse import OptionParser # pylint: disable=deprecated-module

import pymodbus.diag_message as modbus_diag
from pymodbus.bit_read_message import (
ReadCoilsRequest,
ReadCoilsResponse,
Expand All @@ -26,7 +27,6 @@
WriteSingleCoilRequest,
WriteSingleCoilResponse,
)
import pymodbus.diag_message as modbus_diag
from pymodbus.file_message import (
ReadFifoQueueRequest,
ReadFifoQueueResponse,
Expand Down
2 changes: 1 addition & 1 deletion examples/contrib/message_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
import codecs as c
import collections
import logging
from optparse import OptionParser # pylint: disable=deprecated-module
import textwrap
from optparse import OptionParser # pylint: disable=deprecated-module

from pymodbus.factory import ClientDecoder, ServerDecoder
from pymodbus.transaction import (
Expand Down
10 changes: 4 additions & 6 deletions examples/contrib/modbus_mapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,16 +124,14 @@
StartTcpServer(context=context, identity=identity, address=("localhost", 5020))
"""
from collections import defaultdict
import csv
from io import StringIO
import json
from collections import defaultdict
from io import StringIO
from tokenize import generate_tokens

from pymodbus.datastore import (
ModbusSlaveContext,
ModbusSparseDataBlock,
)
from pymodbus.datastore import ModbusSlaveContext, ModbusSparseDataBlock


# --------------------------------------------------------------------------- #
# raw mapping input parsers
Expand Down
2 changes: 1 addition & 1 deletion examples/contrib/modbus_simulator.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
with read/write data as well as user configurable base data
"""
import logging
from optparse import OptionParser # pylint: disable=deprecated-module
import pickle # nosec
from optparse import OptionParser # pylint: disable=deprecated-module

from pymodbus.datastore import ModbusServerContext, ModbusSlaveContext
from pymodbus.server import StartTcpServer
Expand Down
2 changes: 1 addition & 1 deletion examples/contrib/thread_safe_datastore.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# pylint: disable=missing-type-doc
"""Thread safe datastore."""
from contextlib import contextmanager
import threading
from contextlib import contextmanager

from pymodbus.datastore.store import BaseModbusDataBlock

Expand Down
7 changes: 5 additions & 2 deletions examples/contrib/tornado_twisted/modbus_scraper.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,13 @@
them as a collection of sequential data blocks.
"""
import logging
from optparse import OptionParser
import pickle # nosec
from optparse import OptionParser

from twisted.internet import reactor, serialport # pylint: disable=import-error
from twisted.internet import ( # pylint: disable=import-error
reactor,
serialport,
)
from twisted.internet.protocol import (
ClientFactory, # pylint: disable=import-error
)
Expand Down
5 changes: 3 additions & 2 deletions examples/serial_forwarder.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@
python3 serial_forwarder.py --log DEBUG --port "/dev/ttyUSB0" --baudrate 9600 --server_ip "192.168.1.27" --server_port 5020 --slaves 1 2 3
"""
import argparse
import asyncio
import logging
import signal
import asyncio

from pymodbus.server.async_io import ModbusTcpServer
from pymodbus.client import ModbusSerialClient
from pymodbus.datastore import ModbusServerContext
from pymodbus.datastore.remote import RemoteSlaveContext
from pymodbus.server.async_io import ModbusTcpServer


FORMAT = "%(asctime)-15s %(levelname)-8s %(module)-15s:%(lineno)-8s %(message)s"
logging.basicConfig(format=FORMAT)
Expand Down
2 changes: 1 addition & 1 deletion examples/server_async.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@
The corresponding client can be started as:
python3 client_sync.py
"""
import os
import asyncio
import logging
import os

from examples.helper import get_commandline
from pymodbus.datastore import (
Expand Down
2 changes: 1 addition & 1 deletion examples/server_sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@
is just a thin cover on top of the async server and is in some aspects
a lot slower.
"""
import os
import logging
import os

from examples.helper import get_commandline
from examples.server_async import setup_server
Expand Down
7 changes: 2 additions & 5 deletions pymodbus/bit_read_message.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,8 @@
import struct

from pymodbus.constants import Defaults
from pymodbus.pdu import (
ModbusExceptions as merror,
ModbusRequest,
ModbusResponse,
)
from pymodbus.pdu import ModbusExceptions as merror
from pymodbus.pdu import ModbusRequest, ModbusResponse
from pymodbus.utilities import pack_bitstring, unpack_bitstring


Expand Down
7 changes: 2 additions & 5 deletions pymodbus/bit_write_message.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,8 @@
import struct

from pymodbus.constants import ModbusStatus
from pymodbus.pdu import (
ModbusExceptions as merror,
ModbusRequest,
ModbusResponse,
)
from pymodbus.pdu import ModbusExceptions as merror
from pymodbus.pdu import ModbusRequest, ModbusResponse
from pymodbus.utilities import pack_bitstring, unpack_bitstring


Expand Down
2 changes: 1 addition & 1 deletion pymodbus/client/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
import external classes, to make them easier to use:
"""
from pymodbus.client.base import ModbusBaseClient
from pymodbus.client.serial import AsyncModbusSerialClient, ModbusSerialClient
from pymodbus.client.tcp import AsyncModbusTcpClient, ModbusTcpClient
from pymodbus.client.tls import AsyncModbusTlsClient, ModbusTlsClient
from pymodbus.client.udp import AsyncModbusUdpClient, ModbusUdpClient
from pymodbus.client.base import ModbusBaseClient


# ---------------------------------------------------------------------------#
Expand Down
2 changes: 1 addition & 1 deletion pymodbus/client/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
from __future__ import annotations

import asyncio
from dataclasses import dataclass
import logging
import socket
from dataclasses import dataclass

from pymodbus.client.mixin import ModbusClientMixin
from pymodbus.constants import Defaults
Expand Down
4 changes: 2 additions & 2 deletions pymodbus/client/mixin.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@

import pymodbus.bit_read_message as pdu_bit_read
import pymodbus.bit_write_message as pdu_bit_write
from pymodbus.constants import Defaults
import pymodbus.diag_message as pdu_diag
import pymodbus.other_message as pdu_other_msg
from pymodbus.pdu import ModbusRequest, ModbusResponse
import pymodbus.register_read_message as pdu_reg_read
import pymodbus.register_write_message as pdu_req_write
from pymodbus.constants import Defaults
from pymodbus.pdu import ModbusRequest, ModbusResponse
from pymodbus.utilities import ModbusTransactionState


Expand Down
7 changes: 4 additions & 3 deletions pymodbus/client/serial.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
"""Modbus client async serial communication."""
from functools import partial
import asyncio
import time
import logging
import time
from functools import partial

from pymodbus.client.base import ModbusBaseClient, ModbusClientProtocol
from pymodbus.constants import Defaults
from pymodbus.exceptions import ConnectionException
from pymodbus.framer import ModbusFramer
from pymodbus.framer.rtu_framer import ModbusRtuFramer
from pymodbus.exceptions import ConnectionException
from pymodbus.utilities import ModbusTransactionState, hexlify_packets


try:
import serial
from serial_asyncio import create_serial_connection
Expand Down
3 changes: 2 additions & 1 deletion pymodbus/client/tcp.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,12 @@

from pymodbus.client.base import ModbusBaseClient, ModbusClientProtocol
from pymodbus.constants import Defaults
from pymodbus.exceptions import ConnectionException
from pymodbus.framer import ModbusFramer
from pymodbus.framer.socket_framer import ModbusSocketFramer
from pymodbus.exceptions import ConnectionException
from pymodbus.utilities import ModbusTransactionState


_logger = logging.getLogger(__name__)


Expand Down
1 change: 1 addition & 0 deletions pymodbus/client/tls.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from pymodbus.framer import ModbusFramer
from pymodbus.framer.tls_framer import ModbusTlsFramer


_logger = logging.getLogger(__name__)


Expand Down
Loading

0 comments on commit 9356d6b

Please sign in to comment.