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

C++ serial_open函数代码示例

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

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



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

示例1: echodemo_init

/*模块初始化*/
static int echodemo_init()
{
    //char com_port[16];
	//long baud=9600;
    //rtdb_get_data_value_by_name("echodemo", "serialname", com_port);
    //rtdb_get_data_value_by_name("echodemo", "baud", &baud);
 
    //serial_id = serial_open(com_port, baud, SERIAL_PARITY_NO, 8, SERIAL_STOPBIT_ONE, 1000);
    //打开串口,COM1,9600,无校验,8位,一个停止位,通讯超时 100
    serial_id = serial_open("COM1", 9600, SERIAL_PARITY_NO, 8, SERIAL_STOPBIT_ONE, 100);
    if (serial_id < 0)
    {
        return 0;
    }


    return 1;
}
开发者ID:eseawind,项目名称:touchCabinet,代码行数:19,代码来源:echodemo.c


示例2: MOVETO_JOINTS

int MOVETO_JOINTS(float j1, float j2, float j3, float j4, float j5, float j6) {
	READ = 0;
	if (!OPEN_COM) {
		serial_close(hComm);
		if ((hComm=serial_open(0, 1, 1)) < 0) {
			cout<<"Error: cannot connect to Puma"<<endl;
			return -1; }
		else OPEN_COM = TRUE; }
	writeBuffer("point #x\n\r");	
	char buffer[200];	
	sprintf(buffer, "%g, %g, %g, %g, %g, %g\n\r\n\r", j1, j2 ,j3, j4, j5, j6);
	writeBuffer(buffer);
	CheckError();
	//Sleep(100);
	READ = 0;
	writeBuffer("do move #x\n\r");
	
	return CheckError(); }
开发者ID:crag47,项目名称:ECE4330_competition,代码行数:18,代码来源:Puma_OP.cpp


示例3: UNUSED_ARG

/*
 * Class:     ch_jodersky_flow_UnsafeSerial__
 * Method:    open
 * Signature: (Ljava/lang/String;IIZI)J
 */
JNIEXPORT jlong JNICALL Java_ch_jodersky_flow_UnsafeSerial_00024_open
(JNIEnv *env, jobject instance, jstring port_name, jint baud, jint char_size, jboolean two_stop_bits, jint parity)
{
	UNUSED_ARG(instance);

	const char *dev = (*env)->GetStringUTFChars(env, port_name, 0);
	struct serial_config* config;
	int r = serial_open(dev, baud, char_size, two_stop_bits, parity, &config);
	(*env)->ReleaseStringUTFChars(env, port_name, dev);

	if (r < 0) {
		check(env, r);
		return -E_IO;
	}

	long jpointer = (long) config;
	return (jlong) jpointer;
}
开发者ID:csarnevesht,项目名称:flow,代码行数:23,代码来源:flow_jni.c


示例4: serial_open

struct ols_t *OLS_Init(char *port, unsigned long speed)
{
	int fd;
	int ret;
	struct ols_t *ols;

	fd = serial_open(port);
	if (fd < 0) {
		fprintf(stderr, "Unable to open port '%s' \n", port);
		return NULL;
	}

	ret = serial_setup(fd, speed);
	if (ret) {
		fprintf(stderr, "Unable to set serial port parameters \n");
		return NULL;
	}

	ols = malloc(sizeof(struct ols_t));
	if (ols == NULL) {
		fprintf(stderr, "Error allocating memory \n");
		return NULL;
	}

	ols->fd = fd;
	ols->verbose = 0;
	ols->flash = NULL;

	ret = OLS_GetID(ols);
	if (ret) {
		fprintf(stderr, "Unable to read ID \n");
		free(ols);
		return NULL;
	}

	ret = OLS_GetFlashID(ols);
	if (ret) {
		fprintf(stderr, "Unable to read Flash ID \n");
		free(ols);
		return NULL;
	}

	return ols;
}
开发者ID:arthurlutz,项目名称:ols-fwloader,代码行数:44,代码来源:ols.c


示例5: main

int main(void)
{
	serial_open(19200, SERIAL_8N1);
	ADMUX |= (1<<REFS0);
	ADCSRA|=(1<<ADEN)|(1<<ADPS2)|(1<<ADPS1)|(1<<ADPS0);
	
	pinMode(53, OUTPUT);
	pinMode(13, OUTPUT);
	
	x_init();
	x_new(1, dimmer, 1);
	x_new(2, setDelay, 1);
	x_new(3, blinker, 1);
	
	while (1)
	{
		x_delay(500);
	}
}
开发者ID:STashakkori,项目名称:RoboLaserTag,代码行数:19,代码来源:LED_Dimmer_ACX.c


