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

C++ serial_write函数代码示例

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

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



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

示例1: TFI_CJ_clean

void   TFI_CJ_clean ( )
{
	#ifdef OLDCJTFI
	byte command[20];	
	int ret = 0;
	int i = 0;
	memset ( command , 0x00 , 20 ) ;
	command[1] = DISP_OUT_LED;   //命令字
	for (i=3;i<15;++i) 
	{           //数据,清除显示时数据内容为空
        command[i] = ' ';
    }
    command[15] = 0;
	BBC(command);
	ret = serial_write(LED_COM,command  ,18) ;
	#else
	byte command[20];
	int ret = 0;
	memset ( command , 0x00 , 0x00 ) ;
	//0x97	清屏	AA 04 97 BB
	//0x98	清屏,语音:谢谢,祝您一路平安!	AA 04 98 BB
	//0x99	您好	AA 04 99 BB
	//0xA0	谢谢	AA 04 A0 BB
	//0xA1	欢迎光临	AA 04 A1 BB
	//0xA2	别客气	AA 04 A2 BB
	//0xA3	请慢走	AA 04 A3 BB
	//0xA4	走好	AA 04 A4 BB
	//0xA5	再见	AA 04 A5 BB
	command[0] = 0xAA;
	command[1] = 0x04;
	command[2] = 0x97;
	command[3] = 0xBB;
	ret = serial_write(LED_COM,command  ,4) ;
	#endif
}
开发者ID:moyuanming,项目名称:XJZRYK,代码行数:35,代码来源:i_dev_TFI_CJ.c


示例2: msr_iso_write

int
msr_iso_write(int fd, msr_tracks_t * tracks)
{
	int i;
	uint8_t buf[4];

	msr_cmd (fd, MSR_CMD_WRITE);

	buf[0] = MSR_ESC;
	buf[1] = MSR_RW_START;
	serial_write (fd, buf, 2);

	for (i = 0; i < MSR_MAX_TRACKS; i++) {
		buf[0] = MSR_ESC;
		buf[1] = i + 1;
		serial_write (fd, buf, 2);
		serial_write (fd, tracks->msr_tracks[i].msr_tk_data,
			tracks->msr_tracks[i].msr_tk_len);
	}

	buf[0] = MSR_RW_END;
	buf[1] = MSR_FS;
	serial_write (fd, buf, 2);

	serial_readchar (fd, &buf[0]);
	serial_readchar (fd, &buf[0]);

	if (buf[0] != MSR_STS_OK)
		warnx("write failed");

	return (0);
}
开发者ID:BGBEAST,项目名称:libmsr,代码行数:32,代码来源:msr206.c


示例3: serial_println

void serial_println(uint8_t port, String output) {
  for (uint8_t i=0; i<output.length(); i++){
    serial_write(port, output[i]);
  }
  serial_write(port, '\n');
  serial_activate(port);
}
开发者ID:FabianViermetz,项目名称:RC_essentials-Arduino,代码行数:7,代码来源:basic_uart.cpp


示例4: ulcd_blit

int ulcd_blit(ulcd_dev *dev,
              uint16_t x, uint16_t y,
              uint16_t w, uint16_t h,
              const char* data) {

    char buf[10];

    buf[0] = 0x49;
    buf[1] = x >> 8;
    buf[2] = x & 0xFF;
    buf[3] = y >> 8;
    buf[4] = y & 0xFF;
    buf[5] = w >> 8;
    buf[6] = w & 0xFF;
    buf[7] = h >> 8;
    buf[8] = h & 0xFF;
    buf[9] = 0x10;

    serial_write(dev->port, buf, 10);
    serial_write(dev->port, data, w*h*2);

    if(!check_result(dev, "Error while blitting.")) {
        return 0;
    }
    return 1;
}
开发者ID:katajakasa,项目名称:libulcd32pt,代码行数:26,代码来源:ulcd_driver.c


示例5: ulcd_draw_text

int ulcd_draw_text(ulcd_dev *dev,
                   const char* text,
                   int x, int y,
                   int font,
                   uint16_t color) {

    // Init
    int textlen = strlen(text);
    char buf[10];

    // Commands
    buf[0] = 0x53;
    buf[1] = x >> 8;
    buf[2] = x & 0xFF;
    buf[3] = y >> 8;
    buf[4] = y & 0xFF;
    buf[5] = font & 0xFF;
    buf[6] = color >> 8;
    buf[7] = color & 0xFF;
    buf[8] = 0x01;
    buf[9] = 0x01;

    // Send data
    serial_write(dev->port, buf, 10);
    serial_write(dev->port, text, textlen);
    write_char(dev, 0x00);

    // Check results
    if(!check_result(dev, "Text drawing failed.")) {
        return 0;
    }
    return 1;
}
开发者ID:katajakasa,项目名称:libulcd32pt,代码行数:33,代码来源:ulcd_driver.c


示例6: save

