• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C++ serial_read函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C++中serial_read函数的典型用法代码示例。如果您正苦于以下问题:C++ serial_read函数的具体用法?C++ serial_read怎么用?C++ serial_read使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了serial_read函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。

示例1: zigbee_protocol_waitAndcheckReply

static bool zigbee_protocol_waitAndcheckReply(uint32_t fd, uint8_t* receivedFrame, uint32_t sizeBuffer,
    zigbee_decodedFrame* decodedData)
{
  fd_set rfs;
  struct timeval waitTime;
  bool bSuccess;
  uint16_t nextSizeToRead;
  FD_ZERO(&rfs);
  FD_SET(fd, &rfs);
  waitTime.tv_sec = 2;
  waitTime.tv_usec = 0;
  bSuccess = false;
  nextSizeToRead = 0;

  if (select(fd + 1, &rfs, NULL, NULL, &waitTime) > 0)
  {
    if (FD_ISSET(fd, &rfs))
    {
      bSuccess = serial_read(fd, receivedFrame, 3);
      if (bSuccess)
      {
        bSuccess = zigbee_decodeHeader(receivedFrame, 3, &nextSizeToRead);
      }

      if (bSuccess && ((uint16_t)(3 + nextSizeToRead + 1) <= sizeBuffer))
      {
        bSuccess = serial_read(fd, &receivedFrame[3], nextSizeToRead + 1);
      }
      else
      {
        bSuccess = false;
      }

      if (bSuccess)
      {
        bSuccess = zigbee_decodeFrame(&receivedFrame[3], nextSizeToRead + 1, decodedData);
        if (bSuccess == true)
        {
          display_frame("received (ok)", receivedFrame, nextSizeToRead + 1 + 3);
        }
        else
        {
          display_frame("received (ko)", receivedFrame, nextSizeToRead + 1 + 3);
        }
      }
    }
  }
  else
  {
#ifdef TRACE_ACTIVATED
    fprintf(stdout, "Timeout\n");
#endif // TRACE_ACTIVATED
  }

#ifdef TRACE_ACTIVATED
  fprintf(stdout, "bSuccess = %d nextSizeToRead = %d\n", bSuccess, nextSizeToRead);
#endif // TRACE_ACTIVATED

  return bSuccess;
}
开发者ID:miko53,项目名称:zigbee_controller,代码行数:60,代码来源:zigbee_protocol.c


示例2: GPS_DEBUG_READ_PRINTLN

uint8_t GPS_MTK3339::continueRead(){
    #ifdef GPS_DEBUG_READ_VERBOSE
        GPS_DEBUG_READ_PRINTLN("READ GPS CONTINUE");
    #endif
    while(serial_available() > 0){
        char b = (char)serial_read();
        if(b == GPS_START_DELIM){
            GPS_DEBUG_READ_PRINTLN("unexpected start delimiter found");
            _machineState = GPS_MS_ERROR;
            return GPS_ERROR_PARSE_ERR;
        }
        if(b == GPS_CHKSUM_DELIM){
            writeBuffer(b);
            uint32_t ticks = millis();
            while(serial_available() < 2){
                if(millis() - ticks > 250){
                    GPS_DEBUG_READ_PRINTLN("too long to read checksum bytes");
                    _machineState = GPS_MS_ERROR;
                    return GPS_ERROR_TIMEOUT;
                }
            }
            b = serial_read();
            writeBuffer(b);
            
            b = serial_read();
            writeBuffer(b);
            
            writeBuffer(0x00);
            
            return parseSentence();
        }
        writeBuffer(b);
    }
    return GPS_STATUS_READING;
}
开发者ID:secavian,项目名称:arduino,代码行数:35,代码来源:GPS_MTK3339.cpp


示例3: term