示例6: main

// usage: serial <dev>
int
main(int argc, char *argv[])
{
	struct sigaction act;
	int r;
	char buf[BUFSIZ];

	if (argc < 2) {
		fprintf(stderr, "usage: %s <device>\n", argv[0]);
		return EXIT_FAILURE;
	}

	fd = serial_open(argv[1]);

	act.sa_sigaction = sigint_action;
	act.sa_flags = SA_SIGINFO;

	if (sigaction(SIGINT, &act, NULL) < 0) {
		perror("sigaction");
		return EXIT_FAILURE;
	}

	static const char *msg = "SKINFO\r\n";
	r = serial_write(fd, msg, strlen(msg));

	r = serial_read(fd, buf, BUFSIZ);
	printf("%s", buf);

	memset(buf, 0, BUFSIZ);
	static const char *msg2 = "SKTABLE 6\r\n";
	r = serial_write(fd, msg2, strlen(msg2));

	do {
		memset(buf, 0, BUFSIZ);
		r = serial_read(fd, buf, BUFSIZ);
		printf("%s", buf);
	} while (r > 0);

exit:
	serial_close(fd);

	return EXIT_SUCCESS;
}
开发者ID:hro424,项目名称:experiment,代码行数:44,代码来源:main.c


示例7: serialMonitor

int serialMonitor()
{
	serial *s;
	while(serial_open(&s, serialPort, 9600)){	//打开串口出错,2秒后重试
		debug("open serial port error!\n");
		sleep(2);
	}

	struct HCSR501 hcsr501;
	while(1){
		while(get_hcsr501(s,&hcsr501)){	//读取串口数据出错,1秒后重试
			debug("hcsr501 error\n");
			sleep(1);
		}

		if(0 == hcsr501.state){	//HCSR501 :没反应
			usleep(500000);
			continue;
		}
		else if(1 == hcsr501.state){	//HCSR501:有反应
			debug("检测到异常!\n");
			while(get_switch(deviceId,sensorId,API_KEY,&sw)){
				debug("获取开关状态出错\n");
			}
			if(sw.state){
				debug("监控开关状态:开!\n");
				//feixin_count+=MSGRepeat;
				sign=1;
				debug("sign=%d\n",sign);
				sleep(30);	//检测到异常后标记发送飞信,然后30内不再检测
			}
			else{
				debug("监控开关状态:关!\n");
				sleep(3);
			}


		}

	}
	return 0;
}
开发者ID:ledudu,项目名称:Monitor,代码行数:42,代码来源:monitor.c


示例8: serial_fpga_prepare

static bool serial_fpga_prepare(__maybe_unused struct thr_info *thr)
{
	struct cgpu_info *serial_fpga = thr->cgpu;
	struct FPGA_INFO *info = serial_fpga->device_data;

	applog(LOG_DEBUG, "serial_fpga_prepare...");

	if (info->device_fd == -1) {
		
		applog(LOG_INFO, "Open Serial FPGA on %s", serial_fpga->device_path);
		info->device_fd = serial_open(serial_fpga->device_path, SERIAL_IO_SPEED, SERIAL_READ_TIMEOUT, false);
		if (unlikely(info->device_fd == -1)) {
			applog(LOG_ERR, "Failed to open Serial FPGA on %s",
				   serial_fpga->device_path);
			return false;
		}
	}
	
	return true;
}
开发者ID:sprocket-fpga,项目名称:cgminer_3.7.2_ztex,代码行数:20,代码来源:driver-serialfpga.c


示例9: main

int main(int argc, char *argv[])
{
	int serverfd = -1;
	serial_control_t ttyctl;

	printf("\n");
	program_printf("version %s\n", VERSION);

	parse_command_line(argc, argv);

	forward_test_case(0);

	ttyfd = serial_open(tty_name);
	memset(&ttyctl, 0, sizeof(serial_control_t));
	ttyctl.fd = ttyfd;

	if (access(DEFAULT_TTY_CONFIG, F_OK) != 0) {
		/* config file not exsit, just create it */		
		create_config_file(DEFAULT_TTY_CONFIG);
	}

	read_config_file(&ttyctl);
	if (serial_setup(&ttyctl) != EXIT_SUCCESS) {
		error_printf("serial_control error\n");
		return EXIT_FAILURE;
	}

	forward_test_case(1);

	if (forward_create_server(&serverfd) != 0) {
		error_printf("forward_create_server error\n");
		return EXIT_FAILURE;
	}

	if (forward_accept_client(serverfd, ttyfd) != 0) {
		error_printf("forward_accept_client error\n");
		return EXIT_FAILURE;
	}

	return EXIT_SUCCESS;
}
开发者ID:Bai-Yingjie,项目名称:morrowind,代码行数:41,代码来源:forward_server.c


示例10: main

int main(void)
{
    pinMode(LEDPIN,OUTPUT);
    pinMode(LEDPIN2,OUTPUT);
    cli();
    timer1_init();
	serial_open(19200, SERIAL_8N1);
    init_yield_array();
    //int t1 = kn_create_thread(tempHumidity);
    int t2 = kn_create_thread(blink);
    int t3 = kn_create_thread(blink_faster);

    while(1)
    {
        //kn_run_thread(t1);
        kn_run_thread(t2);
        kn_run_thread(t3);
        //init_yield_array();
        // if (tot_overflow >= 10) {
        //     blink();
        //     tot_overflow = 0;
        // }
        // if (tot_overflow2 >= 15) {
        //     blink_faster();
        //     tot_overflow2 = 0;
        // }
        //kn_run_thread(t1);
        //kn_run_thread(t2);
        //kn_run_thread(t3);
        //prints(" $$$$$$$$ ");
        //_delay_ms(800);
        //getTempHumidity();
        //prints((uint8_t*)TOTAL_RAM_SIZE);        
        // char buffer[16];
        // sprintf(buffer,"%d",(int)TOTAL_RAM_SIZE);
        // prints(buffer);
        //kn_create_thread(THREAD1, &threadB, false, NULL);
        // get_temp();
        // _delay_ms(800);
    }
}
开发者ID:scottshuffler,项目名称:AVRSM,代码行数:41,代码来源:main.c


示例11: serial_stdio

int serial_stdio(char *name)
{
  unsigned int subdevice;

  if (serial_open(name, &subdevice))
    return -1;

  // Nuke existing stdin, stdout, stderr

  device_unregister(0);
  device_unregister(1);
  device_unregister(2);

  // Register new stdin, stdout, stderr

  device_register_char_fd(0, subdevice, NULL, serial_read, NULL, serial_rxready);
  device_register_char_fd(1, subdevice, serial_write, NULL, serial_txready, NULL);
  device_register_char_fd(2, subdevice, serial_write, NULL, serial_txready, NULL);

  return 0;
}
开发者ID:zgramana,项目名称:arm-mcu,代码行数:21,代码来源:serial.c


示例12: sr_serial_dev_inst_new

static GSList *center_scan(const char *conn, const char *serialcomm, int idx)
{
	int i;
	struct sr_dev_inst *sdi;
	struct drv_context *drvc;
	struct dev_context *devc;
	struct sr_serial_dev_inst *serial;
	GSList *devices;

	serial = sr_serial_dev_inst_new(conn, serialcomm);

	if (serial_open(serial, SERIAL_RDWR) != SR_OK)
		return NULL;

	drvc = center_devs[idx].di->priv;
	devices = NULL;
	serial_flush(serial);

	sr_info("Found device on port %s.", conn);

	sdi = g_malloc0(sizeof(struct sr_dev_inst));
	sdi->status = SR_ST_INACTIVE;
	sdi->vendor = g_strdup(center_devs[idx].vendor);
	sdi->model = g_strdup(center_devs[idx].device);
	devc = g_malloc0(sizeof(struct dev_context));
	sdi->inst_type = SR_INST_SERIAL;
	sdi->conn = serial;
	sdi->priv = devc;
	sdi->driver = center_devs[idx].di;

	for (i = 0; i < center_devs[idx].num_channels; i++)
		sr_channel_new(sdi, i, SR_CHANNEL_ANALOG, TRUE, channel_names[i]);

	drvc->instances = g_slist_append(drvc->instances, sdi);
	devices = g_slist_append(devices, sdi);

	serial_close(serial);

	return devices;
}
开发者ID:anatol,项目名称:libsigrok,代码行数:40,代码来源:api.c


示例13: main

