2016-07-03 21 views
1

私はtomcat7を使用してラスベリ3にWebサービスを展開しようとしています。webserviceはうまく起動され、おそらくtomcat7でもsudoコマンドを実行できます。このコードは、Bluetoothから値を取得することであり、それはそれは私が解決することができたrfcommがraspberry piのtomcat7と連携していません3

import java.io.*; 
import gnu.io.*; 

//Connect the Raspberry with serial port 
public class AGetBlueIn { 
    private static InputStream inStream; 
    public String getRate(){ 
     String reading=""; 
     //Connecting to BluetoothDevice 
     try { 
      Runtime.getRuntime().exec("sudo rfcomm listen rfcomm0 1"); 
      System.out.println("waiting for connection"); 
      try { 
       Thread.sleep(10000); 
      } catch (InterruptedException e) { 
       e.printStackTrace(); 
      } 
     } catch (IOException e) { 
      e.printStackTrace(); 
      return "Error in Starting the Connection Command"; 

     } 
     try { 
      CommPortIdentifier portId = CommPortIdentifier.getPortIdentifier("/dev/rfcomm0"); 
      SerialPort serialPort = (SerialPort) portId.open("BlueHeart", 5000); 
      // Change baud rate if not 115200 
      /*serialPort.setSerialPortParams(115200, SerialPort.DATABITS_8, 
       SerialPort.STOPBITS_1, SerialPort.PARITY_NONE); 
      serialPort.setFlowControlMode(SerialPort.FLOWCONTROL_NONE);*/ 
      inStream = serialPort.getInputStream(); 
      System.out.println("Enter a value"); 

      for(int i=0;i<10;i++) { 
       Thread.sleep(1000); 
       if(inStream.available() > 0) { 
        int b = inStream.read(); 
        System.out.print((char)b); 
        reading=reading+(char)b; 

       } 
      } 

     } catch (Exception ex) { 
     StringWriter errors=new StringWriter(); 
       ex.printStackTrace(new PrintWriter(errors)); 
       return errors.toString(); 
     } 

     return reading; 
     //serialPort.close(); 
    } 

} 

答えて

1

CommPortIdentifier.getPortIdentifier(「は/ dev/rfcomm0」)の行にNoSuchPortExceptionを与え、例外tomcat7とが、Javaで正常に動作しますターミナルでこのコマンドを実行して、tomcat7をdialoutグループに追加して、rfcomm0にアクセスできるようにしてください。 Sudo usermod -a -G dialout tomcat7

関連する問題