void term(void)
{
  uint8_t length = 4 + 2*6 + 4; //Se va a enviar HOLA
  char rec[length];
  int n;
  packet_t test_packet;
  test_packet.packet_id = PCK_HEADER;
  test_packet.destination = 0x1023;
  test_packet.source = 0x3211;
  test_packet.number = 0x0001;
  test_packet.length = 0x0004;
  test_packet.packet_type = 0x0012;
  test_packet.reserved = 0x0000;
  drone_ID_to_data(0x01FF,&test_packet);
  printf("%d\r\n",data_to_drone_ID(test_packet));

  send_packet(serial_fd,  test_packet);
  //This code shows that a no read character, remains in the buffer and will be processesed later
  n=serial_read(serial_fd,rec,length,TIMEOUT);
  int i;
  for (i = 0; i < n; i++)  
  {
      printf ("|%02x|", rec[i]);
        
  }
  printf ("\n\r");


  for (i = 0; i < n; i++)  
  {
      printf ("|%c|", rec[i]);
        
  }
  printf ("\n\r");
  fflush(stdout);

  sleep(1);

  n=serial_read(serial_fd,rec,length,TIMEOUT);
    
  for (i = 0; i < n; i++)  
  {
      printf ("|%02x|", rec[i]);
        
  }
  printf ("\n\r");


  for (i = 0; i < n; i++)  
  {
      printf ("|%c|", rec[i]);
        
  }
  printf ("\n\r");
  fflush(stdout);
}
开发者ID:franciscocharro,项目名称:LSE-2015,代码行数:56,代码来源:example.c


示例4: test_loopback

void test_loopback(void) {
    serial_t serial;
    unsigned int count;
    time_t start, stop;
    uint8_t lorem_ipsum[] = "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.";
    uint8_t lorem_hugesum[4096*3];
    uint8_t buf[sizeof(lorem_hugesum)];

    ptest();

    passert(serial_open(&serial, device, 115200) == 0);

    /* Test write/flush/read */
    passert(serial_write(&serial, lorem_ipsum, sizeof(lorem_ipsum)) == sizeof(lorem_ipsum));
    passert(serial_flush(&serial) == 0);
    passert(serial_read(&serial, buf, sizeof(lorem_ipsum), -1) == sizeof(lorem_ipsum));
    passert(memcmp(lorem_ipsum, buf, sizeof(lorem_ipsum)) == 0);

    /* Test poll/write/flush/poll/input waiting/read */
    passert(serial_poll(&serial, 500) == 0); /* Should timeout */
    passert(serial_write(&serial, lorem_ipsum, sizeof(lorem_ipsum)) == sizeof(lorem_ipsum));
    passert(serial_flush(&serial) == 0);
    passert(serial_poll(&serial, 500) == 1);
    usleep(500000);
    passert(serial_input_waiting(&serial, &count) == 0);
    passert(count == sizeof(lorem_ipsum));
    passert(serial_read(&serial, buf, sizeof(lorem_ipsum), -1) == sizeof(lorem_ipsum));
    passert(memcmp(lorem_ipsum, buf, sizeof(lorem_ipsum)) == 0);

    /* Test non-blocking poll */
    passert(serial_poll(&serial, 0) == 0);

    /* Test a very large read-write (likely to exceed internal buffer size (~4096)) */
    memset(lorem_hugesum, 0xAA, sizeof(lorem_hugesum));
    passert(serial_write(&serial, lorem_hugesum, sizeof(lorem_hugesum)) == sizeof(lorem_hugesum));
    passert(serial_flush(&serial) == 0);
    passert(serial_read(&serial, buf, sizeof(lorem_hugesum), -1) == sizeof(lorem_hugesum));
    passert(memcmp(lorem_hugesum, buf, sizeof(lorem_hugesum)) == 0);

    /* Test read timeout */
    start = time(NULL);
    passert(serial_read(&serial, buf, sizeof(buf), 2000) == 0);
    stop = time(NULL);
    passert((stop - start) > 1);

    /* Test non-blocking read */
    start = time(NULL);
    passert(serial_read(&serial, buf, sizeof(buf), 0) == 0);
    stop = time(NULL);
    /* Assuming we weren't context switched out for a second and weren't on a
     * thin time boundary ;) */
    passert((stop - start) == 0);

    passert(serial_close(&serial) == 0);
}
开发者ID:HackLinux,项目名称:c-periphery,代码行数:55,代码来源:test_serial.c


