python向打印机发送数据(3)--

发布时间:2019-09-04 06:54:25编辑:auto阅读(1654)

    #!/usr/local/bin/python2.7
    # encoding: utf-8

    import parallel
    import time
    import logging
    from logging.handlers import TimedRotatingFileHandler

    def lpt_data_printer(title,txt):  
        printer=open("LPT1", "wb")
        printer.write(txt)
        printer.close()
        print u"正在运行第"+str(count)+u"次"
        looger.info(u"正在运行第 %s 次" % str(count))
        

    def hello(count):
        if  count%6==1:
            f = open(r"D:\test\FP00001.txt")
            lines1 = f.read()
            f.close()
            lpt_data_printer("lines",lines1)
        elif  count%6==2:
            f = open(r"D:\test\FP00002.txt")
            lines2 = f.read()
            f.close()
            lpt_data_printer("lines",lines2)
        elif  count%6==3:
            f = open(r"D:\test\FP00003.txt")
            lines3 = f.read()
            f.close()
            lpt_data_printer("lines",lines3)
        elif  count%6==4:
            f = open(r"D:\test\FP00004.txt")
            lines4 = f.read()
            f.close()
            lpt_data_printer("lines",lines4)
        elif  count%6==5:
            f = open(r"D:\test\FP00005.txt")
            lines5 = f.read()
            f.close()
            lpt_data_printer("lines",lines5)
        elif  count%6==0:
            f = open(r"D:\test\FP00006.txt")
            lines6 = f.read()
            f.close()
            lpt_data_printer("lines",lines6)
    if __name__ == '__main__':
        looger = logging.getLogger('LPTPrint')
        formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
        LogHandLer=TimedRotatingFileHandler(r'E:\count.log',when="midnight")
        LogHandLer.setFormatter(formatter)
        looger.addHandler(LogHandLer)
        looger.setLevel(logging.INFO)
        
        count=1
        while(1):
            hello(count)
            count = count +1
            f = open(r"D:\time.txt")
            line = f.read()  
            time.sleep(int(line))
            f.close()

关键字