18 #include "../include/tscope5/serialport.h"
19 #include "../include/tscope5/timer.h"
20 #include "../include/tscope5/serialport_internal.h"
21 #include "../include/tscope5/system_internal.h"
48 ts5_log(TS5_LOGLEVEL_3,
"ts5_define_serialport_trigger_input(%s)\n",
51 _ts5_status.timer.serialport_is_trigger_device = 1;
52 _ts5_status.timer.serialport[portnum].is_trigger_input_device = 1;
70 ts5_log(TS5_LOGLEVEL_3,
"ts5_simulate_serialport_trigger_input(%d,%d,%f)\n",
71 device, value, interval);
73 if (device<1 || device>_ts5_status.timer.num_serialports) {
74 ts5_fatal(
"%s: %s %d, %s %d\n",
"ts5_simulate_serialport_trigger_input",
75 "device argument is", device,
76 "number of serial ports is",
77 _ts5_status.timer.num_serialports);
80 _ts5_status.timer.serialport[device-1].simulate_trigger_input =
83 _ts5_status.timer.serialport[device-1].trigger_simulation_interval =
104 ts5_log(TS5_LOGLEVEL_3,
"ts5_define_serialport_trigger_output(%s)\n",
107 _ts5_status.timer.serialport_is_trigger_device = 1;
108 _ts5_status.timer.serialport[portnum].is_trigger_output_device = 1;
122 ts5_log(TS5_LOGLEVEL_3,
"ts5_send_serialport_trigger(%d,%d)\n",
125 if (device<1 || device>_ts5_status.timer.num_serialports) {
126 ts5_fatal(
"%s: %s %d, %s %d\n",
"ts5_send_serialport_trigger",
127 "device argument is", device,
128 "number of serial ports is",
129 _ts5_status.timer.num_serialports);
132 char serial_buff[TS5_MAX_CHAR];
133 sprintf(serial_buff,
"%c", value);
137 unsigned long bytes_to_write = strlen(serial_buff);
138 unsigned long bytes_written;
140 if (!WriteFile(*(_ts5_status.timer.serialport[device-1].port),
141 serial_buff, bytes_to_write, &bytes_written, NULL)) {
142 ts5_fatal(
"ts5_send_serialport_trigger: write error 1\n");
145 if (bytes_written != bytes_to_write) {
146 ts5_fatal(
"ts5_send_serialport_trigger: write error 2\n");
152 unsigned int bytes_to_write = strlen(serial_buff);
153 unsigned int bytes_written;
156 write(*(_ts5_status.timer.serialport[device-1].port),
157 serial_buff, bytes_to_write);
159 if (bytes_written != bytes_to_write) {
160 ts5_fatal(
"ts5_send_serialport_trigger: write error\n");
178 ts5_log(TS5_LOGLEVEL_3,
"ts5_get_serialport(%d)\n", device);
180 if (device < 1 || device>_ts5_status.timer.num_serialports) {
182 "device argument is", device,
183 "number of opened serial ports is",
184 _ts5_status.timer.num_serialports);
187 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_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.
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.