Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
MyEMS
MyEMS能源管理系统
提交
bab6fd5b
M
MyEMS能源管理系统
项目概览
MyEMS
/
MyEMS能源管理系统
通知
46
Star
2
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
M
MyEMS能源管理系统
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
bab6fd5b
编写于
5月 02, 2024
作者:
nengyuangzhang
浏览文件
操作
浏览文件
下载
差异文件
Merge branch 'develop'
上级
41871a42
84a41f8e
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
7 addition
and
10 deletion
+7
-10
myems-modbus-tcp/main.py
myems-modbus-tcp/main.py
+0
-2
myems-modbus-tcp/test.py
myems-modbus-tcp/test.py
+7
-8
未找到文件。
myems-modbus-tcp/main.py
浏览文件 @
bab6fd5b
...
...
@@ -3,9 +3,7 @@ import logging
import
time
from
logging.handlers
import
RotatingFileHandler
from
multiprocessing
import
Process
import
mysql.connector
import
acquisition
import
config
import
gateway
...
...
myems-modbus-tcp/test.py
浏览文件 @
bab6fd5b
import
sys
import
telnetlib3
import
asyncio
from
modbus_tk
import
modbus_tcp
import
byte_swap
...
...
@@ -20,18 +18,19 @@ async def check_connectivity(host, port):
# main procedure
########################################################################################################################
def
main
():
if
len
(
sys
.
argv
)
>
1
:
if
len
(
sys
.
argv
)
>
2
:
host
=
sys
.
argv
[
1
]
port
=
sys
.
argv
[
2
]
else
:
print
(
'Usage: python3 test.py HOST_IP_ADDR '
)
print
(
'Missing arguments'
)
print
(
'Usage: python3 test.py HOST PORT'
)
return
port
=
502
try
:
asyncio
.
run
(
check_connectivity
(
host
,
port
))
print
(
"Succeeded to telnet
%s:%s "
,
host
,
port
)
print
(
"Succeeded to telnet
{0}:{1}"
.
format
(
host
,
port
)
)
except
Exception
as
e
:
print
(
"Failed to telnet
%s:%s : %s "
,
host
,
port
,
str
(
e
))
print
(
"Failed to telnet
{0}:{1} : {2}"
.
format
(
host
,
port
,
str
(
e
)
))
return
"""
...
...
@@ -67,7 +66,7 @@ def main():
try
:
master
=
modbus_tcp
.
TcpMaster
(
host
=
host
,
port
=
port
,
timeout_in_sec
=
5.0
)
master
.
set_timeout
(
5.0
)
print
(
"Connected to
%s:%s "
,
host
,
port
)
print
(
"Connected to
{0}:{1}"
.
format
(
host
,
port
)
)
print
(
"read registers..."
)
result
=
master
.
execute
(
slave
=
1
,
function_code
=
3
,
starting_address
=
1
,
quantity_of_x
=
2
,
data_format
=
'<f'
)
print
(
"51AL1 = "
+
str
(
byte_swap
.
byte_swap_32_bit
(
result
[
0
])))
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录