This is my first post to stackoverflow, so please let me know if I don't follow the correct etiquette.
I am also new to Python and would like to incorporate it into a project. I currently have a Emotiv EEG headset and would like to run a homebuilt 3-D Printer from brain signals. To do so, the EEG headset is read by EmoKey 2.0.0.20 (see attached photo), EmoKey will then send keystrokes to the Python Shell, Python interprets this and sends commands to my Arduino run printer through a COM PORT. This may seem to be an indirect way of doing things, but it works except for one hitch. Lets pretend I think left, this is sent to EmoKey which types 'L' and the keystroke Enter into the Python Shell. In theory this would then move the printer head left. However, when EmoKey sends Enter it only creates a new line in the Shell, it doesn't actually execute. I then have to press enter by hand, which defeats the whole point.
.getch() hasn't worked because I don't think there is an actual key stroke for it to read. The link below also seems like it would be useful, but It hasn't worked thus far.
How to run a shell script without having to press enter/confirm s.th. inbetween
My question is: How can I get Python to execute what is written in the shell when only something like L or R is written? I don't think I can have it wait for a keystroke, Python would have to wait and automatically execute when it sees a specific command.
I understand that this may seem like a duplicate of the link below. However, .getch hasn't worked with EmoKey so far (maybe it's just a mistake on my part). Also, I wan't to find a way for my Python script to read what is put into the shell. Although I've started this project with just the "L" and "R" commands for simplicity and prototyping, I will move into using G-code so I can communicate with other printers or CNC equipment. That is another reason why .getch won't work in my case since it only grabs a single character (A single G-code command will be a few characters long). Python read a single character from the user
I'm using Windows 10 and Python 2.7.11.
import serial
ser = 0
def init_serial():
COMNUM = 3 #Enter Your COM Port Number Here.
global ser #Must be declared in Each Function
ser = serial.Serial()
ser.baudrate = 9600
ser.port = COMNUM - 1 #COM Port Name Start from 0
#ser.port = '/dev/ttyUSB0'
#Specify the TimeOut in seconds, so that SerialPort
#Doesn't hangs
ser.timeout = 10
ser.open() #Opens SerialPort
# print port open or closed
if ser.isOpen():
print 'Open:' + ser.portstr
init_serial()
while 1:
temp = raw_input('Send command + Enter:\r\n')
ser.write(temp) #Writes to the SerialPort
#bytes = ser.readline() #Read from Serial Port
#print 'Response: ' + bytes #Print What is Read from Port