скорее всего оно должно работать так

This commit is contained in:
aarizona 2024-08-11 09:58:58 +03:00
parent 48b237ccb4
commit 1c343108f3
6 changed files with 190 additions and 62 deletions

View File

@ -89,6 +89,14 @@
"detail": "client",
"documentation": {}
},
{
"label": "svg2paths2",
"importPath": "svgpathtools",
"description": "svgpathtools",
"isExtraImport": true,
"detail": "svgpathtools",
"documentation": {}
},
{
"label": "two_byte_convert",
"kind": 2,
@ -116,6 +124,15 @@
"detail": "client",
"documentation": {}
},
{
"label": "collect_coordinates",
"kind": 2,
"importPath": "client",
"description": "client",
"peekOfCode": "def collect_coordinates():\n # собираем предварительные данные\n x = two_byte_convert(client.read_holding_registers(2332, 2, MODBUS_SLAVE_ID))\n y = two_byte_convert(client.read_holding_registers(2334, 2, MODBUS_SLAVE_ID))\n z = two_byte_convert(client.read_holding_registers(2336, 2, MODBUS_SLAVE_ID))\n u = two_byte_convert(client.read_holding_registers(2338, 2, MODBUS_SLAVE_ID))\n v = two_byte_convert(client.read_holding_registers(2340, 2, MODBUS_SLAVE_ID))\n w = two_byte_convert(client.read_holding_registers(2342, 2, MODBUS_SLAVE_ID))\n print(\n f\"Предварительные данные X {x * 0.001}, Y {y * 0.001}, Z {z*0.001}, U {u*0.001}, V {v*0.001}, W {w*0.001}\"",
"detail": "client",
"documentation": {}
},
{
"label": "get_or_set_speed",
"kind": 2,
@ -130,7 +147,7 @@
"kind": 2,
"importPath": "client",
"description": "client",
"peekOfCode": "def set_user_register(n, values):\n client.write_registers(indent + s + k * n, values, MODBUS_SLAVE_ID)\ndef to_double(integr):\n return [(integr >> 16) & 0xFFFF, integr & 0xFFFF]\nclient = ModbusTcpClient(\n host=MODBUS_SERVER_HOST,\n port=MODBUS_SERVER_PORT,\n)\nclient.connect()\n# максимальное количество coils = 286",
"peekOfCode": "def set_user_register(n, values):\n client.write_registers(indent + s + k * n, values, MODBUS_SLAVE_ID)\ndef to_double(integr):\n return [(integr >> 16) & 0xFFFF, integr & 0xFFFF]\ndef set_user_reg_800(data):\n for item in data:\n d, values = item\n set_user_register(d, values)\ndef start_in_auto():\n # старт в авторежиме single loop",
"detail": "client",
"documentation": {}
},
@ -139,7 +156,25 @@
"kind": 2,
"importPath": "client",
"description": "client",
"peekOfCode": "def to_double(integr):\n return [(integr >> 16) & 0xFFFF, integr & 0xFFFF]\nclient = ModbusTcpClient(\n host=MODBUS_SERVER_HOST,\n port=MODBUS_SERVER_PORT,\n)\nclient.connect()\n# максимальное количество coils = 286\n# bulb(0)\n# get_coordinates()",
"peekOfCode": "def to_double(integr):\n return [(integr >> 16) & 0xFFFF, integr & 0xFFFF]\ndef set_user_reg_800(data):\n for item in data:\n d, values = item\n set_user_register(d, values)\ndef start_in_auto():\n # старт в авторежиме single loop\n client.write_register(20002, 1, MODBUS_SLAVE_ID)\nclient = ModbusTcpClient(",
"detail": "client",
"documentation": {}
},
{
"label": "set_user_reg_800",
"kind": 2,
"importPath": "client",
"description": "client",
"peekOfCode": "def set_user_reg_800(data):\n for item in data:\n d, values = item\n set_user_register(d, values)\ndef start_in_auto():\n # старт в авторежиме single loop\n client.write_register(20002, 1, MODBUS_SLAVE_ID)\nclient = ModbusTcpClient(\n host=MODBUS_SERVER_HOST,\n port=MODBUS_SERVER_PORT,",
"detail": "client",
"documentation": {}
},
{
"label": "start_in_auto",
"kind": 2,
"importPath": "client",
"description": "client",
"peekOfCode": "def start_in_auto():\n # старт в авторежиме single loop\n client.write_register(20002, 1, MODBUS_SLAVE_ID)\nclient = ModbusTcpClient(\n host=MODBUS_SERVER_HOST,\n port=MODBUS_SERVER_PORT,\n)\nclient.connect()\n# максимальное количество coils = 286\n# bulb(0)",
"detail": "client",
"documentation": {}
},

