D
D
denis_l_eryomin2016-07-18 05:43:33
linux
denis_l_eryomin, 2016-07-18 05:43:33

How to replace TIOCMIWAIT when using pyserial on Windows?

There is such a solution for visitor sensors. This is for Linux, and everything works correctly. It is required to stir up the same for Windows on the same python. I did not find any sensible examples of reading signals under Windows. I only dug up that this is done through win32api and WaitCommEvent. But what is there and how - there are no materials. Please help if anyone has solved this problem.

#!/usr/bin/python
#coding=utf-8
import os,sys,datetime
from serial import Serial
from fcntl import  ioctl
from termios import (TIOCMIWAIT,TIOCM_RNG,TIOCM_CTS)
ser = Serial('/dev/ttyUSB0')
wait_signals = (TIOCM_RNG | TIOCM_CTS)
ins=0
out=0
status=""
x=0
os.system('clear')
while True:
    ioctl(ser.fd, TIOCMIWAIT, wait_signals)
    if ser.getRI() == True and ser.getCTS() == False:
        x=x+1
        status=status+"in"
    if ser.getRI() == False and ser.getCTS() == True:
        x=x+1
        status=status+"out"
    if x == x*2/2:
        if status == "inout":
            ins=ins+1
            status=""
            f=open("posetiteli.csv", "a+")
            print >>f,datetime.datetime.now().strftime("%d-%m-%Y %H:%M:%S"),'Вошло:',1,'Вышло:',0
            f.close()
            os.system('clear')
            print datetime.datetime.now().strftime("%d-%m-%Y %H:%M:%S"),'Вошло:',ins,'Вышло:',out
        if status == "outin":
            out=out+1
            print >>f,datetime.datetime.now().strftime("%d-%m-%Y %H:%M:%S"),'Вошло:',0,'Вышло:',1
            f.close()
            os.system('clear')
            print datetime.datetime.now().strftime("%d-%m-%Y %H:%M:%S"),'Вошло:',ins,'Вышло:',out
            status=""
            f=open("posetiteli.csv", "a+")

How to do the same in windows python?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question