You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

34 lines
1.4 KiB
Python

import sys
sys.path.append('../')
sys.path.append('../../')
sys.path.append('../../../')
from protocol.Celery.MBRTUSlave import app
def afterRecv(args):
request16 = ' '.join([hex(value)[2:].zfill(2) if index not in [0, 1] else str(int(hex(value), 16)).zfill(2) for index, value in enumerate(args[-1])])
request10 = ' '.join(str(int(hex(value), 16)).zfill(2) for index, value in enumerate(args[-1]))
app.backend.client.rpush("16R", request16)
app.backend.client.rpush("10R", request10)
if app.backend.client.llen('16R') == 81:
app.backend.client.lpop('16R')
if app.backend.client.llen('10R') == 81:
app.backend.client.lpop('10R')
# print(request16)
# print(request10)
def afterSend(args):
request16 = ' '.join([hex(value)[2:].zfill(2) if index not in [0, 1] else str(int(hex(value), 16)).zfill(2) for index, value in enumerate(args[-1])])
request10 = ' '.join(str(int(hex(value), 16)).zfill(2) for index, value in enumerate(args[-1]))
app.backend.client.rpush("16S", request16)
app.backend.client.rpush("10S", request10)
if app.backend.client.llen('16S') == 81:
app.backend.client.ltrim('16S', 1, -1)
if app.backend.client.llen('10S') == 81:
app.backend.client.ltrim('10S', 1, -1)
# request10 = ' '.join(str(int(x, 16)) for x in request16.split(' '))
# print(request16)
# print(request10)