Perhaps start by looking at this recent thread from someone using serial commands to communicate with an EEG: