Scannerize your E-Prime code: Part 1 - General Setup
Note: Scanner compatible code is best written on a computer that has a serial port (many laptops do not have them) as there will be an error when the program tries to find the serial port that is referred to in the code.
Updated Sept 27, 2005 by Ryan Lett
Created July 28, 2005 by Ryan Lett
1. Setup E-studio
Double-click the experiment object in E-Studio.
Click the devices tab and click “Add…”
Select the newly added serial device and click “Edit”
Change the COM Port setting to be 2 and click “OK”
Hit “OK” again. Your comm port is now setup for reading button responses.
2. Insert Scanner Code
I’ve created a set of routines and functions for use in the scanner. Because of the nature of these functions everything is defined in a global sense. For non-programmers, this means that they can be called from anywhere in your program. You can download this code and paste it directly into your user script section.
a) Where do I find the user script section?
Click the “View” menu and select “Script”. If there was already a check mark beside “Script” you might have to do this twice. Alternatively you can use the keys Alt+5 to do the same command. When the window pops up, if you look in the lower left-hand corner of that window, you will see 2 tabs: one called “User” one called “Full”. Click the “User” tab. This is where you will put all the scanner code. Everything in this user script area is global or applies everywhere.
b) Where do I get this scanner code?
You can download is right here: Glorious Scanner Code
3. User Scanner Code
So, now that you’ve setup your comm port and inserted your code, what do you do with it?
Well, here are a list of the functions contained within the scanner code. Included are descriptions of what they do and the results they return.
Note: Functions return information to the calling procedure, subroutines do not.
| Command Name | Information |
|---|---|
| Init_Scanner |
Subroutine This command initializes scanner pulse codes, the timer, the key array, and the button mask. Either Init_Scanner or Init_Beh must be called or your program will NOT work. |
| Init_Beh |
Subroutine This command initializes behavioural pulse codes, the timer, the key array, and the button mask. Either Init_Scanner or Init_Beh must be called or your program will NOT work. |
| Init_KeyArr |
Subroutine This command initializes the key array. This command does not need to be called as it is called when Init_Scanner or Init_Beh are called. |
| mintomilli |
Function mintomilli(minutes As Integer) As Long Converts minutes to milliseconds. Takes an integer and returns a long integer e.g. Dim temp as Long
temp = mintomilli(10)
temp is now set to 600000
|
| initMask | Subroutine Reset all the button masks to off. This is essential to call when changing which buttons you want to use. |
| SetMask | Function SetMask(allowed As String) As Integer Turns the specified button on using a string representing a button. Return 1 on success and -1 on fail. No reason why it should fail but just in case do error checking. "L1" = left thumb "R1" = right thumb "L2" = left index "R2" = right index "L3" = left middle "R3" = right middle "L4" = left ring "R4" = right ring "L5" = left pinky "R5" = right pinkye.g. Clearing the mask and setting a new one initMask
Dim temp as Integer
temp = SetMask("L2")
temp = SetMask("L3")
The left index and middle finger buttons are now enabled. Sub SetProbeMask
initMask
tempint = SetMask("R2")
tempint = SetMask("R3")
tempint = SetMask("R4")
tempint = SetMask("R5")
End Sub
This sets the 4 fingers on the right hand. |
| GetMask | Function GetMask() As String Returns a string interpretation of the current button mask configuration. Used mostly for debugging. e.g. Continuing from the last example Dim mask as String mask = GetMaskmask is now set to “0110000000″ which is a binary representation of the mask. |
| GetResponse | Function GetResponse(max As Integer) As String Parameter max is time in milliseconds. Set max to -1 in order to not return until a button has been pressed. Returns the button that was pressed. e.g. “Right 2″ Dim button as String button = GetResponse(1000) button = GetResponse(-1)The first call waits 1 second for a button press. The second call waits indefinately for a button press. |
| WaitForPulse | Subroutine Waits for a scanner pulse. Waits indefinately. |
| scannersync_start | Subroutine Waits for a scanner pulse and when it gets one starts the timer and sets the timer_on flag. |
| StartTime | Subroutine Starts the timer and sets the timer_on flag. Warning: Do not use StartTimer as it does not set the timer_on flag and will result in failure when GetTime is used. |
| GetTime | Function GetTime() As Double Returns the ammount of time past since the timer was started. Warning: Do not use GetTimer as it does not check the timer_on flag and will result in a program crash if the timer has not been started. e.g. Dim temp as Double temp = GetTime |
| Tic | Function Tic() As Double Sets the start point of an offest calculator. Returns the time marker that was set. For use in conjunction with Toc(). If timer was not running, it starts and Toc returns 0.00 e.g. Dim temp as Double temp = TicReturns current time, e.g. 45.2574 |
| Toc | Function Toc() As Double Calculates the amount of time since Tic() was called and returns that value. If called be e.g. Dim diff as Double diff = TocReturns time since last Tic call. e.g. current time = 58.4863 diff = 13.2289 |
In the scanner code you’ve pasted into your program, there are a handful of global variables that should be reserved by the scanner functions. So you should avoid calling any new variables the same name as these unless you want really bad things to happen to your program.
REMEMBER: E-Basic is case insensitive which means button = Button = BUTTON = bUtToN etc.
Here’s a list of the variable names and their types:
| PAR_PORT_ADDR | const |
| PAR_PORT_BLANK_CODE | const |
| PAR_PORT_PULSE_CODE | const |
| SCANNER_PULSE_CODE | const |
| SCANNER_BLANK_CODE | const |
| BLANK_CODE | Integer |
| PULSE_CODE | Integer |
| timer_on | Boolean |
| timer_start | Double |
| InputCount | Integer |
| validInputCount | Integer |
| n_button | Long |
| buttonStr | String |
| ButtonStart | Double |
| ButtonFlag | Boolean |
| L_1 | Boolean |
| L_2 | Boolean |
| L_3 | Boolean |
| L_4 | Boolean |
| L_5 | Boolean |
| R_1 | Boolean |
| R_2 | Boolean |
| R_3 | Boolean |
| R_4 | Boolean |
| R_5 | Boolean |
Notes
The following is a list of reserved words that should never be used as variable names or object names as the compiler will not know how to properly handle them. A general rule is if the word changes color, it shouldn’t be used as a variable.
-
start
-
end
-
blank
-
string
-
str
-
int
-
time
-
timer
• Phone: 1-604-822-2849 • Location: Rm.3022 •