using libmodbus with python ctypes

Asked by Pradeep Gowda

I'm trying to use libmodbus from python using ctypes. I'm using libmodbus trunk.

I created the python classes for libmodbus header (structures, constants etc.,) using ctypeslib.

The code i wrote to connect to a modbus slave is:

$ cat mbinterface.py

from ctypes import *
from modbus_ctypes import *
try:
    cdll.LoadLibrary("libmodbus.so")
except:
    print "Unable to load libmodbus.so"
    exit(0)

def main():
    mb = CDLL("libmodbus.so")
    mb_param = modbus_param_t()

    mb.modbus_init_rtu(byref(mb_param),"/dev/ttyUSB0", 9600, "none", 8, 1, 1)
    mb.modbus_set_debug(byref(mb_param), True)
    res = mb.modbus_connect(byref(mb_param))
    print 'device : %s, baud: %s' % (mb_param.device, mb_param.baud)
    print 'parity : %s, slave: %s ' % ( mb_param.parity, mb_param.slave)

and the output is:
$ python mbinterface.py

Opening /dev/ttyUSB0 at 9600 bauds (none)
device : , baud: 0
parity : , slave: 3

I'm perplexed that interface and parity paramters have been assigned correctly, but not the slave id.

Question information

Language:
English Edit question
Status:
Solved
For:
libmodbus Edit question
Assignee:
No assignee Edit question
Solved by:
Pradeep Gowda
Solved:
Last query:
Last reply:
Revision history for this message
Stéphane Raimbault (sra) said :
#1

You don't handle correctly the types of data because device and parity are strings and baud and slave must be integers so something is certainly wrong in your modbus_ctypes.

Revision history for this message
Pradeep Gowda (btbytes) said :
#2

It appears i'd not installed (`sudo make install`) the latest version of libmodbus.

This is the working code, which prints the uptime, in seconds of Wattnode Modbus meter.

from ctypes import *
from modbus_ctypes import *
try:
    cdll.LoadLibrary("libmodbus.so")
except:
    print "Unable to load libmodbus.so"
    exit(0)

def main():
    mb = CDLL("libmodbus.so")
    mb_param = modbus_param_t()
    tab_rp_registers = c_uint16()

    bauds = c_int(9600)
    slave = c_int(1)
    bits = c_int(8)
    stop_bits = c_int(1)
    device = c_char_p("/dev/ttyUSB0")
    parity = c_char_p("none")

    mb.modbus_init_rtu(byref(mb_param), device, bauds, parity, bits, stop_bits, slave)
    mb.modbus_set_slave(byref(mb_param), 1)
    mb.modbus_set_debug(byref(mb_param), True)
    mb.modbus_connect(byref(mb_param))
    mb.read_holding_registers(byref(mb_param), 1702, 2, byref(tab_rp_registers));
    val = mb.modbus_read_float(byref(tab_rp_registers))
    print val
    print 'done.'
    mb.modbus_close(byref(mb_param))

if __name__ == '__main__':
    main()

Revision history for this message
Stéphane Raimbault (sra) said :
#3

Great, could you share your code (ctypes), please?

Revision history for this message
matthias (mfuchs) said :
#4

I am also very interested in the modbus_ctypes module. Can you either post it here?

Revision history for this message
Pradeep Gowda (btbytes) said :
#5

This is autogenerated using h2xml.py and xml2py.py scripts
as outlined here: http://starship.python.net/crew/theller/ctypes/old/codegen.html

The file generated by me is below
-------

from ctypes import *

STRING = c_char_p

IPPORT_SMTP = 25
IPPORT_CMDSERVER = 514
IPPORT_EXECSERVER = 512
IPPORT_FINGER = 79
IPPORT_NAMESERVER = 42
IPPORT_DAYTIME = 13
IPPROTO_DCCP = 33
SCM_CREDENTIALS = 2
IPPROTO_IGMP = 2
IPPROTO_FRAGMENT = 44
MSG_SYN = 1024
IPPROTO_RSVP = 46
SCM_RIGHTS = 1
MSG_CONFIRM = 2048
IPPROTO_NONE = 59
FLUSH_OR_CONNECT_ON_ERROR = 0
IPPORT_USERRESERVED = 5000
TCP_CA_CWR = 2
TCP_FIN_WAIT1 = 4
TCP_TIME_WAIT = 6
IPPORT_WHOIS = 43
IPPROTO_ROUTING = 43
MSG_NOSIGNAL = 16384
SHUT_RD = 0
IPPROTO_DSTOPTS = 60
IPPROTO_HOPOPTS = 0
TCP_LAST_ACK = 9
IPPORT_RJE = 77
SHUT_RDWR = 2
IPPROTO_UDP = 17
TCP = 1
MSG_RST = 4096
IPPROTO_IPV6 = 41
IPPROTO_IPIP = 4
IPPORT_DISCARD = 9
TCP_CA_Open = 0
SOCK_NONBLOCK = 2048
IPPORT_SYSTAT = 11
TCP_CA_Loss = 4
IPPROTO_UDPLITE = 136
IPPROTO_AH = 51
IPPORT_RESERVED = 1024
SOCK_PACKET = 10
MSG_MORE = 32768
TCP_CLOSE = 7
SOCK_SEQPACKET = 5
IPPROTO_ESP = 50
IPPORT_NETSTAT = 15
MSG_PROXY = 16
IPPROTO_TP = 29
TCP_CLOSE_WAIT = 8
MSG_PEEK = 2
IPPROTO_GRE = 47
SOCK_CLOEXEC = 524288
SHUT_WR = 1
TCP_FIN_WAIT2 = 5
MSG_CTRUNC = 8
SOCK_STREAM = 1
MSG_TRUNC = 32
TCP_SYN_RECV = 3
IPPORT_WHOSERVER = 513
IPPROTO_ENCAP = 98
IPPORT_TELNET = 23
TCP_CA_Disorder = 1
MSG_DONTROUTE = 4
RTU = 0
IPPORT_TIMESERVER = 37
IPPROTO_IDP = 22
IPPROTO_ICMP = 1
SOCK_RDM = 4
IPPORT_SUPDUP = 95
IPPORT_MTP = 57
SOCK_DCCP = 6
IPPROTO_TCP = 6
IPPROTO_ICMPV6 = 58
MSG_DONTWAIT = 64
MSG_FIN = 512
MSG_EOR = 128
MSG_TRYHARD = 4
TCP_LISTEN = 10
IPPORT_LOGINSERVER = 513
IPPROTO_MTP = 92
MSG_WAITALL = 256
SOCK_DGRAM = 2
IPPROTO_PUP = 12
TCP_ESTABLISHED = 1
IPPROTO_PIM = 103
IPPORT_ECHO = 7
IPPROTO_MAX = 256
IPPORT_FTP = 21
IPPROTO_RAW = 255
TCP_CA_Recovery = 3
NOP_ON_ERROR = 1
IPPORT_ROUTESERVER = 520
IPPORT_TFTP = 69
IPPORT_EFSSERVER = 520
IPPROTO_IP = 0
TCP_SYN_SENT = 2
IPPORT_TTYLINK = 87
MSG_OOB = 1
TCP_CLOSING = 11
IPPROTO_SCTP = 132
MSG_CMSG_CLOEXEC = 1073741824
IPPROTO_COMP = 108
IPPROTO_EGP = 8
MSG_ERRQUEUE = 8192
SOCK_RAW = 3
IPPORT_BIFFUDP = 512

# values for enumeration 'type_com_t'
type_com_t = c_int # enum

# values for enumeration 'error_handling_t'
error_handling_t = c_int # enum
class modbus_param_t(Structure):
    pass
uint8_t = c_uint8
class termios(Structure):
    pass
tcflag_t = c_uint
cc_t = c_ubyte
speed_t = c_uint
termios._fields_ = [
    ('c_iflag', tcflag_t),
    ('c_oflag', tcflag_t),
    ('c_cflag', tcflag_t),
    ('c_lflag', tcflag_t),
    ('c_line', cc_t),
    ('c_cc', cc_t * 32),
    ('c_ispeed', speed_t),
    ('c_ospeed', speed_t),
]
modbus_param_t._fields_ = [
    ('slave', c_int),
    ('fd', c_int),
    ('type_com', type_com_t),
    ('debug', c_int),
    ('port', c_int),
    ('device', c_char * 16),
    ('baud', c_int),
    ('data_bit', uint8_t),
    ('stop_bit', uint8_t),
    ('parity', c_char * 5),
    ('error_handling', uint8_t),
    ('ip', c_char * 16),
    ('old_tios', termios),
]
class modbus_mapping_t(Structure):
    pass
uint16_t = c_uint16
modbus_mapping_t._fields_ = [
    ('nb_coil_status', c_int),
    ('nb_input_status', c_int),
    ('nb_input_registers', c_int),
    ('nb_holding_registers', c_int),
    ('tab_coil_status', POINTER(uint8_t)),
    ('tab_input_status', POINTER(uint8_t)),
    ('tab_input_registers', POINTER(uint16_t)),
    ('tab_holding_registers', POINTER(uint16_t)),
]
class ip_opts(Structure):
    pass
