19 #include "../include/tscope5/timer.h"
21 HANDLE _ts5_cedrusbox_handle[TS5_CEDRUSBOX_MAXPORT] = {TS5_CEDRUSBOX_NODEVICE};
39 int i, num_serial_devices=0;
41 for (i=0; i<TS5_CEDRUSBOX_MAXPORT; i++) {
44 char portname[TS5_MAX_CHAR];
45 sprintf(portname,
"COM%d", i+1);
48 _ts5_cedrusbox_handle[num_serial_devices] = CreateFile(portname,
49 GENERIC_READ | GENERIC_WRITE,
50 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
53 if (_ts5_cedrusbox_handle[num_serial_devices] == INVALID_HANDLE_VALUE) {
58 ts5_log(TS5_LOGLEVEL_1,
"%s: port %s is available\n", calling_function, portname);
63 if (!GetCommState(_ts5_cedrusbox_handle[num_serial_devices], &dcb)) {
64 ts5_log(TS5_LOGLEVEL_1,
"%s: GetCommState failed with error code %d\n",
65 calling_function, GetLastError());
69 dcb.BaudRate = 115200;
70 dcb.ByteSize = (
unsigned char) 8;
75 if (!SetCommState(_ts5_cedrusbox_handle[num_serial_devices], &dcb)) {
76 ts5_log(TS5_LOGLEVEL_1,
"%s: SetCommState failed with error code %d\n",
77 calling_function, GetLastError());
82 ct.ReadIntervalTimeout = MAXDWORD;
83 ct.ReadTotalTimeoutMultiplier = 0;
84 ct.ReadTotalTimeoutConstant = 0;
85 ct.WriteTotalTimeoutMultiplier = 0;
86 ct.WriteTotalTimeoutConstant = 5000;
88 if (!SetCommTimeouts(_ts5_cedrusbox_handle[num_serial_devices], &ct)) {
89 ts5_log(TS5_LOGLEVEL_1,
"%s: SetCommTimeouts failed with error code %d\n",
90 calling_function, GetLastError());
94 if (!SetupComm(_ts5_cedrusbox_handle[num_serial_devices], 2048, 2048)) {
95 ts5_log(TS5_LOGLEVEL_1,
"%s: SetupComm failed with error code %d\n",
96 calling_function, GetLastError());
100 num_serial_devices++;
103 return num_serial_devices;
115 for (i=0; i<_ts5_status.timer.num_cedrusboxes; i++) {
117 int port_num = _ts5_status.timer.cedrusbox[i].port_num;
119 if (!CloseHandle(_ts5_cedrusbox_handle[port_num])) {
120 ts5_log(TS5_LOGLEVEL_1,
"ts5_uninstall_cedrusbox_windows:\n");
121 ts5_log(TS5_LOGLEVEL_1,
"\tcould not uninstall cedrusbox %d\n", i);
124 ts5_log(TS5_LOGLEVEL_1,
"ts5_uninstall_cedrusbox_windows: uninstalled cedrusbox %d\n", i);
136 unsigned long bytes_read;
138 if (!ReadFile(_ts5_cedrusbox_handle[port], buff, bytes_to_read, &bytes_read, NULL)) {
139 ts5_fatal(
"ts5_read_cedrusbox_windows: read error\n");
153 unsigned long bytes_written;
155 if (!WriteFile(_ts5_cedrusbox_handle[port], buff, bytes_to_write, &bytes_written, NULL)) {
156 ts5_fatal(
"ts5_write_cedrusbox_windows: write error 1\n");
159 if (bytes_written != bytes_to_write) {
160 ts5_fatal(
"ts5_write_cedrusbox_windows: write error 2\n");
165 return bytes_written;
176 char buff[TS5_MAX_CHAR];
177 unsigned long bytes_read;
180 ReadFile(_ts5_cedrusbox_handle[port], buff, 1, &bytes_read, NULL);
181 }
while (bytes_read > 0);
void ts5_fflush_cedrusbox_windows(int port)
Windows-specific cedrusbox function.
void ts5_wait(double waittime)
Wait for a number of seconds.
int ts5_install_cedrusbox_windows(char *calling_function)
Windows-specific cedrusbox function.
unsigned int ts5_write_cedrusbox_windows(int port, char *buff, unsigned long bytes_to_write)
Windows-specific cedrusbox function.
void ts5_log(const unsigned int level, const char *format,...)
Send info to a logging window.
void ts5_uninstall_cedrusbox_windows()
Windows-specific cedrusbox function.
unsigned int ts5_read_cedrusbox_windows(int port, char *buff, unsigned long bytes_to_read)
Windows-specific cedrusbox function.
void ts5_fatal(const char *format,...)
Exit safely with an error message.