Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- PySerial and microcontroller
- putsU1("string");
- // print a string
- int putsU1(char *s) {
- while(*s)
- putU1(*s++);
- }
- // print a character
- int putU1(int c) {
- while (_UTXBF);
- U1TXREG = c;
- return c;
- }
- In [13]: ser = serial.Serial('/dev/ttyACM0', 9600, bytesize=7, xonxoff=0)
- In [14]: while True:
- print(struct.unpack('s', ser.read()))
- ....:
- ('x7f',)
- ('c',)
- ('x11',)
- ('t',)
- ('e',)
- ('y',)
- ('=',)
- ('x7f',)
- getsnU1(s, BUF_SIZE);
- char *getsnU1(char *s, int len) {
- char *p = s;
- int cc = 0;
- do {
- *s = getU1();
- putU1(*s);
- if ((*s == 0x8) && (s > p)) {
- putU1(' ');
- putU1(0x8);
- len++;
- s--;
- continue;
- }
- if (*s == 'n')
- continue;
- if (*s == 'r')
- break;
- s++;
- len--;
- } while (len > 1);
- *s = '