class in_addr(Structure):
    pass
uint32_t = c_uint32
in_addr_t = uint32_t
in_addr._fields_ = [
    ('s_addr', in_addr_t),
]
ip_opts._fields_ = [
    ('ip_dst', in_addr),
    ('ip_opts', c_char * 40),
]
class ip_mreqn(Structure):
    pass
ip_mreqn._fields_ = [
    ('imr_multiaddr', in_addr),
    ('imr_address', in_addr),
    ('imr_ifindex', c_int),
]
class in_pktinfo(Structure):
    pass
in_pktinfo._fields_ = [
    ('ipi_ifindex', c_int),
    ('ipi_spec_dst', in_addr),
    ('ipi_addr', in_addr),
]
pthread_t = c_ulong
class pthread_attr_t(Union):
    pass
pthread_attr_t._fields_ = [
    ('__size', c_char * 36),
    ('__align', c_long),
]
class __pthread_internal_slist(Structure):
    pass
__pthread_internal_slist._fields_ = [
    ('__next', POINTER(__pthread_internal_slist)),
]
__pthread_slist_t = __pthread_internal_slist
class __pthread_mutex_s(Structure):
    pass
class N15pthread_mutex_t17__pthread_mutex_s3DOT_5E(Union):
    pass
N15pthread_mutex_t17__pthread_mutex_s3DOT_5E._fields_ = [
    ('__spins', c_int),
    ('__list', __pthread_slist_t),
]
__pthread_mutex_s._anonymous_ = ['_0']
__pthread_mutex_s._fields_ = [
    ('__lock', c_int),
    ('__count', c_uint),
    ('__owner', c_int),
    ('__kind', c_int),
    ('__nusers', c_uint),
    ('_0', N15pthread_mutex_t17__pthread_mutex_s3DOT_5E),
]
class pthread_mutex_t(Union):
    pass
pthread_mutex_t._fields_ = [
    ('__data', __pthread_mutex_s),
    ('__size', c_char * 24),
    ('__align', c_long),
]
class pthread_mutexattr_t(Union):
    pass
pthread_mutexattr_t._fields_ = [
    ('__size', c_char * 4),
    ('__align', c_int),
]
class N14pthread_cond_t3DOT_8E(Structure):
    pass
N14pthread_cond_t3DOT_8E._pack_ = 4
N14pthread_cond_t3DOT_8E._fields_ = [
    ('__lock', c_int),
    ('__futex', c_uint),
    ('__total_seq', c_ulonglong),
    ('__wakeup_seq', c_ulonglong),
    ('__woken_seq', c_ulonglong),
    ('__mutex', c_void_p),
    ('__nwaiters', c_uint),
    ('__broadcast_seq', c_uint),
]
class pthread_cond_t(Union):
    pass
pthread_cond_t._pack_ = 4
pthread_cond_t._fields_ = [
    ('__data', N14pthread_cond_t3DOT_8E),
    ('__size', c_char * 48),
    ('__align', c_longlong),
]
class pthread_condattr_t(Union):
    pass
pthread_condattr_t._fields_ = [
    ('__size', c_char * 4),
    ('__align', c_int),
]
pthread_key_t = c_uint
pthread_once_t = c_int
class N16pthread_rwlock_t4DOT_11E(Structure):
    pass
N16pthread_rwlock_t4DOT_11E._fields_ = [
    ('__lock', c_int),
    ('__nr_readers', c_uint),
    ('__readers_wakeup', c_uint),
    ('__writer_wakeup', c_uint),
    ('__nr_readers_queued', c_uint),
    ('__nr_writers_queued', c_uint),
    ('__flags', c_ubyte),
    ('__shared', c_ubyte),
    ('__pad1', c_ubyte),
    ('__pad2', c_ubyte),
    ('__writer', c_int),
]
class pthread_rwlock_t(Union):
    pass
pthread_rwlock_t._fields_ = [
    ('__data', N16pthread_rwlock_t4DOT_11E),
    ('__size', c_char * 32),
    ('__align', c_long),
]
class pthread_rwlockattr_t(Union):
    pass
pthread_rwlockattr_t._fields_ = [
    ('__size', c_char * 8),
    ('__align', c_long),
]
pthread_spinlock_t = c_int
class pthread_barrier_t(Union):
    pass
