julius1290 Geschrieben July 1, 2024 at 15:33 Share Geschrieben July 1, 2024 at 15:33 Hallo zusammen, ich versuche momentan, Daten über das CAN-Bricklet V2 zu senden. Grundlegend funktioniert das auch gut, allerdings komme ich bei Nutzung der API immer wieder in eine Leistungsgrenze, die bei circa 120 Frames/Sekunde liegt. Folgendes Setup verwende ich dabei: ESP32 Brick 2x CAN Bricklet V2 (einer sendet, einer liest) Nutzung der JavaScript oder Python API unter Verwendung eines modifizierten Beispiels (Code weiter unten) Falls ich etwas übersehen habe, bin ich über jede Hilfe dankbar. Viele Grüße var Tinkerforge = require('tinkerforge'); var HOST = '10.0.0.1'; var PORT = 4223; var UID = 'XXXX'; // Change XYZ to the UID of your CAN Bricklet 2.0 var ipcon = new Tinkerforge.IPConnection(); // Create IP connection var can = new Tinkerforge.BrickletCANV2(UID, ipcon); // Create device object function sleep(ms) { return new Promise((resolve) => { setTimeout(resolve, ms); }); } ipcon.connect(HOST, PORT, function (error) { console.log('Error: ' + error); } ); // Connect to brickd // Don't use device before ipcon is connected ipcon.on(Tinkerforge.IPConnection.CALLBACK_CONNECTED, async function (connectReason) { // Configure transceiver for loopback mode can.setTransceiverConfiguration(125000, 625, 0); // Enable frame read callback can.setFrameReadCallbackConfiguration(false); let counter = 0; // Write standard data frame with identifier 1742 and 3 bytes of data while (true) { can.writeFrame(Tinkerforge.BrickletCANV2.FRAME_TYPE_STANDARD_DATA, 1, [counter, 23, 17]); console.log(counter); counter++; await sleep(1) if (counter == 255) counter = 0 } } ); // Register frame read callback can.on(Tinkerforge.BrickletCANV2.CALLBACK_FRAME_READ, // Callback function for frame read callback function (frameType, identifier, data) { if(frameType === Tinkerforge.BrickletCANV2.FRAME_TYPE_STANDARD_DATA) { console.log('Frame Type: Standard Data'); } else if(frameType === Tinkerforge.BrickletCANV2.FRAME_TYPE_STANDARD_REMOTE) { console.log('Frame Type: Standard Remote'); } else if(frameType === Tinkerforge.BrickletCANV2.FRAME_TYPE_EXTENDED_DATA) { console.log('Frame Type: Extended Data'); } else if(frameType === Tinkerforge.BrickletCANV2.FRAME_TYPE_EXTENDED_REMOTE) { console.log('Frame Type: Extended Remote'); } console.log('Identifier: ' + identifier); var str = 'Data (Length: ' + data.length + '):'; for (var i = 0; i < data.length && i < 8; ++i) { str += ' ' + data[i]; } console.log(str); console.log(); } ); console.log('Press key to exit'); process.stdin.on('data', function (data) { can.setFrameReadCallbackConfiguration(false); ipcon.disconnect(); process.exit(0); } ); Zitieren Link zu diesem Kommentar Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.