567 lines
20 KiB
Python
567 lines
20 KiB
Python
# uncompyle6 version 3.9.2
|
|
# Python bytecode version base 3.7.0 (3394)
|
|
# Decompiled from: Python 3.8.19 (default, Mar 20 2024, 15:27:52)
|
|
# [Clang 14.0.6 ]
|
|
# Embedded file name: /var/user/app/device_supervisorbak/device_supervisor/lib/mcprotocol/mcconst.py
|
|
# Compiled at: 2024-04-18 03:12:58
|
|
# Size of source mod 2**32: 17502 bytes
|
|
"""This file defines mcprotocol constant.
|
|
"""
|
|
Q_SERIES = "Q"
|
|
L_SERIES = "L"
|
|
QnA_SERIES = "QnA"
|
|
iQL_SERIES = "iQ-L"
|
|
iQR_SERIES = "iQ-R"
|
|
BATCHREAD_WORDUNITS = 1
|
|
BATCHREAD_BITUNITS = 2
|
|
BATCHWRITE_WORDUNITS = 3
|
|
BATCHWRITE_BITUNITS = 4
|
|
RANDOMREAD = 5
|
|
RANDOMWRITE = 6
|
|
RANDOMWRITE_BITUNITS = 7
|
|
RANDOMWRITE_WORDUNITS = 8
|
|
COMMTYPE_BINARY = "binary"
|
|
COMMTYPE_ASCII = "ascii"
|
|
FORMAT_ONE = 1
|
|
FORMAT_TWO = 2
|
|
FORMAT_THREE = 3
|
|
FORMAT_FOUR = 4
|
|
FORMAT_FIVE = 5
|
|
FOUR_C_FRAME = 17976
|
|
THREE_C_FRAME = 17977
|
|
TWO_C_FRAME = 17986
|
|
ONE_C_FRAME = None
|
|
CTRL_CODE_STX = 2
|
|
CTRL_CODE_ETX = 3
|
|
CTRL_CODE_EOT = 4
|
|
CTRL_CODE_ENQ = 5
|
|
CTRL_CODE_ACK = 6
|
|
CTRL_CODE_LF = 10
|
|
CTRL_CODE_CL = 12
|
|
CTRL_CODE_CR = 13
|
|
CTRL_CODE_NAK = 21
|
|
|
|
class DeviceCodeError(Exception):
|
|
__doc__ = "devicecode error. Device is not exsist.\n "
|
|
|
|
def __init__(self, plctype, devicename):
|
|
self.plctype = plctype
|
|
self.devicename = devicename
|
|
|
|
def __str__(self):
|
|
error_txt = 'devicename: {} is not support {} series PLC.\nIf you enter hexadecimal device(X, Y, B, W, SB, SW, DX, DY, ZR) with only alphabet number\n(such as XFFF, device name is "X", device number is "FFF"),\nplease insert 0 between device name and device number.\neg: XFFF → X0FFF'.format(self.devicename, self.plctype)
|
|
return error_txt
|
|
|
|
|
|
class DeviceConstants:
|
|
__doc__ = "This class defines mc protocol deveice constatnt.\n "
|
|
SM_DEVICE = 145
|
|
SD_DEVICE = 169
|
|
X_DEVICE = 156
|
|
Y_DEVICE = 157
|
|
M_DEVICE = 144
|
|
L_DEVICE = 146
|
|
F_DEVICE = 147
|
|
V_DEVICE = 148
|
|
B_DEVICE = 160
|
|
D_DEVICE = 168
|
|
W_DEVICE = 180
|
|
TS_DEVICE = 193
|
|
TC_DEVICE = 192
|
|
TN_DEVICE = 194
|
|
SS_DEVICE = 199
|
|
SC_DEVICE = 198
|
|
SN_DEVICE = 200
|
|
CS_DEVICE = 196
|
|
CC_DEVICE = 195
|
|
CN_DEVICE = 197
|
|
SB_DEVICE = 161
|
|
SW_DEVICE = 181
|
|
DX_DEVICE = 162
|
|
DY_DEVICE = 163
|
|
R_DEVICE = 175
|
|
ZR_DEVICE = 176
|
|
LTS_DEVICE = 81
|
|
LTC_DEVICE = 80
|
|
LTN_DEVICE = 82
|
|
LSTS_DEVICE = 89
|
|
LSTC_DEVICE = 88
|
|
LSTN_DEVICE = 90
|
|
LCS_DEVICE = 85
|
|
LCC_DEVICE = 84
|
|
LCN_DEVICE = 86
|
|
LZ_DEVICE = 98
|
|
RD_DEVICE = 44
|
|
BIT_DEVICE = "bit"
|
|
WORD_DEVICE = "word"
|
|
DWORD_DEVICE = "dword"
|
|
|
|
def __init__(self):
|
|
"""Constructor
|
|
"""
|
|
pass
|
|
|
|
@staticmethod
|
|
def get_binary_devicecode(plctype, devicename):
|
|
"""Static method that returns devicecode from device name.
|
|
"""
|
|
if devicename == "SM":
|
|
return (
|
|
DeviceConstants.SM_DEVICE, 10)
|
|
if devicename == "SD":
|
|
return (
|
|
DeviceConstants.SD_DEVICE, 10)
|
|
if devicename == "X":
|
|
return (
|
|
DeviceConstants.X_DEVICE, 16)
|
|
if devicename == "Y":
|
|
return (
|
|
DeviceConstants.Y_DEVICE, 16)
|
|
if devicename == "M":
|
|
return (
|
|
DeviceConstants.M_DEVICE, 10)
|
|
if devicename == "L":
|
|
return (
|
|
DeviceConstants.L_DEVICE, 10)
|
|
if devicename == "F":
|
|
return (
|
|
DeviceConstants.F_DEVICE, 10)
|
|
if devicename == "V":
|
|
return (
|
|
DeviceConstants.V_DEVICE, 10)
|
|
if devicename == "B":
|
|
return (
|
|
DeviceConstants.B_DEVICE, 16)
|
|
if devicename == "D":
|
|
return (
|
|
DeviceConstants.D_DEVICE, 10)
|
|
if devicename == "W":
|
|
return (
|
|
DeviceConstants.W_DEVICE, 16)
|
|
if devicename == "TS":
|
|
return (
|
|
DeviceConstants.TS_DEVICE, 10)
|
|
if devicename == "TC":
|
|
return (
|
|
DeviceConstants.TC_DEVICE, 10)
|
|
if devicename == "TN":
|
|
return (
|
|
DeviceConstants.TN_DEVICE, 10)
|
|
if devicename == "STS":
|
|
return (
|
|
DeviceConstants.SS_DEVICE, 10)
|
|
if devicename == "STC":
|
|
return (
|
|
DeviceConstants.SC_DEVICE, 10)
|
|
if devicename == "STN":
|
|
return (
|
|
DeviceConstants.SN_DEVICE, 10)
|
|
if devicename == "CS":
|
|
return (
|
|
DeviceConstants.CS_DEVICE, 10)
|
|
if devicename == "CC":
|
|
return (
|
|
DeviceConstants.CC_DEVICE, 10)
|
|
if devicename == "CN":
|
|
return (
|
|
DeviceConstants.CN_DEVICE, 10)
|
|
if devicename == "SB":
|
|
return (
|
|
DeviceConstants.SB_DEVICE, 16)
|
|
if devicename == "SW":
|
|
return (
|
|
DeviceConstants.SW_DEVICE, 16)
|
|
if devicename == "DX":
|
|
return (
|
|
DeviceConstants.DX_DEVICE, 16)
|
|
if devicename == "DY":
|
|
return (
|
|
DeviceConstants.DY_DEVICE, 16)
|
|
if devicename == "R":
|
|
return (
|
|
DeviceConstants.R_DEVICE, 10)
|
|
if devicename == "ZR":
|
|
return (
|
|
DeviceConstants.ZR_DEVICE, 16)
|
|
if devicename == "LTS":
|
|
if plctype == iQR_SERIES:
|
|
return (
|
|
DeviceConstants.LTS_DEVICE, 10)
|
|
if devicename == "LTC":
|
|
if plctype == iQR_SERIES:
|
|
return (
|
|
DeviceConstants.LTC_DEVICE, 10)
|
|
if devicename == "LTN":
|
|
if plctype == iQR_SERIES:
|
|
return (
|
|
DeviceConstants.LTN_DEVICE, 10)
|
|
if devicename == "LSTS":
|
|
if plctype == iQR_SERIES:
|
|
return (
|
|
DeviceConstants.LSTS_DEVICE, 10)
|
|
if devicename == "LSTN":
|
|
if plctype == iQR_SERIES:
|
|
return (
|
|
DeviceConstants.LSTN_DEVICE, 10)
|
|
if devicename == "LCS":
|
|
if plctype == iQR_SERIES:
|
|
return (
|
|
DeviceConstants.LCS_DEVICE, 10)
|
|
if devicename == "LCC":
|
|
if plctype == iQR_SERIES:
|
|
return (
|
|
DeviceConstants.LCC_DEVICE, 10)
|
|
if devicename == "LCN":
|
|
if plctype == iQR_SERIES:
|
|
return (
|
|
DeviceConstants.LCN_DEVICE, 10)
|
|
elif devicename == "LZ":
|
|
if plctype == iQR_SERIES:
|
|
return (
|
|
DeviceConstants.LZ_DEVICE, 10)
|
|
if devicename == "RD" and plctype == iQR_SERIES:
|
|
return (
|
|
DeviceConstants.RD_DEVICE, 10)
|
|
raise DeviceCodeError(plctype, devicename)
|
|
|
|
@staticmethod
|
|
def get_ascii_devicecode(plctype, devicename):
|
|
"""Static method that returns devicecode from device name.
|
|
"""
|
|
if plctype == iQR_SERIES:
|
|
padding = 4
|
|
else:
|
|
padding = 2
|
|
if devicename == "SM":
|
|
return (
|
|
devicename.ljust(padding, "*"), 10)
|
|
if devicename == "SD":
|
|
return (
|
|
devicename.ljust(padding, "*"), 10)
|
|
if devicename == "X":
|
|
return (
|
|
devicename.ljust(padding, "*"), 16)
|
|
if devicename == "Y":
|
|
return (
|
|
devicename.ljust(padding, "*"), 16)
|
|
if devicename == "M":
|
|
return (
|
|
devicename.ljust(padding, "*"), 10)
|
|
if devicename == "L":
|
|
return (
|
|
devicename.ljust(padding, "*"), 10)
|
|
if devicename == "F":
|
|
return (
|
|
devicename.ljust(padding, "*"), 10)
|
|
if devicename == "V":
|
|
return (
|
|
devicename.ljust(padding, "*"), 10)
|
|
if devicename == "B":
|
|
return (
|
|
devicename.ljust(padding, "*"), 16)
|
|
if devicename == "D":
|
|
return (
|
|
devicename.ljust(padding, "*"), 10)
|
|
if devicename == "W":
|
|
return (
|
|
devicename.ljust(padding, "*"), 16)
|
|
if devicename == "TS":
|
|
return (
|
|
devicename.ljust(padding, "*"), 10)
|
|
if devicename == "TC":
|
|
return (
|
|
devicename.ljust(padding, "*"), 10)
|
|
if devicename == "TN":
|
|
return (
|
|
devicename.ljust(padding, "*"), 10)
|
|
if devicename == "STS":
|
|
if plctype == iQR_SERIES:
|
|
return (
|
|
"STS".ljust(padding, "*"), 10)
|
|
return ("SS".ljust(padding, "*"), 10)
|
|
else:
|
|
if devicename == "STC":
|
|
if plctype == iQR_SERIES:
|
|
return (
|
|
"STC".ljust(padding, "*"), 10)
|
|
return ("SC".ljust(padding, "*"), 10)
|
|
else:
|
|
if devicename == "STN":
|
|
if plctype == iQR_SERIES:
|
|
return (
|
|
"STN".ljust(padding, "*"), 10)
|
|
return ("SN".ljust(padding, "*"), 10)
|
|
else:
|
|
if devicename == "CS":
|
|
return (
|
|
devicename.ljust(padding, "*"), 10)
|
|
if devicename == "CC":
|
|
return (
|
|
devicename.ljust(padding, "*"), 10)
|
|
if devicename == "CN":
|
|
return (
|
|
devicename.ljust(padding, "*"), 10)
|
|
if devicename == "SB":
|
|
return (
|
|
devicename.ljust(padding, "*"), 16)
|
|
if devicename == "SW":
|
|
return (
|
|
devicename.ljust(padding, "*"), 16)
|
|
if devicename == "DX":
|
|
return (
|
|
devicename.ljust(padding, "*"), 16)
|
|
if devicename == "DY":
|
|
return (
|
|
devicename.ljust(padding, "*"), 16)
|
|
if devicename == "R":
|
|
return (
|
|
devicename.ljust(padding, "*"), 10)
|
|
if devicename == "ZR":
|
|
return (
|
|
devicename.ljust(padding, "*"), 16)
|
|
if devicename == "LTS":
|
|
if plctype == iQR_SERIES:
|
|
return (
|
|
devicename.ljust(padding, "*"), 10)
|
|
if devicename == "LTC":
|
|
if plctype == iQR_SERIES:
|
|
return (
|
|
devicename.ljust(padding, "*"), 10)
|
|
if devicename == "LTN":
|
|
if plctype == iQR_SERIES:
|
|
return (
|
|
devicename.ljust(padding, "*"), 10)
|
|
if devicename == "LSTS":
|
|
if plctype == iQR_SERIES:
|
|
return (
|
|
devicename.ljust(padding, "*"), 10)
|
|
if devicename == "LSTN":
|
|
if plctype == iQR_SERIES:
|
|
return (
|
|
devicename.ljust(padding, "*"), 10)
|
|
if devicename == "LCS":
|
|
if plctype == iQR_SERIES:
|
|
return (
|
|
devicename.ljust(padding, "*"), 10)
|
|
if devicename == "LCC":
|
|
if plctype == iQR_SERIES:
|
|
return (
|
|
devicename.ljust(padding, "*"), 10)
|
|
if devicename == "LCN":
|
|
if plctype == iQR_SERIES:
|
|
return (
|
|
devicename.ljust(padding, "*"), 10)
|
|
elif devicename == "LZ":
|
|
if plctype == iQR_SERIES:
|
|
return (
|
|
devicename.ljust(padding, "*"), 10)
|
|
if devicename == "RD" and plctype == iQR_SERIES:
|
|
return (
|
|
devicename.ljust(padding, "*"), 10)
|
|
raise DeviceCodeError(plctype, devicename)
|
|
|
|
@staticmethod
|
|
def get_devicetype(plctype, devicename):
|
|
"""Static method that returns device type "bit" or "wrod" type.
|
|
"""
|
|
if devicename == "SM":
|
|
return DeviceConstants.BIT_DEVICE
|
|
if devicename == "SD":
|
|
return DeviceConstants.WORD_DEVICE
|
|
if devicename == "X":
|
|
return DeviceConstants.BIT_DEVICE
|
|
if devicename == "Y":
|
|
return DeviceConstants.BIT_DEVICE
|
|
if devicename == "M":
|
|
return DeviceConstants.BIT_DEVICE
|
|
if devicename == "L":
|
|
return DeviceConstants.BIT_DEVICE
|
|
if devicename == "F":
|
|
return DeviceConstants.BIT_DEVICE
|
|
if devicename == "V":
|
|
return DeviceConstants.BIT_DEVICE
|
|
if devicename == "B":
|
|
return DeviceConstants.BIT_DEVICE
|
|
if devicename == "D":
|
|
return DeviceConstants.WORD_DEVICE
|
|
if devicename == "W":
|
|
return DeviceConstants.WORD_DEVICE
|
|
if devicename == "TS":
|
|
return DeviceConstants.BIT_DEVICE
|
|
if devicename == "TC":
|
|
return DeviceConstants.BIT_DEVICE
|
|
if devicename == "TN":
|
|
return DeviceConstants.WORD_DEVICE
|
|
if devicename == "STS":
|
|
return DeviceConstants.BIT_DEVICE
|
|
if devicename == "STC":
|
|
return DeviceConstants.BIT_DEVICE
|
|
if devicename == "STN":
|
|
return DeviceConstants.WORD_DEVICE
|
|
if devicename == "CS":
|
|
return DeviceConstants.BIT_DEVICE
|
|
if devicename == "CC":
|
|
return DeviceConstants.BIT_DEVICE
|
|
if devicename == "CN":
|
|
return DeviceConstants.WORD_DEVICE
|
|
if devicename == "SB":
|
|
return DeviceConstants.BIT_DEVICE
|
|
if devicename == "SW":
|
|
return DeviceConstants.WORD_DEVICE
|
|
if devicename == "DX":
|
|
return DeviceConstants.BIT_DEVICE
|
|
if devicename == "DY":
|
|
return DeviceConstants.BIT_DEVICE
|
|
if devicename == "R":
|
|
return DeviceConstants.WORD_DEVICE
|
|
if devicename == "ZR":
|
|
return DeviceConstants.WORD_DEVICE
|
|
if devicename == "LTS":
|
|
if plctype == iQR_SERIES:
|
|
return DeviceConstants.BIT_DEVICE
|
|
if devicename == "LTC":
|
|
if plctype == iQR_SERIES:
|
|
return DeviceConstants.BIT_DEVICE
|
|
if devicename == "LTN":
|
|
if plctype == iQR_SERIES:
|
|
return DeviceConstants.BIT_DEVICE
|
|
if devicename == "LSTS":
|
|
if plctype == iQR_SERIES:
|
|
return DeviceConstants.BIT_DEVICE
|
|
if devicename == "LSTN":
|
|
if plctype == iQR_SERIES:
|
|
return DeviceConstants.DWORD_DEVICE
|
|
if devicename == "LCS":
|
|
if plctype == iQR_SERIES:
|
|
return DeviceConstants.BIT_DEVICE
|
|
if devicename == "LCC":
|
|
if plctype == iQR_SERIES:
|
|
return DeviceConstants.BIT_DEVICE
|
|
if devicename == "LCN":
|
|
if plctype == iQR_SERIES:
|
|
return DeviceConstants.DWORD_DEVICE
|
|
elif devicename == "LZ":
|
|
if plctype == iQR_SERIES:
|
|
return DeviceConstants.DWORD_DEVICE
|
|
if devicename == "RD" and plctype == iQR_SERIES:
|
|
return DeviceConstants.WORD_DEVICE
|
|
raise DeviceCodeError(plctype, devicename)
|
|
|
|
|
|
class OneCDeviceConstants:
|
|
X_DEVICE = 88
|
|
Y_DEVICE = 89
|
|
M_DEVICE = 77
|
|
S_DEVICE = 83
|
|
TS_DEVICE = 21587
|
|
TN_DEVICE = 21582
|
|
CS_DEVICE = 17235
|
|
CN_DEVICE = 17230
|
|
D_DEVICE = 68
|
|
R_DEVICE = 82
|
|
BIT_DEVICE = "bit"
|
|
WORD_DEVICE = "word"
|
|
DWORD_DEVICE = "dword"
|
|
|
|
@staticmethod
|
|
def get_binary_devicecode(plctype, devicename):
|
|
"""Static method that returns devicecode from device name.
|
|
"""
|
|
if devicename == "X":
|
|
return (
|
|
OneCDeviceConstants.X_DEVICE, 16)
|
|
if devicename == "Y":
|
|
return (
|
|
OneCDeviceConstants.Y_DEVICE, 16)
|
|
if devicename == "M":
|
|
return (
|
|
OneCDeviceConstants.M_DEVICE, 10)
|
|
if devicename == "S":
|
|
return (
|
|
OneCDeviceConstants.S_DEVICE, 10)
|
|
if devicename == "TS":
|
|
return (
|
|
OneCDeviceConstants.TS_DEVICE, 10)
|
|
if devicename == "TN":
|
|
return (
|
|
OneCDeviceConstants.TN_DEVICE, 10)
|
|
if devicename == "CS":
|
|
return (
|
|
OneCDeviceConstants.CS_DEVICE, 10)
|
|
if devicename == "CN":
|
|
return (
|
|
OneCDeviceConstants.CN_DEVICE, 10)
|
|
if devicename == "D":
|
|
return (
|
|
OneCDeviceConstants.D_DEVICE, 10)
|
|
if devicename == "R":
|
|
return (
|
|
OneCDeviceConstants.R_DEVICE, 10)
|
|
raise DeviceCodeError(plctype, devicename)
|
|
|
|
@staticmethod
|
|
def get_ascii_devicecode(plctype, devicename):
|
|
"""Static method that returns devicecode from device name.
|
|
"""
|
|
if plctype == iQR_SERIES:
|
|
padding = 4
|
|
else:
|
|
padding = 1
|
|
if devicename == "X":
|
|
return (
|
|
devicename.ljust(padding, "*"), 16)
|
|
if devicename == "Y":
|
|
return (
|
|
devicename.ljust(padding, "*"), 16)
|
|
if devicename == "M":
|
|
return (
|
|
devicename.ljust(padding, "*"), 10)
|
|
if devicename == "S":
|
|
return (
|
|
devicename.ljust(padding, "*"), 10)
|
|
if devicename == "TS":
|
|
return (
|
|
devicename.ljust(padding, "*"), 10)
|
|
if devicename == "TN":
|
|
return (
|
|
devicename.ljust(padding, "*"), 10)
|
|
if devicename == "CS":
|
|
return (
|
|
devicename.ljust(padding, "*"), 10)
|
|
if devicename == "CN":
|
|
return (
|
|
devicename.ljust(padding, "*"), 10)
|
|
if devicename == "D":
|
|
return (
|
|
devicename.ljust(padding, "*"), 10)
|
|
if devicename == "R":
|
|
return (
|
|
devicename.ljust(padding, "*"), 10)
|
|
raise DeviceCodeError(plctype, devicename)
|
|
|
|
@staticmethod
|
|
def get_devicetype(plctype, devicename):
|
|
"""Static method that returns device type "bit" or "wrod" type.
|
|
"""
|
|
if devicename == "X":
|
|
return DeviceConstants.BIT_DEVICE
|
|
if devicename == "Y":
|
|
return DeviceConstants.BIT_DEVICE
|
|
if devicename == "M":
|
|
return DeviceConstants.BIT_DEVICE
|
|
if devicename == "S":
|
|
return DeviceConstants.BIT_DEVICE
|
|
if devicename == "TS":
|
|
return DeviceConstants.BIT_DEVICE
|
|
if devicename == "TN":
|
|
return DeviceConstants.WORD_DEVICE
|
|
if devicename == "CS":
|
|
return DeviceConstants.BIT_DEVICE
|
|
if devicename == "CN":
|
|
return DeviceConstants.WORD_DEVICE
|
|
if devicename == "D":
|
|
return DeviceConstants.WORD_DEVICE
|
|
if devicename == "R":
|
|
return DeviceConstants.WORD_DEVICE
|
|
raise DeviceCodeError(plctype, devicename)
|