Re: Accessing USB thermometer sensor

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Josh Hammond wrote:

> >> usb 1-2.2: pl2303 converter now attached to ttyUSB0
> >
> > Does "cat /dev/ttyUSB0" work?
> 
> Nope. I get only blank

Thinking about it some more, if the device is outputting binary, the
line buffering performed by the TTY driver and stdio will get in the
way. How about:

	stty raw < /dev/ttyUSB0
	dd if=/dev/ttyUSB0 bs=1 | od -t x1 -w1

Or, in C:

	int fd;
	struct termios t;

	fd = open("/dev/ttyUSB0", O_RDONLY|O_NOCTTY);

	tcgetattr(fd, &t);
	cfmakeraw(&t);
	tcsetattr(fd, TCSANOW, &t);

	for (;;) {
		unsigned char buf[1];
		if (read(fd, buf, 1) <= 0)
			break;
		printf("%02x\n", *buf);
	}

	close(fd);

-- 
Glynn Clements <glynn@xxxxxxxxxxxxxxxxxx>
--
To unsubscribe from this list: send the line "unsubscribe linux-c-programming" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Linux Assembler]     [Git]     [Kernel List]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [C Programming]     [Yosemite Campsites]     [Yosemite News]     [GCC Help]

  Powered by Linux