Is there a way to use interrupts when the input pins change, or is polling my only option?
Polling seems to take a lot of cpu cycles. I've been able to slow it down with time.sleep() but I miss inputs.
Can interrupts be added?
Logged In: NO
sorry this ? is for the pyparallel
Logged In: YES user_id=947280 Originator: NO
I'm also interested in this - mainly Event on RX. Isn't there any nice way of doing so? I hate bruning CPU cicles by waiting.
I'm using Linux - so maybe there is an OS specific implementation?
This a solution using TIOCMIWAIT syscall. Not all USB adapter supporti this feature. It should be integrated in pyserial.
---
from serial import Serial from fcntl import ioctl from termios import ( TIOCMIWAIT, TIOCM_RNG, TIOCM_DSR, TIOCM_CD, TIOCM_CTS )
ser = Serial('/dev/ttyUSB0')
wait_signals = (TIOCM_RNG | TIOCM_DSR | TIOCM_CD | TIOCM_CTS)
if __name__ == '__main__': while True: ioctl(ser.fd, TIOCMIWAIT, wait_signals) print 'RI=%-5s - DSR=%-5s - CD=%-5s - CTS=%-5s' % ( ser.getRI(), ser.getDSR(), ser.getCD(), ser.getCTS(), )
Log in to post a comment.
Logged In: NO
sorry this ? is for the pyparallel
Logged In: YES
user_id=947280
Originator: NO
I'm also interested in this - mainly Event on RX. Isn't there any nice way of doing so? I hate bruning CPU cicles by waiting.
I'm using Linux - so maybe there is an OS specific implementation?
This a solution using TIOCMIWAIT syscall.
Not all USB adapter supporti this feature.
It should be integrated in pyserial.
---
from serial import Serial
from fcntl import ioctl
from termios import (
TIOCMIWAIT,
TIOCM_RNG,
TIOCM_DSR,
TIOCM_CD,
TIOCM_CTS
)
ser = Serial('/dev/ttyUSB0')
wait_signals = (TIOCM_RNG |
TIOCM_DSR |
TIOCM_CD |
TIOCM_CTS)
if __name__ == '__main__':
while True:
ioctl(ser.fd, TIOCMIWAIT, wait_signals)
print 'RI=%-5s - DSR=%-5s - CD=%-5s - CTS=%-5s' % (
ser.getRI(),
ser.getDSR(),
ser.getCD(),
ser.getCTS(),
)