示例#1
0
文件: mc703.c 项目: xzpeter/iMonitor
int mc703_check_device_file(char *dev_name)
{
	int fd, len, ret;
	char *cmd;
	char buf[256];

	snprintf(buf, 256, "%s%s", DEV_DIR, dev_name);

	if ((fd = serial_open_port(buf, 1)) < 0)
		return 0;

	ret = 0;
	cmd = "AT+CGMM\r";
	bzero(buf, sizeof(buf));
	write(fd, cmd, strlen(cmd));
	usleep(200000);
	len = read(fd, buf, 256);
	buf[len] = 0x00;

	if (strstr(buf, "MC703")) {
// 		dm_log(NULL, "%s", buf);
		ret = 1;
	}

	close(fd);

	return ret;
}
示例#2
0
文件: serial.c 项目: cukier/modbus
size_t serial_transaction(uint8_t *tx, uint8_t *rx, uint16_t msg_size,
		uint16_t resp_size) {
	int n, m_tries;
	size_t m_size;
	uint8_t *ptr;

	if (serial_open_port() == -1) {
		serial_close_port();
		return 0;
	}

	n = -1;
	m_tries = TRIES;

#ifdef TIME_FRAME
	usleep(TIME_FRAME);
#endif

	tcflush(fd, TCIFLUSH);
	if (write(fd, tx, msg_size) == -1)
		return -1;

	ptr = NULL;
	m_size = 0;
	while ((m_size != resp_size) && ((m_tries--) > 0)) {
		usleep(100);
		n = read(fd, rx, resp_size);
		if (n != -1 && n > 0) {
			m_size += n;
			ptr = (uint8_t *) realloc(ptr, m_size * sizeof(uint8_t));

			if (ptr == NULL) {
				free(ptr);
				return -1;
			}

			u8_strcpy(ptr, rx, n, (m_size - n));
		}
	}

	serial_close_port();

	if (m_size > 0)
		u8_strcpy(rx, ptr, m_size, 0);

	free(ptr);

	if (n == -1) {
		return -1;
	}

	return m_size;
}
示例#3
0
int sniff(char *porta) {
	int fd, r;
	radio_data_t radio_d;

	fd = serial_open_port(porta);

	if (fd == -1) {
		fprintf(stderr, "Porta nao encontrada: %s\n", porta);
		return -1;
	}

	if (discover_radio(fd, &radio_d) != BINVPS) {
		RF1276_parse_radio(radio_d);
		r = RF1276_get_radio_rssi(fd);
		printf("Rssi: %d\n", r);
	}

	serial_close(fd);
	return 0;
}
示例#4
0
int _ads321_init_port(char *port)
{
	if (_fd)
		return _fd;
	return serial_open_port(port, ADS321_BAUD_RATE, ADS321_CRC_MODE);
}