示例5: get_name

void get_name(void)
{
	int key, i;
	char show_buffer[64] = {0};
	char name[17] = {0};

	while (1) {
        lcd_clrscr();
        lcd_disp_string(0, 0, "      蓝牙名称    ");
	   
	   	/*获取蓝牙地址*/
		serial_clrbuf(CONFIG_BT_SERIAL_NUM, 1, 0);
    	serial_write(CONFIG_BT_SERIAL_NUM, "AT+NAME\r\n", sizeof("AT+NAME\r\n"));
	   	serial_read(CONFIG_BT_SERIAL_NUM, show_buffer, 64, 300);
		if(!strncmp("+NAME=\"", show_buffer, 7)){
            for(i = 0; i < 16; i ++) {
                if (show_buffer[7 + i] == '\"')
                    break;
                name[i] = show_buffer[7 + i];
            }
	   	    lcd_disp_string(0, 16, name);
		}
	   	else
            lcd_disp_string(0, 16, "获取失败");

        key = kb_get_key(0);
        if (key == KEY_ESC)
            return;
    }
}
开发者ID:296791897,项目名称:keilprj,代码行数:30,代码来源:bluetooth_test.c


示例6: get_mac

void get_mac(void)
{
	int key;
	char show_buffer[64];
	char addr[18];

	while (1) {
        lcd_clrscr();
        lcd_disp_string(0, 0, "      蓝牙MAC地址    ");
	   
	   	/*获取蓝牙地址*/
		serial_clrbuf(CONFIG_BT_SERIAL_NUM, 1, 0);
    	serial_write(CONFIG_BT_SERIAL_NUM, "AT+LADDR\r\n", sizeof("AT+LADDR\r\n"));
	   	serial_read(CONFIG_BT_SERIAL_NUM, show_buffer, 64, 300);
		if(!strncmp("+LADDR=", show_buffer, 7)){
            memcpy(addr, show_buffer + 7, 17);
	   	    lcd_disp_string(0, 16, addr);
		}
	   	else
            lcd_disp_string(0, 16, "获取失败");

        key = kb_get_key(0);
        if (key == KEY_ESC)
            return;
    }
}
开发者ID:296791897,项目名称:keilprj,代码行数:26,代码来源:bluetooth_test.c


示例7: main

int main(int argc, char *argv[])
{
	int serial_dev;
	int ret;
	char data[256];

	if (argc < 2) {
		fprintf(stderr, "Please specify serial device to use \r\n");
		return -1;
	}
	
	printf("Serial device to open: %s \r\n", argv[1]);
	
	serial_dev = serial_open(argv[1]);
	if (serial_dev < 0) {
		fprintf(stderr, "Unable to open serial device: %s: %s\r\n", argv[1], strerror(errno));
		return -1;
	}
	
	if (serial_setup(serial_dev, 115200)) {
		fprintf(stderr, "Unable to setup serial device: %s: %s\r\n", argv[1], strerror(errno));
	}

	while (1) {
		serial_write(serial_dev, "Testing");
		ret = serial_read(serial_dev, data, sizeof(data));
		if (ret <= 0) {
			printf("No data available \r\n");
		} else {
			printf("Serial data received:\r\n");
			printf("%s\r\n", data);
		}
		sleep(1);
	}
}
开发者ID:mykhani,项目名称:libserial,代码行数:35,代码来源:serial_test.c


示例8: PUMP_selftest

/*
 * Does OLS self-test
 * pump_fd - fd of pump com port
 */
