19 #include "../include/tscope5/serialport.h"
20 #include "../include/tscope5/timer.h"
21 #include "../include/tscope5/serialport_internal.h"
22 #include "../include/tscope5/system_internal.h"
49 ts5_log(TS5_LOGLEVEL_3,
"ts5_define_serialport_response_input(%s)\n",
52 _ts5_status.timer.serialport_is_response_device = 1;
72 ts5_log(TS5_LOGLEVEL_3,
"ts5_define_serialport_button(%d,%d)\n", device, button);
74 if (device<1 || device>_ts5_status.timer.num_serialports) {
75 ts5_fatal(
"%s: %s %d, %s %d\n",
"ts5_define_serialport_button",
76 "device argument is", device,
"number of serialportes is",
77 _ts5_status.timer.num_serialports);
81 ts5_fatal(
"%s: %s\n",
"ts5_define_serialport_button",
82 "button argument is 0, response buttons are numbered from 1");
86 ts5_fatal(
"%s: %s %s %s\n",
"ts5_define_serialport_button",
87 "button argument is negative.",
88 "button releases are currently not supported",
92 if (button>_ts5_status.timer.serialport[device-1].num_buttons) {
93 ts5_fatal(
"%s: %s %d, %s %d is %d\n",
"ts5_define_serialport_button",
94 "button argument is ", button,
95 "number of serialport buttons for device", device,
96 _ts5_status.timer.serialport[device-1].num_buttons);
99 if (button>0 && _ts5_status.timer.serialport[device-1]
100 .button_press_defined[button-1] !=0) {
101 ts5_fatal(
"%s: %s %d %s\n",
"ts5_define_serialport_button",
102 "button press", button,
"is already defined");
105 _ts5_status.timer.serialport_is_response_device = 1;
106 _ts5_status.timer.num_defined_buttons++;
107 _ts5_status.timer.num_active_buttons++;
108 _ts5_status.timer.serialport[device-1].num_defined_buttons++;
109 _ts5_status.timer.serialport[device-1].num_active_buttons++;
111 _ts5_status.timer.serialport[device-1]
112 .button_press_defined[button-1] =
113 _ts5_status.timer.num_defined_buttons;
115 _ts5_status.timer.serialport[device-1]
116 .button_press_active[button-1] =
117 _ts5_status.timer.num_defined_buttons;
119 return _ts5_status.timer.num_defined_buttons;
131 ts5_log(TS5_LOGLEVEL_4,
"ts5_get_num_serialports()\n");
133 return _ts5_status.timer.num_serialports;
147 ts5_log(TS5_LOGLEVEL_4,
"ts5_get_num_serialport_buttons(%d)\n", device);
149 if (device<1 || device>_ts5_status.timer.num_serialports) {
150 ts5_fatal(
"%s: %s %d, %s %d\n",
"ts5_get_num_serialport_buttons",
151 "device argument is", device,
"number of serialports is",
152 _ts5_status.timer.num_serialports);
155 return _ts5_status.timer.serialport[device-1].num_buttons;
188 ts5_log(TS5_LOGLEVEL_3,
"ts5_define_serialport_trigger_input(%s)\n",
191 _ts5_status.timer.serialport_is_trigger_device = 1;
192 _ts5_status.timer.serialport[portnum].is_trigger_input_device = 1;
210 ts5_log(TS5_LOGLEVEL_3,
"ts5_simulate_serialport_trigger_input(%d,%d,%f)\n",
211 device, value, interval);
213 if (device<1 || device>_ts5_status.timer.num_serialports) {
214 ts5_fatal(
"%s: %s %d, %s %d\n",
"ts5_simulate_serialport_trigger_input",
215 "device argument is", device,
216 "number of serial ports is",
217 _ts5_status.timer.num_serialports);
220 _ts5_status.timer.serialport[device-1].simulate_trigger_input =
223 _ts5_status.timer.serialport[device-1].trigger_simulation_interval =
244 ts5_log(TS5_LOGLEVEL_3,
"ts5_define_serialport_trigger_output(%s)\n",
247 _ts5_status.timer.serialport_is_trigger_device = 1;
248 _ts5_status.timer.serialport[portnum].is_trigger_output_device = 1;
262 ts5_log(TS5_LOGLEVEL_3,
"ts5_send_serialport_trigger(%d,%d)\n",
265 if (device<1 || device>_ts5_status.timer.num_serialports) {
266 ts5_fatal(
"%s: %s %d, %s %d\n",
"ts5_send_serialport_trigger",
267 "device argument is", device,
268 "number of serial ports is",
269 _ts5_status.timer.num_serialports);
272 char serial_buff[TS5_MAX_CHAR];
273 sprintf(serial_buff,
"%c", value);
277 unsigned long bytes_to_write = strlen(serial_buff);
278 unsigned long bytes_written;
280 if (!WriteFile(*(_ts5_status.timer.serialport[device-1].port),
281 serial_buff, bytes_to_write, &bytes_written, NULL)) {
282 ts5_fatal(
"ts5_send_serialport_trigger: write error 1\n");
285 if (bytes_written != bytes_to_write) {
286 ts5_fatal(
"ts5_send_serialport_trigger: write error 2\n");
292 unsigned int bytes_to_write = strlen(serial_buff);
293 unsigned int bytes_written;
296 write(*(_ts5_status.timer.serialport[device-1].port),
297 serial_buff, bytes_to_write);
299 if (bytes_written != bytes_to_write) {
300 ts5_fatal(
"ts5_send_serialport_trigger: write error\n");
318 ts5_log(TS5_LOGLEVEL_3,
"ts5_get_serialport(%d)\n", device);
320 if (device < 1 || device>_ts5_status.timer.num_serialports) {
322 "device argument is", device,
323 "number of opened serial ports is",
324 _ts5_status.timer.num_serialports);
326 return _ts5_status.timer.serialport[device-1].port;
void ts5_simulate_serialport_trigger_input(int device, unsigned char value, double interval)
Turn on serial port input simulation.
int ts5_get_num_serialport_buttons(int device)
Get the number of buttons available on a serial port.
int ts5_define_serialport_button(int device, int button)
Define a serial port button as a response button.
int ts5_define_serialport_response_input(char *portname)
Define a serial port as a response input device.
int ts5_define_serialport_trigger_output(char *portname)
Define a serial port as a trigger output device.
TS5_SERIALPORT * ts5_get_serialport(int device)
Get a pointer to a serial port.
void ts5_send_serialport_trigger(int device, unsigned char value)
Send a trigger trough a serial port.
int ts5_get_num_serialports()
Get the number of serial ports that are connected to the system.
void ts5_check_serialport(char *calling_function)
Do some checks at the start of each serialport function.
void ts5_log(const unsigned int level, const char *format,...)
Send info to a logging window.
int ts5_define_serialport_trigger_input(char *portname)
Define a serial port as a trigger input device.
void ts5_fatal(const char *format,...)
Exit safely with an error message.
int ts5_check_serialport2(char *calling_function, char *portname)
Do some checks at the start of each serialport function.