Skip to content

Commit 6e795f7

Browse files
Merge 1e5a796 into ea11da8
2 parents ea11da8 + 1e5a796 commit 6e795f7

22 files changed

+1681
-599
lines changed

.github/workflows/test.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,12 @@ jobs:
4242
- name: Run Client/Host TCP test
4343
run: |
4444
docker compose -f docker-compose-tcp-test.yaml up --build --exit-code-from micropython-host
45+
- name: Run Client/Host RTU example
46+
run: |
47+
docker compose -f docker-compose-rtu.yaml up --build --exit-code-from micropython-host
48+
- name: Run Client/Host RTU test
49+
run: |
50+
docker compose -f docker-compose-rtu-test.yaml up --build --exit-code-from micropython-host
4551
- name: Build package
4652
run: |
4753
changelog2version \

Dockerfile.client_rtu

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Build image
2+
# $ docker build -t micropython-client-rtu -f Dockerfile.client_rtu .
3+
#
4+
# Run image
5+
# $ docker run -it --rm --name micropython-client-rtu micropython-client-rtu
6+
7+
FROM micropython/unix:v1.18
8+
9+
# use "volumes" in docker-compose file to remove need of rebuilding
10+
# COPY ./ /home
11+
# COPY umodbus /root/.micropython/lib/umodbus
12+
13+
RUN micropython-dev -m upip install micropython-ulogging
14+
15+
CMD [ "micropython-dev", "-m", "examples/rtu_client_example.py" ]

Dockerfile.client renamed to Dockerfile.client_tcp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
# Build image
2-
# $ docker build -t micropython-client -f Dockerfile.client .
2+
# $ docker build -t micropython-client-tcp -f Dockerfile.client_tcp .
33
#
44
# Run image
5-
# $ docker run -it --rm --name micropython-client micropython-client
5+
# $ docker run -it --rm --name micropython-client-tcp micropython-client-tcp
66

77
FROM micropython/unix:v1.18
88

Dockerfile.host_rtu

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Build image
2+
# $ docker build -t micropython-host-rtu -f Dockerfile.host_rtu .
3+
#
4+
# Run image
5+
# $ docker run -it --rm --name micropython-host-rtu micropython-host-rtu
6+
7+
FROM micropython/unix:v1.18
8+
9+
# use "volumes" in docker-compose file to remove need of rebuilding
10+
# COPY ./ /home
11+
# COPY umodbus /root/.micropython/lib/umodbus
12+
13+
RUN micropython-dev -m upip install micropython-ulogging
14+
15+
CMD [ "micropython-dev", "-m", "examples/rtu_host_example.py" ]

Dockerfile.host renamed to Dockerfile.host_tcp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
# Build image
2-
# $ docker build -t micropython-host -f Dockerfile.host .
2+
# $ docker build -t micropython-host-tcp -f Dockerfile.host_tcp .
33
#
44
# Run image
5-
# $ docker run -it --rm --name micropython-host micropython-host
5+
# $ docker run -it --rm --name micropython-host-tcp micropython-host-tcp
66

77
FROM micropython/unix:v1.18
88

File renamed without changes.

changelog.md

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,35 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1515
<!-- ## [Unreleased] -->
1616

1717
## Released
18+
## [2.2.0] - 2023-01-03
19+
### Added
20+
- [Fake machine module](fakes/machine.py) with UART and Pin class to be used on Unix MicroPython container for RTU tests and examples, see #47
21+
- [RTU host example script](examples/rtu_host_example.py)
22+
- [RTU docker compose file](docker-compose-rtu.yaml) and [RTU docker compose file test](docker-compose-rtu-test.yaml) based in MicroPython 1.18 image
23+
- [RTU client Dockerfile](Dockerfile.client_rtu) and [RTU host Dockerfile](Dockerfile.host_rtu) based on MicroPython 1.18 image
24+
- Initial [RTU examples unittest](tests/test_rtu_example.py)
25+
- RTU example section for Client and Host in USAGE
26+
27+
### Changed
28+
- Outsourced the following common functions of [serial.py](umodbus/serial.py) and [tcp.py](umodbus/tcp.py) into `CommonModbusFunctions` of [common.py](umodbus/common.py):
29+
- `read_coils`
30+
- `read_discrete_inputs`
31+
- `read_holding_registers`
32+
- `read_input_registers`
33+
- `write_single_coil`
34+
- `write_single_register`
35+
- `write_multiple_coils`
36+
- `write_multiple_registers`
37+
38+
- Inherit from `CommonModbusFunctions` in `Serial` of [serial.py](umodbus/serial.py) and in `TCP` of of [tcp.py](umodbus/tcp.py)
39+
- Extended RTU client example for Docker usage to load all registers from example JSON file
40+
- Update internal functions parameter name from `slave_id` to `slave_addr` of TCP's `_create_mbap_hdr` and `_validate_resp_hdr` function to be the same as in Serial
41+
- Update Modbus function documentation from TCP specific to common module in USAGE file
42+
- Renamed docker files:
43+
- `Dockerfile.client` -> `Dockerfile.client_tcp`
44+
- `Dockerfile.host` -> `Dockerfile.host_tcp`
45+
- `Dockerfile.test_tcp_example` -> `Dockerfile.test_examples`
46+
1847
## [2.1.3] - 2022-12-30
1948
### Fixed
2049
- `uart_id` can be specified during init of `ModbusRTU` and `Serial` class and is no longer hardcoded to `1`, but set as `1` by default to ensure backwards compability, see #7 and #43
@@ -195,8 +224,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
195224
- PEP8 style issues on all files of [`lib/uModbus`](lib/uModbus)
196225

