Tscope5
serialport02.c
////////////////////////////////////////////////////////////////////////////////
//
// __ ______
// / /_______________ ____ ___ / ____/
// / __/ ___/ ___/ __ \/ __ \/ _ \ /___ )
// / /_(__ ) /__/ /_/ / /_/ / __/ ____/ /
// \__/____/\___/\____/ .___/\___/ /_____/
// /_/
//
// serialport02.c
// - Use the serial port for trigger input.
// - This example can be used separately (use trigger simulation)
// or together with serialport03.c (on another computer).
// - Serial port parameters have to be set by the user
// (see the function in config_serialport.c)
// - This example does not open a display
////////////////////////////////////////////////////////////////////////////////
#include <tscope5.h>
#include <stdio.h>
#include "config_serialport.c"
int main()
{
// set the log level to some high value
ts5_set_log_level(TS5_LOGLEVEL_4);
// register serialport COM1 as a trigger 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_trigger_input("COM1");
TS5_SERIALPORT *portptr = ts5_get_serialport (portnum);
// use os specific functions to configure the serial port
config_serialport(portptr);
// turn on trigger input simulation
// send value 255 to port 1 every 0.1 seconds
// comment this out if you want to receive real triggers
// from a computer that is connected via the serial port
// wait for 10 triggers
int trigger=0;
double trigtime, timing_error;
int i;
for (i=0; i<10; i++) {
trigger = ts5_wait_for_trigger(&trigtime, &timing_error);
printf("trigger %d %f %f\n", trigger, trigtime, timing_error);
}
// write (append) all triggers to a log file
ts5_write_all_triggers("serialport_triggers.txt");
return 0;
}