#include "/pocketc/pcheader.h" char zz,cc; int status; main(){ int wind_event, ret; clear(); settimer(1,200); file://200ms timer "pings" the event queue to prevent lockup. putsl("Serial Chat Demonstration"); // documentation says seropen returns 1, but in fact it returns the serial connection handle, needed // for many subsequent serial i/o calls. ret=seropen(19200,"8N1N",1000); // the timeout (last parameter) does matter, despite the documentation. putsl("Seropen returned: "+ret); putsl("Successful serial port initialization returns a non zero integer."); commsetmask(ret,EV_RXCHAR); // generate comm interrupt on character inputs. showconsole(); // Say hello to the remote terminal. (does this work?) writechars(ret,"Serial chat initiated by WinCE"); writebyte(ret,0x0d); writebyte(ret,0x0a); writechars(ret,"Hello, PC!"); // Here is the main loop: we'll await for user to type a character, or for one to arrive from // the remote terminal via the serial port. If neither, the timer will generate an event to // keep the loop going. while(1){ commwait(ret,0); // If there's data, an event, PM_COMMEVENT will be generated wind_event=event(1); // either got a char (from the keyboard) or PM_DSR from the serial port. sleep(0); // Otherwise program "close window" command won't work. switch(wind_event){ // The kind of windows event that occurred selects our response. case PM_CHAR: // This case results when the local user types a char. { zz=key(); writebyte(ret,(int)zz); // send the char to the serial port. if(zz==0x0d) writebyte(ret, 0x0a); // add a linefeed to the so it will look nice on the PC break; } case PM_COMMEVENT: // This was created by a char arriving on the serial port. { do{ cc=readbyte(ret); if(cc==0x0d) // it's a , so print a new line. putsl(" "); else // just print the char to the console. puts(cc); }while(cc!=0) // until we get a null character from readbyte. break; } case PM_NONE: break; case PM_TIMER: break; }//switch }//while fileclose(ret); }// end main