int PUMP_selftest(int pump_fd) 
{
  static const uint8_t cmd[4] = {0x07, 0x00, 0x00, 0x00};
  uint8_t status;
  int res, retry;

  res = serial_write(pump_fd, cmd, 4);
  if (res != 4) return OLSRESULT_CMDWRITE_ERROR;

  retry=0;
  while (1) {
    res = serial_read(pump_fd, &status, 1);
    if (res<1) retry++;

    if (res == 1)
      break;

    // 20 second timenout
    if (retry > 60) 
      return OLSRESULT_TIMEOUT;
  }

  if (status & 0x01) return OLSRESULT_1V2SUPPLY_BAD;
  if (status & 0x02) return OLSRESULT_2V5SUPPLY_BAD;
  if (status & 0x04) return OLSRESULT_PROGB_BAD;
  if (status & 0x08) return OLSRESULT_DONE_BAD;
  if (status & 0x10) return OLSRESULT_UNKNOWN_JEDICID;
  if (status & 0x20) return OLSRESULT_UPDATE_BAD;
  return OLSRESULT_SUCCESS;
}
开发者ID:ied,项目名称:olswinloader,代码行数:34,代码来源:ols.cpp


示例9: handle_new_data

static void handle_new_data(struct sr_dev_inst *sdi, int dmm, void *info)
{
	struct dev_context *devc;
	int len, i, offset = 0;
	struct sr_serial_dev_inst *serial;

	devc = sdi->priv;
	serial = sdi->conn;

	/* Try to get as much data as the buffer can hold. */
	len = DMM_BUFSIZE - devc->buflen;
	len = serial_read(serial, devc->buf + devc->buflen, len);
	if (len == 0)
		return; /* No new bytes, nothing to do. */
	if (len < 0) {
		sr_err("Serial port read error: %d.", len);
		return;
	}
	devc->buflen += len;

	/* Now look for packets in that data. */
	while ((devc->buflen - offset) >= dmms[dmm].packet_size) {
		if (dmms[dmm].packet_valid(devc->buf + offset)) {
			handle_packet(devc->buf + offset, sdi, dmm, info);
			offset += dmms[dmm].packet_size;
		} else {
			offset++;
		}
	}

	/* If we have any data left, move it to the beginning of our buffer. */
	for (i = 0; i < devc->buflen - offset; i++)
		devc->buf[i] = devc->buf[offset + i];
	devc->buflen -= offset;
}
开发者ID:jeffegg,项目名称:libsigrok,代码行数:35,代码来源:protocol.c


示例10: get_dht11

int get_dht11(serial *s,struct DHT11* data)
{
	int state=0;
//	static int count_err=0;	//连续错误次数
	char buffer[128];

	serial_write(s,"DHT11");
	usleep(90000);
	serial_read(s, buffer, '\n', 128);
	debug("receive from serial's data length is :%d\n",strlen(buffer));
	debug("receive from serial's data content is :%s\n",buffer);

	//判定接收到的字符串长度,小于50失败
	if(strlen(buffer)>50){
		sscanf(buffer,"%*s%*s%*s%*s%d%*s%d",&data->temp,&data->rehum);
		debug("temp:%d rehum:%d\n",data->temp,data->rehum);
		if(data->rehum>100||data->rehum<0||data->temp<0||data->temp>80){
			state=1;
//			count_err++;	//连续错误累加
		}
	}else{
		state=1;
	}

//	if(count_err>=100){	//如果连续错误超过100次,仍然将函数返回值置0,目的是为了让程序跳出死循环
//		state=0;
//	}
//
//	if(state==0){
//		count_err=0;
//	}
	return state;
}
开发者ID:ledudu,项目名称:Monitor,代码行数:33,代码来源:sensor.c


示例11: get_bt_status

void get_bt_status(void)
{
	int key;
	char show_buffer[50];
	char des[10] = {0};

	while (1) {
        lcd_clrscr();
        lcd_disp_string(0, 0, "      蓝牙状态    ");
	   
		serial_clrbuf(CONFIG_BT_SERIAL_NUM, 1, 0);
    	serial_write(CONFIG_BT_SERIAL_NUM, "AT+STATUS\r\n", sizeof("AT+STATUS\r\n"));
	   	serial_read(CONFIG_BT_SERIAL_NUM, show_buffer, 20, 300);
		if(!strncmp(show_buffer, "+STATUS=", sizeof("+STATUS=") - 1)){
			des[0] = show_buffer[sizeof("+STATUS=") - 1];            
            if (strcmp(des, "2") == 0)
                lcd_disp_string(0, 16, "蓝牙已连接");
            else if (strcmp(des, "1") == 0)
                lcd_disp_string(0, 16, "蓝牙广播中...");
            else if (strcmp(des, "0") == 0)
                lcd_disp_string(0, 16, "蓝牙空闲");
	   		else
                lcd_disp_string(0, 16, "未知状态");
		}
	   	else
            lcd_disp_string(0, 16, "获取失败");

        key = kb_get_key(0);
        if (key == KEY_ESC)
            return;
    }
}
开发者ID:296791897,项目名称:keilprj,代码行数:32,代码来源:bluetooth_test.c


示例12: serial_interrupt_rx

serial_interrupt_rx()
{
	uint8_t end = serial_input.end;

	serial_input.buf[end] = serial_read();
	serial_input.end = (end + 1) & (SERIAL_INBUF - 1);
}
开发者ID:labitat,项目名称:jchillerup,代码行数:7,代码来源:serial.c


示例13: __attribute__

void __attribute__((noreturn)) serial_recv_task(struct vcom * vcom)
{
	struct serial_dev * serial = vcom->serial;
	struct usb_cdc_class * cdc = vcom->cdc;
	uint8_t buf[VCOM_BUF_SIZE];
	int len;

	DCC_LOG1(LOG_TRACE, "[%d] started.", thinkos_thread_self());

	/* wait for line configuration */
	usb_cdc_acm_lc_wait(cdc);

	/* enable serial */
	serial_enable(serial);

	for (;;) {
		len = serial_read(serial, buf, VCOM_BUF_SIZE, 1000);
		if (len > 0) {
//			dbg_write(buf, len);
			if (vcom->mode == VCOM_MODE_CONVERTER) {
				led_flash(LED_AMBER, 50);
				usb_cdc_write(cdc, buf, len);
			}
			if (vcom->mode == VCOM_MODE_SDU_TRACE) {
				led_flash(LED_AMBER, 50);
				sdu_decode(buf, len);
			}
#if RAW_TRACE
			if (len == 1)
				DCC_LOG1(LOG_TRACE, "RX: %02x", buf[0]);
			else if (len == 2)
				DCC_LOG2(LOG_TRACE, "RX: %02x %02x", 
						 buf[0], buf[1]);
			else if (len == 3)
				DCC_LOG3(LOG_TRACE, "RX: %02x %02x %02x", 
						 buf[0], buf[1], buf[2]);
			else if (len == 4)
				DCC_LOG4(LOG_TRACE, "RX: %02x %02x %02x %02x", 
						 buf[0], buf[1], buf[2], buf[3]);
			else if (len == 5)
				DCC_LOG5(LOG_TRACE, "RX: %02x %02x %02x %02x %02x", 
						 buf[0], buf[1], buf[2], buf[3], buf[4]);
			else if (len == 6)
				DCC_LOG6(LOG_TRACE, "RX: %02x %02x %02x %02x %02x %02x", 
						 buf[0], buf[1], buf[2], buf[3], buf[4], buf[5]);
			else if (len == 7)
				DCC_LOG7(LOG_TRACE, "RX: %02x %02x %02x %02x %02x %02x %02x ",
						 buf[0], buf[1], buf[2], buf[3], 
						 buf[4], buf[5], buf[6]);
			else
				DCC_LOG8(LOG_TRACE, "RX: %02x %02x %02x %02x %02x %02x "
						 "%02x %02x ...", buf[0], buf[1], buf[2], buf[3], 
						 buf[4], buf[5], buf[6], buf[7]);
#endif
#if SDU_TRACE
			RX(buf, len);
#endif
		}
	}
}
开发者ID:powertang,项目名称:yard-ice,代码行数:60,代码来源:u2s-485.c


示例14: GAgent_Local_RecAll

