LINUX.ORG.RU

История изменений

Исправление nvl, (текущая версия) :

Вроде как 7e1, данные четко идентифицируются. Не понимаю пока, почему получаю данные больше 0x7f...

Что не так?:

public static int main (string[] args) {

	int fd;
	Posix.termios tty;
	string path = "/dev/ttyUSB0";

	fd = Posix.open(path, Posix.O_RDWR | Posix.O_NOCTTY | Posix.O_SYNC);
	if (fd < 0) {
		warning ("Error opening %s", path);
	}

	if (Posix.tcgetattr (fd, out tty) != 0) {
		warning ("Error from tcgetattr");
	}

	Posix.cfsetispeed (ref tty, Posix.B38400);

	// 7E1
	tty.c_cflag |=  Posix.PARENB;
	tty.c_cflag &= ~Posix.PARODD;
	tty.c_cflag &= ~Posix.CSTOPB;
	tty.c_cflag &= ~Posix.CSIZE;
	tty.c_cflag |=  Posix.CS7;

	tty.c_cflag |= Posix.CREAD;
	tty.c_cflag |= Posix.CLOCAL;

	tty.c_iflag &= ~Posix.IXON;
	tty.c_iflag &= ~Posix.IXOFF;
	tty.c_iflag &= ~Posix.IXANY;

	tty.c_lflag &= ~Posix.ICANON;
	tty.c_lflag &= ~Posix.ECHO;
	tty.c_lflag &= ~Posix.ECHOE;
	tty.c_lflag &= ~Posix.ISIG;

	tty.c_oflag &= ~Posix.OPOST;

	tty.c_cc[Posix.VTIME] = 0;
	tty.c_cc[Posix.VMIN]  = 1;

	Posix.cfmakeraw (ref tty);

	if (Posix.tcsetattr(fd, Posix.TCSANOW, tty) != 0) {
		warning ("Error from tcsetattr");
	}


	char buf[1];
	ssize_t count = 0;

	while (true) {
		count = Posix.read (fd, buf, buf.length);
		if (count > 0) {
			for (int i = 0; i < buf.length; i++) {
				stdout.printf ("0x%02hhX\n ", buf[i]);
			}
		}
	}

	return 0;
}


В байте, который предположительно является контрольной суммой, выводит как 0xA5

Исходная версия nvl, :

Вроде как 7e1, данные четко идентифицируются. Не понимаю пока, почему получаю данные больше 0x7f...

Что не так?:

public static int main (string[] args) {

	int fd;
	Posix.termios tty;
	string path = "/dev/ttyUSB0";

	fd = Posix.open(path, Posix.O_RDWR | Posix.O_NOCTTY | Posix.O_SYNC);
	if (fd < 0) {
		warning ("Error opening %s", path);
	}

	if (Posix.tcgetattr (fd, out tty) != 0) {
		warning ("Error from tcgetattr");
	}

	Posix.cfsetispeed (ref tty, Posix.B38400);

	// 7E1
	tty.c_cflag |=  Posix.PARENB;
	tty.c_cflag &= ~Posix.PARODD;
	tty.c_cflag &= ~Posix.CSTOPB;
	tty.c_cflag &= ~Posix.CSIZE;
	tty.c_cflag |=  Posix.CS7;

	tty.c_cflag |= Posix.CREAD;
	tty.c_cflag |= Posix.CLOCAL;

	tty.c_iflag &= ~Posix.IXON;
	tty.c_iflag &= ~Posix.IXOFF;
	tty.c_iflag &= ~Posix.IXANY;

	tty.c_lflag &= ~Posix.ICANON;
	tty.c_lflag &= ~Posix.ECHO;
	tty.c_lflag &= ~Posix.ECHOE;
	tty.c_lflag &= ~Posix.ISIG;

	tty.c_oflag &= ~Posix.OPOST;

	tty.c_cc[Posix.VTIME] = 0;
	tty.c_cc[Posix.VMIN]  = 1;

	Posix.cfmakeraw (ref tty);

	if (Posix.tcsetattr(fd, Posix.TCSANOW, tty) != 0) {
		warning ("Error from tcsetattr");
	}


	char buf[1];
	ssize_t count = 0;

	while (true) {
		count = Posix.read (fd, buf, buf.length);
		if (count > 0) {
			for (int i = 0; i < buf.length; i++) {
				stdout.printf ("0x%02hhX\n ", buf[i]);
			}
		}
	}

	return 0;
}


В байте, который предположительно я вляется контрольной суммой, выводит как 0xA5