medameda
Posts: 1
Joined: Sun Aug 10, 2014 3:21 pm

Pi reads Watchport/H sensor only once

Sun Aug 10, 2014 3:41 pm

Hi, i am new Pi user, and I've been trying to read the temperature from my Watchport/H sensor.
I've installed java JDK 1.7

Code: Select all

java -version
java version "1.7.0_60"
Java(TM) SE Runtime Environment (build 1.7.0_60-b19)
and with help of the jccr libraries I've written the simple code to read the sensor data (the sensor connects to the usb port).

Code: Select all

    public static void main(String[] args) {
        SerialPort serialPort = new SerialPort("/dev/ttyUSB0");
        try {         
            System.out.println("Port opened: " + serialPort.openPort());
            System.out.println("Params setted: " + serialPort.setParams(9600, 8, 1, 0));
            System.out.println("Request for temperature sent " + serialPort.writeBytes("\rT\r".getBytes()));
	    System.out.println("temperature is : "+new String(serialPort.readBytes(10)));  
             System.out.println("Port closed: " + serialPort.closePort());
            }
        catch (SerialPortException ex){
            System.out.println(ex);
        }
    }
Now the funny part - when i run the code for the first time, i get the temperature reading, but every next execution of the code gives me a hang... serialPort.readBytes() hangs, as apparently nothing was received. Only remedy was to physically unplug the usb cable and then plug it in - it works, but as before, only for the first time.
Minicom testing was always successful. Testing of the same code on a pc running Debian was without this problem.
What went wrong?

Return to “Java”