/****************************************************************
FunctionName    :   GAgent_Local_RecAll
Description     :   receive all of data form local io one time.
                    and put data int local cycle buf.This func will
                    change data 0xff55 isn't SYNC HEAD to 0xff
pgc             :   gagent global struct. 
return          :   void.
****************************************************************/
int32 GAgent_Local_RecAll(pgcontext pgc)
{
    int32 fd;
    int32 available_len =0;
    int32 read_count = 0;
    uint32 offRec;

    fd = pgc->rtinfo.local.uart_fd;
    if(fd < 0)
    {
        return RET_FAILED;
    }

    if(RET_SUCCESS == GAgent_Local_IsDataValid(pgc))
    {
        /* step 1.read data into loopbuf */
        available_len = get_available_buf_space( pos_current, pos_start );
        read_count = serial_read( fd, &hal_RxBuffer[pos_current & HAL_BUF_MASK],available_len );
        offRec = pos_current;
        if(read_count <= 0)
        {
            return read_count;
        }

        pos_current += read_count;

    }

    return read_count;
}
开发者ID:joeysun,项目名称:Gizwits-GAgent,代码行数:38,代码来源:hal_receive.c


示例15: protocol_process

// Process and report status one line of incoming serial data. Performs an initial filtering
// by removing spaces and comments and capitalizing all letters.
void protocol_process()
{
  uint8_t c;
  while((c = serial_read()) != SERIAL_NO_DATA) {
    if ((c == '\n') || (c == '\r')) { // End of line reached
      // Runtime command check point before executing line. Prevent any furthur line executions.
      // NOTE: If there is no line, this function should quickly return to the main program when
      // the buffer empties of non-executable data.
      protocol_execute_runtime();
      if (sys.abort) {
		return;  // Bail to main program upon system abort
      }
      if (char_counter > 0) {// Line is complete. Then execute!
        line[char_counter] = 0; // Terminate string
        report_status_message(protocol_execute_line(line));
      }
      else {
        // Empty or comment line. Skip block.
        report_status_message(STATUS_OK); // Send status message for syncing purposes.
      }
      protocol_reset_line_buffer();
    }
    else {
      if (iscomment) {
        // Throw away all comment characters
        if (c == ')') {
          // End of comment. Resume line.
          iscomment = false;
        }
      }
      else {
        if (c <= ' ') {
          // Throw away whitepace and control characters
        }
        else
		if (c == '/') {
          // Block delete not supported. Ignore character.
        }
        else
        if (c == '(') {
          // Enable comments flag and ignore all characters until ')' or EOL.
          iscomment = true;
        }
        else
        if (char_counter >= LINE_BUFFER_SIZE-1) {
          // Report line buffer overflow and reset
          report_status_message(STATUS_OVERFLOW);
          protocol_reset_line_buffer();
        }
        else
        if (c >= 'a' && c <= 'z') { // Upcase lowercase
          line[char_counter++] = c-'a'+'A';
        }
        else {
          line[char_counter++] = c;
        }
      }
    }
  }
}
开发者ID:Eliamegane,项目名称:Grbl-xx_with_Arduino,代码行数:62,代码来源:protocol.cpp


示例16: serial_port_serialr

void serial_port_serialr (struct serial_port* port)
{
	int			r;

	DBG_LOG(fprintf(debug_log_file, "event: serialr\n"));

	/* The serial port has data ready.  Load into the incoming buffer.
	 * Only make one call here, as some operating systems (like the
	 * Windows implementation) won't quite work properly if multiple
	 * serial_read calls were made in one pass in an attempt to fill
	 * the buffer.  On systems like UNIX where you can make read calls
	 * until errno == EAGAIN the loop should be implemented within
	 * serial_read itself.
	 */
	r = serial_read(
		port->chan,
		port->incoming + port->incomingLen,
		port->incomingBufSz - port->incomingLen);

	if (r >= 0)
	{
		port->incomingLen += r;

	} else if (serial_last_error(port->chan))
	{
		port->lastError.error_code = serial_last_error(port->chan);
		serial_format_error(
			port->chan,
			port->lastError.error_code,
			port->lastError.error_msg,
			sizeof(port->lastError.error_msg));
	}
}
开发者ID:tomszilagyi,项目名称:gen_serial,代码行数:33,代码来源:erlang_serial.c


