static bool TryConnect(Port &port, char *user_data) { int retries=10; while (--retries){ port.Write('\x02'); // send IO Mode command unsigned user_size = 0; bool started = false; PeriodClock clock; clock.update(); int i; while ((i = port.GetChar()) != EOF && !clock.check(8000)) { char ch = (char)i; if (!started && ch == '-') started = true; if (started) { if (ch == 0x13) { port.Write('\x16'); user_data[user_size] = 0; // found end of file return true; } else { if (user_size < sizeof(user_data) - 1) { user_data[user_size] = ch; user_size++; } } } } } return false; }