Advertisement
Guest User

Untitled

a guest
Nov 18th, 2017
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.09 KB | None | 0 0
  1. import java.io.IOException;
  2.  
  3. import com.pi4j.io.gpio.exception.UnsupportedBoardType;
  4. import com.pi4j.io.serial.*;
  5.  
  6. public class SerialComms {
  7. public static void main(String[] args) {
  8. // make sure serial console is disabled on the pi
  9. final Serial serial = SerialFactory.createInstance();
  10. // create serial config object
  11. SerialConfig config = new SerialConfig();
  12.  
  13. // set default serial settings (device, baud rate, flow control, etc)
  14. //
  15. // use the DEFAULT com port on the Raspberry Pi
  16. try {
  17. config.device(SerialPort.getDefaultPort()).baud(Baud._38400).dataBits(DataBits._8).parity(Parity.NONE)
  18. .stopBits(StopBits._1).flowControl(FlowControl.NONE);
  19. serial.open(config);
  20. while (true) {
  21. serial.write("wew lad");
  22. System.out.println("wew");
  23. }
  24. } catch (UnsupportedBoardType e) {
  25. // TODO Auto-generated catch block
  26. e.printStackTrace();
  27. } catch (IOException e) {
  28. // TODO Auto-generated catch block
  29. e.printStackTrace();
  30. } catch (InterruptedException e) {
  31. // TODO Auto-generated catch block
  32. e.printStackTrace();
  33. }
  34.  
  35. }
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement