python - Trouble with pyserial on cygwin -
i have written program in python script requirement take input makey-makey
keyboard w-a-s-d-f-g
.
i able input device, facing difficulty in cygwin.
there try except block handle case when device not connected.
problem in cygwin try except block not getting read.
i understand port in cygwin not available, , also, device listed file
.
what problem , how overcome this:
here's code:
#python program capture # makey makey input # program read device connected # , based on keys connected # print approrpriate messages import os,sys import serial plat = sys.platform.lower() if plat == 'win32': #for windows operating system com_port = 'com2' print com_port elif plat == 'cygwin': # cygwin com_port = '/dev/ttys1' print "attempting open com port..." try: # check device com number ser = serial.serial(com_port, 9600, timeout = 10) print "successfully opened com port." print "your com port returned following information:n" except serial.serialutil.serialexception: print("kindly connect usb device") sys.exit(-1) print "listening key presses..." try: msvcrt import getch print "i here" except importerror: print "hi" def getch(): print "i here!" import sys, tty, termios fd = sys.stdin.fileno() old_settings = termios.tcgetattr(fd) try: tty.setraw(fd) ch = sys.stdin.read(1) finally: termios.tcsetattr(fd, termios.tcsadrain, old_settings) return ch def getchs(): while true: yield getch() choice in getchs(): if choice == 'w': print (80 * '-') print ("you have chosen orange...") print ("here's nutritional fact of orange:") print ("'one medium orange contains 1.23 grams of protein, 62 calories , 3.1 grams of dietary fiber.'") print (80 * '-') elif choice == 'a': print (80 * '-') print ("you have chosen banana...") print ("here's nutritional fact of banana:") print ( "'one medium banana contains 1.29 grams of protein, 105 calories , 3.1 grams of dietary fiber") print (80 * '-') elif choice == 's': print (80 * '-') print ("you have chosen apple...") print ("here's nutritional fact of apple:") print ("'one medium apple skin contains 0.47 grams of protein, 95 calories, , 4.4 grams of dietary fiber.'") print (80 * '-') elif choice == ' ': print "see chump!" break ser.close()
and here output in windows , cygwin
thanks
Comments
Post a Comment