Hide keyboard shortcuts

Hot-keys on this page

r m x p   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

77

78

79

80

81

82

83

84

85

86

87

88

89

90

91

92

93

94

95

96

97

98

99

100

101

102

103

104

105

106

107

108

109

110

111

112

113

114

115

116

117

118

119

120

121

122

123

124

125

126

127

128

129

130

131

132

133

134

135

136

137

138

139

140

141

142

143

144

145

146

147

148

149

150

151

152

153

154

155

156

157

158

159

160

161

162

163

164

165

166

167

168

169

170

171

172

173

174

175

176

177

178

179

180

181

182

183

184

185

186

187

188

189

190

191

192

193

194

195

196

197

198

199

200

201

202

203

204

205

206

207

208

209

210

211

212

213

214

215

216

217

218

219

220

221

222

223

224

225

226

227

228

229

230

231

232

233

234

235

236

237

238

239

240

241

242

243

244

245

246

247

248

249

250

251

252

253

254

255

256

257

258

259

260

261

262

263

264

265

266

267

268

269

"""This module provides Python bindings for the Housekeeping API of DGILib.""" 

 

from ctypes import (byref, c_uint, c_ubyte) 

 

from pydgilib.dgilib_exceptions import DeviceReturnError 

 

 

class DGILibHousekeeping(object): 

"""Python bindings for DGILib Housekeeping. 

 

DGILib is a Dynamic-Link Library (DLL) to help software applications 

communicate with Data Gateway Interface (DGI) devices. See the Data 

Gateway Interface user guide for further details. DGILib handles the 

low-level USB communication and adds a level of buffering for minimizing 

the chance of overflows. 

The library helps parse data streams of high complexity. 

""" 

 

dgilib = None 

verbose = None 

dgi_hndl = None 

 

def connect(self, device_sn): 

"""`connect`. 

 

Opens a connection to the specified device. This function must be 

called prior to any function requiring the connection handle. 

 

`int connect(char* sn, uint32_t* dgi_hndl_p)` 

 

+------------+------------+ 

| Parameter | Description | 

+============+============+ 

| *sn* | Buffer holding the serial number of the device to open a 

connection to | 

| *dgi_hndl_p* | Pointer to a variable that will hold the handle of the 

connection | 

+------------+------------+ 

 

:param device_sn: Serial number of the device 

:type device_sn: str 

:return: Variable that holds the handle of the connection 

:rtype: c_uint() 

:raises: :exc:`DeviceReturnError` 

""" 

dgi_hndl = c_uint() # Create the dgi_hndl 

 

# Initialize (not in manual, exists in dgilib.h) 

# self.dgilib.Initialize(byref(dgi_hndl)) 

 

res = self.dgilib.connect(device_sn, byref(dgi_hndl)) 

if self.verbose: 

print(f"\t{res} connect") 

if res: 

raise DeviceReturnError(f"connect returned: {res}") 

 

return dgi_hndl 

 

def disconnect(self): 

"""`disconnect`. 

 

Closes the specified connection. 

 

`int disconnect(uint32_t dgi_hndl)` 

 

+------------+------------+ 

| Parameter | Description | 

+============+============+ 

| *dgi_hndl* | Handle of the connection | 

+------------+------------+ 

 

:raises: :exc:`DeviceReturnError` 

""" 

res = self.dgilib.disconnect(self.dgi_hndl) 

if self.verbose: 

print(f"\t{res} disconnect") 

if res: 

raise DeviceReturnError(f"disconnect returned: {res}") 

 

# UnInitialize (not in manual, exists in dgilib.h) 

# self.dgilib.UnInitialize(dgi_hndl) 

 

def connection_status(self): 

"""`connection_status`. 

 

Verifies that the specified connection is still open. 

 

`int connection_status(uint32_t* dgi_hndl)` 

 

+------------+------------+ 

| Parameter | Description | 

+============+============+ 

| *dgi_hndl* | Handle of the connection | 

+------------+------------+ 

 

:return: A non-zero return value indicates a connection error. 

:rtype: int 

""" 

c_status = self.dgilib.connection_status(self.dgi_hndl) 

if self.verbose: 

print(f"connection_status: {c_status}") 

 

return c_status 

 

def get_major_version(self): 

"""`get_major_version`. 

 

Get the major version of the DGI library. 

 

`int get_major_version(void)` 

 

:return: The major version of the DGI library 

:rtype: int 

""" 

major_version = self.dgilib.get_major_version() 

 

if self.verbose: 

print(f"major_version: {major_version}") 

 

return major_version 

 

def get_minor_version(self): 

"""`get_minor_version`. 

 

Get the minor version of the DGI library. 

 

`int get_minor_version(void)` 

 

:return: The minor version of the DGI library 

:rtype: int 

""" 

minor_version = self.dgilib.get_minor_version() 

 

if self.verbose: 

print(f"minor_version: {minor_version}") 

 

return minor_version 

 

def get_build_number(self): 

"""`get_build_number`. 

 

Get the major version of the DGI library. 

 

Returns the build number of DGILib. If not supported, returns 0. 

 

`int get_build_number(void)` 

 

:return: The build number of DGILib. If not supported, returns 0. 

:rtype: int 

""" 

build_number = self.dgilib.get_build_number() 

 

if self.verbose: 

print(f"build_number: {build_number}") 

 

return build_number 

 

def get_fw_version(self): 

"""`get_fw_version`. 

 

Gets the firmware version of the DGI device connected. Note that this 

is the version of the DGI device, and not the tool. 

 

`int get_fw_version(uint32_t dgi_hndl, unsigned char* major, unsigned 

char* minor)` 

 

+------------+------------+ 

| Parameter | Description | 

+============+============+ 

| *dgi_hndl* | Handle of the connection | 

| *major* | Pointer to a variable where the major version will be 

stored | 

| *minor* | Pointer to a variable where the minor version will be 

stored | 

+------------+------------+ 

 

:return: Version information of the DGI device: 

- major_fw: the major firmware version of the DGI device connected 

- minor_fw: the minor firmware version of the DGI device connected 

:rtype: tuple(int, int) 

""" 

major_fw = c_ubyte() 

minor_fw = c_ubyte() 

res = self.dgilib.get_fw_version( 

self.dgi_hndl, byref(major_fw), byref(minor_fw)) 

if self.verbose: 

print(f"\t{res} get_fw_version") 

if res: 

raise DeviceReturnError(f"get_fw_version returned: {res}") 

if self.verbose: 

print(f"major_fw: {major_fw.value}\nminor_fw: {minor_fw.value}") 

 

return major_fw.value, minor_fw.value 

 

def start_polling(self): 

"""`start_polling`. 

 

This function will start the polling system and start acquisition on 

enabled interfaces. It is possible to enable/disable interfaces both 

before and after the polling has been started. However, no data will be 

transferred until the polling is started. 

 

`int start_polling(uint32_t dgi_hndl)` 

 

+------------+------------+ 

| Parameter | Description | 

+============+============+ 

| *dgi_hndl* | Handle of the connection | 

+------------+------------+ 

 

:param dgi_hndl: Handle of the connection 

:type dgi_hndl: c_uint() 

:raises: :exc:`DeviceReturnError` 

""" 

res = self.dgilib.start_polling(self.dgi_hndl) 

if self.verbose: 

print(f"\t{res} start_polling") 

if res: 

raise DeviceReturnError(f"start_polling returned: {res}") 

 

def stop_polling(self): 

"""`stop_polling`. 

 

This function will stop the polling system and stop acquisition on all 

interfaces. 

 

`int stop_polling(uint32_t dgi_hndl)` 

 

+------------+------------+ 

| Parameter | Description | 

+============+============+ 

| *dgi_hndl* | Handle of the connection | 

+------------+------------+ 

 

:param dgi_hndl: Handle of the connection 

:type dgi_hndl: c_uint() 

:raises: :exc:`DeviceReturnError` 

""" 

res = self.dgilib.stop_polling(self.dgi_hndl) 

if self.verbose: 

print(f"\t{res} stop_polling") 

if res: 

raise DeviceReturnError(f"stop_polling returned: {res}") 

 

def target_reset(self, hold_reset): 

"""`target_reset`. 

 

This function is used to control the state of the reset line connected 

to the target, if available. 

 

`int target_reset(uint32_t dgi_hndl, bool hold_reset)` 

 

+------------+------------+ 

| Parameter | Description | 

+============+============+ 

| *dgi_hndl* | Handle of the connection | 

| *hold_reset* | True will assert reset, false will release it | 

+------------+------------+ 

 

:param hold_reset: True will assert reset, False will release it 

:type hold_reset: bool 

:raises: :exc:`DeviceReturnError` 

""" 

res = self.dgilib.target_reset( 

self.dgi_hndl, hold_reset) 

if self.verbose: 

print(f"\t{res} target_reset {hold_reset}") 

if res: 

raise DeviceReturnError(f"target_reset returned: {res}")