# coding=UTF-8
from ctypes import *
import binascii
import time
import _ctypes
import ctypes
# 定义回调函数参数的结构体
class Sconfig(Structure):
_fields_ = [("tcpserverip", c_char *32),
("tcpport", c_int),
("udpip", c_char *32),
("udpport", c_int),
("broadudpport", c_int),
("logorg", c_int),
("logheart", c_int),
("logsensor", c_int)]
class Gas(Structure):
_fields_= [("uuid", c_char *40),
("iHid", c_int),
("iStationHid", c_int),
("iSEQ", c_int),
("iControlWorld", c_int),
("iFaceGasSensor1", c_int),
("iHighAlarm1", c_int),
("iHighAlarmRevoke1", c_int),
("iLowAlarmRevoke1", c_int),
("iLowAlarm1", c_int),
("iBreakValue1", c_int),
("iRecoveryValue1", c_int),
("iFaceGasSensor2", c_int),
("iHighAlarm2", c_int),
("iHighAlarmRevoke2", c_int),
("iLowAlarmRevoke2", c_int),
("iLowAlarm2", c_int),
("iBreakValue2", c_int),
("iRecoveryValue2", c_int),
("iFaceGasSensor3", c_int),
("iHighAlarm3", c_int),
("iHighAlarmRevoke3", c_int),
("iLowAlarmRevoke3", c_int),
("iLowAlarm3", c_int),
("iBreakValue3", c_int),
("iRecoveryValue3", c_int),
("iThree_point_lock_in_value", c_int),
("iTrisectionValue", c_int)]
class Heart(Structure):
_fields_ = [("uuid", c_char *40),
("iHid", c_int),
("chTime", c_char*32),
("chIP", c_char*32),
("iNumber", c_int),
("iOther", c_int*128*10)]
CALLBACK = CFUNCTYPE(None, Heart)
# 定义回调函数
def _callback(Heart):
print('heart')
print(Heart.uuid, Heart.iHid, Heart.chTime, Heart.chIP)
callBackFunc = CALLBACK(_callback)
my_dll = ctypes.windll.LoadLibrary("./BW_NMCPSystem.dll")
config = Sconfig()
config.tcpserverip = '192.168.108.45'
config.tcpport = 10000
config.udpip = '192.168.108.45'
config.udpport = 4001
config.broadudpport = 10550
config.logorg = 0
config.logheart = 0
config.logsensor = 0
b = my_dll.BW_NMCP_Init(config)
print(b)
my_dll.BW_NMCP_SetServerCallback(callBackFunc,0,0,0,0,0,0,0,0,0,0,0,0,0)
time.sleep(100000)
while True:
senddata=input('想要发送的数据:')
if True:
print('start')
newgas = Gas()
newgas.uuid = '12345678'
newgas.iHid = 80000001
newgas.iStationHid = 80000001
newgas.iSEQ = 1
newgas.iControlWorld = 1
newgas.iFaceGasSensor1 = 1111
newgas.iHighAlarm1 = 11
newgas.iHighAlarmRevoke1 = -22
newgas.iLowAlarmRevoke1 = 33
newgas.iLowAlarm1 = 44
newgas.iBreakValue1 = -55
newgas.iRecoveryValue1 = 66
newgas.iFaceGasSensor2 = 2222
newgas.iHighAlarm2 = 11
newgas.iHighAlarmRevoke2 = -22
newgas.iLowAlarmRevoke2 = 33
newgas.iLowAlarm2 = 44
newgas.iBreakValue2 = -55
newgas.iRecoveryValue2 = 66
newgas.iFaceGasSensor3 = 3333
newgas.iHighAlarm3 = 11
newgas.iHighAlarmRevoke3 = -22
newgas.iLowAlarmRevoke3 = 33
newgas.iLowAlarm3 = 44
newgas.iBreakValue3 = -55
newgas.iRecoveryValue3 = 66
newgas.iThree_point_lock_in_value = 99
newgas.iTrisectionValue = 100
c = my_dll.BW_NMCP_ReadAndSetGasLockParameter(newgas)
print(c)
else:
pass