| 377 | } |
| 378 | |
| 379 | int main(int argc, char* argv[]) |
| 380 | { |
| 381 | txSerialTool self = &tool; |
| 382 | char path[256]; |
| 383 | DWORD size, flags; |
| 384 | int result = fxArguments(self, argc, argv); |
| 385 | if (result) |
| 386 | return result; |
| 387 | |
| 388 | if (!(self->vendorID) || !(self->productID)) { |
| 389 | strcpy(path, "\\\\.\\"); |
| 390 | strcat(path, self->path); |
| 391 | } else { |
| 392 | int port = fxFindPortFromVIDPID(self->vendorID, self->productID); |
| 393 | if (port == -1) { |
| 394 | fprintf(stderr, "Could not find USB COM Port with VID 0x%04X and ID 0x%04X\n", self->vendorID, self->productID); |
| 395 | exit(1); |
| 396 | } |
| 397 | sprintf(path, "\\\\.\\COM%d", port); |
| 398 | } |
| 399 | |
| 400 | self->path = path; |
| 401 | self->serialConnection = INVALID_HANDLE_VALUE; |
| 402 | if (setjmp(self->_jmp_buf) == 0) { |
| 403 | WSADATA wsaData; |
| 404 | self->error = WSAStartup(0x202, &wsaData); |
| 405 | self->signalEvent = CreateEvent(NULL, FALSE, FALSE, NULL); |
| 406 | signal(SIGINT, &fxSignalHandler); |
| 407 | signal(SIGBREAK, &fxSignalHandler); |
| 408 | fxOpenSerial(self); |
| 409 | self->count = 2; |
| 410 | self->events[0] = self->signalEvent; |
| 411 | self->events[1] = self->serialOverlapped.hEvent; |
| 412 | for (;;) { |
| 413 | if (self->reconnecting) { |
| 414 | fxOpenSerial(self); |
| 415 | if (INVALID_HANDLE_VALUE == self->serialConnection) |
| 416 | Sleep(500); |
| 417 | else { |
| 418 | self->reconnecting = 0; |
| 419 | self->events[0] = self->signalEvent; |
| 420 | self->events[1] = self->serialOverlapped.hEvent; |
| 421 | } |
| 422 | continue; |
| 423 | } |
| 424 | DWORD which = WaitForMultipleObjects(self->count, self->events, FALSE, INFINITE); |
| 425 | if (which == 0) { |
| 426 | result = 1; |
| 427 | break; |
| 428 | } |
| 429 | if (which == 1) { |
| 430 | if (!GetOverlappedResult(self->serialConnection, &self->serialOverlapped, &size, FALSE)) { |
| 431 | fxCloseSerial(self); |
| 432 | self->reconnecting = 1; |
| 433 | Sleep(500); |
| 434 | continue; |
| 435 | } |
| 436 | fxReadSerial(self, size); |
nothing calls this directly
no test coverage detected