static gboolean
save(QahiraFormat *self, cairo_surface_t *surface, GOutputStream *stream,
		GCancellable *cancel, GError **error)
{
	struct Private *priv = GET_PRIVATE(self);
	gboolean status = TRUE;
	guchar *data = qahira_format_surface_get_data(self, surface);
	if (!data) {
		g_set_error(error, QAHIRA_ERROR, QAHIRA_ERROR_FAILURE,
				Q_("serial: surface data is NULL"));
		goto error;
	}
	priv->header.stride = qahira_format_surface_get_stride(self, surface);
	if (0 > priv->header.stride) {
		g_set_error(error, QAHIRA_ERROR, QAHIRA_ERROR_FAILURE,
				Q_("serial: invalid stride"));
		goto error;
	}
	qahira_surface_size(surface, &priv->header.width,
			&priv->header.height);
	priv->header.content = cairo_surface_get_content(surface);
	status = serial_write(self, stream, cancel, (gpointer)&priv->header,
			sizeof(priv->header), error);
	if (!status) {
		goto error;
	}
	status = serial_write(self, stream, cancel, data,
			priv->header.stride * priv->header.height, error);
exit:
	return status;
error:
	status = FALSE;
	goto exit;
}
开发者ID:msteinert,项目名称:qahira,代码行数:34,代码来源:serial.c


示例7: IRqueue

void IRqueue(char *param_fname,int fd)
{
    FILE *fp=NULL;
    FILE *fpq=NULL;
	int res,i;
    char buffer[255] = {0};  //   buffer
        //check filename if exist
        printf(" Entering Queue mode: play commands from file\n");

        fpq=fopen(param_fname,"r");
        if (fpq==NULL)
            printf(" Queue command file does not exist. \n");
        else {
            char cmdfile[255];
            int len = 0;
            while (fgets(cmdfile, sizeof(cmdfile), fpq )){
                len = strlen(cmdfile);
                if( cmdfile[len-1] == '\n' )
                    cmdfile[len-1] = 0;
                fp=fopen(cmdfile,"rb");
                if (fp==NULL) {
                    printf("    Comand file %s does not exist. \n", cmdfile);
                    break;
                }
                else{
                    printf("      Sending command file %s \n", cmdfile);
                    serial_write( fd, "\x03", 1);
                    int comsresult = 0;
                    while(!feof(fp)) {
                       if ((res=fread(&buffer,sizeof(unsigned char),sizeof(buffer),fp)) > 0) {
                            if (verbose){
                                printf(" ######Sending -%d- Bytes to IRToy...\n", res);
                                for(i=0;i<res;i++)
                                    printf(" %02X ",(uint8_t) buffer[i]);
                                printf("\n");
                            }
                            comsresult = serial_write( fd, buffer, res);
                            if (comsresult != res){
                                printf("## comms error bytes sent %d <> bytes supposed to be sent %d\n", comsresult, res);
                                serial_write( fd, "\xFF\xFF\x00\x00\x00\x00\x00", 7);       //trying to 'reset' IR Toy after error
                                exit(-1);
                            }
                            comsresult = 0;
#ifdef _WIN32
                            Sleep(500);                                       //wait 500 milliseconds - for comms to finish, else get errors. Could try smaller, but no delay always fails & locks up the ORToy!
#else
                            sleep(500);                                      //wait 500 milliseconds - for comms to finish, else get errors. Could try smaller, but no delay always fails & locks up the ORToy!
#endif
                       }
                    }
                    if(comsresult){
                        printf("comms error level 1 %d\n", comsresult);
                        break;
                    }
                }
                fclose(fp);
            }
        }
        fclose(fpq);
}
开发者ID:BrzTit,项目名称:dangerous-prototypes-open-hardware,代码行数:60,代码来源:queue.c


示例8: msr_raw_write

int
msr_raw_write(int fd, msr_tracks_t * tracks)
{
	int i;
	uint8_t buf[4];

	msr_cmd (fd, MSR_CMD_RAW_WRITE);


	buf[0] = MSR_ESC;
	buf[1] = MSR_RW_START;
	serial_write (fd, buf, 2);

	for (i = 0; i < MSR_MAX_TRACKS; i++) {
		buf[0] = MSR_ESC; /* start delimiter */
		buf[1] = i + 1; /* track number */
		buf[2] = tracks->msr_tracks[i].msr_tk_len; /* data length */
		serial_write (fd, buf, 3);
		serial_write (fd, tracks->msr_tracks[i].msr_tk_data,
			tracks->msr_tracks[i].msr_tk_len);
	}

	buf[0] = MSR_RW_END;
	buf[1] = MSR_FS;
	serial_write (fd, buf, 2);

	serial_readchar (fd, &buf[0]);
	serial_readchar (fd, &buf[0]);

	if (buf[0] != MSR_STS_OK)
		warnx("raw write failed");

	return (0);
}
开发者ID:BGBEAST,项目名称:libmsr,代码行数:34,代码来源:msr206.c


示例9: TFI_CJ_LedShow

