Tscope5
serialport01.c
////////////////////////////////////////////////////////////////////////////////
//
// __ ______
// / /_______________ ____ ___ / ____/
// / __/ ___/ ___/ __ \/ __ \/ _ \ /___ )
// / /_(__ ) /__/ /_/ / /_/ / __/ ____/ /
// \__/____/\___/\____/ .___/\___/ /_____/
// /_/
//
// serialport01.c
// - Basic response timing example.
// - Use the serial port for response registration.
////////////////////////////////////////////////////////////////////////////////
#include <tscope5.h>
#include "config_serialport.c"
int main()
{
// open a display
ts5_set_coordinate_scale(TS5_RELATIVE_COORDINATES);
ts5_set_coordinate_system(TS5_DISPLAY_COORDINATES);
ts5_set_text_alignment(TS5_ALIGN_LEFT);
// register serialport COM1 as a response input device
// use /dev/ttys0 or something similar on Mac OS X and Linux
// this wil open the port, but it won't configure the port
int portnum = ts5_define_serialport_response_input("/dev/tty.usbmodemfd1431");
TS5_SERIALPORT *portptr = ts5_get_serialport (portnum);
// use os specific functions to configure the serial port
config_serialport(portptr);
//ts5_define_serialport_button(1, 50);
//ts5_define_serialport_button(1, 51);
//ts5_define_serialport_button(1, 52);
// timing variables
double start, stop, rt, error;
int resp;
// instruction
ts5_printf(0.1, 0.1, "press a serial port box button");
ts5_printf(0.1, 0.2, "within 5 seconds");
start = ts5_flip_display();
// flush the response buffer
// wait for a response
resp = ts5_wait_for_response_timed(&stop, &error, 5.0);
rt = stop-start;
// print response time and measurement error
// measurement error is only known
// for parallel port response boxes
// and cedrusboxes
ts5_printf(0.1, 0.3, "response %d", resp);
ts5_printf(0.1, 0.4, "start time %f", start);
ts5_printf(0.1, 0.5, "stop time %f", stop);
ts5_printf(0.1, 0.6, "response time %f", rt);
ts5_printf(0.1, 0.7, "measurement error %f", error);
// wait for a click
return 0;
}