Jump to content

Recommended Posts

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();
    }
}
Edited by tinytinkerer
Link to post
Share on other sites

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...