You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.

pl2303_gprs_terminal.ino 2.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. /* Arduino terminal for PL2303 USB to serial converter and DealeXtreme GPRS modem. */
  2. /* USB support */
  3. #include <usbhub.h>
  4. /* CDC support */
  5. #include <cdcacm.h>
  6. #include <cdcprolific.h>
  7. // Satisfy the IDE, which needs to see the include statment in the ino too.
  8. #ifdef dobogusinclude
  9. #include <spi4teensy3.h>
  10. #include <SPI.h>
  11. #endif
  12. class PLAsyncOper : public CDCAsyncOper
  13. {
  14. public:
  15. uint8_t OnInit(ACM *pacm);
  16. };
  17. uint8_t PLAsyncOper::OnInit(ACM *pacm)
  18. {
  19. uint8_t rcode;
  20. // Set DTR = 1
  21. rcode = pacm->SetControlLineState(1);
  22. if (rcode)
  23. {
  24. ErrorMessage<uint8_t>(PSTR("SetControlLineState"), rcode);
  25. return rcode;
  26. }
  27. LINE_CODING lc;
  28. //lc.dwDTERate = 9600;
  29. lc.dwDTERate = 115200;
  30. lc.bCharFormat = 0;
  31. lc.bParityType = 0;
  32. lc.bDataBits = 8;
  33. rcode = pacm->SetLineCoding(&lc);
  34. if (rcode)
  35. ErrorMessage<uint8_t>(PSTR("SetLineCoding"), rcode);
  36. return rcode;
  37. }
  38. USB Usb;
  39. //USBHub Hub(&Usb);
  40. PLAsyncOper AsyncOper;
  41. PL2303 Pl(&Usb, &AsyncOper);
  42. void setup()
  43. {
  44. Serial.begin( 115200 );
  45. #if !defined(__MIPSEL__)
  46. while (!Serial); // Wait for serial port to connect - used on Leonardo, Teensy and other boards with built-in USB CDC serial connection
  47. #endif
  48. Serial.println("Start");
  49. if (Usb.Init() == -1)
  50. Serial.println("OSCOKIRQ failed to assert");
  51. delay( 200 );
  52. }
  53. void loop()
  54. {
  55. Usb.Task();
  56. if( Usb.getUsbTaskState() == USB_STATE_RUNNING )
  57. {
  58. uint8_t rcode;
  59. /* reading the keyboard */
  60. if(Serial.available()) {
  61. uint8_t data= Serial.read();
  62. /* sending to the phone */
  63. rcode = Pl.SndData(1, &data);
  64. if (rcode)
  65. ErrorMessage<uint8_t>(PSTR("SndData"), rcode);
  66. }//if(Serial.available()...
  67. /* reading the converter */
  68. /* buffer size must be greater or equal to max.packet size */
  69. /* it it set to 64 (largest possible max.packet size) here, can be tuned down
  70. for particular endpoint */
  71. uint8_t buf[64];
  72. uint16_t rcvd = 64;
  73. rcode = Pl.RcvData(&rcvd, buf);
  74. if (rcode && rcode != hrNAK)
  75. ErrorMessage<uint8_t>(PSTR("Ret"), rcode);
  76. if( rcvd ) { //more than zero bytes received
  77. for(uint16_t i=0; i < rcvd; i++ ) {
  78. Serial.print((char)buf[i]); //printing on the screen
  79. }
  80. }//if( rcvd ...
  81. }//if( Usb.getUsbTaskState() == USB_STATE_RUNNING..
  82. }