MCPcopy Create free account
hub / github.com/cinder/Cinder / setup

Method setup

samples/SerialCommunication/src/SerialCommunicationApp.cpp:36–73  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

34};
35
36void SerialCommunicationApp::setup()
37{
38 mCounter = 0;
39 mLastRead = 0;
40 mLastUpdate = 0;
41 mSendSerialMessage = false;
42
43 // print the devices
44 for( const auto &dev : Serial::getDevices() )
45 console() << "Device: " << dev.getName() << endl;
46
47 try {
48 Serial::Device dev = Serial::findDeviceByNameContains( "tty.usbserial" );
49 mSerial = Serial::create( dev, 9600 );
50 }
51 catch( SerialExc &exc ) {
52 CI_LOG_EXCEPTION( "coult not initialize the serial device", exc );
53 exit( -1 );
54 }
55
56 // wait for * as a sign for first contact
57 char contact = 0;
58 while( contact != '*' ) {
59 contact = (char)mSerial->readByte();
60 }
61
62 // request actual data
63 mSerial->writeByte( mCounter );
64
65 // clear accumulated contact messages in buffer
66 char b = '*';
67 while( mSerial->getNumBytesAvailable() > -1 ) {
68 b = mSerial->readByte();
69 console() << b << "_";
70 }
71
72 mSerial->flush();
73}
74
75void SerialCommunicationApp::mouseDown( MouseEvent event )
76{

Callers

nothing calls this directly

Calls 6

readByteMethod · 0.80
writeByteMethod · 0.80
getNumBytesAvailableMethod · 0.80
createFunction · 0.50
getNameMethod · 0.45
flushMethod · 0.45

Tested by

no test coverage detected