pthread_barrier_t._fields_ = [
    ('__size', c_char * 20),
    ('__align', c_long),
]
class pthread_barrierattr_t(Union):
    pass
pthread_barrierattr_t._fields_ = [
    ('__size', c_char * 4),
    ('__align', c_int),
]
__sig_atomic_t = c_int
class __sigset_t(Structure):
    pass
__sigset_t._fields_ = [
    ('__val', c_ulong * 32),
]
sa_family_t = c_ushort
__socklen_t = c_uint
socklen_t = __socklen_t

# values for enumeration '__socket_type'
__socket_type = c_int # enum
class sockaddr(Structure):
    pass
sockaddr._fields_ = [
    ('sa_family', sa_family_t),
    ('sa_data', c_char * 14),
]
class sockaddr_storage(Structure):
    pass
sockaddr_storage._fields_ = [
    ('ss_family', sa_family_t),
    ('__ss_align', c_ulong),
    ('__ss_padding', c_char * 120),
]

# values for unnamed enumeration
class msghdr(Structure):
    pass
class iovec(Structure):
    pass
size_t = c_uint
msghdr._fields_ = [
    ('msg_name', c_void_p),
    ('msg_namelen', socklen_t),
    ('msg_iov', POINTER(iovec)),
    ('msg_iovlen', size_t),
    ('msg_control', c_void_p),
    ('msg_controllen', size_t),
    ('msg_flags', c_int),
]
class cmsghdr(Structure):
    pass
cmsghdr._fields_ = [
    ('cmsg_len', size_t),
    ('cmsg_level', c_int),
    ('cmsg_type', c_int),
    ('__cmsg_data', c_ubyte * 0),
]

# values for unnamed enumeration
class ucred(Structure):
    pass
__pid_t = c_int
pid_t = __pid_t
__uid_t = c_uint
uid_t = __uid_t
__gid_t = c_uint
gid_t = __gid_t
ucred._fields_ = [
    ('pid', pid_t),
    ('uid', uid_t),
    ('gid', gid_t),
]
class linger(Structure):
    pass
linger._fields_ = [
    ('l_onoff', c_int),
    ('l_linger', c_int),
]
class timeval(Structure):
    pass
__time_t = c_long
__suseconds_t = c_long
timeval._fields_ = [
    ('tv_sec', __time_t),
    ('tv_usec', __suseconds_t),
]
__u_char = c_ubyte
__u_short = c_ushort
__u_int = c_uint
__u_long = c_ulong
__int8_t = c_byte
__uint8_t = c_ubyte
__int16_t = c_short
__uint16_t = c_ushort
__int32_t = c_int
__uint32_t = c_uint
__int64_t = c_longlong
__uint64_t = c_ulonglong
__quad_t = c_longlong
__u_quad_t = c_ulonglong
__dev_t = __u_quad_t
__ino_t = c_ulong
__ino64_t = __u_quad_t
__mode_t = c_uint
__nlink_t = c_uint
__off_t = c_long
__off64_t = __quad_t
class __fsid_t(Structure):
    pass
__fsid_t._fields_ = [
    ('__val', c_int * 2),
]
__clock_t = c_long
__rlim_t = c_ulong
__rlim64_t = __u_quad_t
__id_t = c_uint
__useconds_t = c_uint
__daddr_t = c_int
__swblk_t = c_long
__key_t = c_int
__clockid_t = c_int
__timer_t = c_void_p
__blksize_t = c_long
__blkcnt_t = c_long
__blkcnt64_t = __quad_t
__fsblkcnt_t = c_ulong
__fsblkcnt64_t = __u_quad_t
__fsfilcnt_t = c_ulong
__fsfilcnt64_t = __u_quad_t
__ssize_t = c_int
__loff_t = __off64_t
__qaddr_t = POINTER(__quad_t)
__caddr_t = STRING
__intptr_t = c_int
iovec._fields_ = [
    ('iov_base', c_void_p),
    ('iov_len', size_t),
]

# values for unnamed enumeration
in_port_t = uint16_t

# values for unnamed enumeration
class in6_addr(Structure):
    pass
class N8in6_addr4DOT_20E(Union):
    pass
N8in6_addr4DOT_20E._fields_ = [
    ('__u6_addr8', uint8_t * 16),
    ('__u6_addr16', uint16_t * 8),
    ('__u6_addr32', uint32_t * 4),
]
in6_addr._fields_ = [
    ('__in6_u', N8in6_addr4DOT_20E),
]
class sockaddr_in(Structure):
    pass
sockaddr_in._fields_ = [
    ('sin_family', sa_family_t),
    ('sin_port', in_port_t),
    ('sin_addr', in_addr),
    ('sin_zero', c_ubyte * 8),
]
class sockaddr_in6(Structure):
    pass
sockaddr_in6._fields_ = [
    ('sin6_family', sa_family_t),
    ('sin6_port', in_port_t),
    ('sin6_flowinfo', uint32_t),
    ('sin6_addr', in6_addr),
    ('sin6_scope_id', uint32_t),
]
class ip_mreq(Structure):
    pass
ip_mreq._fields_ = [
    ('imr_multiaddr', in_addr),
    ('imr_interface', in_addr),
]
class ip_mreq_source(Structure):
    pass
ip_mreq_source._fields_ = [
    ('imr_multiaddr', in_addr),
    ('imr_interface', in_addr),
    ('imr_sourceaddr', in_addr),
]
class ipv6_mreq(Structure):
    pass
ipv6_mreq._fields_ = [
    ('ipv6mr_multiaddr', in6_addr),
    ('ipv6mr_interface', c_uint),
]
class group_req(Structure):
    pass
group_req._fields_ = [
    ('gr_interface', uint32_t),
    ('gr_group', sockaddr_storage),
]
class group_source_req(Structure):
    pass
group_source_req._fields_ = [
    ('gsr_interface', uint32_t),
    ('gsr_group', sockaddr_storage),
    ('gsr_source', sockaddr_storage),
]
class ip_msfilter(Structure):
    pass
ip_msfilter._fields_ = [
    ('imsf_multiaddr', in_addr),
    ('imsf_interface', in_addr),
    ('imsf_fmode', uint32_t),
    ('imsf_numsrc', uint32_t),
    ('imsf_slist', in_addr * 1),
]
class group_filter(Structure):
    pass
group_filter._fields_ = [
    ('gf_interface', uint32_t),
    ('gf_group', sockaddr_storage),
    ('gf_fmode', uint32_t),
    ('gf_numsrc', uint32_t),
    ('gf_slist', sockaddr_storage * 1),
]
class in6_pktinfo(Structure):
    pass
in6_pktinfo._fields_ = [
    ('ipi6_addr', in6_addr),
    ('ipi6_ifindex', c_uint),
]
class ip6_mtuinfo(Structure):
    pass
ip6_mtuinfo._fields_ = [
    ('ip6m_addr', sockaddr_in6),
    ('ip6m_mtu', uint32_t),
]
class timestamp(Structure):
    pass
u_int8_t = c_ubyte
u_int32_t = c_uint
timestamp._fields_ = [
    ('len', u_int8_t),
    ('ptr', u_int8_t),
    ('flags', c_uint, 4),
    ('overflow', c_uint, 4),
    ('data', u_int32_t * 9),
]
class iphdr(Structure):
    pass
u_int16_t = c_ushort
iphdr._fields_ = [
    ('ihl', c_uint, 4),
    ('version', c_uint, 4),
    ('tos', u_int8_t),
    ('tot_len', u_int16_t),
    ('id', u_int16_t),
    ('frag_off', u_int16_t),
    ('ttl', u_int8_t),
    ('protocol', u_int8_t),
    ('check', u_int16_t),
    ('saddr', u_int32_t),
    ('daddr', u_int32_t),
]
class ip(Structure):
    pass
u_short = __u_short
ip._fields_ = [
    ('ip_hl', c_uint, 4),
    ('ip_v', c_uint, 4),
    ('ip_tos', u_int8_t),
    ('ip_len', u_short),
    ('ip_id', u_short),
    ('ip_off', u_short),
    ('ip_ttl', u_int8_t),
    ('ip_p', u_int8_t),
    ('ip_sum', u_short),
    ('ip_src', in_addr),
    ('ip_dst', in_addr),
]
class ip_timestamp(Structure):
    pass
ip_timestamp._fields_ = [
    ('ipt_code', u_int8_t),
    ('ipt_len', u_int8_t),
    ('ipt_ptr', u_int8_t),
    ('ipt_flg', c_uint, 4),
    ('ipt_oflw', c_uint, 4),
    ('data', u_int32_t * 9),
]
class tcphdr(Structure):
    pass
