您当前的位置:首页 > IT编程 > C++
| C语言 | Java | VB | VC | python | Android | TensorFlow | C++ | oracle | 学术与代码 | cnn卷积神经网络 | gnn | 图像修复 | Keras | 数据集 | Neo4j | 自然语言处理 | 深度学习 | 医学CAD | 医学影像 | 超参数 | pointnet | pytorch | 异常检测 | Transformers | 情感分类 | 知识图谱 |

自学教程:C++ tty_read函数代码示例

51自学网 2021-06-03 09:00:35
  C++
这篇教程C++ tty_read函数代码示例写得很实用,希望能帮到您。

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

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

示例1: tty_read_timeout

/* * On success return number of bytes received */int tty_read_timeout(unsigned char *buf, size_t size, int timeout){	int rc;	bool rd = FALSE;		tty_status = TTY_SUCCESS;	DEB((D_TTYIO, "tty_read_timeout: want read %d byte(s), timeout = %d", size, timeout));		if( timeout > 0 )	{		if( (rc = tty_select(&rd, NULL, timeout)) < 0 )			return rc;				if( rd )		{			if( (rc = tty_read(buf, size)) == 0 )				return TTY_ERROR;						return rc;		}				return TTY_TIMEOUT;	}	return tty_read(buf, size);}
开发者ID:askovpen,项目名称:binkleyforce,代码行数:30,


示例2: tty_write

