1

I have a small Problem in Python, i want to start the "gsmsmsd" daemon (to read incoming SMS) with python and read the output from this daemon. If i start this daemon with my console there is like an running output of nothing until an SMS comes in, then this SMS displays in the Console. But there must be an solution to read this incoming SMS into Python....

First I have tried this with:

while True:
    a = os.popen("gsmsmsd -d /dev/ttyACM1 -b 9600 -t SM")
    print a
    time.sleep(1)

But i think the os.popen function only reads the output directly after the command, is this right? If yes and the sms comes 5min later there is nothing red anymore. How can i solve this Problem? Are there other Functions who can read the Output from the Console over a longer period of time, without starting the daemon multiple times?

I would be happy to hear from someone.

Greets Jakob

1 Answers1

0

I think what you need is to use the select module and poll on events where somethoing is written on the device. Something like: (Disclaimer: not tested, might not work. so you should read the link):

import select
import os 

epoll = select.epoll()
dev = os.open("/dev/ttyACM1",os.O_RDONLY)
epoll.register(dev, select.EPOLLIN)
event = dev, selecet.EPOLLIN

while True:
     events = epoll.poll(1)
     if event in events:
        print dev.read()
plover
  • 439
  • 5
  • 17