├── README.txt ├── RS232enum.ino ├── _scans.ino ├── _softserial.ino ├── _utils.ino └── clienttest.py /README.txt: -------------------------------------------------------------------------------- 1 | RS232enum 2 | When you are presented with pins that you suspect provide Serial but 3 | you do not have access to the documentation. Connect your Arduino 4 | to all of the pins (limited by the number of Ditial pins you have on 5 | your board) and this sketch will try every possible pin combination 6 | and baud rate to determine RX/TX. It will also try to send wakeup 7 | characters to stimulate the line, such as a carriage return or other 8 | txpatterns that you add. This code sends data using a custom 9 | SoftwareSerial library. 10 | For the Parallel scans interpreting the return data would not be 11 | reliable. Instead the software just gives a good indication of 12 | active lines (parallel scan) and specifically serial lines that 13 | respond to wakeup patterns / stimulation (active parallel and active 14 | per pin scans). Where reports indicate likely serial the user should 15 | then plug up a serial cable and confirm with terminal software on 16 | their workstation using the indicated baud rate and wakeup patterns. 17 | 18 | Further documentation: http://deadhacker.com/tools/ 19 | 20 | SETUP: 21 | 1. set pins[] to the arduino pins being used for the scan 22 | 2. set pinnames[] to the names for each pin (that better relate to 23 | your target) 24 | 3. set baudrates[] to a list of baudrates we should use when 25 | sending txpattern wakeup signals on the TX line 26 | 4. (optional) set txpatters[] to desired stimulation patterns 27 | 5. (optional) if your board does not have enough memory uncomment 28 | the "#define SHRINK" line. Note: "information" function will be 29 | disabled as a result 30 | 6. (optional) set Arduino CPU to 8MHZ if using 3.3v logic 31 | 32 | USAGE: 33 | - load sketch and attach to arduino at 115200 baud 34 | - type '?' or 'help' for command information 35 | 36 | TESTING: 37 | - "clienttest.py" included with the code can be run for a virtual test. 38 | execute the script and connect your arduino to the RX/TX lines of your 39 | workstation. clienttest.py only prints out on the serial line when it 40 | receives a carriage return (at its baudrate) 41 | 42 | AUTHORS & CODE BRANCHES: 43 | cyphunk http://github.com/cyphunk/RS232enum/ 44 | 45 | DEVELOPER NOTES: 46 | - pfmt() = local printf() 47 | - ppgm() = print() which uses the FLASH memory of the board. Some 48 | boards have limited SRAM so we use the FLASH ram where possible. 49 | - Supports up to 64 pins atm (because report buffer stores pin state 50 | in 2 byte bit array) 51 | - the arduino IDE tries to silently build and include function prototypes 52 | from companion sketch files, however it doesn't work when you return 53 | or have as arguments non standard arduino types. Hence, sometimes we 54 | we declare them, and sometimes not 55 | - As of Arduino 1 the softserial delay required per baudrate definitions. 56 | Don't ask why. This means that only common buadrates are supported. 57 | Perhaps it was always this way. Also, with the new changes I did not 58 | test if older Arduino versions worked so just use Arduino >= v1 59 | This code is public domain, abuse as you wish and at your own risk 60 | -------------------------------------------------------------------------------- /RS232enum.ino: -------------------------------------------------------------------------------- 1 | /* 2 | RS232enum (v0.3.0 20110924) 3 | When you are presented with pins that you suspect provide Serial but 4 | you do not have access to the documentation. Connect your Arduino 5 | to all of the pins (limited by the number of Ditial pins you have on 6 | your board) and this sketch will try every possible pin combination 7 | and baud rate to determine RX/TX. It will also try to send wakeup 8 | characters to stimulate the line, such as a carriage return or other 9 | txpatterns that you add. This code sends data using a custom 10 | SoftwareSerial library. 11 | For the Parallel scans interpreting the return data would not be 12 | reliable. Instead the software just gives a good indication of 13 | active lines (parallel scan) and specifically serial lines that 14 | respond to wakeup patterns / stimulation (active parallel and active 15 | per pin scans). Where reports indicate likely serial the user should 16 | then plug up a serial cable and confirm with terminal software on 17 | their workstation using the indicated baud rate and wakeup patterns. 18 | 19 | Further documentation: http://deadhacker.com/tools/ 20 | 21 | SETUP: 22 | 1. set pins[] to the arduino pins being used for the scan 23 | 2. set pinnames[] to the names for each pin (that better relate to 24 | your target) 25 | 3. set baudrates[] to a list of baudrates we should use when 26 | sending txpattern wakeup signals on the TX line 27 | 4. (optional) set txpatters[] to desired stimulation patterns 28 | 5. (optional) if your board does not have enough memory uncomment 29 | the "#define SHRINK" line. Note: "information" function will be 30 | disabled as a result 31 | 6. (optional) set Arduino CPU to 8MHZ if using 3.3v logic 32 | 33 | USAGE: 34 | - load sketch and attach to arduino at 115200 baud 35 | - type '?' or 'help' for command information 36 | 37 | TESTING: 38 | - "clienttest.py" included with the code can be run for a virtual test. 39 | execute the script and connect your arduino to the RX/TX lines of your 40 | workstation. clienttest.py only prints out on the serial line when it 41 | receives a carriage return (at its baudrate) 42 | 43 | AUTHORS & CODE BRANCHES: 44 | cyphunk http://github.com/cyphunk/RS232enum/ 45 | 46 | DEVELOPER NOTES: 47 | - pfmt() = local printf() 48 | - ppgm() = print() which uses the FLASH memory of the board. Some 49 | boards have limited SRAM so we use the FLASH ram where possible. 50 | - Supports up to 64 pins atm (because report buffer stores pin state 51 | in 2 byte bit array) 52 | - the arduino IDE tries to silently build and include function prototypes 53 | from companion sketch files, however it doesn't work when you return 54 | or have as arguments non standard arduino types. Hence, sometimes we 55 | we declare them, and sometimes not 56 | - As of Arduino 1 the softserial delay required per baudrate definitions. 57 | Don't ask why. This means that only common buadrates are supported. 58 | Perhaps it was always this way. Also, with the new changes I did not 59 | test if older Arduino versions worked so just use Arduino >= v1 60 | 61 | This code is public domain, abuse as you wish and at your own risk 62 | */ 63 | 64 | 65 | 66 | 67 | /* 68 | 69 | BEGIN USER DEFINITIONS 70 | 71 | */ 72 | 73 | // DEFINE PINS 74 | // Arduino must use microcontroller pin numbers for pins[]: 75 | byte pins[] = { 12, 13, 14 }; 76 | char * pinnames[] = { "aaa", "b", "ccccc" }; 77 | // Teensy can use board based names: 78 | //byte pins[] = { PIN_B7, PIN_D0, PIN_D1, PIN_D2, PIN_D3, PIN_D4, PIN_D5, PIN_D6, 79 | // PIN_D7, PIN_E0, PIN_E1, PIN_C0}; 80 | //char * pinnames[] = { "aa", "bbb", "cc", "d", "eeee", "ff", "gg", "hh", 81 | // "ii", "jjjjjj", "kk", "ll"}; 82 | // Client test: 83 | //byte pins[] = { PIN_F2, PIN_F1 }; 84 | //char * pinnames[] = { "rx", "tx" }; 85 | 86 | 87 | // DEFINE BAUDRATES 88 | // supporte baudrates: 89 | //uint32_t baudrates[] = { 300, 1200, 2400, 4800, 9600, 14400, 19200, 28800, 31250, 38400, 57600, 115200 }; 90 | //uint32_t baudrates[] = { 9600 }; // dont search, assume 9600 91 | uint32_t baudrates[] = { 9600, 115200}; 92 | 93 | // DEFINE TX WAKEUP PATTERNS (LSB first): 94 | //uint16_t txpatterns[] = { 0x0000, 0xFFFF, 0x0a00, ~0x0a00 }; // 10=0xA=CR 95 | //byte txpatterns[] = { B11111111,B00000000,B01010101,B10101010 }; // 10=0xA=CR, 0x41="A" 96 | //byte txpatterns[] = { 0x0a, 0x0d, 0x41 }; 97 | byte txpatterns[] = { 0x0a }; 98 | 99 | //#define SHRINK // uncomment to reduce size of program. information() 100 | // function will be disabled 101 | #define SHOWTXSTATUS // creates longer reports for "active" scans but usefull 102 | // just to see where the scan currently is 103 | 104 | 105 | 106 | /* 107 | END OF USER DEFINITIONS 108 | */ 109 | 110 | 111 | uint32_t mstous(uint32_t); // resolves https://github.com/cyphunk/RS232enum/issues/1 112 | 113 | //needed to put help strings into flash 114 | #include 115 | 116 | //#define DEBUGLOOPS // count and show loops in test (slows down and reduces reliability) 117 | //#define DEBUGSTATEBUF // print bit level info of state buf (slows down and reduces reliability) 118 | 119 | boolean printnames = true; 120 | byte pinslen = sizeof(pins); 121 | byte baudrateslen = sizeof(baudrates)/sizeof(uint32_t); 122 | byte txpatternslen = sizeof(txpatterns); 123 | 124 | // default time required to poll for rx response (in us): 125 | uint32_t usperrx = mstous(2000); 126 | 127 | // Report buffer values 128 | uint16_t reserveram = 500; // number of bytes to keep free - safty measure 129 | // reportbuf will be malloc'ed in remaining free space 130 | uint16_t rambeforealloc; 131 | byte pinstatelen = ((pinslen-1) / 8) + 1; // bitfield len. calc backwards, but im sleep deprived so im leavin it 132 | byte *pinstatebuf; // bitfield. alloc later, bit array 133 | byte *reportbuf; // size based on free ram 134 | uint16_t reportbuflen; 135 | uint16_t reportbuf_i = 0; 136 | 137 | 138 | // FROM UTILS 139 | void pfmt(char *fmt, ... ); 140 | void ppgm(const char *str); 141 | boolean noprint = 0; 142 | #ifndef SHRINK 143 | uint32_t timefunction(void (*function)(uint32_t), uint32_t arg); 144 | uint32_t timefunction(void (*function)(byte), byte arg); 145 | uint32_t timefunction(int (*function)()); 146 | #endif 147 | 148 | 149 | 150 | void usage() 151 | { 152 | ppgm(PSTR("USAGE\r\n" 153 | "-----\r\n" 154 | "TESTS:\r\n" 155 | "All\r\n\truns all of the following tests in sequence\r\n" 156 | "Passive Parallel\r\n\tpoll all RX pins in parallel\r\n\tno active TX\r\n\tnotes: issues at high baud\r\n" 157 | "Active Parallel\r\n\tpoll all RX pins in parallel\r\n\tone TX pins used to print patterns\r\n\tnotes: issues at high baud\r\n" 158 | "Active Per Pin\r\n\tpoll RX pins incrementally (less error prone)\r\n\tone TX pins used to print patterns\r\n\r\n" 159 | //"Active Per Pin With Times\r\n\tpoll RX pins incrementally (less error prone)\r\n\tone TX pins used to print patterns\r\n\tstate change timing recorded (requires more memory)\r\n" 160 | "COMMANDS:\r\n\t" 161 | "(long form [short form])\r\n\t" 162 | "passive parallel [pp]\r\n\t" 163 | "active parallel [ap]\r\n\t" 164 | "active per pin [apin]\r\n\t" 165 | "all [all]\r\n\r\n\t" 166 | "information [info] shows the time required to complete each test and other info\r\n\t" 167 | "pin state [state] just shows current value on pins\r\n\t" 168 | "rx wait [wait] show or set number of milliseconds test wait when polling rx lines\r\n\t" 169 | "help [?] show this message\r\n\r\n")); 170 | } 171 | 172 | /* initialize pins to read or write depending on test */ 173 | void setup_pins (byte outpin_i=0) 174 | { 175 | for (int i=0; i "); 266 | } 267 | 268 | char command[20]; 269 | void loop() 270 | { 271 | // EMULATE DEBUG 272 | /* 273 | delay(10000); // wait 10 seconds before starting 274 | for (byte i=0; i < pinslen; i++) // toggles pin state to 01010101 for debug testing 275 | bitWrite(pinstatebuf[i/8], i%8, i&1); 276 | passive_parallel_scan(4); 277 | for (byte i=0; i < pinslen; i++) 278 | bitWrite(pinstatebuf[i/8], i%8, i&1); 279 | active_parallel_scan(4); 280 | for (byte i=0; i < pinslen; i++) 281 | bitWrite(pinstatebuf[i/8], i%8, i&1); 282 | active_per_pin_scan(4); 283 | while (1) {} // endless loop 284 | */ 285 | 286 | 287 | // WAIT FOR COMMAND 288 | if (Serial.available()) 289 | { 290 | 291 | // READ COMMAND 292 | delay(5); // hoping read buffer is idle after 5 ms 293 | int i = 0; 294 | while (Serial.available() && i < 19) { 295 | command[i++] = Serial.read(); 296 | } 297 | Serial.flush(); 298 | command[i] = 0; // terminate string 299 | Serial.println(command); // echo back 300 | 301 | // EXECUTE COMMAND 302 | if (strcmp(command, "information") == 0 || strcmp(command, "info") == 0) 303 | information(); 304 | else if(strcmp(command, "pin state") == 0 || strcmp(command, "state") == 0) 305 | pins_state(); 306 | else if(strcmp(command, "rx wait") == 0 || strcmp(command, "wait") == 0) 307 | set_rx_wait(); 308 | else if(strcmp(command, "passive parallel") == 0 || strcmp(command, "pp") == 0) 309 | passive_parallel_scan(usperrx); 310 | else if(strcmp(command, "active parallel") == 0 || strcmp(command, "ap") == 0) 311 | active_parallel_scan(usperrx); 312 | else if(strcmp(command, "active per pin") == 0 || strcmp(command, "apin") == 0) 313 | active_per_pin_scan(usperrx); 314 | else if(strcmp(command, "run all") == 0 || strcmp(command, "all") == 0) 315 | { information(); passive_parallel_scan(usperrx); active_parallel_scan(usperrx); active_per_pin_scan(usperrx); } 316 | else 317 | usage(); 318 | Serial.print("> "); 319 | } 320 | } 321 | -------------------------------------------------------------------------------- /_scans.ino: -------------------------------------------------------------------------------- 1 | 2 | // fyi, numer of runs to take for rx pins check 3 | // nruns = passive parallel scan loops 4 | // active parallel scan = sizeof(txpatterns) * sizeof(rxpins) * nruns 5 | // active per pin scan = sizeof(txpatterns) * sizeof(txpins) * sizeof(rxpins-1 for current tx pin) 6 | 7 | 8 | 9 | /* passive_parallel_scan 10 | * Assume there is an active RX line presenting data. 11 | * this is usefull only for tool verfication. An active RX 12 | * would negate the need to use a serial detection tool. You 13 | * could just use an oscilloscope. 14 | */ 15 | void passive_parallel_scan (uint32_t usperrx) 16 | { 17 | ppgm(PSTR("-> passive_parallel_scan()\r\n")); 18 | pfmt( " listens to all pins in parallel for %lu microseconds\r\n",usperrx); 19 | ppgm(PSTR(" tx stimulation and baudrate check not needed\r\n")); 20 | ppgm(PSTR(" prints pins whose bits change at the end of test\r\n")); 21 | microsbegin(); 22 | 23 | byte testmode = 0; 24 | if (usperrx <= 1) 25 | testmode = 1; 26 | 27 | byte state; 28 | uint32_t usstop = micros() + usperrx; 29 | #ifdef DEBUGLOOPS 30 | uint32_t loops = 0; 31 | #endif 32 | while (micros() <= usstop || testmode) { 33 | for (byte rx = 0; rx < pinslen; rx++) { 34 | #ifdef DEBUGLOOPS 35 | loops++; 36 | #endif 37 | state = digitalRead(pins[rx]) ? HIGH : LOW; // BUGBUG? 38 | #ifdef DEBUGSTATEBUF 39 | pfmt("cmp: %d != bitRead(pinstatebuf[%d]=%d, %d)=%d\r\n",state, rx/8, pinstatebuf[rx/8], rx%8, bitRead(pinstatebuf[rx/8], rx%8) ); 40 | #endif 41 | if (state != bitRead(pinstatebuf[rx/8], rx%8) ) { 42 | append_to_report(rx, state); 43 | bitWrite(pinstatebuf[rx/8], rx%8, state); // need to check the efficiency of bitWrite 44 | 45 | } 46 | } 47 | if(testmode) // run only one iteration 48 | break; 49 | } 50 | print_report(); 51 | ustotime(microselapsed()); 52 | #ifdef DEBUGLOOPS 53 | pfmt("loops: %lu\r\n",loops); 54 | #endif 55 | } 56 | 57 | /* active_parallel_scan 58 | * Assume there is an active RX line presenting data. 59 | * will send a txpattern wakeup pattern hoping this will 60 | * stimulate the target to start printing to the console 61 | * (it is common that some terminals require you send a 62 | * carriage return before they present a login screen) 63 | * all non-tx pins are then scanned in parallel 64 | */ 65 | void active_parallel_scan (uint32_t usperrx) 66 | { 67 | ppgm(PSTR("-> active_parallel_scan\r\n")); 68 | pfmt( " listens to all non tx pins in parallel for %lu microseconds\r\n",usperrx); 69 | ppgm(PSTR(" sends wakeup stimulant to tx pin at defined baudrates\r\n")); 70 | ppgm(PSTR(" prints pins whose bits change during test\r\n")); 71 | microsbegin(); 72 | 73 | byte testmode = 0; 74 | if (usperrx <= 1) 75 | testmode = 1; 76 | 77 | uint32_t usstop; 78 | uint16_t baud_i; 79 | byte pat, tx, rx, state; 80 | #ifdef DEBUGLOOPS 81 | uint32_t loops=0; 82 | #endif 83 | for (baud_i = 0; baud_i < baudrateslen; baud_i++) { 84 | pfmt("baud: %lu\r\n",baudrates[baud_i]); 85 | softserial_setup(baudrates[baud_i]); 86 | for (pat = 0; pat < txpatternslen; pat++) { 87 | for (tx = 0; tx < pinslen; tx++) { 88 | #ifdef SHOWTXSTATUS 89 | pfmt("0x%02X -> %s\r\n",txpatterns[pat],pinnames[tx]); 90 | #endif 91 | pinMode(pins[tx], OUTPUT); 92 | softserial_write(pins[tx], txpatterns[pat]); 93 | usstop = micros() + usperrx; 94 | while (micros() <= usstop || testmode){ 95 | for (rx = 0; rx < pinslen; rx++) { 96 | if(rx == tx) continue; 97 | #ifdef DEBUGLOOPS 98 | loops++; 99 | #endif 100 | state = digitalRead(pins[rx]) ? HIGH : LOW; // BUGBUG? 101 | if (state != bitRead(pinstatebuf[rx/8], rx%8) ) { 102 | append_to_report(rx, state); 103 | bitWrite(pinstatebuf[rx/8], rx%8, state); 104 | } 105 | } 106 | if (testmode) 107 | break; // run combined iterations only once 108 | } 109 | pinMode(pins[tx], INPUT); // reset 110 | digitalWrite(pins[tx], HIGH); // pull-up resistor 111 | print_report(tx, txpatterns[pat]); 112 | 113 | } 114 | } 115 | } 116 | ustotime(microselapsed()); 117 | #ifdef DEBUGLOOPS 118 | pfmt("loops: %lu\r\n",loops); 119 | #endif 120 | } 121 | 122 | /* active_per_pin_scan 123 | * exactly the same as active_parallel_scan except that 124 | * the each RX pin is scanned individually 125 | */ 126 | void active_per_pin_scan (uint32_t usperrx) 127 | { 128 | ppgm(PSTR("-> active_per_pin_scan\r\n")); 129 | pfmt( " listens to 1 rx pin at a time for %lu microseconds\r\n",usperrx); 130 | ppgm(PSTR(" sends wakeup stimulant to tx pin at defined baudrates\r\n")); 131 | ppgm(PSTR(" prints pins whose bits change during test\r\n")); 132 | microsbegin(); 133 | 134 | byte testmode = 0; 135 | if (usperrx <= 1) 136 | testmode = 1; 137 | 138 | uint32_t usstop; 139 | uint16_t baud_i; 140 | byte pat,tx,rx,state; 141 | #ifdef DEBUGLOOPS 142 | uint32_t loops=0; 143 | #endif 144 | for (pat=0; pat < txpatternslen; pat++) { 145 | for (tx=0; tx < pinslen; tx++) { 146 | #ifdef SHOWTXSTATUS 147 | pfmt("0x%02X -> txpin %s\r\n",txpatterns[pat],pinnames[tx]); 148 | #endif 149 | pinMode(pins[tx], OUTPUT); 150 | // no need to delay before read. just need to be sure we can 151 | // poll all pins long enough to detect low serial baud. 152 | for (rx=0; rx < pinslen; rx++) { 153 | if(rx==tx) continue; // no need to digitalRead(rxpin) 154 | for (baud_i=0; baud_i < baudrateslen; baud_i++) { 155 | pfmt("tx:%s rx:%s baud:%lu \r\n",pinnames[tx],pinnames[rx],baudrates[baud_i]); 156 | softserial_setup(baudrates[baud_i]); 157 | softserial_write(pins[tx], txpatterns[pat]); 158 | usstop = usperrx+micros(); 159 | while (micros() <= usstop || testmode) { 160 | #ifdef DEBUGLOOPS 161 | loops++; 162 | #endif 163 | state = digitalRead(pins[rx]) ? HIGH : LOW; // BUGBUG? 164 | #ifdef DEBUGSTATEBUF 165 | pfmt("cmp: %d != bitRead(pinstatebuf[%d]=%d, %d)=%d\r\n",state, rx/8, pinstatebuf[rx/8], rx%8, bitRead(pinstatebuf[rx/8], pat%8) ); 166 | #endif 167 | if (state != bitRead(pinstatebuf[rx/8], rx%8) ) { 168 | append_to_report(rx, state); 169 | bitWrite(pinstatebuf[rx/8], rx%8, state); 170 | } 171 | if (testmode) 172 | break; // read pin once 173 | } 174 | print_report(tx,txpatterns[pat]); 175 | } 176 | 177 | } 178 | pinMode(pins[tx], INPUT); // reset to INPUT 179 | digitalWrite(pins[tx], HIGH); //pull-up 180 | } 181 | } 182 | #ifdef DEBUGLOOPS 183 | pfmt("loops: %lu\r\n",loops); 184 | #endif 185 | } 186 | 187 | /* pins_state 188 | * prints the current high/low state of all the pins 189 | */ 190 | void pins_state () 191 | { 192 | // align names and pin state columns by finding the max string length 193 | ppgm(PSTR("pin: ")); 194 | for (byte i = 0; i < pinslen; i++) { 195 | pfmt("%s ", pinnames[i]); 196 | } 197 | ppgm(PSTR("\r\nstatebuf: ")); 198 | for (byte i = 0; i < pinslen; i++) { 199 | // align columns using space: 200 | for (byte j = 0; j < strlen(pinnames[i])-1; j++) 201 | pfmt(" "); 202 | pfmt("%d ", bitRead(pinstatebuf[i/8], i%8)); 203 | } 204 | ppgm(PSTR("\r\ncurrent: ")); 205 | for (int i = 0; i < pinslen; i++) { 206 | for (byte j = 0; j < strlen(pinnames[i])-1; j++) 207 | pfmt(" "); 208 | pfmt("%d ", digitalRead(pins[i])); 209 | } 210 | ppgm(PSTR("\r\n")); 211 | } 212 | 213 | 214 | void append_to_report(byte rxpin_i, byte state) 215 | { 216 | if ( reportbuf_i <= reportbuflen-2 ) { 217 | reportbuf[reportbuf_i++] = rxpin_i; 218 | reportbuf[reportbuf_i++] = state; 219 | } 220 | else { 221 | pfmt("."); // indication that memory is full 222 | } 223 | } 224 | 225 | // return 1 if anything was reported 226 | byte print_report(int16_t tx, uint16_t txpattern) 227 | { 228 | byte ret=0; 229 | if (reportbuf_i>0) { 230 | ret=1; 231 | if (tx >= 0) { 232 | pfmt("\t0x%02X -> %s:\t", txpattern,pinnames[tx]); 233 | } 234 | for (uint16_t i=0; i<=reportbuf_i-2;) { 235 | // if (i%(pinslen)==0) 236 | if (i%16==0 && i!=0) 237 | pfmt("\r\n \t"); 238 | pfmt("%s=%d ",pinnames[reportbuf[i++]],reportbuf[i++]); 239 | } 240 | pfmt("\r\n"); 241 | //clear_report_buffer(); // resource intensive 242 | reportbuf_i=0; 243 | } 244 | return ret; 245 | } 246 | void print_report() 247 | { 248 | print_report(-1,0); 249 | } 250 | 251 | 252 | void clear_report_buffer() 253 | { 254 | for (uint16_t i=0; i 1: 14 | baud = sys.argv[1] 15 | if baud not in ["300", "1200", "2400", "4800", "9600", "14400", "19200", "28800", "31250", "38400", "57600", "115200"]: 16 | print "RS232enum only supports baudrates:" 17 | print "300, 1200, 2400, 4800, 9600, 14400, 19200, 28800, 31250, 38400, 57600, 115200" 18 | exit(1) 19 | if baud 20 | else: 21 | print "provide baudrate as arguemnt" 22 | exit(1) 23 | 24 | ser = serial.Serial(device, baud) #, timeout=0, parity=serial.PARITY_EVEN, rtscts=1) 25 | print "opened tty: %s"%ser.portstr 26 | print "valid baudrates:" 27 | print ser.BAUDRATES 28 | print "RS232enum only supports baudrates:" 29 | print "300, 1200, 2400, 4800, 9600, 14400, 19200, 28800, 31250, 38400, 57600, 115200" 30 | print "valid bytesizes:" 31 | print ser.BYTESIZES 32 | print "valid parities:" 33 | print ser.PARITIES 34 | print "valid stopbits:" 35 | print ser.STOPBITS 36 | i=0 37 | #9 = 0 9/10=0 38 | #10 = 1 10/10=1 39 | #100 = 2 10/10=10 40 | #1000 = 3 41 | 42 | while True: 43 | #i+=1 44 | #print '\x08\x08\x08\x08\x08x08\x08\x08\x08\x08\x08\x08\x08\x08x08\x08\x08\x08\x08x08\x08\x08\x08\x08x08\x08\x08\x08\x08x08\x08\x08\x08\x08', 45 | #sys.stdout.flush() 46 | ret = "" 47 | if ser.inWaiting(): 48 | ret = ser.read() 49 | if ord(ret) == 0x0a or ord(ret) == 0x0d: # 0x10 == CR 50 | print "recieved CR (0x10)" 51 | ser.write("abcdefghijklmnopqrstuvwxyzABCDEFJHIJKLMNOPQRSTUVWXYZ") 52 | else: 53 | print ret 54 | 55 | #print "%12d"%(i), 56 | #time.sleep(1) 57 | --------------------------------------------------------------------------------