Download presentation
Presentation is loading. Please wait.
Published bySheena Holmes Modified over 9 years ago
1
Reading and Writing Text over USB A Colony Project Tutorial
2
2 Differences between Windows and Linux On Windows, the robot is connected to a com port, usually com1 – com4 – This can be found in the device manager On Linux, the robot is connected to /dev/ttyUSB0 or higher numbers – Guess the number until you get it right
3
Tera Term Serial input and output program Lets you view stuff that the robot has printed to USB Can also write responses to robot 3
4
Open a Serial Connection In Tera Term, use Setup->Serial Port to start a session Use File->Disconnect to end a session The Baud rate should be 115200 4
5
Basic USB Write Functions usb_putc(char c) – ex: usb_putc(‘a’); usb_puts(char* s) – ex: usb_puts(“testing”); usb_puti(int i) – ex: usb_puti(12); 5
6
Advanced USB Write Functions usb_puth8(int i) – print 8 bit hex value – ex: usb_puth8(0xA6); usb_puth16(int i) – also named usb_puth(int i) – print 16 bit hex value – ex: usb_puth16(0x5D2F); 6
7
USB Read Functions int usb_getc() – returns a character – ex: c = usb_getc(); int usb_getc_nb() – nonblocking form of usb_getc – returns -1 if no character present in input buffer – ex: c = usb_getc_nb(); 7
8
Example – test_usb.c usb_init(); usb_puts("usb turned on, test starting:\r\n"); usb_puts("\r\n\n"); delay_ms(1000); // print some values to usb usb_puts("Testing...\r\n"); usb_puti(1); usb_putc(','); usb_putc(' '); usb_puti(2); usb_putc(','); usb_putc(' '); usb_puti(3); usb_putc('\r'); usb_putc('\n'); usb_puth8(0x2A); usb_putc(','); usb_putc(' '); usb_puth16(0xF4); usb_putc(','); usb_putc(' '); usb_puth(0xC8E1); usb_putc('\r'); usb_putc('\n'); usb_puts("enter an 'a':"); if (usb_getc() == 'a') usb_puts("\r\ngetc() works\r\n"); else usb_puts("\r\ngetc() fails\r\n"); usb_puts("done.\r\n\r\n"); 8
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.