自动化测试的功能迁移完毕,待测试
This commit is contained in:
@ -11,8 +11,8 @@ import time
|
||||
from common import clibs
|
||||
|
||||
from os import listdir
|
||||
# from pymodbus.payload import BinaryPayloadDecoder, BinaryPayloadBuilder
|
||||
# from pymodbus.constants import Endian
|
||||
from pymodbus.payload import BinaryPayloadDecoder, BinaryPayloadBuilder
|
||||
from pymodbus.constants import Endian
|
||||
import os.path
|
||||
from ctypes import *
|
||||
import hashlib
|
||||
@ -148,6 +148,32 @@ class ModbusRequest(object):
|
||||
clibs.insert_logdb("INFO", "openapi", f"modbus: 40018-{action} 执行{actions}安全区 safe region 03")
|
||||
time.sleep(clibs.interval)
|
||||
|
||||
def write_act(self, number):
|
||||
self.__c.write_register(40100, number)
|
||||
clibs.insert_logdb("INFO", "openapi", f"modbus: 40100 将 {number} 写入")
|
||||
|
||||
def write_probe(self, probe):
|
||||
self.__c.write_register(40101, probe)
|
||||
clibs.insert_logdb("INFO", "openapi", f"modbus: 40101 将 {probe} 写入")
|
||||
|
||||
def write_pon(self, pon):
|
||||
self.__c.write_register(40101, pon)
|
||||
clibs.insert_logdb("INFO", "openapi", f"modbus: 40102 将 {pon} 写入")
|
||||
|
||||
def write_axis(self, axis):
|
||||
builder = BinaryPayloadBuilder(byteorder=Endian.BIG, wordorder=Endian.LITTLE)
|
||||
builder.add_32bit_int(int(axis))
|
||||
payload = builder.to_registers()
|
||||
self.__c.write_registers(40103, payload)
|
||||
clibs.insert_logdb("INFO", "openapi", f"modbus: 40103 将 {axis} 写入")
|
||||
|
||||
def write_speed_max(self, speed):
|
||||
builder = BinaryPayloadBuilder(byteorder=Endian.BIG, wordorder=Endian.LITTLE)
|
||||
builder.add_32bit_float(float(speed))
|
||||
payload = builder.build()
|
||||
self.__c.write_registers(40105, payload, skip_encode=True)
|
||||
clibs.insert_logdb("INFO", "openapi", f"modbus: 40105 将 {speed} 写入")
|
||||
|
||||
def r_write_signals(self, addr: int, value): # OK | 40100 - 40109: signal_0 ~ signal_9
|
||||
if -1 < addr < 10 and addr.is_integer():
|
||||
self.__c.write_register(40100+addr, value)
|
||||
@ -287,6 +313,20 @@ class ModbusRequest(object):
|
||||
clibs.insert_logdb("INFO", "openapi", f"modbus: 执行读取所有 DO 的结果为 {res}")
|
||||
return res
|
||||
|
||||
def read_ready_to_go(self):
|
||||
result = self.__c.read_holding_registers(40600, count=1)
|
||||
return result.registers[0]
|
||||
|
||||
def read_scenario_time(self):
|
||||
results = self.__c.read_holding_registers(41002, count=2)
|
||||
result = BinaryPayloadDecoder.fromRegisters(results.registers, byteorder=Endian.BIG, wordorder=Endian.LITTLE)
|
||||
result = f"{result.decode_32bit_float():.3f}"
|
||||
return result
|
||||
|
||||
def read_brake_done(self):
|
||||
result = self.__c.read_holding_registers(41007, count=1)
|
||||
return result.registers[0]
|
||||
|
||||
|
||||
class HmiRequest(object):
|
||||
socket.setdefaulttimeout(clibs.interval * 6)
|
||||
|
Reference in New Issue
Block a user