…\DirectRT\samples\5- other features\13 ttl signals
In order to communicate with external equipment (e.g., physiological equipment, response boxes, other computers), you can send and receive TTL (Transistor-Transistor Logic) signals through any of your computer's accessible ports (e.g., parallel or serial ports). In English, this means you can ask DirectRT to send a value from 0-255 to your external equipment any time you like, and/or you can have DirectRT wait for any value from 0-255 to come from the external equipment. To accomplish sending a value, you list a TTL signal just like any other stimulus in the Stim column of your input file. To receive a value, you list a TTL signal just like any other RT in the Time column. Consequently, you can synchronize the TTL signals with other stimuli in your experiment and use TTL signals as way to record precise RTs from external equipment.
In jargonese, a TTL signal is an 8-bit value (e.g., 00101001) represented in decimal form as a value from 0-5. You should check the documentation that came with your external equipment to see what values it can send and receive. Since 8-bit values can be represented either as their individual bit values (e.g., 00101001) or as their decimal equivalent (e.g., 41), you may need to convert between them (since they're simpler to comprehend, DirectRT uses decimal values exclusively). You can use the Windows calculator program to do this quite easily. Type "calc" from the Run command on the Start menu. From the view menu, click "Scientific." To convert from Binary to Decimal, click "Bin" and type in the bit value (e.g., 00101001) and then click "Dec". You will see the decimal equivalent appear (e.g., 41). To convert from Decimal to Binary, click "Dec" and type in the decimal value (e.g., 41) and then click "Bin". You will see the binary equivalent appear (e.g., 00101001). For future reference you can also use this method to convert to and from Hexadecimal format as well.
So far, we know that DirectRT can exchange values from 0-255 with your external equipment. The second thing we need to know is where that exchange will take place. This meeting place is going to be a "port" located on the same computer as DirectRT. A port is a place where values can be written and read. Ports that are accessible to outside equipment include the serial and parallel ports. You will need to know which port your external equipment connects to and the port address. With this information, you will be set to go. For example, you will be able to tell DirectRT to "send the value 155 to port 330" or "go to port 330 and wait for the values 155, 156, or 157." DirectRT 2016 can use port address decimal values ranging from 0 to 65535.
Initial Testing with your External Equipment
DirectRT comes will a tool called IOTest located in the DirectRT\Utilities/TTL folder. This program uses the same code as DirectRT to send and receive byte values from specified ports, but is simpler to work with during initial testing. If you can get your external equipment to work properly with IOTest, then it should work well with DirectRT. Try running IOTest and follow these directions:
When IOTest starts, you will see a pull down list of ports-these will include port addresses that IOTest immediately recognizes as being available for read/write access. You can choose one of these, or you can enter a port address of your choosing. Some ports (esp. serial ports) may not show up automatically and will have to be entered manually—(see technical note below, COM1 is often 1016). Note that IOTest as well as DirectRT will expect a port address in Decimal form. Since ports addresses are often referred to in Hexadecimal format, you may need to convert a hexadecimal address to decimal. You can use the Windows program calc.exe to do this (see above). Contact us if you have trouble identifying your port.
After selecting a port address, click the "Read" button next to it. Below where it says "Monitor" you can watch the value of this port. For example, if you select port 888 (often the address for parallel port LPT1) or 1016 (often the value for the COM1 serial port), you can see its current value. If the value at this port address changes, you will see it change here. You can test to see if your external equipment can send values to this port address. Try it and see. If successful, you will see the value change to whatever value you send from your external equipment.
You can also test to see if DirectRT can send values to your external equipment. In the text box where it says "Byte Value (0-255)" try entering a value, and then click the "Send Byte Now" button. If the port is willing and able to accept data then you should see the value update on the monitor, and you should see your external equipment react accordingly if it is able to read the data from that port address successfully. You can also send a byte value for a specified number of milliseconds by entering a value in the "Duration" field. Try entering a new byte value (e.g., 123) and a value of 100 in the Duration field. Then click "Send Byte Now." You should see the monitor briefly display the new value and then return to its original value.
That's it. If the testing was successful, then you should be able to proceed with the samples.
Take a look at the sample input file "sendTTL.csv" in this folder for an illustration. In the Stim column, enter "ttl:x" where x is any value from 0 to 255. in the Loc column enter the decimal value of the port you want it sent to such as 888 for lpt1 on most systems, and then in the time column, enter the number of milliseconds you want the value to be maintained before being reset to its prior value. Just enter "0" for "Time" if you want the default behavior of a 10ms set then reset to 0.
Sending ttl signals will not hold up the trial--it's a parallel process; if you request that it be sent for 10ms, that doesn't mean the trial in the input file will be held up at all—the onset of the signal will occur in synch with the next stimulus in the trial.
IMPORTANT: A outward bound TTL signal must be followed by another stimulus—it can be any but the last stimulus on a trial.
Take a look at the sample input file "receiveTTL.csv" in this folder for an illustration. To *read* signals, just specify the rt in the time column as always with one addition: place the port you want to read the signals from in parentheses after the list of valid ttl codes, e.g., if you want to allow 4, 5, and 11 as valid signals from port 889, then enter the following in your time column with no spaces:
As with keystrokes, the first code listed will be treated as the correct response. For convenience, the TTL codes can also be activated by hitting the corresponding keys on the keyboard (in case your external hardware is not connected)--e.g., if ttl signal "44" is a valid response, you could also hit the "Z" key.
IMPORTANT: As in the sample, you need to SEND one TTL signal somewhere (anywhere) in order for receiving to work. One outward signal initializes everything that all subsequent inward and outward signals need. Note also that the sample input file "receiveTTL.csv" uses port 889 rather than 888 for the parallel port--this is a common port address for incoming data through the parallel port.
Note that multiple TTL signals may be sent and received within a single trial.
Send or Receive a TTL Signal Via Serial Ports
The 2016 versions DirectRT can send and receive data through via a serial port. To do so you just need to create a file called comport.txt in your experiment folder and copy the following text into it:
comPort, baudRate, parity, dataBit, stopBit
input code (1-255), response value (1-12)
You should not modify the first or third line. The second line represents the values of the variables listed on the first line. You can change any of these as necessary. Be sure that the first number of the second row is the same as the comport you want the computer to use to send the ttl signal. In this example, the 1 as the first value in the second row tells DirectRT to use the port labeled as port 1 on your computer.
The remaining lines tell DirectRT how to map incoming signals to response keys. You should use as many lines as different signal values you wish to use. On each line you can list a pair where the first value is the signal sent to the serial port (i.e., 1-255) and the second value is the response it should map on to (i.e., 1 to 12). In the example above, if DirectRT detects a "1" coming through the serial port, it will react as though the 1 key was pressed; the same is true of responses and key mapping values 2 through 6. To see what values to use as the second number in these lines, see the key codes for DirectRT.
You will still set up the .csv input file to send or receive ttl signals as if using a parallel port; DirectRT still needs to see the ttl values in .csv file folder. As long as there is a comport.txt file in the same file folder as your .csv input file, DirectRT will ignore the values in the .csv input flie and use the ones in the comport.txt file.
To obtain the decimal address of a port, right click on "My Computer" and select "Properties" and the "Hardware" or "Device Manager". Under "Ports" you should see your various ports listed which should include your standard serial port (e.g., COM1 or COM2 usually). Double click on the port of interest and select "Resources". You'll see an input-output range like "03F8-03FF" or something like that. That's HEX and you need to convert it to decimal. You can do that with the Windows calculator put into scientific mode. Select HEX and enter the value and select DEC and it will be converted. e.g., try entering 03F8 and convert it--you should see the decimal value which is 1016. If that all sounds like total Greek to you then just ask one of your tech people--they'll probably be able to tell you in 2 seconds.