45 lines
1.7 KiB
Python
45 lines
1.7 KiB
Python
import string
|
||
import modbus_tk.defines as cst
|
||
from modbus_tk import modbus_rtu, modbus_tcp, modbus
|
||
from print_color import *
|
||
import enum as Enum
|
||
|
||
#所有协议基类
|
||
class class_protocol() :
|
||
def __init__(self, protocol_name) :
|
||
self.protocol_name = protocol_name
|
||
self.mode : string = None
|
||
self.timeout = 5.0
|
||
return
|
||
|
||
def set_timeout(self, timeout = 5.0) :
|
||
self.timeout = timeout
|
||
|
||
def open(self, mode : string) :
|
||
self.mode = mode
|
||
print_error_msg("class_protocol派生类未实现open函数")
|
||
raise NotImplementedError()
|
||
|
||
def close(self) :
|
||
print_error_msg("class_protocol派生类未实现close函数")
|
||
raise NotImplementedError()
|
||
|
||
#返回 math.nan 表示读取失败, 否则读取成功
|
||
def read_float(self, device_addr : int, comm_str : string, scale : float = 1.0, offset : float = 0.0) -> float:
|
||
raise NotImplementedError()
|
||
|
||
#返回 False 表示读取失败
|
||
#返回 True 表示读取成功
|
||
def write_float(self, device_addr : int, comm_str : string, fvalue : float, scale : float = 1.0, offset : float = 0.0) -> bool:
|
||
raise NotImplementedError()
|
||
|
||
#读取comm_str地址开始的连续地址count个数, 地址连续
|
||
#返回 math.nan 表示读取失败, 否则读取成功
|
||
def read_float_arr(self, device_addr : int, comm_str : string, count : int) :
|
||
raise NotImplementedError()
|
||
|
||
#写入comm_str地址开始的连续地址 写入总个数由 len(fvalue_arr)决定
|
||
#返回 False 表示读取失败, 否则读取成功
|
||
def write_float_arr(self, device_addr : int, comm_str : string, fvalue_arr : list) -> bool:
|
||
raise NotImplementedError()
|
||
|