Protocol for transferring data to and from the SAP... The SAP waits for input on the USB port, and replies as necessary. Think of it a bit like an SMTP server (or a command line). All transactions are terminated by /n PC side should be fairly easy - just use ordinary file interactions... Theoretically, we could just use minicom to communicate... commands should be limited to 256 bytes; wait for an OK back before sending more data... any data sent after a \n and before the OK will be ignored. General rules - Any command setting an attribute will receive the value set back, followed by an OK on the next line If the set command is sent without a value, the current value is returned anyway. SAP side - use an intermediary buffer... On each run if there is any data in the usb buffer copy into my_buf. if there is a CR in the buffer call service routine send OK if happy, KO if not reset buffer counter to 0. unsigned char readHexByte(char *text, char *result) { unsigned char tempa,tempb; tempa = text[0] - 0x30; if (tempa > 9) temp -= 7; // A..F if (tempa > 15) temp -= 0x20; // a..f if (tempa > 15) return -1; // invalid conversion tempb = text[1] - 0x30; if (tempb > 9) temp -= 7; if (tempb > 15) temp -= 0x20; if (tempb > 15) return -1; // invalid conversion result* = (tempa << 4) + tempb; return 0; } unsigned char readHexWord(char *text, char *result) { unsignec char tempa, tempb; if (readHexByte(text,&tempa) return -1; if (readHexByte(text+2,&tempb) return -1; result* = tempa * 256 + tempb; return 0; } Commands H (Hiya) No response - just send back an OK. "OK" L XX (Laser brightness) Set laser brightness to 0xXX. if 0xXX == 0, turn laser off. "%02hhX\n", laser brightness D XX (Display brightness) Set Display brightness to 0xXX (max FFh). "%02hhX\n" B [01] (Battery) Turns on/off whether the battery reading is shown on startup. "%02hhd\n" T [01] (Temperature) Turns on/off whether the temp reading is shown on startup "%2hhd\n" G[sensor] (get raw sensor readings) sensor = G|M|T|V|I ( gravitic | magnetic | temp | volts | current) get most recent raw sensor readings, as signed 16-bit ints, in hex format "%04X %04X %04X\n" // for GM "%2hd\n" // for TVI return XXXX YYYY ZZZZ\n S[sensor][index] XXXX(set calibration matrix) sensor = G|M ( gravitic | magnetic ) index = [0..9|A|B] Set grav or cal matrix item to (XXXX) / 0x4000 (gives us a max of +/-2.0) "%04X\n" return OK\n R (Readings) get current calculated readings "%03d +02d\n" // compass, clino OK C commit readings to long_term memory "\nOK" Advanced commands (for retrieving stored legs) /* note lower case */ l [01] Turn leg recording on or off "%hhX\n" return OK g [index] index = XXXX (hex address of leg to retrieve) if no index is sent, return last leg sent... "%03d +02d\n" // compass, clino OK s [index] set index of next leg to be stored. (ie s 0000 should reset the device (but data will persist until overwritten) will wrap at some point, not sure how big, just yet. Prolly 512d "%04X\n" return OK Sample transcript.... > is sent from PC -> SAP < is sent from SAP -> PC. One space added after > or < for clarity ; Comments ; verify connected > H < OK ; bad command > V < KO ; check current laser brightness > L < 8F < OK ; set laser to max brightness > L FF < FF < OK ; get current raw mag readings > GM < 20A6 E5F2 0034 < OK ; get current raw grav readings > GG < 4534 0003 FFF3 < OK ; bad message > GQ < KO ; set Gc[4] to 0x400/0x4000 (ie +1/16) > SG4 0400 < 0400 < OK ; get Mc[10] - its 0x4200 (ie 1.125) > SMA < 4200 < OK ; bad string sent > SG2 phil < KO ; check current calculated bearings ; facing 35 degs upwards, headed due east > G < 090 +35 < OK