int main(int argc, char * argv[])
{
	int fd = -1;
	int serial;
	int ret;

	/* Default device selection per platform */
#ifdef __linux__
	char *device = "/dev/ttyUSB0";
#else
	char *device = "/dev/cuaU0";
#endif

	if (argv[1] != NULL)
		device = argv[1];
	else
		printf ("no device specified, defaulting to %s\n", device);

	serial = serial_open (device, &fd, MAK_BLOCKING, MAK_BAUD);

	if (serial == -1) {
		err(1, "Serial open of %s failed", device);
		exit(1);
	}
	printf("Ready to populate MAKStripe buffer...\n");
	ret = mak_successful_read(fd, MAKSTRIPE_TK_ALL);
	if (ret != 0) {
		printf("Unable to populate MAKStripe buffer!\n");
		exit(ret);
	}
	printf("Ready to clone buffer onto blank card...\n");
	ret = mak_successful_clone(fd);
	if (ret != 0) {
		printf("Unable to clone buffer onto blank card!\n");
		exit(ret);
	}
	serial_close (fd);
	exit(ret);
}
开发者ID:BGBEAST,项目名称:libmsr,代码行数:39,代码来源:makstripe-quick-clone.c


示例14: g_variant_get_string

static GSList *scan(struct sr_dev_driver *di, GSList *options)
{
	struct dev_context *devc;
	struct sr_config *src;
	struct sr_serial_dev_inst *serial;
	struct sr_dev_inst *sdi;
	GSList *l;
	const char *conn;

	conn = NULL;
	for (l = options; l; l = l->next) {
		src = l->data;
		if (src->key == SR_CONF_CONN)
			conn = g_variant_get_string(src->data, NULL);
	}
	if (!conn)
		return NULL;

	serial = sr_serial_dev_inst_new(conn, SERIALCOMM);

	if (serial_open(serial, SERIAL_RDONLY) != SR_OK)
		return NULL;

	sdi = g_malloc0(sizeof(struct sr_dev_inst));
	sdi->status = SR_ST_INACTIVE;
	sdi->vendor = g_strdup("PCE");
	sdi->model = g_strdup("PCE-322A");
	devc = g_malloc0(sizeof(struct dev_context));
	devc->cur_mqflags = SR_MQFLAG_SPL_TIME_WEIGHT_F | SR_MQFLAG_SPL_FREQ_WEIGHT_A;
	sdi->conn = sr_serial_dev_inst_new(conn, SERIALCOMM);
	sdi->inst_type = SR_INST_SERIAL;
	sdi->priv = devc;
	sr_channel_new(sdi, 0, SR_CHANNEL_ANALOG, TRUE, "SPL");

	serial_close(serial);

	return std_scan_complete(di, g_slist_append(NULL, sdi));
}
开发者ID:abraxa,项目名称:libsigrok,代码行数:38,代码来源:api.c


示例15: serial_posix_setup

int
serial_posix_setup(const char *device, int baud, serial **serialobj)
{

    /* open serial */
    *serialobj = serial_create();
    if (*serialobj == NULL) {
        printf("Unable to instantiate object: serial\n");
        goto fail;
    }

    if (serial_open(*serialobj, device) < 0) {
        printf("Unable to open serial devicer\n");
        goto fail;
    }

    if (serial_set_speed(*serialobj, baud) < 0) {
        printf("Unable to set serial speedr\n");
        goto fail;
    }

    if (serial_set_timeout(*serialobj, 10000) < 0) {
        printf("Unable to set timeoutr\n");
        goto fail;
    }

    if (serial_set_cts_flow(*serialobj, 1) < 0) {
        printf("Unable to set flow controlr\n");
        goto fail;
    }
    printf("%s is opened\n", device);
    return (0);

fail:
    serial_close(*serialobj);
    serial_destroy(*serialobj);
    return (1);
}
开发者ID:abit-corp,项目名称:phs-shield,代码行数:38,代码来源:serial_posix_api.c


示例16: hw_dev_open

