Another NOOB question relating to the uasyncio way of doing things:
In the section of code below, if I wanted to call one routine from another. The routine will execute then return a value.
I am clearly doing something incorrectly. Again I hope an expert will point out the error with a short explanation as to how to do this properly.
Code: Select all
async def adc_right():
while True:
### Do things
### Do things
### Do things
await asyncio.sleep_ms(8)
### Do things
### Do things
### Do things
if index_put_R == BUFFERSIZE:
### How do I call the function write_ADC_log_to_file???...
### And get a value back from this function???
async def write_ADC_log_to_file():
global index_put_R
with open('ADC_log_R.csv', 'w') as ADC_log_R:
for line in range(0, index_put_R):
ADC_log_R.write(str(line) + "/" + str(data_ch0_R[line]) + "/" + str(data_ch1_R[line]) + '\n')
### Do things
### return (value)
async def heater_control():
while True:
### Do things
await asyncio.sleep_ms(1000)
### Do things
loop = asyncio.get_event_loop()
t1 = loop.create_task(adc_right())
t2 = loop.create_task(heater_control())
loop.run_forever()