Skip to content

Instantly share code, notes, and snippets.

@JimiC
Created December 18, 2017 14:51
Show Gist options
  • Save JimiC/37230a840b85d221a299b682a889d44b to your computer and use it in GitHub Desktop.
Save JimiC/37230a840b85d221a299b682a889d44b to your computer and use it in GitHub Desktop.
Demo
import asyncio
import threading
status = 0
def set_interval(func, sec):
def func_wrapper():
set_interval(func, sec)
func()
t = threading.Timer(sec, func_wrapper)
t.start()
return t
def modbus_read():
global status
while status != 0:
print('waiting')
status = -1
print("reading from mod_bus")
status = 0
def modbus_write():
global status
while status != 0:
print('waiting')
status = 1
print("writing to mod_bus")
status = 0
def on_message():
modbus_write()
@asyncio.coroutine
def main():
set_interval(modbus_read, 1)
set_interval(on_message, 5)
loop = asyncio.get_event_loop()
future = asyncio.Future()
asyncio.async(main())
loop.run_forever()
loop.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment