本文整理汇总了C++中serial_close函数的典型用法代码示例。如果您正苦于以下问题:C++ serial_close函数的具体用法?C++ serial_close怎么用?C++ serial_close使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了serial_close函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: serial_flush
static GSList *mic_scan(const char *conn, const char *serialcomm, int idx)
{
struct sr_dev_inst *sdi;
struct drv_context *drvc;
struct dev_context *devc;
struct sr_probe *probe;
struct sr_serial_dev_inst *serial;
GSList *devices;
if (!(serial = sr_serial_dev_inst_new(conn, serialcomm)))
return NULL;
if (serial_open(serial, SERIAL_RDWR | SERIAL_NONBLOCK) != SR_OK)
return NULL;
drvc = mic_devs[idx].di->priv;
devices = NULL;
serial_flush(serial);
/* TODO: Query device type. */
// ret = mic_cmd_get_device_info(serial);
sr_info("Found device on port %s.", conn);
/* TODO: Fill in version from protocol response. */
if (!(sdi = sr_dev_inst_new(0, SR_ST_INACTIVE, mic_devs[idx].vendor,
mic_devs[idx].device, "")))
goto scan_cleanup;
if (!(devc = g_try_malloc0(sizeof(struct dev_context)))) {
sr_err("Device context malloc failed.");
goto scan_cleanup;
}
sdi->inst_type = SR_INST_SERIAL;
sdi->conn = serial;
sdi->priv = devc;
sdi->driver = mic_devs[idx].di;
if (!(probe = sr_probe_new(0, SR_PROBE_ANALOG, TRUE, "Temperature")))
goto scan_cleanup;
sdi->probes = g_slist_append(sdi->probes, probe);
if (mic_devs[idx].has_humidity) {
if (!(probe = sr_probe_new(1, SR_PROBE_ANALOG, TRUE, "Humidity")))
goto scan_cleanup;
sdi->probes = g_slist_append(sdi->probes, probe);
}
drvc->instances = g_slist_append(drvc->instances, sdi);
devices = g_slist_append(devices, sdi);
scan_cleanup:
serial_close(serial);
return devices;
}
开发者ID:russdill,项目名称:libsigrok,代码行数:58,代码来源:api.c
示例2: cleanup
void cleanup()
{
if(serial) {
serial_close(serial);
}
if(input != STDIN_FILENO) {
close(input);
}
}
开发者ID:samv,项目名称:reprap-utils,代码行数:9,代码来源:gcdump.c
示例3: fgInputDeviceClose
void fgInputDeviceClose( void )
{
if ( fgState.InputDevsInitialised )
{
serial_close ( dialbox_port );
dialbox_port = NULL;
fgState.InputDevsInitialised = GL_FALSE;
}
}
开发者ID:meshdgp,项目名称:MeshDGP,代码行数:9,代码来源:freeglut_input_devices.c
示例4: close
/*----------------------------------------------------------------------------*/
void DDAProtocol :: close()
{
m_log->Info("Port close");
if(m_serial > 0)
{
serial_close(m_serial);
m_serial = -1;
}
}
开发者ID:olegyurchenko,项目名称:dda-control,代码行数:10,代码来源:dda_protocol.cpp
示例5: gps_exit
void gps_exit (void) {
gps_thread_running = 0;
if ( sdl_thread_serial_gps != NULL ) {
printf("gps: wait thread\n");
SDL_WaitThread(sdl_thread_serial_gps, NULL);
sdl_thread_serial_gps = NULL;
}
serial_close(serial_fd_gps);
}
开发者ID:GuJiGuJi,项目名称:multigcs,代码行数:9,代码来源:my_gps.c
示例6: serial_dtr_off
void serial_dtr_off(void)
{
#if SERIALDEBUG > 0
write_log ("DTR off.\n");
#endif
dtr = 0;
if (currprefs.serial_demand)
serial_close ();
}
开发者ID:voorhees1979,项目名称:PUAE,代码行数:9,代码来源:serial.c
示例7: gcs_gps_exit
void gcs_gps_exit (void) {
if ( gcs_sdl_thread_serial_gps != NULL ) {
SDL_Log("gcs-gps: wait thread\n");
SDL_WaitThread(gcs_sdl_thread_serial_gps, NULL);
gcs_sdl_thread_serial_gps = NULL;
}
serial_close(gcs_serial_fd_gps);
gcs_serial_fd_gps = -1;
}
开发者ID:crashmatt,项目名称:multigcs,代码行数:9,代码来源:my_gps.c
示例8: switch
static GSList *scan(struct sr_dev_driver *di, GSList *options)
{
struct dev_context *devc;
struct sr_dev_inst *sdi;
struct sr_config *src;
struct sr_serial_dev_inst *serial;
GSList *l;
const char *conn, *serialcomm;
conn = serialcomm = NULL;
for (l = options; l; l = l->next) {
src = l->data;
switch (src->key) {
case SR_CONF_CONN:
conn = g_variant_get_string(src->data, NULL);
break;
case SR_CONF_SERIALCOMM:
serialcomm = g_variant_get_string(src->data, NULL);
break;
}
}
if (!conn)
return NULL;
if (!serialcomm)
serialcomm = SERIALCOMM;
/*
* We cannot scan for this device because it is write-only.
* So just check that the port parameters are valid and assume that
* the device is there.
*/
serial = sr_serial_dev_inst_new(conn, serialcomm);
if (serial_open(serial, SERIAL_RDWR) != SR_OK)
return NULL;
serial_flush(serial);
serial_close(serial);
sr_spew("Conrad DIGI 35 CPU assumed at %s.", conn);
sdi = g_malloc0(sizeof(struct sr_dev_inst));
sdi->status = SR_ST_INACTIVE;
sdi->vendor = g_strdup("Conrad");
sdi->model = g_strdup("DIGI 35 CPU");
devc = g_malloc0(sizeof(struct dev_context));
sr_sw_limits_init(&devc->limits);
sdi->inst_type = SR_INST_SERIAL;
sdi->conn = serial;
sdi->priv = devc;
sr_channel_new(sdi, 0, SR_CHANNEL_ANALOG, TRUE, "CH1");
return std_scan_complete(di, g_slist_append(NULL, sdi));
}
开发者ID:abraxa,项目名称:libsigrok,代码行数:56,代码来源:api.c
示例9: close_tty
static void
close_tty (void *ignore)
{
if (!remote_desc)
return;
serial_close (remote_desc);
remote_desc = NULL;
}
开发者ID:jichu4n,项目名称:prc-tools-remix,代码行数:10,代码来源:sparcl-tdep.c
示例10: sh3_close
static void
sh3_close (int quitting)
{
monitor_close (quitting);
if (parallel_in_use)
{
serial_close (parallel);
parallel_in_use = 0;
}
}
开发者ID:3125788,项目名称:android_toolchain_gdb,代码行数:10,代码来源:sh3-rom.c
示例11: serial_free
static void serial_free(void *handle)
{
Serial serial = (Serial) handle;
serial_close(serial);
bufchain_clear(&serial->output_data);
sfree(serial);
}
开发者ID:halcy,项目名称:PuTTY,代码行数:10,代码来源:uxser.c
示例12: 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
示例13: test_open_config_close
void test_open_config_close(void) {
serial_t serial;
uint32_t baudrate;
unsigned int databits;
serial_parity_t parity;
unsigned int stopbits;
bool xonxoff;
bool rtscts;
ptest();
passert(serial_open(&serial, device, 115200) == 0);
/* Check default settings */
passert(serial_get_baudrate(&serial, &baudrate) == 0);
passert(baudrate == 115200);
passert(serial_get_databits(&serial, &databits) == 0);
passert(databits == 8);
passert(serial_get_parity(&serial, &parity) == 0);
passert(parity == PARITY_NONE);
passert(serial_get_stopbits(&serial, &stopbits) == 0);
passert(stopbits == 1);
passert(serial_get_xonxoff(&serial, &xonxoff) == 0);
passert(xonxoff == false);
passert(serial_get_rtscts(&serial, &rtscts) == 0);
passert(rtscts == false);
/* Change some stuff around */
passert(serial_set_baudrate(&serial, 4800) == 0);
passert(serial_get_baudrate(&serial, &baudrate) == 0);
passert(baudrate == 4800);
passert(serial_set_baudrate(&serial, 9600) == 0);
passert(serial_get_baudrate(&serial, &baudrate) == 0);
passert(baudrate == 9600);
passert(serial_set_databits(&serial, 7) == 0);
passert(serial_get_databits(&serial, &databits) == 0);
passert(databits == 7);
passert(serial_set_parity(&serial, PARITY_ODD) == 0);
passert(serial_get_parity(&serial, &parity) == 0);
passert(parity == PARITY_ODD);
passert(serial_set_stopbits(&serial, 2) == 0);
passert(serial_get_stopbits(&serial, &stopbits) == 0);
passert(stopbits == 2);
passert(serial_set_xonxoff(&serial, true) == 0);
passert(serial_get_xonxoff(&serial, &xonxoff) == 0);
passert(xonxoff == true);
#if 0
passert(serial_set_rtscts(&serial, true) == 0);
passert(serial_get_rtscts(&serial, &rtscts) == 0);
passert(rtscts == true);
#endif
/* Test serial port may not support rtscts */
passert(serial_close(&serial) == 0);
}
开发者ID:HackLinux,项目名称:c-periphery,代码行数:55,代码来源:test_serial.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, *devices;
gint64 start;
const char *conn;
unsigned char c;
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;
devices = NULL;
start = g_get_monotonic_time();
while (g_get_monotonic_time() - start < MAX_SCAN_TIME_US) {
if (serial_read_nonblocking(serial, &c, 1) == 1 && c == 0xa5) {
/* Found one. */
sdi = g_malloc0(sizeof(struct sr_dev_inst));
sdi->status = SR_ST_INACTIVE;
sdi->vendor = g_strdup("CEM");
sdi->model = g_strdup("DT-885x");
devc = g_malloc0(sizeof(struct dev_context));
devc->cur_mqflags = 0;
devc->recording = -1;
devc->cur_meas_range = 0;
devc->cur_data_source = DATA_SOURCE_LIVE;
devc->enable_data_source_memory = FALSE;
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");
devices = g_slist_append(devices, sdi);
break;
}
/* It takes about 1ms for a byte to come in. */
g_usleep(1000);
}
serial_close(serial);
return std_scan_complete(di, devices);
}
开发者ID:abraxa,项目名称:libsigrok,代码行数:55,代码来源:api.c
示例15: serial_select_result
static int serial_select_result(int fd, int event)
{
Serial serial;
char buf[4096];
int ret;
int finished = FALSE;
serial = find234(serial_by_fd, &fd, serial_find_by_fd);
if (!serial)
return 1; /* spurious event; keep going */
if (event == 1) {
ret = read(serial->fd, buf, sizeof(buf));
if (ret == 0) {
/*
* Shouldn't happen on a real serial port, but I'm open
* to the idea that there might be two-way devices we
* can treat _like_ serial ports which can return EOF.
*/
finished = TRUE;
} else if (ret < 0) {
#ifdef EAGAIN
if (errno == EAGAIN)
return 1; /* spurious */
#endif
#ifdef EWOULDBLOCK
if (errno == EWOULDBLOCK)
return 1; /* spurious */
#endif
perror("read serial port");
exit(1);
} else if (ret > 0) {
serial->inbufsize = from_backend(serial->frontend, 0, buf, ret);
serial_uxsel_setup(serial); /* might acquire backlog and freeze */
}
} else if (event == 2) {
/*
* Attempt to send data down the pty.
*/
serial_try_write(serial);
}
if (finished) {
serial_close(serial);
serial->finished = TRUE;
notify_remote_exit(serial->frontend);
}
return !finished;
}
开发者ID:halcy,项目名称:PuTTY,代码行数:54,代码来源:uxser.c
示例16: lua_serial_close
static int lua_serial_close(lua_State *L) {
serial_t *serial;
int ret;
serial = luaL_checkudata(L, 1, "periphery.Serial");
if ((ret = serial_close(serial)) < 0)
return lua_serial_error(L, ret, serial_errno(serial), "Error: %s", serial_errmsg(serial));
return 0;
}
开发者ID:coolwaterld,项目名称:lua-periphery,代码行数:11,代码来源:lua_serial.c
示例17: m600_initialize
int m600_initialize(const char* devname)
{
return 0;
on_error:
serial_close(&handle);
return -1;
}
开发者ID:HugoCunha,项目名称:picisp,代码行数:11,代码来源:m600.c
示例18: arduino_close
static void arduino_close(PROGRAMMER * pgm)
{
#ifdef CUSTOMER_REST_PIN
gpio_set_value(pgm->reset_pin,LOW);
gpio_unexport(pgm->reset_pin);
#else
serial_set_dtr_rts(&pgm->fd, 0);
#endif
serial_close(&pgm->fd);
pgm->fd.ifd = -1;
}
开发者ID:Pillar1989,项目名称:Grove-for-linux,代码行数:11,代码来源:arduino.c
示例19: serial_destroy
/*
* @brief Destroy serial object instance
* @param[in] obj pointer to object instance
* @retval None
*/
void
serial_destroy(serial *obj)
{
serial_private *prv;
prv = (serial_private *) obj->prv;
serial_close(obj);
free(prv);
return;
}
开发者ID:abit-corp,项目名称:phs-shield,代码行数:17,代码来源:serial_posix_api.c
示例20: dev_close
static int dev_close(struct sr_dev_inst *sdi)
{
struct sr_serial_dev_inst *serial;
serial = sdi->conn;
if (serial && serial->fd != -1) {
serial_close(serial);
sdi->status = SR_ST_INACTIVE;
}
return SR_OK;
}
开发者ID:adlerweb,项目名称:libsigrok,代码行数:12,代码来源:api.c
注:本文中的serial_close函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论