#include <tscope.h>
int main()
{
#ifdef ALLEGRO_WINDOWS
ts_debug(DEBUG0);
ts_scrsize(SIZE1);
ts_init();
char portname[20];
HANDLE test;
int i, nports = 0, plist[16];
ts_printf(-XMAX + 20, YMAX - 20,
"The first screen will detect the available COM ports on your system");
for (i = 0; i < 16; i++) {
sprintf(portname, "COM%d", i + 1);
test =
CreateFile(portname, GENERIC_READ | GENERIC_WRITE, 0, NULL,
OPEN_EXISTING, 0, NULL);
ts_wait(mtt(200));
if (test != INVALID_HANDLE_VALUE) {
ts_fgcolor(RED);
ts_printf(-XMAX + 40, YMAX - 40 - i * 10, "%s is available",
portname);
ts_fgcolor(WHITE);
plist[i] = 1;
nports++;
} else {
ts_printf(-XMAX + 40, YMAX - 40 - i * 10,
"%s is not available", portname);
plist[i] = 0;
}
CloseHandle(test);
}
if (nports) {
ts_printf(-XMAX + 20, YMAX - 210,
"The next screen will check whether a response box is attached");
ts_printf(-XMAX + 20, YMAX - 220,
"to one of the available COM ports");
ts_button(XMAX - 20, -YMAX + 20);
} else {
ts_printf(-XMAX + 20, YMAX - 210,
"None of the COM ports are available");
ts_printf(-XMAX + 20, YMAX - 220, "Click next to exit");
ts_button(XMAX - 20, -YMAX + 20);
return 0;
}
int j = 5, r = 0, firsttry = 1, box = 0;
__int64 junk;
for (i = 0; i < 16; i++) {
if (!plist[i])
continue;
ts_setserialport(i + 1);
if (firsttry) {
firsttry = 0;
ts_defkey(S1);
ts_defkey(S2);
ts_defkey(S3);
ts_defkey(S4);
ts_defkey(S5);
ts_defkey(S6);
ts_defkey(S7);
}
for (j = 5; j > 0; j--) {
ts_clrscr();
ts_printf(-XMAX + 20, YMAX - 20,
"testing COM%d, press a key within %d seconds",
i + 1, j);
r = ts_resp(&junk, &junk, mtt(1000));
if (r)
break;
}
if (!r) {
ts_printf(-XMAX + 20, YMAX - 40, "No keypress detected");
ts_printf(-XMAX + 20, YMAX - 50, "Click next to continue");
ts_button(XMAX - 20, -YMAX + 20);
} else {
ts_printf(-XMAX + 20, YMAX - 40,
"Cedrus box is attached to COM%d", i + 1);
ts_printf(-XMAX + 20, YMAX - 50,
"The next screen will check the response mapping of this box",
i + 1);
box = i + 1;
ts_button(XMAX - 20, -YMAX + 20);
break;
}
}
if (!box) {
ts_clrscr();
ts_printf(-XMAX + 20, YMAX - 40, "No keypresses detected");
ts_printf(-XMAX + 20, YMAX - 50,
"On any of the available COM ports");
ts_printf(-XMAX + 20, YMAX - 60, "Click next to exit");
ts_button(XMAX - 20, -YMAX + 20);
return 0;
}
ts_clrscr();
ts_printf(-XMAX + 20, YMAX - 40,
"When a keypress is detected the corresponding code will be highlighted");
ts_printf(-XMAX + 20, YMAX - 50, "Press space to exit");
for (i = 1; i <= 7; i++)
ts_printf_centre(0 + i * 20 - 80, 0, "S%d", i);
int space = ts_defkey(KEY_SPACE);
do {
r = ts_respstatus();
if (r) {
for (i = 1; i <= 7; i++) {
if (i == r) {
ts_fgcolor(RED);
ts_printf_centre(0 + i * 20 - 80, 0, "S%d", i);
ts_wait(mtt(1000));
ts_fgcolor(WHITE);
ts_printf_centre(0 + i * 20 - 80, 0, "S%d", i);
}
}
}
} while (r != space);
return 0;
#elif ALLEGRO_LINUX
ts_fatal("testsport.c: serial port not implemented in linux version.");
return 1;
#endif
}
END_OF_MAIN();