This article applies to:
E-Prime 3.0
E-Prime 2.0
Detail
This set of samples demonstrates how to send or receive TCP or UDP data over a Socket Device. For more detailed information on TCP and UDP communication, see DEVICE: Socket Device supports TCP and UDP communication [16877].
NOTE: By default, each sample is configured to be run locally on a single machine using localhost (127.0.0.1).
Abstract
EPrimeSocketDeviceTest.exe
This application is provided as a method to verify the receipt of markers sent from E-Prime or to send markers to E-Prime via a Socket Device. It can be used for each sample. Make sure to also provide the application with the appropriate firewall permissions. When configured to receive markers from E-Prime, it will listen for incoming data on the specified port and display the markers received. When configured to send markers to E-Prime, incrementing string values are sent over the port every second (e.g., "Test 1", "Test 2", and so on). When using this application, it must be launched and configured prior to running the experiment. The application prompts for the following parameters:
- Send or Receive
- TCP or UDP
- Port Number
- IP Address (only when configured to send UDP data). This should be set to the IP address of the receiving machine.
When the experiment is over, remember to stop and close EPrimeSocketDeviceTest.exe.
NOTE: When using E-Prime 3.0, it is easiest to watch both applications simultaneously by running the experiment Windowed Mode (E-STUDIO: Windowed Mode [23587]), though this is not recommended for actual data collection. This feature is not available in E-Prime 2.0.
SendTCP
This experiment contains a Socket Device that is added via the Experiment Object Properties > Devices tab. Its Server (IP address) is set to localhost. The Port is set to use port 4900. Its Connection Type is set to TCP. If EPrimeSocketDeviceTest.exe or other receiving software is run on a machine other than the E-Prime machine, the Server and Port properties of the Socket Device need to be set accordingly.
The ReadMe Inline in this experiment does not execute. Instead, it contains comments on how to configure EPrimeSocketDeviceTest.exe to run in conjunction with this particular experiment.
This experiment runs a single trial in which markers are sent over the Socket using TCP communication. The way in which markers are sent differs between the E-Prime 3.0 and E-Prime 2.0 versions of the sample.
In the E-Prime 3.0 version of this experiment, 3 separate markers are sent by means of Task Events. In the Stimulus object properties > Task Events tab, 3 Stimulus.OnsetTime Task Events are created. Each one sends a single string marker. Each Task Event has its Action set to WriteString and its Data Type set to String in order to send string-based markers. The Custom value is set to "Sent At" followed by the time it is scheduled to be sent, relative to Stimulus.OnsetTime. The time at which each Task Event fires, relative to Stimulus.OnsetTime, is controlled by the Delay property of the Task Event. The Task Events are configured to send a marker at Stimulus.OnsetTime, 250 milliseconds after Stimulus.OnsetTime, and 500 milliseconds after Stimulus.OnsetTime.
In the E-Prime 2.0 version of the experiment, Inline script is used to send markers. A Do While...Loop is used in script so that the script within the loop runs continuously until a Keyboard response is made. During the loop, Socket.WriteString is called to send a marker though the Socket Device. The marker values are "Test #" where # is determined by a counter variable that gets incremented during the loop. The current time is checked during the loop to ensure that each marker is sent in 1 second intervals.
NOTE: The use of Inline script in the E-Prime 2.0 version of this experiment was done for 2 reasons: A) The experiment was developed using E-Prime 2.0 Standard. Task Events are not available in any version of E-Prime 2.0 Standard edition or E-Prime 2.0 Professional, versions 2.0.8.x or prior. B) Task Events are PST's recommended method of sending markers to an external device. However, this sample illustrates the use of Inline script as an alternative solution to using Task Events.
NOTE: If you are using E-Prime 2.0 Professional 2.0.10.x, you can convert the .es2 file to Professional format upon opening the experiment and modify the sample to use Task Events instead of Inline script using the same Task Event configurations as the E-Prime 3.0 version of the experiment mentioned above. Be sure to remove the SendData inline in this scenario to avoid conflicting markers.
ReceiveTCP
This experiment contains a Socket Device that is added via the Experiment Object Properties > Devices tab. Its Server (IP address) is set to localhost. The Port is set to use port 4900. Its Connection Type is set to TCP.
The ReadMe Inline in this experiment does not execute. Instead, it contains comments on how to configure EPrimeSocketDeviceTest.exe to run in conjunction with this particular experiment.
This experiment runs a single trial in which E-Prime listens for incoming markers. The Stimulus Slide presents the incoming markers. The ReadData Inline uses a Do While...Loop in script to wait for input to be made on the Socket Device. If there is, Socket.ReadString is called to identify the marker value. Script is then used to update SlideText's text property to show the marker value that was read. Each new marker read is updated on the Stimulus Slide until a Keyboard response is made.
SendUDP
This experiment contains a Socket Device that is added via the Experiment Object Properties > Devices tab. Its Server (IP address) is set to localhost. The Port is set to use port 4900. Its Connection Type is set to UDP. If EPrimeSocketDeviceTest.exe or other receiving software is run on a machine other than the E-Prime machine, the Server and Port properties of the Socket Device need to be set accordingly.
The ReadMe Inline in this experiment does not execute. Instead, it contains comments on how to configure EPrimeSocketDeviceTest.exe to run in conjunction with this particular experiment.
This experiment runs a single trial in which markers are sent over the Socket using TCP communication. The way in which markers are sent differs between the E-Prime 3.0 and E-Prime 2.0 versions of the sample.
In the E-Prime 3.0 version of this experiment, 3 separate markers are sent by means of Task Events. In the Stimulus object properties > Task Events tab, 3 Stimulus.OnsetTime Task Events are created. Each one sends a single string marker. Each Task Event has its Action set to WriteString and its Data Type set to String in order to send string-based markers. The Custom value is set to "Sent At" followed by the time it is scheduled to be sent, relative to Stimulus.OnsetTime. The time at which each Task Event fires, relative to Stimulus.OnsetTime, is controlled by the Delay property of the Task Event. The Task Events are configured to send a marker at Stimulus.OnsetTime, 250 milliseconds after Stimulus.OnsetTime, and 500 milliseconds after Stimulus.OnsetTime.
In the E-Prime 2.0 version of the experiment, Inline script is used to send markers. A Do While...Loop is used in script so that the script within the loop runs continuously until a Keyboard response is made. During the loop, Socket.WriteString is called to send a marker though the Socket Device. The marker values are "Test #" where # is determined by a counter variable that gets incremented during the loop. The current time is checked during the loop to ensure that each marker is sent in 1 second intervals.
NOTE: The use of Inline script in the E-Prime 2.0 version of this experiment was done for 2 reasons: A) The experiment was developed using E-Prime 2.0 Standard. Task Events are not available in any version of E-Prime 2.0 Standard edition or E-Prime 2.0 Professional, versions 2.0.8.x or prior. B) Task Events are PST's recommended method of sending markers to an external device. However, this sample illustrates the use of Inline script as an alternative solution to using Task Events.
NOTE: If you are using E-Prime 2.0 Professional 2.0.10.x, you can convert the .es2 file to Professional format upon opening the experiment and modify the sample to use Task Events instead of Inline script using the same Task Event configurations as the E-Prime 3.0 version of the experiment mentioned above. Be sure to remove the SendData inline in this scenario to avoid conflicting markers.
ReceiveUDP
NOTE: This sample is provided for E-Prime 3.0 only. Receiving UDP data is only supported in versions 3.0.3.60 and later. Please see BUG FIX: UDP Sockets cannot receive data [25865].
This experiment contains a Socket Device that is added via the Experiment Object Properties > Devices tab. Its Server (IP address) is set to localhost. The Port is set to use port 4900. Its Connection Type is set to UDP.
Socket.UDPRecvServer must also be set to the hostname or IP address of the receiving machine. This is configured as a Startup Info parameter in the Experiment Object properties > Startup Info tab. This way, the hostname or IP address can be set after specifying the Subject and Session number when launching the experiment. Alternatively, this property can be set using a Startup Info file.
NOTE: The solution in BUG FIX: UDP Sockets cannot receive data [25865] illustrates implementing 2 Startup Info Parameters, Socket.UDPRecvServer and Socket.UDPRecvPort. Creating a Startup Info Parameter for Socket.UDPRecvPort is only necessary if the port number that is being used to receive markers is different from the port number specified in the Socket Device properties. The Startup Info Parameter for Socket.UDPRecvPort is not implemented in this sample.
The ReadMe Inline in this experiment does not execute. Instead, it contains comments on how to configure EPrimeSocketDeviceTest.exe to run in conjunction with this particular experiment.
This experiment runs a single trial in which E-Prime listens for incoming markers. The Stimulus Slide presents the incoming markers. The ReadData Inline uses a Do While...Loop in script to wait for input to be made on the Socket Device. If there is, Socket.ReadString is called to identify the marker value. Script is then used to update SlideText's text property to show the marker value that was read. Each new marker read is updated on the Stimulus Slide until a Keyboard response is made.
See Also:
DEVICE: Socket Device supports TCP and UDP communication [16877]
INFO: How do I send a marker to an external device? [42521]
INFO: How do I receive a marker in E-Prime from an external device? [42530]
Comments
0 comments
Please sign in to leave a comment.