void  TFI_CJ_LedShow (   int CarType , int charge )
{	
	#ifdef OLDCJTFI
	byte command[20];	
	int ret = 0;
	memset ( command , 0x00 , 20 ) ;
	command[1] = DISP_OUT_LED;   //命令字
	sprintf(&command[3],"% 4d% 4d% 4d",CarType,charge,0);
	if(charge)
	{
		command[15] = CarType;
	}
	BBC(command);
	ret = serial_write(LED_COM,command  ,18) ;
	#else
	byte command[20];	
	int ret = 0;
	memset ( command , 0x00 , 20 ) ;
	//金额显示器显示 1 型车 金额 25元 余额不显示,语音:1型车 缴费25元
	//AA 0B 95 31 30 32 35 30 30 30 BB 
	if(CarType>0&&CarType<10&&charge>0)
	{
		command[0] = 0xAA;
		command[1] = 0x0B;
		command[2] = 0x95;//95报价 95不报价
		sprintf(&command[3],"%d%03d%03d",CarType,charge,0);
		command[10] = 0xBB;
		ret = serial_write(LED_COM,command  ,11) ;
	}
	#endif	
}
开发者ID:moyuanming,项目名称:XJZRYK,代码行数:31,代码来源:i_dev_TFI_CJ.c


示例10: serial_write_hex_digit

static void serial_write_hex_digit(const uint32_t value) {
	if( value < 10 ) {
		serial_write((uint8_t)value + (uint8_t)'0');
	} else if( value < 16 ) {
		serial_write((uint8_t)(value - 10) + (uint8_t)'A');
	} else {
		serial_write('?');
	}
}
开发者ID:ChrisGammell,项目名称:daisho,代码行数:9,代码来源:serial.cpp


示例11: sendByte

inline void sendByte(unsigned char b)
{
	if (b==HDLC_frameFlag || b==HDLC_escapeFlag) 
	{
		serial_write(HDLC_escapeFlag);
		b ^= HDLC_escapeXOR;
	}
	serial_write(b);
}
开发者ID:LOGre,项目名称:fpgaSynths,代码行数:9,代码来源:linestream.c


示例12: loop

void loop()
{
serial_write("TEST\n\r");
if (serial_available()) {
					 serial_write("caractere");
					 caractere=serial_read();
					 serial_write(chaine);
					 serial_write(&caractere);
					 }
}
开发者ID:rafnixg,项目名称:pinguino-qubotic,代码行数:10,代码来源:simpleserial.c


示例13: gprs_uart_tx

static void gprs_uart_tx(uint8_t *pData, uint16_t len)
{
    DBG_ASSERT(pData != NULL __DBG_LINE);
    DBG_ASSERT(len != 0 __DBG_LINE);
    
#if GPRS_DEBUG
    serial_write(HAL_UART_2, pData, len);            
#endif  
    serial_write(HAL_UART_4, pData, len);
}
开发者ID:fuosck,项目名称:gprs-of-sim928a,代码行数:10,代码来源:gprs.c


示例14: acc_dump

void acc_dump(void) {
#ifdef ENABLE_DEBUG_SERIAL_DUMP
	serial_write_str("ACC: ");
	for (uint8_t i=0; i<3; i++) {
		serial_write_int(acc_data[i]);
		serial_write(' ');
	}
	serial_write('\n');
#endif
}
开发者ID:eqxro2001,项目名称:funkenschlag,代码行数:10,代码来源:acc.c


示例15: 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


示例16: sendFrame1

inline void sendFrame1(unsigned int value)
{
    unsigned int checksum=0xaa;
	serial_write(HDLC_frameFlag);
	
	sendByte(value);
	
	checksum ^= value;
	sendByte(checksum);
	
	serial_write(HDLC_frameFlag);
}
开发者ID:LOGre,项目名称:fpgaSynths,代码行数:12,代码来源:linestream.c


示例17: serial_proxy

void serial_proxy(int com) {
	console_write("Serial proxy on\n");
	while (1) {
		int len_a = serial_proxy_read(__console, __buf_a);
		int len_b = serial_proxy_read(com, __buf_b);

		if (len_a > 0) {
			serial_write(com, len_a, __buf_a);
		}
		if (len_b > 0) {
			serial_write(__console, len_b, __buf_b);
		} 
	}
}
开发者ID:henjuv,项目名称:ajtcl-s20c,代码行数:14,代码来源:esputil.c


示例18: PUMP_FlashErase

/*
 * erases OLS flash
 * pump_fd - fd of pump com port
 */
int PUMP_FlashErase(int pump_fd, int flashid) {
  static const uint8_t cmd[4] = {0x04, 0x00, 0x00, 0x00};
  uint8_t status;
  int res;
  int retry = 0;

  if (flashid < 0)
    return OLSRESULT_FLASHID_UNKNOWN;

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

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

    if (res == 1)
      return (status == 0x01) ? OLSRESULT_SUCCESS : OLSRESULT_ERASE_ERROR;

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

  return OLSRESULT_SUCCESS;
}
开发者ID:ied,项目名称:olswinloader,代码行数:32,代码来源:ols.cpp


示例19: 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


示例20: 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



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
C++ serialize函数代码示例发布时间:2022-05-30
下一篇:
C++ serial_setbrg函数代码示例发布时间: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