tinytinkerer Geschrieben February 18, 2020 at 13:59 Geschrieben February 18, 2020 at 13:59 (bearbeitet) Hallo zusammen, ich soll Sensordaten vom RED-Brick persistieren. Kann mir da wer weiterhelfen? Ich stehe gerade voll auf dem Schlauch.//Edit hat sich erledigt: package com.company; import com.tinkerforge.IPConnection; import com.tinkerforge.BrickletAccelerometer; import java.io.*; public class Main { private static final String HOST = "localhost"; private static final int PORT = 4223; // Change XYZ to the UID of your Accelerometer Bricklet private static final String UID = "Cge"; // Note: To make the example code cleaner we do not handle exceptions. Exceptions // you might normally want to catch are described in the documentation public static void main(String args[]) throws Exception { IPConnection ipcon = new IPConnection(); // Create IP connection BrickletAccelerometer a = new BrickletAccelerometer(UID, ipcon); // Create device object ipcon.connect(HOST, PORT); // Connect to brickd // Don't use device before ipcon is connected // Add acceleration listener a.addAccelerationListener(new BrickletAccelerometer.AccelerationListener() { public void acceleration(short x, short y, short z) { PrintWriter outputfile = null; try { outputfile = new PrintWriter((new BufferedWriter(new FileWriter("Beschleunigung.txt",true)))); //replace your System.out.print("your output"); outputfile.println(+x/1000.0+";"+y/1000.0+";"+z/1000.0+";"); outputfile.println(""); }catch (IOException ioe) { ioe.printStackTrace(); }finally { if (outputfile != null){ outputfile.flush(); outputfile.close(); } } } }); // Set period for acceleration callback to 1s (1000ms) // Note: The acceleration callback is only called every second // if the acceleration has changed since the last call! a.setAccelerationCallbackPeriod(1000); System.out.println("Press key to exit"); System.in.read(); ipcon.disconnect(); } } bearbeitet February 20, 2020 at 10:32 von tinytinkerer Zitieren
jgmischke Geschrieben February 19, 2020 at 09:36 Geschrieben February 19, 2020 at 09:36 OK, ich versteh dafür dein Problem nicht. Daten können einfach auf die SD geschrieben werden oder bei Bedarf auf einen externen Speicher. Zitieren
tinytinkerer Geschrieben February 20, 2020 at 08:13 Autor Geschrieben February 20, 2020 at 08:13 (bearbeitet) Problem gelöst. bearbeitet February 20, 2020 at 10:33 von tinytinkerer Zitieren
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.