static int hw_dev_open(int dev_index)
{
	struct sr_dev_inst *sdi;
	struct context *ctx;

	if (!(sdi = sr_dev_inst_get(genericdmm_dev_insts, dev_index))) {
		sr_err("genericdmm: sdi was NULL.");
		return SR_ERR_BUG;
	}

	if (!(ctx = sdi->priv)) {
		sr_err("genericdmm: sdi->priv was NULL.");
		return SR_ERR_BUG;
	}

	sr_dbg("genericdmm: Opening serial port '%s'.", ctx->serial->port);

	switch (ctx->profile->transport) {
	case DMM_TRANSPORT_USBHID:
		/* TODO */
		break;
	case DMM_TRANSPORT_SERIAL:
		/* TODO: O_NONBLOCK? */
		ctx->serial->fd = serial_open(ctx->serial->port, O_RDWR | O_NONBLOCK);
		if (ctx->serial->fd == -1) {
			sr_err("genericdmm: Couldn't open serial port '%s'.",
			       ctx->serial->port);
			return SR_ERR;
		}
		//	serial_set_params(ctx->serial->fd, 2400, 8, 0, 1, 2);
		break;
	default:
		sr_err("No transport set.");
	}

	return SR_OK;
}
开发者ID:jeras,项目名称:sigrok,代码行数:37,代码来源:api.c


示例17: main

int main(int argc, char **argv)
{
	int rc;
	int max_fd;
	fd_set rfds;
	int port;

	if (argc != 3) {
		printf("usage: %s <uart_dev> <uart_index>\n", argv[0]);
		printf("exampel:\n");
		printf("	uart_tgt_cfg /dev/ttyCm1Serial 2\n");
		exit(0);
	}
	port = rmm_cfg_get_port(IPMIUARTTGTCFG_PORT);
	if (libipmi_init(port) < 0)
		return -1;

	serial_index = atoi(argv[2]);

	serial_open(argv[1]);

	for (;;) {
		max_fd = -1;
		FD_ZERO(&rfds);

		libipmi_callback_selectfds(&rfds, &max_fd);

		rc = select(max_fd + 1, &rfds, NULL, NULL, NULL);
		if (rc <= 0)
			continue;

		libipmi_callback_processfds(&rfds);
	}

	return 0;
}
开发者ID:iamyaw,项目名称:IntelRackScaleArchitecture,代码行数:36,代码来源:uart_tgt_cfg.c


示例18: test_interactive

void test_interactive(void) {
    serial_t serial;
    uint8_t buf[] = "Hello World";

    ptest();

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

    printf("Starting interactive test. Get out your logic analyzer, buddy!\n");
    printf("Press enter to continue...\n");
    getc(stdin);

    printf("Press enter to start transfer...");
    getc(stdin);
    passert(serial_write(&serial, buf, sizeof(buf)) == sizeof(buf));
    printf("Serial transfer baudrate 4800, 8n1 occurred? y/n\n");
    passert(getc_yes());

    passert(serial_set_baudrate(&serial, 9600) == 0);

    printf("Press enter to start transfer...");
    getc(stdin);
    passert(serial_write(&serial, buf, sizeof(buf)) == sizeof(buf));
    printf("Serial transfer baudrate 9600, 8n1 occurred? y/n\n");
    passert(getc_yes());

    passert(serial_set_baudrate(&serial, 115200) == 0);

    printf("Press enter to start transfer...");
    getc(stdin);
    passert(serial_write(&serial, buf, sizeof(buf)) == sizeof(buf));
    printf("Serial transfer baudrate 115200, 8n1 occurred? y/n\n");
    passert(getc_yes());

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


示例19: open_tty

static struct serial *
open_tty (char *name)
{
  struct serial *desc;

  desc = serial_open (name);
  if (!desc)
    perror_with_name (name);

  if (baud_rate != -1)
    {
      if (serial_setbaudrate (desc, baud_rate))
	{
	  serial_close (desc);
	  perror_with_name (name);
	}
    }

  serial_raw (desc);

  serial_flush_input (desc);

  return desc;
}
开发者ID:jichu4n,项目名称:prc-tools-remix,代码行数:24,代码来源:sparcl-tdep.c


示例20: main

int main(int argc, char **argv)
{
	serial_handle_t handle = INVALID_HANDLE_VALUE;
	SerialOption opt;
	opt.port = COMPORT;
	opt.speed = 115200;
	if (serial_open(&opt, &handle)) {
		esp_run_command(handle, "AT+GMR", true);

		mac_address_t stmac;
		esp_get_st_mac_address(handle, &stmac);

		mac_address_t apmac;
		esp_get_ap_mac_address(handle, &apmac);

		puts("---");
		puts(("ST " + to_s(stmac)).c_str());
		puts(("AP " + to_s(apmac)).c_str());

		serial_close(handle, &opt);
	}

	return 0;
}
开发者ID:soramimi,项目名称:esp8266start,代码行数:24,代码来源:main.cpp



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

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