I am new to Python and programming in general. I am trying to write a device driver using pyserial. I opened a thread that would read data from the device and send it to std
You can do it like this:
import serial
from threading import Thread
from functools import wraps
# decorate the function - start another thread
def run_async(func):
@wraps(func)
def async_func(*args, **kwargs):
func_hl = Thread(target = func, args = args, kwargs = kwargs)
func_hl.start()
return func_hl
return async_func
@run_async #use asyncronously
def writeInstruction(ser):
#reads command from stdin
#Writes the command to the device (enabling data output)
@run_async #use asynchronously
def readData(ser):
#reads the packets coming from the device
#prints it through std out
your_arg = 'test'
writeInstruction(your_arg)