本文整理汇总了C++中serial_open函数的典型用法代码示例。如果您正苦于以下问题:C++ serial_open函数的具体用法?C++ serial_open怎么用?C++ serial_open使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了serial_open函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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;
}
示例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(); }
示例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;
}
示例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;
}
示例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);
}
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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);
}
}
示例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;
}
示例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;
}
示例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);
}
示例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));
}
示例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);
}