131
client.py
View File

@ -71,6 +71,20 @@ def get_coordinates():
raise e
def collect_coordinates():
# собираем предварительные данные
x = two_byte_convert(client.read_holding_registers(2332, 2, MODBUS_SLAVE_ID))
y = two_byte_convert(client.read_holding_registers(2334, 2, MODBUS_SLAVE_ID))
z = two_byte_convert(client.read_holding_registers(2336, 2, MODBUS_SLAVE_ID))
u = two_byte_convert(client.read_holding_registers(2338, 2, MODBUS_SLAVE_ID))
v = two_byte_convert(client.read_holding_registers(2340, 2, MODBUS_SLAVE_ID))
w = two_byte_convert(client.read_holding_registers(2342, 2, MODBUS_SLAVE_ID))
print(
f"Предварительные данные X {x * 0.001}, Y {y * 0.001}, Z {z*0.001}, U {u*0.001}, V {v*0.001}, W {w*0.001}"
)
return [x, y, z, u, v, w]
def get_or_set_speed(number=None):
result = client.read_holding_registers(20200, 1, MODBUS_SLAVE_ID)
print("сейчас скорость", result.registers[0] * 0.1)
@ -88,6 +102,17 @@ def to_double(integr):
return [(integr >> 16) & 0xFFFF, integr & 0xFFFF]
def set_user_reg_800(data):
for item in data:
d, values = item
set_user_register(d, values)
def start_in_auto():
# старт в авторежиме single loop
client.write_register(20002, 1, MODBUS_SLAVE_ID)
client = ModbusTcpClient(
host=MODBUS_SERVER_HOST,
port=MODBUS_SERVER_PORT,
@ -99,7 +124,22 @@ client.connect()
# get_coordinates()
# get_or_set_speed(10)
try:
data = [
total = 0
state = None
step = 0
counter = 0
type = "rel"
paths = [
("line", 100, 100, 0),
("line", 100, -100, 0),
("line", -100, -100, 0),
("line", -100, 100, 0),
("line", 0, -50, 0),
]
# ставим пользовательские переменные в ноль
set_user_reg_800(
[
(0, to_double(0)),
(1, to_double(0)),
(2, to_double(0)),
@ -107,83 +147,56 @@ try:
(4, [0, 0]),
(5, [0, 0]),
]
for item in data:
d, values = item
set_user_register(d, values)
# старт в авторежиме single loop
client.write_register(20002, 1, MODBUS_SLAVE_ID)
)
# старт в авторежиме single loop
start_in_auto()
total = 0
state = None
step = 0
counter = 0
while True:
time.sleep(1)
total += 1
green_light = client.read_coils(0, 1, MODBUS_SLAVE_ID).bits[0]
print(f"total {total}, state {state}, green light {green_light}")
if state == green_light:
continue
state = green_light
if state == True:
continue
step += 1
# собираем предварительные данные
# x = two_byte_convert(client.read_holding_registers(2332, 2, MODBUS_SLAVE_ID))
# y = two_byte_convert(client.read_holding_registers(2334, 2, MODBUS_SLAVE_ID))
# z = two_byte_convert(client.read_holding_registers(2336, 2, MODBUS_SLAVE_ID))
# u = two_byte_convert(client.read_holding_registers(2338, 2, MODBUS_SLAVE_ID))
# v = two_byte_convert(client.read_holding_registers(2340, 2, MODBUS_SLAVE_ID))
# w = two_byte_convert(client.read_holding_registers(2342, 2, MODBUS_SLAVE_ID))
# print(
# f"Предварительные данные X {x * 0.001}, Y {y * 0.001}, Z {z*0.001}, U {u*0.001}, V {v*0.001}, W {w*0.001}"
# )
# работаем с REL относительными координатами
x = 0
y = 0
z = 0
w = 100
h = 100
if step == 1:
x -= w * 1000
elif step == 2:
y -= h * 1000
elif step == 3:
x += w * 1000
elif step == 4:
y += h * 1000
elif step == 5:
z += h * 1000
elif step == 6:
z -= h * 1000
if type == "rel":
# работаем с REL относительными координатами
x = 0
y = 0
z = 0
else:
# работаем с абсолютными координатами
x, y, z, u, v, w = collect_coordinates()
if step >= len(paths):
counter += 1
step = 0
state = None
current_step = paths[step]
line_type, *coord = current_step
data = [
(0, to_double(x)),
(1, to_double(y)),
(2, to_double(z)),
(3, [0, 0]),
(4, [0, 0]),
(5, [0, 0]),
]
for item in data:
d, values = item
set_user_register(d, values)
result = client.read_holding_registers(
indent + s + k * d, k, MODBUS_SLAVE_ID
if line_type == "line":
x, y, z = coord
set_user_reg_800(
[
(0, to_double(x)),
(1, to_double(y)),
(2, to_double(z)),
]
)
print(s + d, "===", two_byte_convert(result) * 0.001)
bulb(4)
bulb(0)
step += 1
except Exception as e:

71
poetry.lock generated
View File

@ -221,6 +221,48 @@ files = [
[package.extras]
cp2110 = ["hidapi"]
[[package]]
name = "scipy"
version = "1.14.0"
description = "Fundamental algorithms for scientific computing in Python"
optional = false
python-versions = ">=3.10"
files = [
{file = "scipy-1.14.0-cp310-cp310-macosx_10_9_x86_64.whl", hash = "sha256:7e911933d54ead4d557c02402710c2396529540b81dd554fc1ba270eb7308484"},
{file = "scipy-1.14.0-cp310-cp310-macosx_12_0_arm64.whl", hash = "sha256:687af0a35462402dd851726295c1a5ae5f987bd6e9026f52e9505994e2f84ef6"},
{file = "scipy-1.14.0-cp310-cp310-macosx_14_0_arm64.whl", hash = "sha256:07e179dc0205a50721022344fb85074f772eadbda1e1b3eecdc483f8033709b7"},
{file = "scipy-1.14.0-cp310-cp310-macosx_14_0_x86_64.whl", hash = "sha256:6a9c9a9b226d9a21e0a208bdb024c3982932e43811b62d202aaf1bb59af264b1"},
{file = "scipy-1.14.0-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:076c27284c768b84a45dcf2e914d4000aac537da74236a0d45d82c6fa4b7b3c0"},
{file = "scipy-1.14.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:42470ea0195336df319741e230626b6225a740fd9dce9642ca13e98f667047c0"},
{file = "scipy-1.14.0-cp310-cp310-musllinux_1_1_x86_64.whl", hash = "sha256:176c6f0d0470a32f1b2efaf40c3d37a24876cebf447498a4cefb947a79c21e9d"},
{file = "scipy-1.14.0-cp310-cp310-win_amd64.whl", hash = "sha256:ad36af9626d27a4326c8e884917b7ec321d8a1841cd6dacc67d2a9e90c2f0359"},
{file = "scipy-1.14.0-cp311-cp311-macosx_10_9_x86_64.whl", hash = "sha256:6d056a8709ccda6cf36cdd2eac597d13bc03dba38360f418560a93050c76a16e"},
{file = "scipy-1.14.0-cp311-cp311-macosx_12_0_arm64.whl", hash = "sha256:f0a50da861a7ec4573b7c716b2ebdcdf142b66b756a0d392c236ae568b3a93fb"},
{file = "scipy-1.14.0-cp311-cp311-macosx_14_0_arm64.whl", hash = "sha256:94c164a9e2498e68308e6e148646e486d979f7fcdb8b4cf34b5441894bdb9caf"},
{file = "scipy-1.14.0-cp311-cp311-macosx_14_0_x86_64.whl", hash = "sha256:a7d46c3e0aea5c064e734c3eac5cf9eb1f8c4ceee756262f2c7327c4c2691c86"},
{file = "scipy-1.14.0-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:9eee2989868e274aae26125345584254d97c56194c072ed96cb433f32f692ed8"},
{file = "scipy-1.14.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:9e3154691b9f7ed73778d746da2df67a19d046a6c8087c8b385bc4cdb2cfca74"},
{file = "scipy-1.14.0-cp311-cp311-musllinux_1_1_x86_64.whl", hash = "sha256:c40003d880f39c11c1edbae8144e3813904b10514cd3d3d00c277ae996488cdb"},
{file = "scipy-1.14.0-cp311-cp311-win_amd64.whl", hash = "sha256:5b083c8940028bb7e0b4172acafda6df762da1927b9091f9611b0bcd8676f2bc"},
{file = "scipy-1.14.0-cp312-cp312-macosx_10_9_x86_64.whl", hash = "sha256:bff2438ea1330e06e53c424893ec0072640dac00f29c6a43a575cbae4c99b2b9"},
{file = "scipy-1.14.0-cp312-cp312-macosx_12_0_arm64.whl", hash = "sha256:bbc0471b5f22c11c389075d091d3885693fd3f5e9a54ce051b46308bc787e5d4"},
{file = "scipy-1.14.0-cp312-cp312-macosx_14_0_arm64.whl", hash = "sha256:64b2ff514a98cf2bb734a9f90d32dc89dc6ad4a4a36a312cd0d6327170339eb0"},
{file = "scipy-1.14.0-cp312-cp312-macosx_14_0_x86_64.whl", hash = "sha256:7d3da42fbbbb860211a811782504f38ae7aaec9de8764a9bef6b262de7a2b50f"},
{file = "scipy-1.14.0-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:d91db2c41dd6c20646af280355d41dfa1ec7eead235642178bd57635a3f82209"},
{file = "scipy-1.14.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:a01cc03bcdc777c9da3cfdcc74b5a75caffb48a6c39c8450a9a05f82c4250a14"},
{file = "scipy-1.14.0-cp312-cp312-musllinux_1_1_x86_64.whl", hash = "sha256:65df4da3c12a2bb9ad52b86b4dcf46813e869afb006e58be0f516bc370165159"},
{file = "scipy-1.14.0-cp312-cp312-win_amd64.whl", hash = "sha256:4c4161597c75043f7154238ef419c29a64ac4a7c889d588ea77690ac4d0d9b20"},
{file = "scipy-1.14.0.tar.gz", hash = "sha256:b5923f48cb840380f9854339176ef21763118a7300a88203ccd0bdd26e58527b"},
]
[package.dependencies]
numpy = ">=1.23.5,<2.3"
[package.extras]
dev = ["cython-lint (>=0.12.2)", "doit (>=0.36.0)", "mypy (==1.10.0)", "pycodestyle", "pydevtool", "rich-click", "ruff (>=0.0.292)", "types-psutil", "typing_extensions"]
doc = ["jupyterlite-pyodide-kernel", "jupyterlite-sphinx (>=0.13.1)", "jupytext", "matplotlib (>=3.5)", "myst-nb", "numpydoc", "pooch", "pydata-sphinx-theme (>=0.15.2)", "sphinx (>=5.0.0)", "sphinx-design (>=0.4.0)"]
test = ["Cython", "array-api-strict", "asv", "gmpy2", "hypothesis (>=6.30)", "meson", "mpmath", "ninja", "pooch", "pytest", "pytest-cov", "pytest-timeout", "pytest-xdist", "scikit-umfpack", "threadpoolctl"]
[[package]]
name = "setuptools"
version = "72.1.0"
@ -248,6 +290,33 @@ files = [
{file = "six-1.16.0.tar.gz", hash = "sha256:1e61c37477a1626458e36f7b1d82aa5c9b094fa4802892072e49de9c60c4c926"},
]
[[package]]
name = "svgpathtools"
version = "1.6.1"
description = "A collection of tools for manipulating and analyzing SVG Path objects and Bezier curves."
optional = false
python-versions = "*"
files = [
{file = "svgpathtools-1.6.1-py2.py3-none-any.whl", hash = "sha256:39967f9a817b8a12cc6dd1646fc162d522fca6c3fd5f8c94913c15ee4cb3a906"},
{file = "svgpathtools-1.6.1.tar.gz", hash = "sha256:7054e6de1953e295bf565d535d585695453b09f8db4a2f7c4853348732097a3e"},
]
[package.dependencies]
numpy = "*"
scipy = "*"
svgwrite = "*"
[[package]]
name = "svgwrite"
version = "1.4.3"
description = "A Python library to create SVG drawings."
optional = false
python-versions = ">=3.6"
files = [
{file = "svgwrite-1.4.3-py3-none-any.whl", hash = "sha256:bb6b2b5450f1edbfa597d924f9ac2dd099e625562e492021d7dd614f65f8a22d"},
{file = "svgwrite-1.4.3.zip", hash = "sha256:a8fbdfd4443302a6619a7f76bc937fc683daf2628d9b737c891ec08b8ce524c3"},
]
[[package]]
name = "tomli"
version = "2.0.1"
@ -388,4 +457,4 @@ testing = ["coverage (>=5.0.3)", "zope.event", "zope.testing"]
[metadata]
lock-version = "2.0"
python-versions = "3.10.12"
content-hash = "fb99dcafd58fb92524e36eaac634c3dde9966e9cb14bfba758076e057ae0fb5a"
content-hash = "c7d6bddfce25fa53e5a29e91975eacc36d85962e2d132e0f892a2fdfb956bbef"

View File

@ -11,6 +11,7 @@ modbus = "^3.2"
pymodbustcp = "^0.2.2"
pymodbus = "^3.7.0"
pymodbus3 = "^1.0.0"
svgpathtools = "^1.6.1"
[build-system]

5
svg_convert.py Normal file
View File

@ -0,0 +1,5 @@
from svgpathtools import svg2paths2
paths, attributes, svg_attributes = svg2paths2('test.svg')
print(paths)
print(attributes)

5
test.svg Normal file

File diff suppressed because one or more lines are too long

After

Width:  |  Height:  |  Size: 8.7 KiB