bool SynscanMount::Goto(double ra,double dec){    char str[20];    int n1,n2;    int numread, bytesWritten, bytesRead;    //  not fleshed in yet    tty_write(PortFD,"Ka",2, &bytesWritten);  //  test for an echo    tty_read(PortFD,str,2,2, &bytesRead);  //  Read 2 bytes of response    if(str[1] != '#') {        //  this is not a correct echo        //  so we are not talking to a mount properly        return false;    }    //  Ok, mount is alive and well    //  so, lets format up a goto command    n1=ra*0x1000000/24;    n2=dec*0x1000000/360;    n1=n1<<8;    n2=n2<<8;    sprintf((char *)str,"r%08X,%08X",n1,n2);    tty_write(PortFD,str,18, &bytesWritten);    TrackState=SCOPE_SLEWING;    numread=tty_read(PortFD,str,1,60, &bytesRead);    if (bytesRead!=1||str[0]!='#')    {        if (isDebug())            IDLog("Timeout waiting for scope to complete slewing.");        return false;    }    return true;}
开发者ID:LabAixBidouille,项目名称:Indi,代码行数:33,


示例3: serial_read

static intserial_read(device_t dev, char *buf, size_t *nbyte, int blkno){	struct serial_softc *sc = device_private(dev);	return tty_read(&sc->tty, buf, nbyte);}
开发者ID:AdamRLukaitis,项目名称:prex,代码行数:7,


示例4: scpi_write

/* * writes count bytes from the buffer (buf) to the  * scpi instrument referred to by the descriptor *scpi. * * On  success, the number of bytes written is returned * (zero indicates nothing was written). * On error, -1 is returned */static ssize_t scpi_write(struct scpi_instrument *scpi, const void *buf, size_t count){	int retval = -1;	if (!scpi->network && !scpi->serial)		return -ENOENT;	if (scpi->network && !scpi->control_socket)		return -ENXIO;	else if (scpi->network) {		retval = send(scpi->control_socket, buf, count, 00);		if (retval == count && memchr(buf, '?', count)) {			memset(scpi->response, 0, SOCKETS_BUFFER_SIZE);			scpi_network_read(scpi);		}	}	if (scpi->serial && scpi->ttyfd < 0)		return -ENXIO;	else if (scpi->serial) {		retval  = write(scpi->ttyfd, buf, count);		if (retval == count) {			if (memchr(buf, '?', count)) {				memset(scpi->response, 0, SOCKETS_BUFFER_SIZE);				tty_read(scpi);			}		} else			fprintf(stderr, "SCPI:%s tty didn't write the entire buffer/n", __func__);		tcflush(scpi->ttyfd, TCIOFLUSH);	}	return retval;}
开发者ID:AlphaCafe,项目名称:iio-oscilloscope,代码行数:43,


示例5: tcflush

bool MoonLite::Ack(){    int nbytes_written=0, nbytes_read=0, rc=-1;    char errstr[MAXRBUF];    char resp[5];    short pos=-1;    tcflush(PortFD, TCIOFLUSH);    if ( (rc = tty_write(PortFD, ":GP#", 4, &nbytes_written)) != TTY_OK)    {        tty_error_msg(rc, errstr, MAXRBUF);        DEBUGF(INDI::Logger::DBG_ERROR, "updatePostion error: %s.", errstr);        return false;    }    if ( (rc = tty_read(PortFD, resp, 5, 2, &nbytes_read)) != TTY_OK)    {        tty_error_msg(rc, errstr, MAXRBUF);        DEBUGF(INDI::Logger::DBG_ERROR, "updatePostion error: %s.", errstr);        return false;    }    rc = sscanf(resp, "%hX#", &pos);    if (rc > 0)        return true;    else        return false;}
开发者ID:mp77,项目名称:indi,代码行数:31,


示例6: tty_input

void tty_input (HANDLE fd, short events, void *udata){	char		ch;	unsigned	n;	ARG_NOT_USED (fd)	ARG_NOT_USED (events)	ARG_NOT_USED (udata)	DDS_continue ();	n = tty_read (&ch, 1);	if (!n)		return;	if (full) {		printf ("/a");		return;	}	tty_queue [wp++] = ch;	if (wp >= MAX_QUEUE)		wp = 0;	empty = 0;	if (wp == rp)		full = 1;}
开发者ID:FlavioFalcao,项目名称:tinq-core,代码行数:26,


示例7: DEBUGF

int ioptronHC8406::slewioptronHC8406(){    DEBUGF(DBG_SCOPE, "<%s>", __FUNCTION__);    char slewNum[2];    int error_type;    int nbytes_write = 0, nbytes_read = 0;    DEBUGF(DBG_SCOPE, "CMD <%s>", ":MS#");    if ((error_type = tty_write_string(PortFD, ":MS#", &nbytes_write)) != TTY_OK)        return error_type;    error_type = tty_read(PortFD, slewNum, 1, 3, &nbytes_read);    if (nbytes_read < 1)    {        DEBUGF(DBG_SCOPE, "RES ERROR <%d>", error_type);        return error_type;    }    /* We don't need to read the string message, just return corresponding error code */    tcflush(PortFD, TCIFLUSH);    DEBUGF(DBG_SCOPE, "RES <%c>", slewNum[0]);    return slewNum[0];}
开发者ID:rrogge,项目名称:indi,代码行数:27,


示例8: DEBUGF

bool LX200SS2000PC::setCalenderDate(int year, int month, int day) {  // This method differs from the setCalenderDate function in lx200driver.cpp  // in that it reads and checks the complete respons from the SkySensor2000PC.  // In addition, this method only sends the date when it differs from the date  // of the SkySensor2000PC because the resulting update of the planetary data  // takes quite some time.  bool result = true;  int  ss_year, ss_month, ss_day;  const bool send_to_skysensor = (!getCalenderDate(ss_year,ss_month,ss_day) || year != ss_year || month != ss_month || day != ss_day );  DEBUGF(INDI::Logger::DBG_DEBUG, "LX200SS2000PC::setCalenderDate(): Driver date %02d/%02d/%02d, SS2000PC date %02d/%02d/%02d.", month, day, year, ss_month, ss_day, ss_year);  if (send_to_skysensor) {    char buffer[64];    int  nbytes_written = 0;    snprintf(buffer, sizeof(buffer), ":SC %02d/%02d/%02d#", month, day, (year%100));    result = ( tty_write_string(PortFD, buffer, &nbytes_written) == TTY_OK && nbytes_written == strlen(buffer) );    if (result) {      int nbytes_read = 0;      result = ( tty_read(PortFD, buffer, 1, ShortTimeOut, &nbytes_read) == TTY_OK && nbytes_read == 1 && buffer[0] == '1' );          if (result) {	if (tty_read_section(PortFD, buffer, '#', ShortTimeOut, &nbytes_read) != TTY_OK || strncmp(buffer,"Updating        planetary data#",24) != 0) {	  DEBUGF(INDI::Logger::DBG_ERROR, "LX200SS2000PC::setCalenderDate(): Received unexpected first line '%s'.", buffer);	  result = false;	}	else if (tty_read_section(PortFD, buffer, '#', LongTimeOut, &nbytes_read) != TTY_OK && strncmp(buffer,"                              #",24) != 0) {	  DEBUGF(INDI::Logger::DBG_ERROR, "LX200SS2000PC::setCalenderDate(): Received unexpected second line '%s'.", buffer);	  result = false;	}      }    }  }  return result;}
开发者ID:daggerstab,项目名称:indi,代码行数:32,


示例9: tcflush

bool SynscanDriver::sendCommand(const char * cmd, char * res, int cmd_len, int res_len){    int nbytes_written = 0, nbytes_read = 0, rc = -1;    tcflush(PortFD, TCIOFLUSH);    if (cmd_len > 0)    {        char hex_cmd[SYN_RES * 3] = {0};        hexDump(hex_cmd, cmd, cmd_len);        LOGF_DEBUG("CMD <%s>", hex_cmd);        rc = tty_write(PortFD, cmd, cmd_len, &nbytes_written);    }    else    {        LOGF_DEBUG("CMD <%s>", cmd);        rc = tty_write_string(PortFD, cmd, &nbytes_written);    }    if (rc != TTY_OK)    {        char errstr[MAXRBUF] = {0};        tty_error_msg(rc, errstr, MAXRBUF);        LOGF_ERROR("Serial write error: %s.", errstr);        return false;    }    if (res == nullptr)        return true;    if (res_len > 0)        rc = tty_read(PortFD, res, res_len, SYN_TIMEOUT, &nbytes_read);    else        rc = tty_nread_section(PortFD, res, SYN_RES, SYN_DEL, SYN_TIMEOUT, &nbytes_read);    if (rc != TTY_OK)    {        char errstr[MAXRBUF] = {0};        tty_error_msg(rc, errstr, MAXRBUF);        LOGF_ERROR("Serial read error: %s.", errstr);        return false;    }    if (res_len > 0)    {        char hex_res[SYN_RES * 3] = {0};        hexDump(hex_res, res, res_len);        LOGF_DEBUG("RES <%s>", hex_res);    }    else    {        LOGF_DEBUG("RES <%s>", res);    }    tcflush(PortFD, TCIOFLUSH);    return true;}
开发者ID:azwing,项目名称:indi,代码行数:58,


示例10: stop_ieqpro_motion

bool stop_ieqpro_motion(int fd, IEQ_DIRECTION dir){    char cmd[16];    int errcode = 0;    char errmsg[MAXRBUF];    char response[8];    int nbytes_read=0;    int nbytes_written=0;    switch (dir)    {        case IEQ_N:        case IEQ_S:            strcpy(cmd, ":qD#");            break;       case IEQ_W:       case IEQ_E:            strcpy(cmd, ":qR#");            break;    }    DEBUGFDEVICE(ieqpro_device, INDI::Logger::DBG_DEBUG, "CMD (%s)", cmd);    if (ieqpro_simulation)    {        strcpy(response, "1");        nbytes_read = strlen(response);    }    else    {        if ( (errcode = tty_write(fd, cmd, strlen(cmd), &nbytes_written)) != TTY_OK)        {            tty_error_msg(errcode, errmsg, MAXRBUF);            DEBUGFDEVICE(ieqpro_device, INDI::Logger::DBG_ERROR, "%s", errmsg);            return false;        }        if ( (errcode = tty_read(fd, response, 1, IEQPRO_TIMEOUT, &nbytes_read)))        {            tty_error_msg(errcode, errmsg, MAXRBUF);            DEBUGFDEVICE(ieqpro_device, INDI::Logger::DBG_ERROR, "%s", errmsg);            return false;        }    }    if (nbytes_read > 0)    {      response[nbytes_read] = '/0';      DEBUGFDEVICE(ieqpro_device, INDI::Logger::DBG_DEBUG, "RES (%s)", response);      tcflush(fd, TCIFLUSH);      return true;    }    DEBUGFDEVICE(ieqpro_device, INDI::Logger::DBG_ERROR, "Only received #%d bytes, expected 1.", nbytes_read);    return false;}
开发者ID:daggerstab,项目名称:indi,代码行数:58,


示例11: tty_rename

static inttty_rename(ARCHD *arcn){	char tmpname[PAXPATHLEN+2];	int res;	/*	 * prompt user for the replacement name for a file, keep trying until	 * we get some reasonable input. Archives may have more than one file	 * on them with the same name (from updates etc). We print verbose info	 * on the file so the user knows what is up.	 */	tty_prnt("/nATTENTION: %s interactive file rename operation./n", argv0);	for (;;) {		ls_tty(arcn);		tty_prnt("Input new name, or a /"./" to keep the old name, ");		tty_prnt("or a /"return/" to skip this file./n");		tty_prnt("Input > ");		if (tty_read(tmpname, sizeof(tmpname)) < 0)			return(-1);		if (strcmp(tmpname, "..") == 0) {			tty_prnt("Try again, illegal file name: ../n");			continue;		}		if (strlen(tmpname) > PAXPATHLEN) {			tty_prnt("Try again, file name too long/n");			continue;		}		break;	}	/*	 * empty file name, skips this file. a "." leaves it alone	 */	if (tmpname[0] == '/0') {		tty_prnt("Skipping file./n");		return(1);	}	if ((tmpname[0] == '.') && (tmpname[1] == '/0')) {		tty_prnt("Processing continues, name unchanged./n");		return(0);	}	/*	 * ok the name changed. We may run into links that point at this	 * file later. we have to remember where the user sent the file	 * in order to repair any links.	 */	tty_prnt("Processing continues, name changed to: %s/n", tmpname);	res = add_name(arcn->name, arcn->nlen, tmpname);	arcn->nlen = strlcpy(arcn->name, tmpname, sizeof(arcn->name));	if (arcn->nlen >= sizeof(arcn->name))		arcn->nlen = sizeof(arcn->name) - 1; /* XXX truncate? */	if (res < 0)		return(-1);	return(0);}
开发者ID:MirBSD,项目名称:opax,代码行数:58,


示例12: set_ieqpro_dec

bool set_ieqpro_dec(int fd, double dec){    char cmd[32];    char sign;    int errcode = 0;    char errmsg[MAXRBUF];    char response[8];    int nbytes_read=0;    int nbytes_written=0;    if (dec >= 0)        sign = '+';    else        sign = '-';    // Send as 0.01 arcseconds resolution    int ieqValue = fabs(dec) * 60 * 60 * 100;    snprintf(cmd, 32, ":Sd%c%08d#", sign, ieqValue);    DEBUGFDEVICE(ieqpro_device, INDI::Logger::DBG_DEBUG, "CMD (%s)", cmd);    if (ieqpro_simulation)    {        simData.dec = dec;        strcpy(response, "1");        nbytes_read = strlen(response);    }    else    {        if ( (errcode = tty_write(fd, cmd, strlen(cmd), &nbytes_written)) != TTY_OK)        {            tty_error_msg(errcode, errmsg, MAXRBUF);            DEBUGFDEVICE(ieqpro_device, INDI::Logger::DBG_ERROR, "%s", errmsg);            return false;        }        if ( (errcode = tty_read(fd, response, 1, IEQPRO_TIMEOUT, &nbytes_read)))        {            tty_error_msg(errcode, errmsg, MAXRBUF);            DEBUGFDEVICE(ieqpro_device, INDI::Logger::DBG_ERROR, "%s", errmsg);            return false;        }    }    if (nbytes_read > 0)    {      response[nbytes_read] = '/0';      DEBUGFDEVICE(ieqpro_device, INDI::Logger::DBG_DEBUG, "RES (%s)", response);      tcflush(fd, TCIFLUSH);      return true;    }    DEBUGFDEVICE(ieqpro_device, INDI::Logger::DBG_ERROR, "Only received #%d bytes, expected 1.", nbytes_read);    return false;}
开发者ID:daggerstab,项目名称:indi,代码行数:57,


示例13: get_ieqpro_guide_rate

bool get_ieqpro_guide_rate(int fd, double *rate){    char cmd[] = ":AG#";    int errcode = 0;    char errmsg[MAXRBUF];    char response[8];    int nbytes_read=0;    int nbytes_written=0;    DEBUGFDEVICE(ieqpro_device, INDI::Logger::DBG_DEBUG, "CMD (%s)", cmd);    if (ieqpro_simulation)    {        snprintf(response, 8, "%3d#", (int) (simData.guide_rate * 100));        nbytes_read = strlen(response);    }    else    {        if ( (errcode = tty_write(fd, cmd, strlen(cmd), &nbytes_written)) != TTY_OK)        {            tty_error_msg(errcode, errmsg, MAXRBUF);            DEBUGFDEVICE(ieqpro_device, INDI::Logger::DBG_ERROR, "%s", errmsg);            return false;        }        if ( (errcode = tty_read(fd, response, 4, IEQPRO_TIMEOUT, &nbytes_read)))        {            tty_error_msg(errcode, errmsg, MAXRBUF);            DEBUGFDEVICE(ieqpro_device, INDI::Logger::DBG_ERROR, "%s", errmsg);            return false;        }    }    if (nbytes_read > 0)    {      response[nbytes_read] = '/0';      DEBUGFDEVICE(ieqpro_device, INDI::Logger::DBG_DEBUG, "RES (%s)", response);      int rate_num;      if (sscanf(response, "%d#", &rate_num) > 0)      {          *rate = rate_num / 100.0;          tcflush(fd, TCIFLUSH);          return true;      }      else      {          DEBUGFDEVICE(ieqpro_device, INDI::Logger::DBG_ERROR, "Error: Malformed result (%s).", response);          return false;      }    }    DEBUGFDEVICE(ieqpro_device, INDI::Logger::DBG_ERROR, "Only received #%d bytes, expected 1.", nbytes_read);    return false;}
开发者ID:daggerstab,项目名称:indi,代码行数:57,


示例14: slew_ieqpro

bool slew_ieqpro(int fd){    char cmd[] = ":MS#";    int errcode = 0;    char errmsg[MAXRBUF];    char response[8];    int nbytes_read=0;    int nbytes_written=0;    DEBUGFDEVICE(ieqpro_device, INDI::Logger::DBG_DEBUG, "CMD (%s)", cmd);    if (ieqpro_simulation)    {        simInfo.systemStatus = ST_SLEWING;        strcpy(response, "1");        nbytes_read = strlen(response);    }    else    {        if ( (errcode = tty_write(fd, cmd, strlen(cmd), &nbytes_written)) != TTY_OK)        {            tty_error_msg(errcode, errmsg, MAXRBUF);            DEBUGFDEVICE(ieqpro_device, INDI::Logger::DBG_ERROR, "%s", errmsg);            return false;        }        if ( (errcode = tty_read(fd, response, 1, IEQPRO_TIMEOUT, &nbytes_read)))        {            tty_error_msg(errcode, errmsg, MAXRBUF);            DEBUGFDEVICE(ieqpro_device, INDI::Logger::DBG_ERROR, "%s", errmsg);            return false;        }    }    if (nbytes_read > 0)    {      response[nbytes_read] = '/0';      DEBUGFDEVICE(ieqpro_device, INDI::Logger::DBG_DEBUG, "RES (%s)", response);      if (!strcmp(response, "1"))      {          tcflush(fd, TCIFLUSH);          return true;      }      else      {          DEBUGDEVICE(ieqpro_device, INDI::Logger::DBG_ERROR, "Requested object is below horizon.");          tcflush(fd, TCIFLUSH);          return false;      }    }    DEBUGFDEVICE(ieqpro_device, INDI::Logger::DBG_ERROR, "Only received #%d bytes, expected 1.", nbytes_read);    return false;}
开发者ID:daggerstab,项目名称:indi,代码行数:56,


示例15: set_ieqpro_utc_offset

bool set_ieqpro_utc_offset(int fd, double offset){    char cmd[16];    char sign;    int errcode = 0;    char errmsg[MAXRBUF];    char response[8];    int nbytes_read=0;    int nbytes_written=0;    if (offset >= 0)        sign = '+';    else        sign = '-';    int offset_minutes = fabs(offset) * 60.0;    snprintf(cmd, 16, ":SG%c%03d#", sign, offset_minutes);    DEBUGFDEVICE(ieqpro_device, INDI::Logger::DBG_DEBUG, "CMD (%s)", cmd);    if (ieqpro_simulation)    {        strcpy(response, "1");        nbytes_read = strlen(response);    }    else    {        if ( (errcode = tty_write(fd, cmd, strlen(cmd), &nbytes_written)) != TTY_OK)        {            tty_error_msg(errcode, errmsg, MAXRBUF);            DEBUGFDEVICE(ieqpro_device, INDI::Logger::DBG_ERROR, "%s", errmsg);            return false;        }        if ( (errcode = tty_read(fd, response, 1, IEQPRO_TIMEOUT, &nbytes_read)))        {            tty_error_msg(errcode, errmsg, MAXRBUF);            DEBUGFDEVICE(ieqpro_device, INDI::Logger::DBG_ERROR, "%s", errmsg);            return false;        }    }    if (nbytes_read > 0)    {      response[nbytes_read] = '/0';      DEBUGFDEVICE(ieqpro_device, INDI::Logger::DBG_DEBUG, "RES (%s)", response);      tcflush(fd, TCIFLUSH);      return true;    }    DEBUGFDEVICE(ieqpro_device, INDI::Logger::DBG_ERROR, "Only received #%d bytes, expected 1.", nbytes_read);    return false;}
开发者ID:daggerstab,项目名称:indi,代码行数:55,


示例16: memset

/************************************************************************************ ** ***********************************************************************************/IPState BaaderDome::ControlShutter(ShutterOperation operation){    int nbytes_written = 0, nbytes_read = 0, rc = -1;    char errstr[MAXRBUF];    char cmd[DOME_BUF];    char resp[DOME_BUF];    memset(cmd, 0, sizeof(cmd));    if (operation == SHUTTER_OPEN)    {        targetShutter = operation;        strncpy(cmd, "d#opeshut", DOME_CMD);    }    else    {        targetShutter = operation;        strncpy(cmd, "d#closhut", DOME_CMD);    }    tcflush(PortFD, TCIOFLUSH);    if (!sim && (rc = tty_write(PortFD, cmd, DOME_CMD, &nbytes_written)) != TTY_OK)    {        tty_error_msg(rc, errstr, MAXRBUF);        DEBUGF(INDI::Logger::DBG_ERROR, "%s ControlDomeShutter error: %s.", cmd, errstr);        return IPS_ALERT;    }    DEBUGF(INDI::Logger::DBG_DEBUG, "CMD (%s)", cmd);    if (sim)    {        simShutterTimer = SIM_SHUTTER_TIMER;        strncpy(resp, "d#gotmess", DOME_CMD);        nbytes_read = DOME_CMD;    }    else if ((rc = tty_read(PortFD, resp, DOME_CMD, DOME_TIMEOUT, &nbytes_read)) != TTY_OK)    {        tty_error_msg(rc, errstr, MAXRBUF);        DEBUGF(INDI::Logger::DBG_ERROR, "ControlDomeShutter error: %s.", errstr);        return IPS_ALERT;    }    resp[nbytes_read] = '/0';    DEBUGF(INDI::Logger::DBG_DEBUG, "RES (%s)", resp);    if (strcmp(resp, "d#gotmess") == 0)    {        shutterState = simShutterStatus = SHUTTER_MOVING;        return IPS_BUSY;    }    return IPS_ALERT;}
开发者ID:rrogge,项目名称:indi,代码行数:58,


示例17: DEBUGFDEVICE

bool Driver::sendCommand(const char *command, int count, char *response, uint8_t timeout, uint8_t debugLog){    int errCode = 0;    int nbytes_read    = 0;    int nbytes_written = 0;    char errMsg[MAXRBUF];    char res[IOP_BUFFER] = {0};    DEBUGFDEVICE(m_DeviceName, debugLog, "CMD <%s>", command);    if (m_Simulation)        return true;    tcflush(PortFD, TCIOFLUSH);    if ((errCode = tty_write(PortFD, command, strlen(command), &nbytes_written)) != TTY_OK)    {        tty_error_msg(errCode, errMsg, MAXRBUF);        DEBUGFDEVICE(m_DeviceName, INDI::Logger::DBG_ERROR, "Write Command Error: %s", errMsg);        return false;    }    if (count == 0)        return true;    if (count == -1)        errCode = tty_read_section(PortFD, res, '#', timeout, &nbytes_read);    else        errCode = tty_read(PortFD, res, count, timeout, &nbytes_read);    if (errCode != TTY_OK)    {        tty_error_msg(errCode, errMsg, MAXRBUF);        DEBUGFDEVICE(m_DeviceName, INDI::Logger::DBG_ERROR, "Read Command Error: %s", errMsg);        return false;    }    // Remove the extra #    if (count == -1)        res[nbytes_read-1] = 0;    DEBUGFDEVICE(m_DeviceName, debugLog, "RES <%s>", res);    tcflush(PortFD, TCIOFLUSH);    // Copy response to buffer    if (response)        strncpy(response, res, IOP_BUFFER);    if (count == -1 || (count == 1 && res[0] == '1') || count == nbytes_read)        return true;    return false;}
开发者ID:djibb,项目名称:indi,代码行数:54,


示例18: IDLog

int NFocus::ReadResponse(char *buf, int nbytes, int timeout){  char nfocus_error[MAXRBUF];  int bytesRead = 0;  int totalBytesRead = 0;  int err_code;  if (isDebug())      IDLog("##########################################/n");  while (totalBytesRead < nbytes)  {      if ( (err_code = tty_read(PortFD, buf+totalBytesRead, nbytes-totalBytesRead, timeout, &bytesRead)) != TTY_OK)      {              tty_error_msg(err_code, nfocus_error, MAXRBUF);              if (isDebug())              {                  IDLog("TTY error detected: %s/n", nfocus_error);                  IDMessage(getDeviceName(), "TTY error detected: %s/n", nfocus_error);              }              return -1;      }      if (isDebug())        IDLog("Bytes Read: %d/n", bytesRead);      if (bytesRead < 0 )      {          if (isDebug())            IDLog("Bytesread < 1/n");          return -1;      }        totalBytesRead += bytesRead;    }    tcflush(PortFD, TCIOFLUSH);   if (isDebug())   {       fprintf(stderr, "READ : (%s,%d), %d/n", buf, 9, totalBytesRead) ;        fprintf(stderr, "READ : ") ;        for(int i=0; i < 9; i++)        {         fprintf(stderr, "0x%2x ", (unsigned char)buf[i]) ;        }        fprintf(stderr, "/n") ;   }  return 9;}
开发者ID:A-j-K,项目名称:indi,代码行数:53,


示例19: ReadResponse_MaxDomeII

/*	Reads a response from MAX DOME II	It verifies message sintax and checksum		@param fd File descriptor	@param cMessage Pointer to a buffer to receive the message	@return 0 if message is Ok. -1 if no response or no start caracter found. -2 invalid declared message length. -3 message too short. -4 checksum error*/int ReadResponse_MaxDomeII(int fd, char *cMessage){	int nBytesRead;	int nLen = MAX_BUFFER;	int nErrorType = TTY_OK;	char nChecksum;		*cMessage = 0x00;	cMessage[13] = 0x00;	// Look for a 0x01 starting character, until time out occurs or MAX_BUFFER characters was read	while (*cMessage != 0x01 && nErrorType == TTY_OK)	{		nErrorType = tty_read(fd, cMessage, 1, MAXDOME_TIMEOUT, &nBytesRead);		//fprintf(stderr,"/nIn 1: %ld %02x/n", nBytesRead, (int)cMessage[0]);	}		if (nErrorType != TTY_OK || *cMessage != 0x01)		return -1;		// Read message length 	nErrorType = tty_read(fd, cMessage + 1, 1, MAXDOME_TIMEOUT, &nBytesRead);		//fprintf(stderr,"/nInLen: %d/n",(int) cMessage[1]);	if (nErrorType != TTY_OK || cMessage[1] < 0x02 || cMessage[1] > 0x0E)		return -2;		nLen = cMessage[1];	// Read the rest of the message	nErrorType = tty_read(fd, cMessage + 2, nLen, MAXDOME_TIMEOUT, &nBytesRead);		//fprintf(stderr,"/nIn: %s/n", cMessage);	if (nErrorType != TTY_OK || nBytesRead != nLen)		return -3;		nChecksum = checksum_MaxDomeII(cMessage, nLen + 2);	if (nChecksum != 0x00)		return -4;			return 0;}
开发者ID:daggerstab,项目名称:indi,代码行数:48,


示例20: tty_read

void tty_read(void *data,size_t size,int timeout){    const uint8_t *start = data;    size_t left = size;    while (left) {	fd_set set;	struct timeval to = { .tv_sec = timeout, .tv_usec = 0 };	int res;	ssize_t got;	FD_ZERO(&set);	FD_SET(fd,&set);	res = select(fd+1,&set,NULL,NULL,&to);	if (res < 0) {	    perror("select");	    exit(1);	}	if (!res) {	    fprintf(stderr,"timeout reading from programmer/n");	    exit(1);	}	got = read(fd,data,left);	if (got < 0) {	    perror("read from serial port");	    exit(1);	}	if (!got) {	    perror("EOF on serial port");	    exit(1);	}	left -= got;	data += got;    }    if (verbose > 2) {	int i;	fprintf(stderr,"TTY READ:");	for (i = 0; i != size; i++)	    fprintf(stderr," %02x",start[i]);	putc('/n',stderr);    }}uint8_t tty_read_byte(int timeout){    uint8_t c;    tty_read(&c,1,timeout);    return c;}
开发者ID:steve-m,项目名称:m8cutils,代码行数:52,


示例21: ttym_read

static ssize_t ttym_read(dev_cookie _cookie, void *buf, off_t pos, ssize_t len){	tty_master_cookie *cookie = (tty_master_cookie *)_cookie;	ssize_t ret;	TRACE(("ttym_read: tty %d cookie %p, buf %p, len %d/n", cookie->tty->index, cookie, buf, len));	ret = tty_read(cookie->tty, buf, len, ENDPOINT_MASTER_READ);	TRACE(("ttym_read: tty %d returns %d/n", cookie->tty->index, ret));	return ret;}
开发者ID:HTshandou,项目名称:newos,代码行数:13,


示例22: memset

bool SynscanMount::Park(){    char str[20];    int numread, bytesWritten, bytesRead;    memset(str,0,3);    tty_write(PortFD,"Ka",2, &bytesWritten);  //  test for an echo    tty_read(PortFD,str,2,2, &bytesRead);  //  Read 2 bytes of response    if(str[1] != '#')    {        //  this is not a correct echo        //  so we are not talking to a mount properly        return false;    }    //  Now we stop tracking    tty_write(PortFD,"T0",2, &bytesWritten);    numread=tty_read(PortFD,str,1,60, &bytesRead);    if (bytesRead!=1||str[0]!='#')    {        if (isDebug())            IDLog("Timeout waiting for scope to stop tracking.");        return false;    }    //sprintf((char *)str,"b%08X,%08X",0x0,0x40000000);    tty_write(PortFD,"B0000,4000",10, &bytesWritten);    numread=tty_read(PortFD,str,1,60, &bytesRead);    if (bytesRead!=1||str[0]!='#')    {        if (isDebug())            IDLog("Timeout waiting for scope to respond to park.");        return false;    }    TrackState=SCOPE_PARKING;    IDMessage(getDeviceName(),"Parking Telescope...");    return true;}
开发者ID:LabAixBidouille,项目名称:Indi,代码行数:39,


示例23: get_term_title

void get_term_title(char *title){	int n;	static char buffer[BUFSIZ];	char temp[20];	snprintf(temp,sizeof(temp),"/033[%dt",21);	raw_print(temp);	n = tty_read(buffer,sizeof(buffer));	if(n==0)		goto read_failure;	if(n==1)	{		int n2 = tty_read(buffer+1,sizeof(buffer)-1);		if(n2==0)			goto read_failure;		n+=n2;	}//	n+= tty_read(buffer+1,sizeof(buffer)-1);	while( !(buffer[n-2] == '/033' && buffer[n-1] == '//') ) {//		n += tty_read(buffer+n,sizeof(buffer)-n);		int n2 = tty_read(buffer+1,sizeof(buffer)-1);		if(n2==0)			goto read_failure;		n+=n2;	}	buffer[n-2]= '/0';	snprintf((char *)title,sizeof(buffer),"%s",buffer+3);	return;read_failure:	sprintf((char *)title,"xterm");}
开发者ID:mvd7793,项目名称:RED-SIREN,代码行数:38,


示例24: tcflush

bool MoonLite::Ack(){    int nbytes_written = 0, nbytes_read = 0, rc = -1;    char errstr[MAXRBUF];    char resp[5]={0};    short pos = -1;    tcflush(PortFD, TCIOFLUSH);    //Try to request the position of the focuser    //Test for success on transmission and response    //If either one fails, try again, up to 3 times, waiting 1 sec each time    //If that fails, then return false.    int numChecks = 0;    bool success = false;    while(numChecks < 3 && !success)    {        numChecks++;        sleep(1); //wait 1 second between each test.        bool transmissionSuccess = (rc = tty_write(PortFD, ":GP#", 4, &nbytes_written)) == TTY_OK;        if(!transmissionSuccess)        {            tty_error_msg(rc, errstr, MAXRBUF);            LOGF_ERROR("Handshake Attempt %i, tty transmission error: %s.", numChecks, errstr);        }        bool responseSuccess = (rc = tty_read(PortFD, resp, 5, MOONLITE_TIMEOUT, &nbytes_read)) == TTY_OK;        if(!responseSuccess)        {            tty_error_msg(rc, errstr, MAXRBUF);            LOGF_ERROR("Handshake Attempt %i, updatePosition response error: %s.", numChecks, errstr);        }        success = transmissionSuccess && responseSuccess;    }    if(!success)    {        LOG_INFO("Handshake failed after 3 attempts");        return false;    }    tcflush(PortFD, TCIOFLUSH);    rc = sscanf(resp, "%hX#", &pos);    return rc > 0;}
开发者ID:djibb,项目名称:indi,代码行数:50,


示例25: set_ieqpro_daylight_saving

bool set_ieqpro_daylight_saving(int fd, bool enabled){    char cmd[16];    int errcode = 0;    char errmsg[MAXRBUF];    char response[8];    int nbytes_read=0;    int nbytes_written=0;    if (enabled)        strcpy(cmd, ":SDS1#");    else        strcpy(cmd, ":SDS0#");    DEBUGFDEVICE(ieqpro_device, INDI::Logger::DBG_DEBUG, "CMD (%s)", cmd);    if (ieqpro_simulation)    {        strcpy(response, "1");        nbytes_read = strlen(response);    }    else    {        if ( (errcode = tty_write(fd, cmd, strlen(cmd), &nbytes_written)) != TTY_OK)        {            tty_error_msg(errcode, errmsg, MAXRBUF);            DEBUGFDEVICE(ieqpro_device, INDI::Logger::DBG_ERROR, "%s", errmsg);            return false;        }        if ( (errcode = tty_read(fd, response, 1, IEQPRO_TIMEOUT, &nbytes_read)))        {            tty_error_msg(errcode, errmsg, MAXRBUF);            DEBUGFDEVICE(ieqpro_device, INDI::Logger::DBG_ERROR, "%s", errmsg);            return false;        }    }    if (nbytes_read > 0)    {      response[nbytes_read] = '/0';      DEBUGFDEVICE(ieqpro_device, INDI::Logger::DBG_DEBUG, "RES (%s)", response);      tcflush(fd, TCIFLUSH);      return true;    }    DEBUGFDEVICE(ieqpro_device, INDI::Logger::DBG_ERROR, "Only received #%d bytes, expected 1.", nbytes_read);    return false;}
开发者ID:daggerstab,项目名称:indi,代码行数:50,


示例26: DEBUG

/************************************************************************************ ** ***********************************************************************************/IPState BaaderDome::MoveAbs(double az){    int nbytes_written = 0, nbytes_read = 0, rc = -1;    char errstr[MAXRBUF];    char cmd[DOME_BUF];    char resp[DOME_BUF];    if (status == DOME_UNKNOWN)    {        DEBUG(INDI::Logger::DBG_WARNING, "Dome is not calibrated. Please calibrate dome before issuing any commands.");        return IPS_ALERT;    }    targetAz = az;    snprintf(cmd, DOME_BUF, "d#azi%04d", MountAzToDomeAz(targetAz));    tcflush(PortFD, TCIOFLUSH);    if (!sim && (rc = tty_write(PortFD, cmd, DOME_CMD, &nbytes_written)) != TTY_OK)    {        tty_error_msg(rc, errstr, MAXRBUF);        DEBUGF(INDI::Logger::DBG_ERROR, "%s MoveAbsDome error: %s.", cmd, errstr);        return IPS_ALERT;    }    DEBUGF(INDI::Logger::DBG_DEBUG, "CMD (%s)", cmd);    if (sim)    {        strncpy(resp, "d#gotmess", DOME_CMD);        nbytes_read = DOME_CMD;    }    else if ((rc = tty_read(PortFD, resp, DOME_CMD, DOME_TIMEOUT, &nbytes_read)) != TTY_OK)    {        tty_error_msg(rc, errstr, MAXRBUF);        DEBUGF(INDI::Logger::DBG_ERROR, "MoveAbsDome error: %s.", errstr);        return IPS_ALERT;    }    resp[nbytes_read] = '/0';    DEBUGF(INDI::Logger::DBG_DEBUG, "RES (%s)", resp);    if (strcmp(resp, "d#gotmess") == 0)        return IPS_BUSY;    return IPS_ALERT;}
开发者ID:rrogge,项目名称:indi,代码行数:52,


示例27: set_ieqpro_guide_rate

bool set_ieqpro_guide_rate(int fd, double rate){    char cmd[16];    int errcode = 0;    char errmsg[MAXRBUF];    char response[8];    int nbytes_read=0;    int nbytes_written=0;    int num = rate * 100;    snprintf(cmd, 16, ":RG%03d#", num );    DEBUGFDEVICE(ieqpro_device, INDI::Logger::DBG_DEBUG, "CMD (%s)", cmd);    if (ieqpro_simulation)    {        simData.guide_rate = rate;        strcpy(response, "1");        nbytes_read = strlen(response);    }    else    {        if ( (errcode = tty_write(fd, cmd, strlen(cmd), &nbytes_written)) != TTY_OK)        {            tty_error_msg(errcode, errmsg, MAXRBUF);            DEBUGFDEVICE(ieqpro_device, INDI::Logger::DBG_ERROR, "%s", errmsg);            return false;        }        if ( (errcode = tty_read(fd, response, 1, IEQPRO_TIMEOUT, &nbytes_read)))        {            tty_error_msg(errcode, errmsg, MAXRBUF);            DEBUGFDEVICE(ieqpro_device, INDI::Logger::DBG_ERROR, "%s", errmsg);            return false;        }    }    if (nbytes_read > 0)    {      response[nbytes_read] = '/0';      DEBUGFDEVICE(ieqpro_device, INDI::Logger::DBG_DEBUG, "RES (%s)", response);      tcflush(fd, TCIFLUSH);      return true;    }    DEBUGFDEVICE(ieqpro_device, INDI::Logger::DBG_ERROR, "Only received #%d bytes, expected 1.", nbytes_read);    return false;}
开发者ID:daggerstab,项目名称:indi,代码行数:49,



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


C++ tty_register_driver函数代码示例
C++ tty_puts函数代码示例
万事OK自学网:51自学网_软件自学网_CAD自学网自学excel、自学PS、自学CAD、自学C语言、自学css3实例,是一个通过网络自主学习工作技能的自学平台,网友喜欢的软件自学网站。