-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Spitballing new API ideas #18
Comments
Seems like most of what you want is available now. When you create a async def main(con):
with DPMContext(con) as dpm_periodic:
await dpm_periodic.add_entry(...)
await dpm_periodic.add_entry(...)
with DPMContext(con) as dpm_button:
await dpm_button.add_entry(...)
# Collection doesn't start on either DPM connection
# until .start() is called.
await main_loop(dpm_periodic, dpm_button) You can build your button's handler to use the pre-made context so you're not doing service discoveries each time the button is pressed: def mk_button_handler(dpm):
async def button_pushed():
await dpm.start()
async for ii in dpm.replies():
# Do something with button-related data. Exit
# this loop when done with data.
await dpm.stop()
return button_pushed If your script raises an exception up through the async def main_loop(dpm_p, dpm_b):
# register button handler with GUI.
register_button_handler(mk_button_handler(dpm_b))
# Start-up DPM data collection for the main loop. Presumably
# this is data you want to collect constantly during execution.
await dpm_p.start()
async for ii in dpm_p.replies():
# handle periodic data |
The current API closely follows the underlying DPM protocol. I was hoping for an API that was a little more exotic. For instance: # Get devices. If a device doesn't exist, an exception will be raised.
d_temp = Device('M:OUTTMP')
d_humid = Device('G:HUMID')
# Create a collection rate context
a = Acquisition('e,8f')
# Now enjoy correlated data
async for (ts, v_temp, v_humid) in a.start(d_temp, d_humid):
print(f'timestamp: {ts}, temperature: {v_temp}, humidity: {v_humid}') |
Quick thought on potential API
Inside dpm start() the code could group like handler_methods and attach it to a Thread. Maintain threads in a pool so that the number of threads is manageable and that dead time between thread executions allow threads to pop.
The text was updated successfully, but these errors were encountered: