fork download
  1. package com.company;
  2.  
  3. import jssc.SerialPort;
  4. import jssc.SerialPortEvent;
  5. import jssc.SerialPortEventListener;
  6. import jssc.SerialPortException;
  7.  
  8. import java.util.Arrays;
  9.  
  10. public class Main
  11. {
  12. public static void main(String[] args)
  13. {
  14. final SerialPort serialPort = new SerialPort("/dev/ttyACM1");
  15.  
  16. try
  17. {
  18. serialPort.openPort();
  19.  
  20. serialPort.setParams(SerialPort.BAUDRATE_9600, SerialPort.DATABITS_8, SerialPort.STOPBITS_1, SerialPort.PARITY_NONE);
  21.  
  22. int mask = SerialPort.MASK_RXCHAR + SerialPort.MASK_CTS + SerialPort.MASK_DSR;
  23. serialPort.setEventsMask(mask);
  24.  
  25. serialPort.addEventListener
  26. (
  27. new SerialPortEventListener()
  28. {
  29. @Override
  30. public void serialEvent(SerialPortEvent serialPortEvent)
  31. {
  32. if(serialPortEvent.isRXCHAR())
  33. {
  34. if(serialPortEvent.getEventValue() == 10)
  35. {//Check bytes count in the input buffer
  36. //Read data, if 10 bytes available
  37. try
  38. {
  39. byte buffer[] = serialPort.readBytes(10);
  40. System.out.println("DATA: " + Arrays.toString(buffer));
  41. }
  42. catch(SerialPortException ex)
  43. {
  44. ex.printStackTrace();
  45. }
  46. }
  47. }
  48. else if(serialPortEvent.isCTS())
  49. {//If CTS line has changed state
  50. if(serialPortEvent.getEventValue() == 1)
  51. {//If line is ON
  52. System.out.println("CTS - ON");
  53. }
  54. else
  55. {
  56. System.out.println("CTS - OFF");
  57. }
  58. }
  59. else if(serialPortEvent.isDSR())
  60. {///If DSR line has changed state
  61. if(serialPortEvent.getEventValue() == 1)
  62. {//If line is ON
  63. System.out.println("DSR - ON");
  64. }
  65. else
  66. {
  67. System.out.println("DSR - OFF");
  68. }
  69. }
  70. else
  71. {
  72. System.out.println("to w ogole mozliwe?");
  73. }
  74. }
  75. }
  76. );
  77. }
  78. catch(SerialPortException ex)
  79. {
  80. ex.printStackTrace();
  81. }
  82. finally
  83. {
  84. try
  85. {
  86. serialPort.closePort();
  87. }
  88. catch(SerialPortException e)
  89. {
  90. e.printStackTrace();
  91. }
  92. }
  93. }
  94. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
Main.java:3: error: package jssc does not exist
import jssc.SerialPort;
           ^
Main.java:4: error: package jssc does not exist
import jssc.SerialPortEvent;
           ^
Main.java:5: error: package jssc does not exist
import jssc.SerialPortEventListener;
           ^
Main.java:6: error: package jssc does not exist
import jssc.SerialPortException;
           ^
Main.java:14: error: cannot find symbol
        final SerialPort serialPort = new SerialPort("/dev/ttyACM1");
              ^
  symbol:   class SerialPort
  location: class Main
Main.java:14: error: cannot find symbol
        final SerialPort serialPort = new SerialPort("/dev/ttyACM1");
                                          ^
  symbol:   class SerialPort
  location: class Main
Main.java:20: error: cannot find symbol
            serialPort.setParams(SerialPort.BAUDRATE_9600, SerialPort.DATABITS_8, SerialPort.STOPBITS_1, SerialPort.PARITY_NONE);
                                 ^
  symbol:   variable SerialPort
  location: class Main
Main.java:20: error: cannot find symbol
            serialPort.setParams(SerialPort.BAUDRATE_9600, SerialPort.DATABITS_8, SerialPort.STOPBITS_1, SerialPort.PARITY_NONE);
                                                           ^
  symbol:   variable SerialPort
  location: class Main
Main.java:20: error: cannot find symbol
            serialPort.setParams(SerialPort.BAUDRATE_9600, SerialPort.DATABITS_8, SerialPort.STOPBITS_1, SerialPort.PARITY_NONE);
                                                                                  ^
  symbol:   variable SerialPort
  location: class Main
Main.java:20: error: cannot find symbol
            serialPort.setParams(SerialPort.BAUDRATE_9600, SerialPort.DATABITS_8, SerialPort.STOPBITS_1, SerialPort.PARITY_NONE);
                                                                                                         ^
  symbol:   variable SerialPort
  location: class Main
Main.java:22: error: cannot find symbol
            int mask = SerialPort.MASK_RXCHAR + SerialPort.MASK_CTS + SerialPort.MASK_DSR;
                       ^
  symbol:   variable SerialPort
  location: class Main
Main.java:22: error: cannot find symbol
            int mask = SerialPort.MASK_RXCHAR + SerialPort.MASK_CTS + SerialPort.MASK_DSR;
                                                ^
  symbol:   variable SerialPort
  location: class Main
Main.java:22: error: cannot find symbol
            int mask = SerialPort.MASK_RXCHAR + SerialPort.MASK_CTS + SerialPort.MASK_DSR;
                                                                      ^
  symbol:   variable SerialPort
  location: class Main
Main.java:27: error: cannot find symbol
                new SerialPortEventListener()
                    ^
  symbol:   class SerialPortEventListener
  location: class Main
Main.java:78: error: cannot find symbol
        catch(SerialPortException ex)
              ^
  symbol:   class SerialPortException
  location: class Main
Main.java:88: error: cannot find symbol
            catch(SerialPortException e)
                  ^
  symbol:   class SerialPortException
  location: class Main
16 errors
stdout
Standard output is empty