// // egg5071a.exe - Trigger 5071A "easter egg" display. // // 23-Dec-2005 tvb // #include #include #define WIN32_LEAN_AND_MEAN #include void CommOpen (int Port, int Baud, int Parity, int Flow); void CommWrite (char *Buffer, DWORD Size); void CommClose (void); #define CMD(s) { CommWrite(s, strlen(s)); CommWrite("\n", 1); \ printf(" %s\n", s); Sleep(100); } void main (int argc, char *argv[]) { int port, baud, parity; if (argc == 1) { fprintf(stderr, "Usage: %s [port] [baud] [parity]\n", argv[0]); exit(1); } port = (argc > 1) ? atoi(argv[1]) : 1; baud = (argc > 2) ? atoi(argv[2]) : 9600; parity = (argc > 3) ? atoi(argv[3]) : 0; CommOpen(port, baud, parity, 0); CMD("*cls"); CMD("syst:key 142"); // TOP CMD("syst:key 132"); // <-- (UTIL) CMD("syst:key 147"); // ENTER CMD("syst:key 132"); // <-- (TEST) CMD("syst:key 147"); // ENTER CMD("syst:key 148"); // SHIFT CMD("syst:key 143"); // PREV CommClose(); } HANDLE hCom; void CommOpen (int Port, int Baud, int Parity, int Flow) { char CommPath[100]; DCB Dcb; BOOL Success; // // Open COM port. // sprintf(CommPath, "\\\\.\\COM%d", Port); fprintf(stderr, "Opening port %s (%d baud)...\n", CommPath, Baud); hCom = CreateFile(CommPath, GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, NULL); if (hCom == INVALID_HANDLE_VALUE) { fprintf(stderr, "CreateFile failed: %s (%.8x)\n", CommPath, GetLastError()); exit(1); } // // Set comm parameters. // memset(&Dcb, 0x0, sizeof(DCB)); Dcb.DCBlength = sizeof (DCB); Success = GetCommState(hCom, &Dcb); // ASSERT_SUCCESS(GetCommState); // Set parity Dcb.Parity = Parity; if (Parity == 0) { Dcb.Parity = NOPARITY; } else if (Parity & 1) { Dcb.Parity = ODDPARITY; } else { Dcb.Parity = EVENPARITY; } // Set frame size Dcb.BaudRate = Baud; Dcb.ByteSize = (Dcb.Parity == NOPARITY) ? 8 : 7; Dcb.StopBits = ONESTOPBIT; // Set raw mode Dcb.fDsrSensitivity = FALSE; Dcb.fOutxCtsFlow = FALSE; Dcb.fOutX = FALSE; Dcb.fInX = FALSE; Dcb.fNull = FALSE; Dcb.fBinary = TRUE; // PC write flow control Dcb.fOutxCtsFlow = FALSE; Dcb.fOutxDsrFlow = FALSE; // PC read flow control Dcb.fDtrControl = Flow ? DTR_CONTROL_HANDSHAKE : DTR_CONTROL_ENABLE; Dcb.fRtsControl = Flow ? RTS_CONTROL_HANDSHAKE : RTS_CONTROL_ENABLE; Success = SetCommState(hCom, &Dcb); // ASSERT_SUCCESS(SetCommState); SetupComm(hCom, 2048, 2048); return; } void CommWrite (char *Buffer, DWORD Size) { DWORD Count; BOOL Success; Success = WriteFile(hCom, Buffer, Size, &Count, 0); // ASSERT_SUCCESS(WriteFile); if (!Success || Count != Size) { fprintf(stderr, "WriteFile Count (%d) != Size (%d)\n", Count, Size); exit(1); } return; } void CommClose (void) { CloseHandle(hCom); hCom = NULL; fprintf(stderr, "Closed.\n"); }