示例17: readSerialCmd

void readSerialCmd() {
	int result;
	char data;
	static uint8_t pos = 0;

	while (serial_available() && (serialMode == SERIALCMDMODE)) { //ATSL changes commandmode while there is a char waiting in the serial buffer.
		result = NOTHING;
		data = serial_read();
		serialData[pos++] = data; //serialData is our global serial buffer
		if (data == SERIALCMDTERMINATOR) {
			if (pos > 3) { // we need 4 bytes
				result = processSerialCmd(pos);
			} else {
				result = ERR;
			}
			pos = 0;
		}
		// check if we don't overrun the buffer, if so empty it
		if (pos > BUFFLEN) {
			result = ERR;
			pos = 0;
		}
		if (result == OK) {
			printf("ok\r\n");
		} else if (result == ERR) {
			printf("error\r\n");
		}
	}
}
开发者ID:bpg,项目名称:RFBee,代码行数:29,代码来源:rfBeeSerial.c


示例18: GPS_Read

void GPS_Read(GpsInfo *pGPS)
{
	
	while(1){
		memset((char *)Gps_str, 0, 512);
		len = serial_read(&GpsDevice, Gps_str, 512);
		
		if(len>0){

			if(strstr(Gps_str,"$GPRMC")!=NULL){
				nmea_parse_GPRMC(Gps_str, len, &vGPRMC);

				pGPS->status    = vGPRMC.status;
				pGPS->lat       = vGPRMC.lat;
				pGPS->ns        = vGPRMC.ns;
				pGPS->lon       = vGPRMC.lon;
				pGPS->ew        = vGPRMC.ew;
				pGPS->speed     = (vGPRMC.speed * NMEA_TUD_KNOTS);
				pGPS->direction = vGPRMC.direction;
				
				break;
			}
		}
	}
}
开发者ID:SGGS-IT,项目名称:VehicleTracking,代码行数:25,代码来源:GPS.c


示例19: get_num_files

int get_num_files(serial_handle_t serial_handle) {
    int r;
    char reply[2];


    // flush the serial port
    r = serial_flush(serial_handle);
    if (r < 0) {
        return -1;
    }

    // send the command to request the number of recorded files
    r = serial_write_byte(serial_handle, 0x01);
    if (r < 1) {
        return -1;
    }

    // read the reply, 2 bytes
    r = serial_read(serial_handle, reply, 2, 500*1000);
    if (r < 2) {
        return -1;
    }

    g_debug("cmd 0x01 (get num files), 2-byte response: 0x%02x 0x%02x", reply[0], reply[1]);

    // but only the second byte matters
    return reply[1];
} 
开发者ID:SebKuzminsky,项目名称:hammerhead,代码行数:28,代码来源:get-num-files.c


示例20: read_byte

static int read_byte(serial_source src, int non_blocking)
/* Returns: next byte (>= 0), or -1 if no data available and non-blocking is true.
*/
{
  if (src->recv.bufpos >= src->recv.bufused)
    {
      for (;;)
	{
	  int n = serial_read(src, non_blocking, src->recv.buffer, sizeof src->recv.buffer);

	  if (n == 0) /* Can't occur because of serial_read bug workaround */
	    {
	      message(src, msg_closed);
	      return -1;
	    }
	  if (n > 0)
	    {
#ifdef DEBUG
	      dump("raw", src->recv.buffer, n);
#endif
	      src->recv.bufpos = 0;
	      src->recv.bufused = n;
	      break;
	    }
#ifndef LOSE32
	  if (errno == EAGAIN)
	    return -1;
	  if (errno != EINTR)
	    message(src, msg_unix_error);
#endif
    }
    }
  return src->recv.buffer[src->recv.bufpos++];
}
开发者ID:mszczodrak,项目名称:otf,代码行数:34,代码来源:serialsource.c



注:本文中的serial_read函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ serial_send函数代码示例发布时间:2022-05-30
下一篇:
C++ serial_puts函数代码示例发布时间:2022-05-30
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap