6This script simply connects to a most recently used instance of winIDEA
7and starts recording data using the fast data acquisition (DAQ) controller.
8In order to do this the application must be running on the target, otherwise
9no data will be received.
11Specify variable names and their acquisition times in command line.
16import isystem.connect
as ic
23 print(
"Usage: daqRecorder.py [--verbose] <var1 samplingRate1> <var2 samplingRate2> ... <varN samplingRateN>")
25 print(
" Max number of DAQ items (N) is displayed before the start of the DAQ acquisition process.")
27 print(
" --verbose: also prints details regarding the DAQ acquisition process.")
29 print(
" If 'samplingRateInSeconds' == 0, the smallest possible sampling")
30 print(
" time is used. Supported values: 0.001, 0.01, 0.1, 1 second.")
32 print(
" To read data from digital and analog channels use name")
33 print(
" DigitalIn.DIN# and AnalogIn.AIN# where # is the desired channel number.")
35 print(
" To read from a desired (32bit only) memory location use 0x#")
36 print(
" where # is the desired memory address.")
38 print(
"Example: daqRecorder.py main_loop_counter 0.1 g_int 0.001")
39 print(
" records main_loop_counter each 100 ms, and g_int with 1 ms period.")
44 This function initializes the target. Customize it according to
48 debugCtrl = ic.CDebugFacade(cmgr)
50 debugCtrl.runUntilFunction('main')
51 debugCtrl.waitUntilStopped()
56def realTimeToDAQTimeFlags(samplTime):
58 Converts the given sampling time in seconds to EDAQSamplingFlags.
61 return ic.CDAQController.daqSampleMax
62 elif samplTime < 0.01:
63 return ic.CDAQController.daqSample1ms
65 return ic.CDAQController.daqSample10ms
67 return ic.CDAQController.daqSample100ms
69 return ic.CDAQController.daqSample1s
76def getDinSignalMask(varName):
77 prefix =
'DigitalIn.DIN'
80 if not varName.startswith(prefix):
83 indices = varName[len(prefix):].strip()
97 if (num >= 0
and num < 8):
106 return bitCount, mask
109def recordVariables(cmgr,
116 debugCtrl - iSYSTEM's debugCtrl controller, which provides access to target
118 variables - array of two element arrays, where the first element contains
119 variable name and the second element contains sampling interval,
120 for example: [[
'main_loop_counter', 0.1], [
'g_char', 0]].
121 Sampling interval set to 0 means the smallest interval possible.
123 isVerboseLogging - prints details regarding daq acquisition process.
126 List of rows, where each row
is a list containing time stamp
and recorded
127 values
in the same order
as variable names were specified. Example
for
128 two samples of three variables:
130 [0.1, 24, -525, 1.78]
134 daqCtrl = ic.CDAQController(cmgr)
136 daqInfo = daqCtrl.info()
137 if daqInfo.getMaxItems() == 0:
138 raise Exception(
"Data Acquisition (DAQ) system is not available.")
140 print(
'System properties:')
141 print(
' MaxItems = ', daqInfo.getMaxItems())
142 print(
' MaxItemSize = ', daqInfo.getMaxItemSize())
145 print(
'Configuration:')
146 for varSamplData
in variables:
147 varName = varSamplData[0]
148 samplingTime = varSamplData[1]
149 print(
" - '%s': %f"%(varName, samplingTime))
152 daqVariables = ic.DAQConfigVector()
153 for varSamplData
in variables:
154 varName = varSamplData[0]
155 samplTime = realTimeToDAQTimeFlags(varSamplData[1])
158 if varName.startswith(
'0x'):
160 bitNumIdx = varName.index(
',')
162 bySizeStr = varName[bitNumIdx+1:]
163 bySize = int(bySizeStr) // 8
164 varName = varName[:bitNumIdx]
165 print(
" Size in bytes: %d"%(bySize))
168 memAddr = int(addr, 16)
169 print(
" addr: 0x%x"%(memAddr))
171 daqVariables.append(ic.CDAQConfigItem(bySize, 0, memAddr, samplTime))
175 daqVariables.append(ic.CDAQConfigItem(varName, samplTime))
177 daqCtrl.configure(daqVariables)
180 daqTimeStart = daqCtrl.status().getTime()
183 daqCtrl.enableGlobal(
True)
185 numVars = len(variables)
189 for varData
in variables:
191 varNames.append(varName)
192 nameLen = len(varName)
193 if nameLen > longestVarName:
194 longestVarName = nameLen
196 startTime = time.time()
198 RECORDING_END_TIME = startTime + RECORDING_TIME_S
200 while time.time() < RECORDING_END_TIME:
201 daqStatus = daqCtrl.status()
203 if daqStatus.getNumSamplesAvailable() > 0:
205 print(f
"available no. of samples: {daqStatus.getNumSamplesAvailable()}")
206 if daqStatus.getOverflow():
207 print(
'SAMPLING OVERFLOW!')
210 daqSamples = ic.DAQSampleVector()
214 daqCtrl.read(daqSamples)
220 print(
"Sample acquisition duration: %fms"%((t1-t0)*1000))
221 print(
"Sample count: %d"%(len(daqSamples)))
224 for daqSample
in daqSamples:
226 varName = varNames[daqSample.getIndex()]
228 sampleTimeMs = (daqSample.getTime() - daqTimeStart) / 1000
229 columnIndex = daqSample.getIndex()+1
231 var = daqCtrl.getDataValue(daqSample)
233 if var.isTypeUnsigned()
or var.isTypeSigned ():
234 value = var.getLong()
235 elif var.isTypeFloat():
236 value = var.getDouble()
237 elif var.isTypeAddress():
238 value = var.getAddress().m_aAddress
239 elif var.isTypeCompound():
242 print(f
"{varName:>12} @ {sampleTimeMs:9.3f} ms: {value}")
246 daqCtrl.enableGlobal(
False)
250 if len(sys.argv) < 2
or '--help' in sys.argv:
256 isVerboseLogging =
False
258 if '--verbose' in sys.argv:
259 isVerboseLogging =
True
260 sys.argv.remove(
'--verbose')
267 for idx
in range(1, len(sys.argv), 2):
268 varName = sys.argv[idx]
269 varNames.append(varName)
270 samplingInfo.append([varName, float(sys.argv[idx + 1])])
272 cmgr = ic.ConnectionMgr()
273 cmgr.initLogger(
'daq',
'daqExample.log', ic.CLogger.PYTHON)
274 cmgr.connect(ic.CConnectionConfig().instanceId(winidea_id))
276 if not cmgr.isAttached():
277 print(
"The connection to winIDEA has not been established - exiting script.")
280 print(
"Established connection to winIDEA.")
282 debugCtrl = initTarget(cmgr)
287 recordVariables(cmgr, debugCtrl, samplingInfo, isVerboseLogging)
290if __name__ ==
'__main__':