prog.c 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. //Include Header-----------------------------------------------------
  2. #include"prog.h"
  3. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  4. //Main-Program
  5. int main(int argc, const char * argv[]){
  6. delay(1000); //delete me!!
  7. //initializing USART at USB_PORT-------------------------------------
  8. int USB = open("/dev/ttyACM3", O_RDWR|O_NOCTTY);
  9. if(isatty(USB)==0){
  10. printf("ERROR: No File Descriptor! \n");
  11. return 0;
  12. }
  13. struct termios * termios_ptr = (struct termios *)
  14. malloc(sizeof(struct termios));
  15. if(termios_ptr==NULL){
  16. printf("ERROR: Termios not available! \n");
  17. return 0;
  18. }
  19. (*termios_ptr).c_iflag = IGNPAR; //ignore Parity-Err
  20. (*termios_ptr).c_oflag = 0;
  21. (*termios_ptr).c_cflag = CS8|CREAD; //set Size, enable RX
  22. (*termios_ptr).c_lflag = 0;
  23. // (*termios_ptr).c_cc[VMIN] = 2; //set min Characters
  24. // (*termios_ptr).c_cc[VTIME] = 0.1; //Timeout after 10ms
  25. cfsetspeed(termios_ptr, B19200); //set Baudrate 19.2k
  26. tcsetattr(USB, TCSANOW ,termios_ptr);
  27. //Get Command--------------------------------------------------------
  28. cmd_t * cmd_ptr = cmd_build(page_read, 0xFF);
  29. char * frame_ptr = &((*cmd_ptr).mode);
  30. for(int i=0; i<3; i++, frame_ptr++){
  31. write(USB, frame_ptr, sizeof(char));
  32. tcflush(USB, TCIFLUSH);
  33. }
  34. // frame_ptr = &frame[0];
  35. // read(USB, frame_ptr, sizeof(frame));
  36. // tcflush(USB, TCOFLUSH);
  37. close(USB);
  38. return EXIT_SUCCESS;
  39. }
  40. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  41. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++