Beispiel #1
0
 def connect(self, value, frame):
     try:
         self.ser = Ser(value)
         frame.destroy()
         self.set_main()
     except:
         messagebox.showerror(message='设备连接失败')
Beispiel #2
0
def execute_options():
    parser = argparse.ArgumentParser(
        description="""This is SMS Modem Python""")
    parser.add_argument('-s',
                        '--sms',
                        nargs=2,
                        help='Send sms <With text> to <Phone_number>',
                        metavar=('SMS_Text', 'Phone_Number'))
    parser.add_argument('-c',
                        '--call',
                        nargs=1,
                        help='Calling number xxx',
                        metavar='Phone_Number')
    args = parser.parse_args()

    if args.sms is not None:
        modem = Modem()
        devices = modem.devices

        pool = ThreadPool(16)
        f = partial(sms_function, *args.sms)
        result = pool.map(f, devices)

        # # close the pool and wait for the work to finish
        pool.close()
        pool.join()
        _file = Utils(constant.SMS_FILE)
        for iterator in result:
            (port, phone_number, sms) = iterator
            try:
                _file.write_sms_to_file(port, phone_number.decode(), sms)
            except:
                print('No number')

    elif args.call is not None:
        modem = Modem()
        devices = modem.devices
        for iterator in devices:
            ser = Ser(iterator)
            ser.call(*args.call)
    else:
        sys.exit(2)
Beispiel #3
0
def sms_function(sms_text, phone, port):
    ser = Ser(port)
    # ser.delete_sms()
    time.sleep(2)
    ser.send_sms(sms_text, phone)
    phone_number = ser.get_phone_number("*101#")[0]
    return (port, phone_number, ser.read_sms())
Beispiel #4
0
from ser import Ser
from ik import calc_arms
from time import sleep

angles = calc_arms(6, 25)
print(angles)

s = Ser('w')
s.idle()
sleep(2)

s.move(4, 2500)
sleep(2)

s.move(3, angles[2])
sleep(2)
s.move(2, angles[1])
sleep(0.2)
s.move(1, angles[0])
sleep(2)

s.move(4, 500)
sleep(2)

s.move(3, 1500)
sleep(2)
s.move(2, 1500)
sleep(2)
s.move(1, 1500)
sleep(2)
Beispiel #5
0
import serial.tools.list_ports
from ser import Ser

plist = list(serial.tools.list_ports.comports())

if len( plist ) == 0:
    print 'no port found'
    exit()

idx = 0
for port in list( plist ):
    print '%s %s' % (idx, port)
    idx += 1

idx = int( raw_input("Input port number:") )

if idx < 0 or idx >= len( plist ):
    print 'invalid number'
    exit()

port = plist[idx]
print port

ser = Ser( port[0] )
print ser.send_cmd('010591F50000F104')
Beispiel #6
0
from ser import Ser
import cv2
import numpy as np
from astropy.io import fits


if __name__ == "__main__":
    import sys
    
    
    fid = Ser(sys.argv[-1])
    
    for i in range(0, fid.count - 1):
        img = fid.load_img(i)
        hdr = fits.header.Header()
        fits.writeto(sys.argv[-1] + str(i) + ".fits", img, hdr, overwrite=True)

        v = img - np.min(img)
        v = img / np.max(img)
        
        cv2.imshow("image", v)
        cv2.waitKey(1)
        
        
    fid.close()

Beispiel #7
0
        break
    elif play == 'no' or play == 'n':
        exit(0)
    else:
        print('Please enter yes or no')
        play = input("Do you want to play? (y/n): ")

color = input("What color do you want to be? ")

moves = []
order = []

while True:
    if color == 'white' or color == 'w':
        order = ["Human player", "Stockfish"]
        s = Ser('b')
        print('Starting game...')
        break
    elif color == 'black' or color == 'b':
        order = ["Stockfish", "Human player"]
        s = Ser('w')
        print('Starting game...')
        first_move = stockfish.get_best_move_time(thinking)
        print(f'White moves: {board.san(chess.Move.from_uci(first_move))}')
        board.push_uci(first_move)
        moves.append(first_move)
        break
    else:
        print('Please enter white (w) or black (b)')
        color = input("What color do you want to be? ")
Beispiel #8
0
class Box(object):
    def __init__(self):
        self.top = Tk()
        self.top.title('旗丰控制系统')

        self.set_menu()
        #self.set_main()
        self.login()
        #self.config()

    def set_menu(self):
        menu = Menu(self.top)
        self.top.config(menu=menu)

        menu.add_command(label='参数设置', command=lambda: self.config())
        menu.add_command(label='帮助', command=self.show_help)
        menu.add_command(label='退出', command=lambda: self.top.quit())

    def show_help(self):
        f = open('data.txt', 'rb')
        data = marshal.load(f)
        f.close()
        messagebox.showinfo(message='售后电话: \n%s' % data[3])

    def config(self):
        top = Toplevel()
        frame = Frame(top, padx=20, pady=20)
        frame.grid(row=0)

        title = Label(frame, text='参数设置')

        v1 = StringVar()
        v2 = StringVar()
        v3 = StringVar()
        v4 = StringVar()
        label1 = Label(frame, text='冷凝器', wraplength=100)
        entry1 = Entry(frame, width=40, textvariable=v1)
        label2 = Label(frame, text='蒸发箱')
        entry2 = Entry(frame, width=40, textvariable=v2)
        label3 = Label(frame, text='空调管道')
        entry3 = Entry(frame, width=40, textvariable=v3)
        label4 = Label(frame, text='维修电话')
        entry4 = Entry(frame, width=40, textvariable=v4)

        f = open('data.txt', 'rb')
        data = marshal.load(f)
        v1.set(data[0])
        v2.set(data[1])
        v3.set(data[2])
        v4.set(data[3])
        f.close()

        ok = Button(frame,
                    text='保存',
                    command=lambda: self.set_config(top, entry1.get(
                    ), entry2.get(), entry3.get(), entry4.get()))

        cancle = Button(frame, text='返回', command=lambda: top.destroy())

        title.grid(row=0, column=1, columnspan=2)
        label1.grid(row=1, column=0, padx=20, pady=20)
        entry1.grid(row=1, column=1, columnspan=3, padx=20, pady=20)
        label2.grid(row=2, column=0, padx=20, pady=20)
        entry2.grid(row=2, column=1, columnspan=3, padx=20, pady=20)
        label3.grid(row=3, column=0, padx=20, pady=20)
        entry3.grid(row=3, column=1, columnspan=3, padx=20, pady=20)
        label4.grid(row=4, column=0, padx=20, pady=20)
        entry4.grid(row=4, column=1, columnspan=3, padx=20, pady=20)
        ok.grid(row=5, column=1, padx=20, pady=20)
        cancle.grid(row=5, column=2, padx=20, pady=20)

    def set_config(self, top, v1, v2, v3, v4):
        f = open('data.txt', 'wb')
        #data = {
        #    {'lengnq', v1},
        #    {'zhengfx', v2},
        #    {'konggd', v3},
        #    {'phone', v4}
        #}
        data = [v1, v2, v3, v4]
        marshal.dump(data, f)
        f.close()
        top.destroy()

    def cload(self, current, new):
        current.destroy()
        if new == 'main':
            self.set_main()
        elif new == 'config':
            self.config()

    def login(self):
        frame = Frame(self.top, padx=160, pady=120)
        frame.grid(row=0)

        label = Label(frame, text='设备地址', width=10)
        label.grid(row=0, column=0)

        entry = Entry(frame, width=20)
        entry.grid(row=0, column=1)

        button = Button(frame, text='连接',\
                command=lambda:self.connect(entry.get(), frame))
        button.grid(row=1, column=0, columnspan=2, pady=10)

    def connect(self, value, frame):
        try:
            self.ser = Ser(value)
            frame.destroy()
            self.set_main()
        except:
            messagebox.showerror(message='设备连接失败')

        #frame.destroy()
        #self.set_main()

    def set_main(self):
        main = Frame(self.top, pady=60)
        main.grid(sticky='nsew')

        label = Label(main, text='可视化空调清洗设备', font='Times 22', fg='#316be6')
        label.grid(column=0, row=0, columnspan=3, padx=240, pady=60)

        button1 = Button(main,
                         text='冷凝器',
                         command=lambda: self.start(1, [0, 1]))
        button2 = Button(main,
                         text='蒸发箱',
                         command=lambda: self.start(2, [0, 2]))
        button3 = Button(main,
                         text='空调管道',
                         command=lambda: self.start(3, [0, 3]))

        button1.grid(column=0, row=2, pady=60)
        button2.grid(column=1, row=2, pady=60)
        button3.grid(column=2, row=2, pady=60)

    def start(self, config, num_list):
        for item in num_list:
            self.ser.turn_on(item)

        f = open('data.txt', 'rb')
        data = marshal.load(f)
        f.close()
        if data[config - 1]:
            timer = int(data[config - 1]) * 1000

        top = Toplevel()
        frame = Frame(top, padx=80, pady=40)
        frame.pack()
        message = Message(frame, text='正在清洗中...', width=200, pady=20)
        message.pack()
        message.after(timer, lambda: self.end(top, num_list))
        Button(frame, text='取消',
               command=lambda: self.end(top, num_list)).pack()

    def end(self, top, num_list):
        for item in num_list:
            self.ser.turn_off(item)
        top.destroy()