Skip to content

Commit a6812e6

Browse files
author
neil.hamilton
committed
Add usbPT104.py
1 parent 9c81b7a commit a6812e6

File tree

1 file changed

+133
-0
lines changed

1 file changed

+133
-0
lines changed

picosdk/usbPT104.py

Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
#
2+
# Copyright (C) 2020 Pico Technology Ltd. See LICENSE file for terms.
3+
#
4+
"""
5+
This is a Python module defining the functions from the usbPT104Api.h C header
6+
file for Pico USB PT-104 datalogger using the usb PT104 driver API functions.
7+
"""
8+
9+
from ctypes import *
10+
from picosdk.library import Library
11+
from picosdk.ctypes_wrapper import C_CALLBACK_FUNCTION_FACTORY
12+
from picosdk.constants import make_enum
13+
14+
class usbPT104lib(Library):
15+
def __init__(self):
16+
super(usbPT104lib, self).__init__("usbPt104")
17+
18+
19+
usbPt104 = usbPT104lib()
20+
21+
usbPt104.PT104_CHANNELS = {
22+
'USBPT104_CHANNEL_1' : 1,
23+
'USBPT104_CHANNEL_2' : 2,
24+
'USBPT104_CHANNEL_3' : 3,
25+
'USBPT104_CHANNEL_4' : 4,
26+
'USBPT104_CHANNEL_5' : 5,
27+
'USBPT104_CHANNEL_6' : 6,
28+
'USBPT104_CHANNEL_7' : 7,
29+
'USBPT104_CHANNEL_8' : 8,
30+
'USBPT104_MAX_CHANNELS' : 8
31+
}
32+
33+
usbPt104.PT104_DATA_TYPE = make_enum([
34+
'USBPT104_OFF',
35+
'USBPT104_PT100',
36+
'USBPT104_PT1000',
37+
'USBPT104_RESISTANCE_TO_375R',
38+
'USBPT104_RESISTANCE_TO_10K',
39+
'USBPT104_DIFFERENTIAL_TO_115MV',
40+
'USBPT104_DIFFERENTIAL_TO_2500MV',
41+
'USBPT104_SINGLE_ENDED_TO_115MV',
42+
'USBPT104_SINGLE_ENDED_TO_2500MV',
43+
'USBPT104_MAX_DATA_TYPES'
44+
])
45+
46+
usbPt104.IP_DETAILS_TYPE = make_enum([
47+
'IDT_GET'
48+
'IDT_SET'
49+
])
50+
51+
def _define_communication_type():
52+
CT_USB = 0x00000001
53+
CT_ETHERNET = 0x00000002
54+
CT_ALL = 0xFFFFFFFF
55+
56+
return {k.upper(): v for k, v in locals().items() if k.startswith("CT")}
57+
58+
usbPt104.COMMUNICATION_TYPE = _define_communication_type
59+
60+
doc = """ PICO_STATUS UsbPt104CloseUnit
61+
(
62+
int16_t handle
63+
); """
64+
usbPt104.make_symbol("_CloseUnit", "UsbPt104CloseUnit", c_uint32, [c_int16], doc)
65+
66+
doc = """ PICO_STATUS UsbPt104Enumerate
67+
(
68+
int8_t *details,
69+
uint32_t *length,
70+
COMMUNICATION_TYPE type
71+
); """
72+
usbPt104.make_symbol("_Enumerate", "UsbPt104Enumerate", c_uint32, [c_int8, c_uint32, c_uint32], doc)
73+
74+
doc = """ PICO_STATUS UsbPt104GetUnitInfo
75+
(
76+
int16_t handle,
77+
int8_t *string,
78+
int16_t stringLength,
79+
int16_t *requiredSize,
80+
PICO_INFO info
81+
); """
82+
usbPt104.make_symbol("_GetUnitInfo", "UsbPt104GetUnitInfo", c_uint32, [c_int16, c_void_p, c_int16, c_void_p, c_uint32], doc)
83+
84+
doc = """ PICO_STATUS UsbPt104GetValue
85+
(
86+
int16_t handle,
87+
USBPT104_CHANNELS channel,
88+
int32_t *value,
89+
int16_t filtered
90+
); """
91+
usbPt104.make_symbol("_GetValue", "UsbPt104GetValue", c_uint32, [c_int16, c_uint32, c_void_p, c_int16], doc)
92+
93+
doc = """ PICO_STATUS UsbPt104IpDetails
94+
(
95+
int16_t handle,
96+
int16_t *enabled,
97+
int8_t *ipaddress,
98+
uint16_t *length,
99+
uint16_t *listeningPort,
100+
IP_DETAILS_TYPE type
101+
); """
102+
usbPt104.make_symbol("_IpDetails", "UsbPt104IpDetails", c_uint32, [c_int16, c_void_p, c_void_p, c_void_p, c_void_p, c_uint32], doc)
103+
104+
doc = """ PICO_STATUS UsbPt104OpenUnit
105+
(
106+
int16_t *handle,
107+
int8_t *serial
108+
); """
109+
usbPt104.make_symbol("_OpenUnit", "UsbPt104OpenUnit", c_uint32, [c_void_p, c_void_p], doc)
110+
111+
doc = """ PICO_STATUS UsbPt104OpenUnitViaIp
112+
(
113+
int16_t *handle,
114+
int8_t *serial,
115+
int8_t *ipAddress
116+
); """
117+
usbPt104.make_symbol("_OpenUnitViaIp", "UsbPt104OpenUnitViaIp", c_uint32, [c_void_p, c_void_p, c_void_p], doc)
118+
119+
doc = """ PICO_STATUS UsbPt104SetChannel
120+
(
121+
int16_t handle,
122+
USBPT104_CHANNELS channel,
123+
USBPT104_DATA_TYPES type,
124+
int16_t noOfWires
125+
); """
126+
usbPt104.make_symbol("_SetChannel", "UsbPt104SetChannel", c_uint32, [c_int16, c_uint32, c_uint32, c_int16], doc)
127+
128+
doc = """ PICO_STATUS UsbPt104SetMains
129+
(
130+
int16_t handle,
131+
uint16_t sixty_hertz
132+
); """
133+
usbPt104.make_symbol("_SetMains", "UsbPt104SetMains", c_uint32, [c_int16, c_uint16], doc)

0 commit comments

Comments
 (0)