Ejemplo n.º 1
0
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;
}
Ejemplo n.º 2
0
void cleanup() 
{
	if(serial) {
		serial_close(serial);
	}
	if(input != STDIN_FILENO) {
		close(input);
	}
}
Ejemplo n.º 3
0
void fgInputDeviceClose( void )
{
    if ( fgState.InputDevsInitialised )
    {
        serial_close ( dialbox_port );
        dialbox_port = NULL;
        fgState.InputDevsInitialised = GL_FALSE;
    }
}
Ejemplo n.º 4
0
/*----------------------------------------------------------------------------*/
void DDAProtocol :: close()
{
  m_log->Info("Port close");
  if(m_serial > 0)
  {
    serial_close(m_serial);
    m_serial = -1;
  }
}
Ejemplo n.º 5
0
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);
}
Ejemplo n.º 6
0
void serial_dtr_off(void)
{
#if SERIALDEBUG > 0
    write_log ("DTR off.\n");
#endif
    dtr = 0;
    if (currprefs.serial_demand)
		serial_close ();
}
Ejemplo n.º 7
0
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;
}
Ejemplo n.º 8
0
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));
}
Ejemplo n.º 9
0
static void
close_tty (void *ignore)
{
  if (!remote_desc)
    return;

  serial_close (remote_desc);

  remote_desc = NULL;
}
Ejemplo n.º 10
0
dc_status_t
shearwater_common_close (shearwater_common_device_t *device)
{
	// Close the device.
	if (serial_close (device->port) == -1) {
		return DC_STATUS_IO;
	}

	return DC_STATUS_SUCCESS;
}
Ejemplo n.º 11
0
static void
sh3_close (int quitting)
{
  monitor_close (quitting);
  if (parallel_in_use)
    {
      serial_close (parallel);
      parallel_in_use = 0;
    }
}
Ejemplo n.º 12
0
Archivo: uxser.c Proyecto: halcy/PuTTY
static void serial_free(void *handle)
{
    Serial serial = (Serial) handle;

    serial_close(serial);

    bufchain_clear(&serial->output_data);

    sfree(serial);
}
Ejemplo n.º 13
0
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);
}
Ejemplo n.º 14
0
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);
}
Ejemplo n.º 15
0
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);
}
Ejemplo n.º 16
0
Archivo: uxser.c Proyecto: halcy/PuTTY
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;
}
Ejemplo n.º 17
0
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;
}
Ejemplo n.º 18
0
int m600_initialize(const char* devname)
{

  return 0;

 on_error:

  serial_close(&handle);

  return -1;
}
Ejemplo n.º 19
0
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;
}
Ejemplo n.º 20
0
/*
 * @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;
}
Ejemplo n.º 21
0
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;
}
Ejemplo n.º 22
0
/**
 * Standard serial driver dev_close() helper.
 *
 * This function can be used to implement the dev_close() driver API
 * callback in drivers that use a serial port.
 *
 * After closing the port, the status field of the given sdi is set
 * to SR_ST_INACTIVE.
 *
 * @retval SR_OK Success.
 */
SR_PRIV int std_serial_dev_close(struct sr_dev_inst *sdi)
{
	struct sr_serial_dev_inst *serial;

	serial = sdi->conn;
	if (serial && sdi->status == SR_ST_ACTIVE) {
		serial_close(serial);
		sdi->status = SR_ST_INACTIVE;
	}

	return SR_OK;
}
Ejemplo n.º 23
0
/*
 * Close interface
 */
void
stk500v2_close(const char *interface)
{
	if (interface[0] == '/') {
		if (stk_fsock >= 0)
			serial_close(stk_fsock);
	} else {
		if (stk_fsock >= 0)
			close(stk_fsock);
	}
	stk_fsock = -1;
}
Ejemplo n.º 24
0
int doNest() {
	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("do nest\n\r");
	return 1;
//	return CheckError();
}
Ejemplo n.º 25
0
int main(void){
  uint8_t c;
  char j[20];
  serial_open();
  while(1){
    c=readline(j,5);
    print (j);
  }
  serial_close();

  return 0;
} 
Ejemplo n.º 26
0
Archivo: amcc.c Proyecto: andersma/amcc
/*
 * destroy (program quits)
 */
void destroy (GtkWidget *widget, gpointer data)
{
	gtk_main_quit ();
	serial_close(&serial);
	mx_destroy(&mx);
	if (copter_normals)
		free((void*)copter_normals);
	if (copter_vertices)
		free((void*)copter_vertices);
	if (copter_colors)
		free((void*)copter_colors);
}
Ejemplo n.º 27
0
int MOVE_JOINT(int jo, float degree, int spd) {
	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; }
	char buffer[200];	
	sprintf(buffer, "do drive %d, %g, %d\n\r", jo, degree,spd);
	writeBuffer(buffer);
	return 0; }
Ejemplo n.º 28
0
int main(int argc, char **argv)
{
#ifndef _MSC_VER
	int fd;
	struct termios oldtio;
#else	/* _MSC_VER */
	HANDLE handle;
	DCB olddcb;
#endif	/* _MSC_VER */
	char *devname;

	if (argc == 2) {
		devname = argv[1];
	} else {
		printf("usage: %s <serial device>\n", argv[0]);
		return 1;
	}

#ifndef _MSC_VER
	if ((fd = serial_open(devname, &oldtio)) < 0) {
		perror(devname);
#else	/* _MSC_VER */
	if ((handle = serial_open(devname, &olddcb)) < 0) {
		pwinerror(devname);
#endif	/* _MSC_VER */
		return 1;
	}

#ifndef _MSC_VER
	main_loop(fd);

	serial_close(fd, &oldtio);
#else	/* _MSC_VER */
	main_loop(handle);

	serial_close(handle, &olddcb);
#endif	/* _MSC_VER */

	return 0;
}
Ejemplo n.º 29
0
static int hw_dev_close(struct sr_dev_inst *sdi)
{
	struct dev_context *devc;

	devc = sdi->priv;

	if (devc->serial && devc->serial->fd != -1) {
		serial_close(devc->serial);
		sdi->status = SR_ST_INACTIVE;
	}

	return SR_OK;
}
Ejemplo n.º 30
0
BOOL WINAPI win32_ctrlc_handler( DWORD type )
{
	fprintf( stderr, "\n" );
	g_emergency = 1;
#ifdef HAVE_SSM
	/* SSM終了処理 */
	if( !option( OPTION_WITHOUT_SSM ) )
		end_ypspurSSM(  );
#endif
	serial_close(  );
	
	return TRUE;
}