33 std::cout <<
"Test Program for mitkSerialCommunication.cpp\n";
34 std::cout <<
"Using com port COM7\n";
45 serial->SetSendTimeout(2000);
46 serial->SetReceiveTimeout(2000);
47 if (serial->OpenConnection() ==
false)
49 std::cout <<
"Error Opening connection to com port #" << serial->GetPortNumber() << std::endl;
52 std::string message =
"Hello World\r\n";
53 if (serial->Send(message) ==
false)
55 std::cout <<
"Error sending string '" << message <<
"'" << std::endl;
56 serial->CloseConnection();
60 serial->Send(std::string(
"Oh, Hello again, dort am Fluss wo die Baeume steh'n, will ich Dir in die Augen seh'n, ob ich da bleiben kann.\r\n"));
62 std::cout <<
"Waiting to receive 4 characters. [readtimeout = 0! --> blocking --> waiting until 4 characters are send in windows implementation!]\n";
63 if (serial->Receive(message, 4) ==
false)
64 std::cout <<
"Error receiving message. Only " << message.size() <<
" characters received: '" << message <<
"'.\n";
66 std::cout <<
"Received message: '" << message <<
"'.\n";
68 std::cout <<
"Setting Receive timeout to 6 seconds, waiting to receive 10 more characters.\n";
69 serial->CloseConnection();
70 serial->SetReceiveTimeout(6000);
71 serial->OpenConnection();
72 if (serial->Receive(message, 10) ==
false)
73 std::cout <<
"Error receiving message. Received " << message.size() <<
" characters: '" << message <<
"'.\n";
75 std::cout <<
"Received message: '" << message <<
"' without errors.\n";
77 std::cout <<
"sending a new message.\n";
78 serial->Send(std::string(
"all your base are belong to us\r\n"));
79 std::cout <<
"Waiting to receive 20 characters.\n";
80 serial->Receive(message, 20);
81 std::cout <<
"Received " << message.size() <<
" characters. Message: '" << message <<
"'.\n";
82 serial->CloseConnection();
83 std::cout <<
"closing connection.\n";
84 std::cout <<
"good bye.\n";
itk::SmartPointer< Self > Pointer
int main()
SerialCommunicationTest - send and receive bytes over a com port.