I have trouble replacing device in/output commands like:
echo 100 > /dev/rtmotor_raw_l0 # output 100hz frequency
cat /dev/rtswitch0 # read switch state
output problem(python)
I tried replacing that command with python.
file = open('/dev/rtmotor_raw_l0','w')
file.write('100\n') # I want output in this timing
file.close() # output reflected after closing file
The problem is that the output appears after closing the file.
Does this mean I have to open and close this device each time I want to change its value? Also, changing 'w' to 'a' did not work.
input problem(python)
Almost the same problem happens in input observation.
file = open('/dev/rtswitch','r')
file.read() # works
file.read() # after first read it does't work anymore
file.close() # need to reopen the file to get newer value
I could only read 1 input in each opening files.
So, currently I have to reopen the devices each time I want to write/read new values. Are there any way to avoid this problem?
Thank you.
'/dev/rtswitchis seekable, you need to rewind the file pointer to the beginning of the file before you can read the contents again: putfile.seek(0)between the two reads.