Esempio n. 1
0
static int multimeter_read(void) {
  double value;

  if (fd < 0)
    return -1;

  if (multimeter_read_value(&value) != 0)
    return -1;

  multimeter_submit(value);
  return 0;
} /* int multimeter_read */
Esempio n. 2
0
static int multimeter_init (void)
{
	char device[] = "/dev/ttyS ";

	for (int i = 0; i < 10; i++)
	{
		device[strlen(device)-1] = i + '0';

		if ((fd = open(device, O_RDWR | O_NOCTTY)) != -1)
		{
			struct termios tios = { 0 };
			int rts = TIOCM_RTS;
			double value;

			tios.c_cflag = B1200 | CS7 | CSTOPB | CREAD | CLOCAL;
			tios.c_iflag = IGNBRK | IGNPAR;
			tios.c_oflag = 0;
			tios.c_lflag = 0;
			tios.c_cc[VTIME] = 3;
			tios.c_cc[VMIN]  = LINE_LENGTH;

			tcflush(fd, TCIFLUSH);
			tcsetattr(fd, TCSANOW, &tios);
			ioctl(fd, TIOCMBIC, &rts);

    			if (multimeter_read_value (&value) < -1)
			{
				close (fd);
				fd = -1;
			}
			else
			{
				INFO ("multimeter plugin: Device "
						"found at %s", device);
				return (0);
			}
		}
	}

	ERROR ("multimeter plugin: No device found");
	return (-1);
}