AIO thread

 1'''
 2Tutorial - Thread_AIO.py
 3
 4This example project demonstrates how use one thread to write AO value and the other thread to read AI data.
 5
 6For other examples please check:
 7    https://github.com/WPC-Systems-Ltd/WPC_Stand-alone_Python_release/tree/main/examples
 8
 9Copyright (c) 2024 WPC Systems Ltd.
10All rights reserved.
11'''
12
13## import
14import pywpc
15import time
16import _thread
17import random
18
19## Define AI thread
20def AI_thread():
21    while True:
22        print(pywpc.AI_readOnDemand())
23        time.sleep(1)
24
25## Define AO thread
26def AO_thread():
27    while True:
28        channel = random.randint(0, 7)     ## Channel   0~7
29        ao_value = random.randint(-10, 10) ## Voltage -10~10
30        pywpc.AO_writeOneChannel(channel, ao_value)
31        print(f'Set channel {channel} to {ao_value}V')
32        time.sleep(5)
33
34## Start AI and AO thread
35_thread.start_new_thread(AI_thread, ())
36_thread.start_new_thread(AO_thread, ())