tcphdr._fields_ = [
    ('source', u_int16_t),
    ('dest', u_int16_t),
    ('seq', u_int32_t),
    ('ack_seq', u_int32_t),
    ('res1', u_int16_t, 4),
    ('doff', u_int16_t, 4),
    ('fin', u_int16_t, 1),
    ('syn', u_int16_t, 1),
    ('rst', u_int16_t, 1),
    ('psh', u_int16_t, 1),
    ('ack', u_int16_t, 1),
    ('urg', u_int16_t, 1),
    ('res2', u_int16_t, 2),
    ('window', u_int16_t),
    ('check', u_int16_t),
    ('urg_ptr', u_int16_t),
]

# values for unnamed enumeration

# values for enumeration 'tcp_ca_state'
tcp_ca_state = c_int # enum
class tcp_info(Structure):
    pass
tcp_info._fields_ = [
    ('tcpi_state', u_int8_t),
    ('tcpi_ca_state', u_int8_t),
    ('tcpi_retransmits', u_int8_t),
    ('tcpi_probes', u_int8_t),
    ('tcpi_backoff', u_int8_t),
    ('tcpi_options', u_int8_t),
    ('tcpi_snd_wscale', u_int8_t, 4),
    ('tcpi_rcv_wscale', u_int8_t, 4),
    ('tcpi_rto', u_int32_t),
    ('tcpi_ato', u_int32_t),
    ('tcpi_snd_mss', u_int32_t),
    ('tcpi_rcv_mss', u_int32_t),
    ('tcpi_unacked', u_int32_t),
    ('tcpi_sacked', u_int32_t),
    ('tcpi_lost', u_int32_t),
    ('tcpi_retrans', u_int32_t),
    ('tcpi_fackets', u_int32_t),
    ('tcpi_last_data_sent', u_int32_t),
    ('tcpi_last_ack_sent', u_int32_t),
    ('tcpi_last_data_recv', u_int32_t),
    ('tcpi_last_ack_recv', u_int32_t),
    ('tcpi_pmtu', u_int32_t),
    ('tcpi_rcv_ssthresh', u_int32_t),
    ('tcpi_rtt', u_int32_t),
    ('tcpi_rttvar', u_int32_t),
    ('tcpi_snd_ssthresh', u_int32_t),
    ('tcpi_snd_cwnd', u_int32_t),
    ('tcpi_advmss', u_int32_t),
    ('tcpi_reordering', u_int32_t),
    ('tcpi_rcv_rtt', u_int32_t),
    ('tcpi_rcv_space', u_int32_t),
    ('tcpi_total_retrans', u_int32_t),
]
class tcp_md5sig(Structure):
    pass
tcp_md5sig._fields_ = [
    ('tcpm_addr', sockaddr_storage),
    ('__tcpm_pad1', u_int16_t),
    ('tcpm_keylen', u_int16_t),
    ('__tcpm_pad2', u_int32_t),
    ('tcpm_key', u_int8_t * 80),
]
int8_t = c_int8
int16_t = c_int16
int32_t = c_int32
int64_t = c_int64
uint64_t = c_uint64
int_least8_t = c_byte
int_least16_t = c_short
int_least32_t = c_int
int_least64_t = c_longlong
uint_least8_t = c_ubyte
uint_least16_t = c_ushort
uint_least32_t = c_uint
uint_least64_t = c_ulonglong
int_fast8_t = c_byte
int_fast16_t = c_int
int_fast32_t = c_int
int_fast64_t = c_longlong
uint_fast8_t = c_ubyte
uint_fast16_t = c_uint
uint_fast32_t = c_uint
uint_fast64_t = c_ulonglong
intptr_t = c_int
uintptr_t = c_uint
intmax_t = c_longlong
uintmax_t = c_ulonglong
sigset_t = __sigset_t
__fd_mask = c_long
class fd_set(Structure):
    pass
fd_set._fields_ = [
    ('fds_bits', __fd_mask * 32),
]
fd_mask = __fd_mask
class osockaddr(Structure):
    pass
osockaddr._fields_ = [
    ('sa_family', c_ushort),
    ('sa_data', c_ubyte * 14),
]

# values for unnamed enumeration
u_char = __u_char
u_int = __u_int
u_long = __u_long
quad_t = __quad_t
u_quad_t = __u_quad_t
fsid_t = __fsid_t
loff_t = __loff_t
ino_t = __ino_t
ino64_t = __ino64_t
dev_t = __dev_t
mode_t = __mode_t
nlink_t = __nlink_t
off_t = __off_t
off64_t = __off64_t
id_t = __id_t
ssize_t = __ssize_t
daddr_t = __daddr_t
caddr_t = __caddr_t
key_t = __key_t
useconds_t = __useconds_t
suseconds_t = __suseconds_t
ulong = c_ulong
ushort = c_ushort
uint = c_uint
u_int64_t = c_ulonglong
register_t = c_int
blksize_t = __blksize_t
blkcnt_t = __blkcnt_t
fsblkcnt_t = __fsblkcnt_t
fsfilcnt_t = __fsfilcnt_t
blkcnt64_t = __blkcnt64_t
fsblkcnt64_t = __fsblkcnt64_t
fsfilcnt64_t = __fsfilcnt64_t
clock_t = __clock_t
time_t = __time_t
clockid_t = __clockid_t
timer_t = __timer_t
class timespec(Structure):
    pass
timespec._fields_ = [
    ('tv_sec', __time_t),
    ('tv_nsec', c_long),
]
__all__ = ['__uint16_t', '__pthread_mutex_s', '__int16_t', 'uid_t',
           'modbus_mapping_t', 'FLUSH_OR_CONNECT_ON_ERROR',
           'IPPORT_RESERVED', 'MSG_PEEK', '__time_t',
           'pthread_condattr_t', 'uint_least32_t', 'in_pktinfo',
           'fsfilcnt_t', '__fsid_t', 'mode_t', 'MSG_DONTROUTE',
           'size_t', 'tcp_info', 'tcphdr', 'ip_timestamp',
           'SOCK_SEQPACKET', 'intptr_t', 'IPPROTO_IPIP',
           'TCP_SYN_SENT', 'gid_t', 'ino_t', 'IPPORT_EXECSERVER',
           'pthread_barrierattr_t', 'uint_least16_t',
           'IPPROTO_ICMPV6', 'IPPORT_ROUTESERVER', '__ino64_t',
           'fsblkcnt64_t', '__qaddr_t', 'IPPROTO_COMP', 'iphdr',
           'SOCK_DCCP', 'IPPROTO_FRAGMENT', 'off64_t', 'id_t',
           'blksize_t', 'uint_fast64_t', 'timestamp', 'int_least32_t',
           'MSG_CTRUNC', 'IPPROTO_RSVP', 'MSG_TRUNC', 'u_char',
           'dev_t', 'int32_t', 'SOCK_RDM', 'IPPROTO_AH', 'u_int64_t',
           'u_int16_t', 'IPPROTO_UDPLITE', 'TCP_CA_CWR', 'in_port_t',
           'MSG_RST', 'IPPORT_MTP', 'MSG_OOB', 'IPPORT_TTYLINK',
           'int_least16_t', 'TCP_CA_Loss', 'IPPORT_SMTP',
           'uint_fast16_t', 'sigset_t', '__int32_t', 'IPPROTO_MAX',
           'ip_mreqn', 'pthread_rwlock_t', 'IPPROTO_IP', '__nlink_t',
           '__swblk_t', 'time_t', 'IPPORT_USERRESERVED', 'fd_set',
           '__ssize_t', 'fsid_t', 'TCP_TIME_WAIT', 'u_long',
           'IPPORT_EFSSERVER', 'IPPORT_WHOIS', 'SOCK_STREAM',
           'type_com_t', '__fd_mask', 'intmax_t', 'int16_t',
           'uintmax_t', 'clock_t', 'u_int32_t', 'MSG_NOSIGNAL',
           'TCP_FIN_WAIT2', 'IPPROTO_PUP', 'TCP_FIN_WAIT1',
           '__sigset_t', '__clockid_t', '__useconds_t',
           'uint_fast32_t', 'int_least8_t', 'ip6_mtuinfo',
           'SOCK_NONBLOCK', 'IPPROTO_RAW', 'IPPROTO_TP', 'socklen_t',
           'TCP', 'RTU', '__fsfilcnt64_t', 'IPPORT_SUPDUP',
           'timespec', 'off_t', 'IPPORT_DISCARD', '__off64_t',
           'MSG_TRYHARD', 'MSG_ERRQUEUE', 'uint_least8_t',
           'pthread_barrier_t', '__gid_t', 'ucred', 'IPPROTO_IGMP',
           'in_addr', 'pthread_mutexattr_t', 'SHUT_RDWR',
           'SOCK_CLOEXEC', '__uint32_t', 'SCM_CREDENTIALS',
           'IPPROTO_ENCAP', 'IPPROTO_ESP', 'IPPROTO_IPV6',
           '__blkcnt64_t', 'SHUT_RD', 'in6_addr', 'IPPORT_FINGER',
           'ip_mreq_source', '__uint64_t', 'MSG_WAITALL', 'linger',
           'SCM_RIGHTS', 'ushort', '__blkcnt_t', 'pthread_t',
           'clockid_t', 'IPPROTO_DSTOPTS', 'pthread_attr_t',
           'cmsghdr', 'IPPROTO_DCCP', 'msghdr', '__rlim64_t',
           'uint16_t', 'IPPROTO_GRE', 'uint_fast8_t', 'u_int8_t',
           'IPPROTO_TCP', 'SHUT_WR', 'group_filter', 'uint',
           'IPPROTO_ICMP', '__mode_t', 'uint_least64_t',
           'MSG_CONFIRM', 'IPPROTO_HOPOPTS', 'speed_t',
           'IPPORT_DAYTIME', '__blksize_t', 'SOCK_RAW',
           'pthread_spinlock_t', '__off_t', '__pthread_slist_t',
           'blkcnt_t', '__intptr_t', 'IPPROTO_IDP', 'IPPORT_BIFFUDP',
           'u_quad_t', 'group_source_req', 'SOCK_DGRAM', '__loff_t',
           '__u_long', 'modbus_param_t', 'fsfilcnt64_t',
           'TCP_CLOSING', 'tcp_md5sig', 'IPPROTO_EGP', '__daddr_t',
           '__timer_t', 'IPPORT_WHOSERVER', 'ip', '__sig_atomic_t',
           'ino64_t', 'TCP_LAST_ACK', 'int_least64_t',
           '__pthread_internal_slist', 'IPPORT_FTP', 'SOCK_PACKET',
           '__quad_t', 'uintptr_t', 'TCP_LISTEN', '__uint8_t',
           'sockaddr_storage', 'key_t', '__u_char', '__fsblkcnt64_t',
           'termios', '__caddr_t', 'MSG_EOR', 'int_fast8_t',
           '__dev_t', 'IPPORT_SYSTAT', 'ip_msfilter', 'IPPORT_TELNET',
           'IPPORT_TIMESERVER', 'MSG_SYN', '__suseconds_t', 'pid_t',
           'N15pthread_mutex_t17__pthread_mutex_s3DOT_5E', 'timer_t',
           'quad_t', 'MSG_PROXY', 'IPPORT_NAMESERVER', 'MSG_FIN',
           'pthread_once_t', 'useconds_t', '__socklen_t',
           'pthread_key_t', 'register_t', 'uint64_t', 'fd_mask',
           'blkcnt64_t', 'IPPORT_TFTP', 'sockaddr',
           'N14pthread_cond_t3DOT_8E', 'pthread_cond_t', 'group_req',
           'IPPORT_LOGINSERVER', 'tcflag_t', 'sockaddr_in', 'int64_t',
           'TCP_ESTABLISHED', 'IPPORT_NETSTAT', '__socket_type',
           'int_fast16_t', 'u_int', 'TCP_CA_Disorder', 'in6_pktinfo',
           'iovec', '__fsblkcnt_t', 'error_handling_t', '__rlim_t',
           'MSG_DONTWAIT', 'TCP_CA_Open', 'u_short', 'int_fast32_t',
           'nlink_t', 'tcp_ca_state', 'ssize_t', 'sa_family_t',
           'timeval', 'daddr_t', '__int64_t', '__u_quad_t',
           '__u_short', 'loff_t', 'int_fast64_t', 'IPPROTO_SCTP',
           '__int8_t', '__id_t', 'ip_opts', 'ipv6_mreq',
           'TCP_CLOSE_WAIT', '__pid_t', 'IPPROTO_MTP', 'ip_mreq',
           'ulong', 'IPPROTO_ROUTING', 'N16pthread_rwlock_t4DOT_11E',
           'fsblkcnt_t', 'TCP_SYN_RECV', 'caddr_t', '__ino_t',
           'N8in6_addr4DOT_20E', 'IPPORT_CMDSERVER', 'sockaddr_in6',
           'pthread_rwlockattr_t', 'TCP_CA_Recovery', 'NOP_ON_ERROR',
           'int8_t', 'IPPROTO_PIM', 'IPPROTO_NONE', 'in_addr_t',
           'osockaddr', 'IPPROTO_UDP', 'TCP_CLOSE', '__u_int',
           'suseconds_t', 'IPPORT_RJE', 'IPPORT_ECHO',
           'pthread_mutex_t', 'cc_t', '__key_t', 'uint32_t',
           '__clock_t', 'MSG_MORE', '__uid_t', 'uint8_t',
           '__fsfilcnt_t', 'MSG_CMSG_CLOEXEC']