1 /* Arduino terminal for PL2303 USB to serial converter and XBee radio. */
2 /* Inserts linefeed after carriage return in data sent to and received from Xbee */
7 #include <cdcprolific.h>
9 // Satisfy the IDE, which needs to see the include statment in the ino too.
11 #include <spi4teensy3.h>
15 class PLAsyncOper : public CDCAsyncOper
18 uint8_t OnInit(ACM *pacm);
21 uint8_t PLAsyncOper::OnInit(ACM *pacm)
26 rcode = pacm->SetControlLineState(1);
30 ErrorMessage<uint8_t>(PSTR("SetControlLineState"), rcode);
35 lc.dwDTERate = 115200;
40 rcode = pacm->SetLineCoding(&lc);
43 ErrorMessage<uint8_t>(PSTR("SetLineCoding"), rcode);
49 PLAsyncOper AsyncOper;
50 PL2303 Pl(&Usb, &AsyncOper);
54 Serial.begin( 115200 );
55 #if !defined(__MIPSEL__)
56 while (!Serial); // Wait for serial port to connect - used on Leonardo, Teensy and other boards with built-in USB CDC serial connection
58 Serial.println("Start");
61 Serial.println("OSCOKIRQ failed to assert");
70 if( Usb.getUsbTaskState() == USB_STATE_RUNNING )
74 /* reading the keyboard */
75 if(Serial.available()) {
76 uint8_t data= Serial.read();
79 Serial.print("\r\n"); //insert linefeed
82 Serial.print( data ); //echo back to the screen
85 /* sending to the phone */
86 rcode = Pl.SndData(1, &data);
88 ErrorMessage<uint8_t>(PSTR("SndData"), rcode);
89 }//if(Serial.available()...
93 /* reading the converter */
94 /* buffer size must be greater or equal to max.packet size */
95 /* it it set to 64 (largest possible max.packet size) here, can be tuned down
96 for particular endpoint */
99 rcode = Pl.RcvData(&rcvd, buf);
100 if (rcode && rcode != hrNAK)
101 ErrorMessage<uint8_t>(PSTR("Ret"), rcode);
103 if( rcvd ) { //more than zero bytes received
104 for(uint16_t i=0; i < rcvd; i++ ) {
105 if( buf[i] =='\r' ) {
106 Serial.print("\r\n"); //insert linefeed
109 Serial.print((char)buf[i]); //printing on the screen
114 }//if( Usb.getUsbTaskState() == USB_STATE_RUNNING..