void SerialCommunicationApp::update() { if (serialInitiallized()){ if(serial.getNumBytesAvailable() > 0){ console() << "Bytes available: " << serial.getNumBytesAvailable() << std::endl; try{ lastString = serial.readStringUntil('\n'); } catch(SerialTimeoutExc e) { console() << "timeout" << endl; } console() << lastString << endl; int16_t temp = lastString[0]; //OSC MESSAGE osc::Message message; message.addIntArg(temp); message.setAddress("coinTrigger"); message.setRemoteEndpoint(host, port); sender.sendMessage(message); TextLayout simple; simple.setFont( Font( "Arial Black", 54 ) ); simple.setColor( Color( .7, .7, .2 ) ); simple.addLine( lastString ); simple.setLeadingOffset( 0 ); mTexture = gl::Texture( simple.render( true, false ) ); bTextureComplete = true; serial.flush(); } } serial.flush(); }
void SerialCommunicationApp::update() { // console() << "Bytes available: " << serial.getNumBytesAvailable() << std::endl; double now = getElapsedSeconds(); double deltaTime = now - lastUpdate; lastUpdate = now; sinceLastRead += deltaTime; if(sinceLastRead > READ_INTERVAL) { bSendSerialMessage = true; sinceLastRead = 0.0; } if (bSendSerialMessage) { // request next chunk serial.writeByte(ctr); try{ // read until newline, to a maximum of BUFSIZE bytes lastString = serial.readStringUntil('\n', BUFSIZE ); } catch(SerialTimeoutExc e) { console() << "timeout" << endl; } bSendSerialMessage = false; ctr+=8; console() << lastString << endl; TextLayout simple; simple.setFont( Font( "Arial Black", 24 ) ); simple.setColor( Color( .7, .7, .2 ) ); simple.addLine( lastString ); simple.setLeadingOffset( 0 ); mTexture = gl::Texture( simple.render( true, false ) ); bTextureComplete = true; serial.flush(); } }