Jump to content

Node.js applikation funktioniert nur mit geöffnetem BrickViewer Tab


Recommended Posts

Posted

Habe ein sehr seltsames Problem.

 

Hier mein Setup:

 

Master Brick per USB an einem Debian Laptop.

Am Master Brick hängt 1x Segment-Display(4x7), 1x Linear Poti.

Meine Anwendung visualisiert den Wert des Poti (0-100) auf der Segment-Anzeige.

 

Wenn ich den code via nodejs ausführe funktioniert erstmal garnichts. Erst wenn ich den BrickViewer starte und auf den Tab des "Linear Poti" gehe, funktioniert es plötzlich. Kennt dieses Problem jemand, beziehungsweise kann mir jemand weiterhelfen?

 

 

Hier der Code (index.js):

 

var Tinkerforge = require('tinkerforge');

var HOST = 'localhost';
var PORT = 4223;

var DIGITS = [
    0x3f,
    0x06,
    0x5b,
    0x4f,
    0x66,
    0x6d,
    0x7d,
    0x07,
    0x7f,
    0x6f
];

var ipcon = new Tinkerforge.IPConnection();

var poti = new Tinkerforge.BrickletLinearPoti('r73', ipcon);
var segment = new Tinkerforge.BrickletSegmentDisplay4x7('pMU', ipcon);

ipcon.connect(HOST, PORT,
    function (error) {
        console.log('Error: ' + error);
    }
);

// Linear poti callback
poti.on(Tinkerforge.BrickletLinearPoti.CALLBACK_POSITION,
    function (position) {
        var number_array = toArray(position);
        var result_segments = [0x00, 0x00, 0x00, 0x00];
        for (var i = 0; i < number_array.length; i++) {
            result_segments[i] = DIGITS[number_array[i]];
        }
        segment.setSegments(result_segments, 5, false);
    }
);
console.log("Press any key to exit ...");

function toArray(number) {
    return number.toString(10).replace(/\D/g, '0').split('').map(Number);
}

function getRandom(from, to) {
    return Math.floor((Math.random() * to) + from);
}

 

Posted

Fixed it, forgot to setup the PositionCallbackPeriod

ipcon.on(Tinkerforge.IPConnection.CALLBACK_CONNECTED,
    function(connectReason) {
        // Set Period for position callback to 0.05s (50ms)
        // Note: The position position is only called every 50ms if the
        // position has changed since the last call!
        poti.setPositionCallbackPeriod(50);
    }
);

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...