@mattc wrote:
Hi! I'm trying to setup ofxSimpleSerial with no luck.
Second device is connected through MAX3232 chip to UART pins on my Raspberry Pi B, minibian, OF0.9.2.
Second device is sending me messages on each button press on this device.
In minicom I can see the massages as expected:0006
and0007
depending on the button, so the connection is OK.
I've added fewofLog()
functions to check what's going on and it seams that thevoid ofApp::onNewMessage(string & message)
is not running since I don't see onNewMessage in ofApp is running! in my logs.main.cpp:
#include "ofMain.h" #include "ofApp.h" //======================================================================== int main( ){ ofSetupOpenGL(1024,768, OF_WINDOW); ofSetFrameRate(30); ofRunApp( new ofApp()); }
ofApp.h:
#pragma once #include "ofMain.h" #include "testApp.h" class ofApp : public ofBaseApp{ public: void setup(); void update(); void draw(); void keyPressed(int key); void keyReleased(int key); void mouseMoved(int x, int y); void mouseDragged(int x, int y, int button); void mousePressed(int x, int y, int button); void mouseReleased(int x, int y, int button); void mouseEntered(int x, int y); void mouseExited(int x, int y); void windowResized(int w, int h); void dragEvent(ofDragInfo dragInfo); void gotMessage(ofMessage msg); void onNewMessage(string & message); testApp justTesting; };
ofApp.cpp:
#include "ofApp.h" //-------------------------------------------------------------- void ofApp::setup(){ justTesting.setup(); } //-------------------------------------------------------------- void ofApp::update(){ justTesting.update(); } //-------------------------------------------------------------- void ofApp::draw(){ justTesting.draw(); } //-------------------------------------------------------------- void ofApp::keyPressed(int key){ justTesting.keyPressed(key); } //-------------------------------------------------------------- void ofApp::keyReleased(int key){ } //-------------------------------------------------------------- void ofApp::mouseMoved(int x, int y){ } //-------------------------------------------------------------- void ofApp::mouseDragged(int x, int y, int button){ } //-------------------------------------------------------------- void ofApp::mousePressed(int x, int y, int button){ justTesting.mousePressed(x, y, button); } //-------------------------------------------------------------- void ofApp::mouseReleased(int x, int y, int button){ } //-------------------------------------------------------------- void ofApp::mouseEntered(int x, int y){ } //-------------------------------------------------------------- void ofApp::mouseExited(int x, int y){ } //-------------------------------------------------------------- void ofApp::windowResized(int w, int h){ } //-------------------------------------------------------------- void ofApp::gotMessage(ofMessage msg){ } //-------------------------------------------------------------- void ofApp::dragEvent(ofDragInfo dragInfo){ } //-------------------------------------------------------------- void ofApp::onNewMessage(string & message){ ofLog(OF_LOG_NOTICE, "onNewMessage in ofApp is running!"); justTesting.onNewMessage(message); }
testApp.h:
#ifndef _TEST_APP #define _TEST_APP #include "ofMain.h" #include "ofxSimpleSerial.h" using namespace std; class testApp : public ofBaseApp{ public: ofxSimpleSerial serial; string message; bool red; bool green; bool blue; bool requestRead; void setup(); void update(); void draw(); void mousePressed(int x, int y, int button); void keyPressed(int key); void onNewMessage(string & message); protected: }; #endif
testApp.cpp:
#include "testApp.h" //-------------------------------------------------------------- void testApp::setup() { ofSetVerticalSync(true); ofBackground(0, 0, 0); ofLog(OF_LOG_NOTICE, "Background is set to 000."); serial.setup("/dev/ttyAMA0", 9600); serial.startContinuousRead(); ofLog(OF_LOG_NOTICE, "Serial connection should be workin by now."); ofAddListener(serial.NEW_MESSAGE,this,&testApp::onNewMessage); ofLog(OF_LOG_NOTICE, "Listener event set."); message = ""; } void testApp::onNewMessage(string & message) { ofLog(OF_LOG_NOTICE, "onNewMessage is working!"); cout << "onNewMessage, message: " << message << "\n"; red = (message == "0006"); green = (message == "0007"); blue = (message == "800000000060"); } void testApp::update() { } //-------------------------------------------------------------- void testApp::draw() { int redColor = (red)? 255 : 0; int greenColor = (green)? 255 : 0; int blueColor = (blue)? 255 : 0; ofBackground(redColor, greenColor, blueColor); } //-------------------------------------------------------------- void testApp::mousePressed(int x, int y, int button){ serial.sendRequest(); ofLog(OF_LOG_NOTICE, "mouse pressed!"); } void testApp::keyPressed(int key){ serial.sendRequest(); ofLog(OF_LOG_NOTICE, "key pressed!"); }
terminal logs:
[notice ] Background is set to 000. [notice ] ofSerial: opening /dev/ttyAMA0 @ 9600 bps [notice ] ofSerial: opened /dev/ttyAMA0 sucessfully @ 9600 bps [notice ] Serial connection should be workin by now. [notice ] Listener event set. [notice ] key pressed! [notice ] key pressed! [notice ] key pressed!
Posts: 1
Participants: 1