197226
<!-- Links -->
198-
[Unreleased]: https://github.com/brainelectronics/micropython-modbus/compare/2.1.3...develop
227+
[Unreleased]: https://github.com/brainelectronics/micropython-modbus/compare/2.2.0...develop
199228

229+
[2.2.0]: https://github.com/brainelectronics/micropython-modbus/tree/2.2.0
200230
[2.1.3]: https://github.com/brainelectronics/micropython-modbus/tree/2.1.3
201231
[2.1.2]: https://github.com/brainelectronics/micropython-modbus/tree/2.1.2
202232
[2.1.1]: https://github.com/brainelectronics/micropython-modbus/tree/2.1.1

docker-compose-rtu-test.yaml

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
#
2+
# build all non-image containers
3+
# $ docker-compose -f docker-compose-rtu-test.yaml build
4+
# can be combined into one command to also start it afterwards
5+
# $ docker-compose -f docker-compose-rtu-test.yaml up --build
6+
#
7+
8+
version: "3.8"
9+
10+
services:
11+
micropython-client:
12+
build:
13+
context: .
14+
dockerfile: Dockerfile.client_rtu
15+
container_name: micropython-client
16+
volumes:
17+
- ./:/home
18+
- ./registers:/home/registers
19+
- ./umodbus:/root/.micropython/lib/umodbus
20+
- ./fakes:/usr/lib/micropython
21+
expose:
22+
- "65433"
23+
ports:
24+
- "65433:65433" # reach "micropython-client" at 172.25.0.2:65433, see networks
25+
networks:
26+
serial_bridge:
27+
# fix IPv4 address to be known and in the MicroPython scripts
28+
# https://docs.docker.com/compose/compose-file/#ipv4_address
29+
ipv4_address: 172.25.0.2
30+
31+
micropython-host:
32+
build:
33+
context: .
34+
dockerfile: Dockerfile.test_examples
35+
container_name: micropython-host
36+
volumes:
37+
- ./:/home
38+
- ./umodbus:/root/.micropython/lib/umodbus
39+
- ./fakes:/usr/lib/micropython
40+
- ./mpy_unittest.py:/root/.micropython/lib/mpy_unittest.py
41+
depends_on:
42+
- micropython-client
43+
command:
44+
- /bin/bash
45+
- -c
46+
- |
47+
micropython-dev -c "import mpy_unittest as unittest; unittest.main(name='tests.test_rtu_example', fromlist=['TestRtuExample'])"
48+
networks:
49+
serial_bridge:
50+
# fix IPv4 address to be known and in the MicroPython scripts
51+
# https://docs.docker.com/compose/compose-file/#ipv4_address
52+
ipv4_address: 172.25.0.3
53+
54+
networks:
55+
serial_bridge:
56+
# use "external: true" if the network already exists
57+
# check available networks with "docker network ls"
58+
# external: true
59+
driver: bridge
60+
# https://docs.docker.com/compose/compose-file/#ipam
61+
ipam:
62+
config:
63+
- subnet: 172.25.0.0/16
64+
gateway: 172.25.0.1

docker-compose-rtu.yaml

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
#
2+
# build all non-image containers
3+
# $ docker-compose build
4+
# can be combined into one command to also start it afterwards
5+
# $ docker-compose up --build
6+
#
7+
8+
version: "3.8"
9+
10+
services:
11+
micropython-client:
12+
build:
13+
context: .
14+
dockerfile: Dockerfile.client_rtu
15+
container_name: micropython-client
16+
volumes:
17+
- ./:/home
18+
- ./umodbus:/root/.micropython/lib/umodbus
19+
- ./fakes:/usr/lib/micropython
20+
expose:
21+
- "65433"
22+
ports:
23+
- "65433:65433" # reach "micropython-client" at 172.25.0.2:65433, see networks
24+
networks:
25+
serial_bridge:
26+
# fix IPv4 address to be known and in the MicroPython scripts
27+
# https://docs.docker.com/compose/compose-file/#ipv4_address
28+
ipv4_address: 172.25.0.2
29+
30+
micropython-host:
31+
build:
32+
context: .
33+
dockerfile: Dockerfile.host_rtu
34+
container_name: micropython-host
35+
volumes:
36+
- ./:/home
37+
- ./umodbus:/root/.micropython/lib/umodbus
38+
- ./fakes:/usr/lib/micropython
39+
depends_on:
40+
- micropython-client
41+
networks:
42+
serial_bridge:
43+
# fix IPv4 address to be known and in the MicroPython scripts
44+
# https://docs.docker.com/compose/compose-file/#ipv4_address
45+
ipv4_address: 172.25.0.3
46+
47+
networks:
48+
serial_bridge:
49+
# use "external: true" if the network already exists
50+
# check available networks with "docker network ls"
51+
# external: true
52+
driver: bridge
53+
# https://docs.docker.com/compose/compose-file/#ipam
54+
ipam:
55+
config:
56+
- subnet: 172.25.0.0/16
57+
gateway: 172.25.0.1

docker-compose-tcp-test.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ services:
1111
micropython-client:
1212
build:
1313
context: .
14-
dockerfile: Dockerfile.client
14+
dockerfile: Dockerfile.client_tcp
1515
container_name: micropython-client
1616
volumes:
1717
- ./:/home
@@ -30,7 +30,7 @@ services:
3030
micropython-host:
3131
build:
3232
context: .
33-
dockerfile: Dockerfile.test_tcp_example
33+
dockerfile: Dockerfile.test_examples
3434
container_name: micropython-host
3535
volumes:
3636
- ./:/home

0 commit comments

Comments
 (0)