mirror of
https://gitee.com/Lyon1998/pikapython.git
synced 2025-01-15 17:02:53 +08:00
update modbus
This commit is contained in:
parent
bb0631db1e
commit
cd3585c14c
@ -1,9 +1,7 @@
|
|||||||
#include "_modbus__ModBus.h"
|
#include "_modbus__ModBus.h"
|
||||||
#include "_modbus__ModBusRTU.h"
|
|
||||||
#include "_modbus__ModBusTCP.h"
|
|
||||||
#include "agile_modbus.h"
|
#include "agile_modbus.h"
|
||||||
|
|
||||||
void _modbus__ModBusRTU___init__(PikaObj* self,
|
void _modbus__ModBus___init__rtu(PikaObj* self,
|
||||||
int sendBUffSize,
|
int sendBUffSize,
|
||||||
int readBuffSize) {
|
int readBuffSize) {
|
||||||
agile_modbus_rtu_t ctx_rtu = {0};
|
agile_modbus_rtu_t ctx_rtu = {0};
|
||||||
@ -22,7 +20,7 @@ void _modbus__ModBus_setSlave(PikaObj* self, int slave) {
|
|||||||
agile_modbus_set_slave(ctx, slave);
|
agile_modbus_set_slave(ctx, slave);
|
||||||
}
|
}
|
||||||
|
|
||||||
void _modbus__ModBusTCP___init__(PikaObj* self,
|
void _modbus__ModBus___init__tcp(PikaObj* self,
|
||||||
int sendBuffSize,
|
int sendBuffSize,
|
||||||
int readBuffSize) {
|
int readBuffSize) {
|
||||||
agile_modbus_tcp_t ctx_tcp = {0};
|
agile_modbus_tcp_t ctx_tcp = {0};
|
||||||
@ -181,3 +179,13 @@ int _modbus__ModBus_serializeWriteRegisters(PikaObj* self,
|
|||||||
return agile_modbus_serialize_write_registers(ctx, addr, nb,
|
return agile_modbus_serialize_write_registers(ctx, addr, nb,
|
||||||
(uint16_t*)src);
|
(uint16_t*)src);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Arg* _modbus__ModBus_getSendBuff(PikaObj* self) {
|
||||||
|
agile_modbus_t* ctx = obj_getPtr(self, "ctx");
|
||||||
|
return arg_newBytes(ctx->send_buf, ctx->send_bufsz);
|
||||||
|
}
|
||||||
|
|
||||||
|
Arg* _modbus__ModBus_getReadBuff(PikaObj* self) {
|
||||||
|
agile_modbus_t* ctx = obj_getPtr(self, "ctx");
|
||||||
|
return arg_newBytes(ctx->read_buf, ctx->read_bufsz);
|
||||||
|
}
|
||||||
|
@ -1,31 +1,32 @@
|
|||||||
class _ModBus:
|
class _ModBus:
|
||||||
def setSlave(self, slave: int): ...
|
def setSlave(self, slave: int): ...
|
||||||
def serializeReadBits(self, addr: int, nb: int) -> int: ...
|
def serializeReadBits(self, addr: int, nb: int) -> int: ...
|
||||||
def deserializeReadBits(self, msgLength: int, dest: bytes) -> int: ...
|
|
||||||
def serializeReadInputBits(self, addr: int, nb: int) -> int: ...
|
def serializeReadInputBits(self, addr: int, nb: int) -> int: ...
|
||||||
def deserializeReadInputBits(self, msgLength: int, dest: bytes) -> int: ...
|
|
||||||
def serializeReadRegisters(self, addr: int, nb: int) -> int: ...
|
def serializeReadRegisters(self, addr: int, nb: int) -> int: ...
|
||||||
def deserializeReadRegisters(self, msgLength: int, dest: bytes) -> int: ...
|
|
||||||
def serializeReadInputRegisters(self, addr: int, nb: int) -> int: ...
|
def serializeReadInputRegisters(self, addr: int, nb: int) -> int: ...
|
||||||
def deserializeReadInputRegisters(self, msgLength: int, dest: bytes) -> int: ...
|
|
||||||
def serializeWriteBit(self, addr: int, status: int) -> int: ...
|
def serializeWriteBit(self, addr: int, status: int) -> int: ...
|
||||||
def deserializeWriteBit(self, msgLength: int) -> int: ...
|
def deserializeWriteBit(self, msgLength: int) -> int: ...
|
||||||
def serializeWriteRegister(self, addr: int, value: int) -> int: ...
|
def serializeWriteRegister(self, addr: int, value: int) -> int: ...
|
||||||
def deserializeWriteRegister(self, msgLength: int) -> int: ...
|
def deserializeWriteRegister(self, msgLength: int) -> int: ...
|
||||||
def serializeWriteBits(self, addr: int, nb: int, src: bytes) -> int: ...
|
|
||||||
def deserializeWriteBits(self, msgLength: int) -> int: ...
|
def deserializeWriteBits(self, msgLength: int) -> int: ...
|
||||||
def serializeWriteRegisters(self, addr: int, nb: int, src: bytes) -> int: ...
|
|
||||||
def deserializeWriteRegisters(self, msgLength: int) -> int: ...
|
def deserializeWriteRegisters(self, msgLength: int) -> int: ...
|
||||||
def serializeMaskWriteRegister(self, addr: int, andMask: int, orMask: int) -> int: ...
|
def serializeMaskWriteRegister(self, addr: int, andMask: int, orMask: int) -> int: ...
|
||||||
def deserializeMaskWriteRegister(self, msgLength: int) -> int: ...
|
def deserializeMaskWriteRegister(self, msgLength: int) -> int: ...
|
||||||
def serializeWriteAndReadRegisters(self, writeAddr: int, writeNb: int, src: bytes, readAddr: int, readNb: int) -> int: ...
|
def serializeWriteAndReadRegisters(self, writeAddr: int, writeNb: int, src: bytes, readAddr: int, readNb: int) -> int: ...
|
||||||
def deserializeWriteAndReadRegisters(self, msgLength: int, dest: bytes) -> int: ...
|
|
||||||
def serializeReportSlaveId(self) -> int: ...
|
def serializeReportSlaveId(self) -> int: ...
|
||||||
|
|
||||||
|
def deserializeReadBits(self, msgLength: int, dest: bytes) -> int: ...
|
||||||
|
def deserializeReadInputBits(self, msgLength: int, dest: bytes) -> int: ...
|
||||||
|
def deserializeReadRegisters(self, msgLength: int, dest: bytes) -> int: ...
|
||||||
|
def deserializeReadInputRegisters(self, msgLength: int, dest: bytes) -> int: ...
|
||||||
|
def serializeWriteBits(self, addr: int, nb: int, src: bytes) -> int: ...
|
||||||
|
def serializeWriteRegisters(self, addr: int, nb: int, src: bytes) -> int: ...
|
||||||
|
def deserializeWriteAndReadRegisters(self, msgLength: int, dest: bytes) -> int: ...
|
||||||
|
|
||||||
def deserializeReportSlaveId(self, msgLength: int, maxDest: int, dest: bytes) -> int: ...
|
def deserializeReportSlaveId(self, msgLength: int, maxDest: int, dest: bytes) -> int: ...
|
||||||
|
|
||||||
class _ModBusRTU(_ModBus):
|
def getSendBuff(self) -> bytes: ...
|
||||||
def __init__(self, sendBuffSize: int, readBuffSize: int): ...
|
def getReadBuff(self) -> bytes: ...
|
||||||
|
def __init__rtu(self, sendBuffSize: int, readBuffSize: int): ...
|
||||||
|
def __init__tcp(self, sendBuffSize: int, readBuffSize: int): ...
|
||||||
class _ModBusTCP(_ModBus):
|
|
||||||
def __init__(self, sendBuffSize: int, readBuffSize: int): ...
|
|
||||||
|
@ -1,5 +1,58 @@
|
|||||||
import _modbus
|
import _modbus
|
||||||
|
|
||||||
|
|
||||||
class ModBus(_modbus._Modbus):
|
class ModBus(_modbus._ModBus):
|
||||||
...
|
def deserializeReadBits(self, msgLength: int):
|
||||||
|
dest = bytes(msgLength)
|
||||||
|
super().deserializeReadBits(msgLength, dest)
|
||||||
|
return list(dest)
|
||||||
|
|
||||||
|
def deserializeReadInputBits(self, msgLength: int):
|
||||||
|
dest = bytes(msgLength)
|
||||||
|
super().deserializeReadInputBits(msgLength, dest)
|
||||||
|
return list(dest)
|
||||||
|
|
||||||
|
def deserializeReadRegisters(self, msgLength: int) -> list:
|
||||||
|
dest = bytes(2 * msgLength)
|
||||||
|
super().deserializeReadRegisters(msgLength, dest)
|
||||||
|
ret = []
|
||||||
|
for i in range(0, len(dest), 2):
|
||||||
|
ret.append(dest[i] + dest[i + 1] * 256)
|
||||||
|
return ret
|
||||||
|
|
||||||
|
def deserializeReadInputRegisters(self, msgLength: int) -> list:
|
||||||
|
dest = bytes(2 * msgLength)
|
||||||
|
super().deserializeReadInputRegisters(msgLength, dest)
|
||||||
|
ret = []
|
||||||
|
for i in range(0, len(dest), 2):
|
||||||
|
ret.append(dest[i] + dest[i + 1] * 256)
|
||||||
|
return ret
|
||||||
|
|
||||||
|
def serializeWriteBits(self, addr: int, nb: int, src: list):
|
||||||
|
src = bytes(src)
|
||||||
|
return super().serializeWriteBits(addr, nb, src)
|
||||||
|
|
||||||
|
def serializeWriteRegisters(self, addr: int, nb: int, src: list):
|
||||||
|
_src = bytes(2 * len(src))
|
||||||
|
for i in range(len(src)):
|
||||||
|
_src[2 * i] = src[i] % 256
|
||||||
|
_src[2 * i + 1] = src[i] // 256
|
||||||
|
return super().serializeWriteRegisters(addr, nb, _src)
|
||||||
|
|
||||||
|
def deserializeWriteAndReadRegisters(self, msgLength: int) -> list:
|
||||||
|
dest = bytes(2 * msgLength)
|
||||||
|
super().deserializeWriteAndReadRegisters(msgLength, dest)
|
||||||
|
ret = []
|
||||||
|
for i in range(0, len(dest), 2):
|
||||||
|
ret.append(dest[i] + dest[i + 1] * 256)
|
||||||
|
return ret
|
||||||
|
|
||||||
|
|
||||||
|
class ModBusRTU(ModBus):
|
||||||
|
def __init__(self, sendBuffSize: int, readBuffSize: int):
|
||||||
|
self.__init__rtu(sendBuffSize, readBuffSize)
|
||||||
|
|
||||||
|
|
||||||
|
class ModBusTCP(ModBus):
|
||||||
|
def __init__(self, sendBuffSize: int, readBuffSize: int):
|
||||||
|
self.__init__tcp(sendBuffSize, readBuffSize)
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import _modbus
|
import _modbus
|
||||||
|
|
||||||
"""
|
|
||||||
class ModBus(_modbus._ModBus):
|
class ModBus(_modbus._ModBus):
|
||||||
def deserializeReadBits(self, msgLength: int):
|
def deserializeReadBits(self, msgLength: int):
|
||||||
dest = bytes(msgLength)
|
dest = bytes(msgLength)
|
||||||
@ -12,7 +12,7 @@ class ModBus(_modbus._ModBus):
|
|||||||
super().deserializeReadInputBits(msgLength, dest)
|
super().deserializeReadInputBits(msgLength, dest)
|
||||||
return list(dest)
|
return list(dest)
|
||||||
|
|
||||||
def deserializeReadRegisters(self, msgLength: int):
|
def deserializeReadRegisters(self, msgLength: int) -> list:
|
||||||
dest = bytes(2 * msgLength)
|
dest = bytes(2 * msgLength)
|
||||||
super().deserializeReadRegisters(msgLength, dest)
|
super().deserializeReadRegisters(msgLength, dest)
|
||||||
ret = []
|
ret = []
|
||||||
@ -56,4 +56,3 @@ class ModBusRTU(ModBus):
|
|||||||
class ModBusTCP(ModBus):
|
class ModBusTCP(ModBus):
|
||||||
def __init__(self, sendBuffSize: int, readBuffSize: int):
|
def __init__(self, sendBuffSize: int, readBuffSize: int):
|
||||||
self.__init__tcp(sendBuffSize, readBuffSize)
|
self.__init__tcp(sendBuffSize, readBuffSize)
|
||||||
"""
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user