zykes

Untitled

May 21st, 2017
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.17 KB | None | 0 0
  1.  
  2. // For printf used below
  3. #include <stdio.h>
  4. // PJON library
  5. #include <inttypes.h>
  6. #include <stdlib.h>
  7. #include <string.h>
  8. // RPI serial interface
  9. #include <wiringPi.h>
  10. #include <wiringSerial.h>
  11.  
  12. #ifndef RPI
  13. #define RPI true
  14. #endif
  15.  
  16. #define PJON_INCLUDE_TS true // Include only ThroughSerial
  17. #define TS_RESPONSE_TIMEOUT 0
  18.  
  19. #include "PJON/PJON.h"
  20.  
  21. int main() {
  22. printf("PJON instantiation... \n");
  23. PJON<ThroughSerial> bus(45);
  24.  
  25. bus.strategy.set_enable_RS485_pin(0);
  26. bus.set_synchronous_acknowledge(false);
  27. bus.set_asynchronous_acknowledge(true);
  28.  
  29. printf("Opening serial... \n");
  30. int s = serialOpen("/dev/ttyAMA0", 9600);
  31. if(s < 0) printf("Serial open fail!");
  32. if(wiringPiSetup() == -1) printf("WiringPi setup fail");
  33. printf("Setting serial... \n");
  34. bus.strategy.set_serial(s);
  35.  
  36. printf("Opening bus... \n");
  37. bus.begin();
  38. printf("Attempting to send a packet... \n");
  39. bus.send(44, "B", 1);
  40. printf("Attempting to roll bus... \n");
  41. bus.update();
  42. printf("Attempting to receive from bus... \n");
  43. bus.receive();
  44. printf("Success! \n");
  45.  
  46. while(true) {
  47. bus.update();
  48. bus.receive();
  49. }
  50.  
  51. return 0;
  52. };
Advertisement
Add Comment
Please, Sign In to add comment