Logo Search packages:      
Sourcecode: hamlib version File versions  Download package

int HAMLIB_API read_block ( hamlib_port_t p,
char *  rxbuffer,
size_t  count 

Read bytes from an fd.

prig port descriptor
rxbufferbuffer to receive text
countnumber of bytes
count of bytes received

Read "num" bytes from "fd" and put results into an array of unsigned char pointed to by "rxbuffer"

Blocks on read until timeout hits.

It then reads "num" bytes into rxbuffer.

Actually, this function has nothing specific to serial comm, it could work very well also with any file handle, like a socket.

Definition at line 171 of file iofunc.c.

References dump_hex(), hamlib_port_t::fd, rig_debug(), RIG_DEBUG_ERR, RIG_DEBUG_TRACE, RIG_DEBUG_WARN, RIG_EIO, RIG_ETIMEOUT, and hamlib_port_t::timeout.

  fd_set rfds;
  struct timeval tv, tv_timeout;
  int rd_count, total_count = 0;
  int retval;

  FD_SET(p->fd, &rfds);

   * Wait up to timeout ms.
  tv_timeout.tv_sec = p->timeout/1000;
  tv_timeout.tv_usec = (p->timeout%1000)*1000;

  while (count > 0) {
            tv = tv_timeout;  /* select may have updated it */

            retval = select(p->fd+1, &rfds, NULL, NULL, &tv);
            if (retval == 0) {
                  dump_hex((unsigned char *) rxbuffer, total_count);
                  rig_debug(RIG_DEBUG_WARN, "read_block: timedout after %d chars\n",
                        return -RIG_ETIMEOUT;
            if (retval < 0) {
                  dump_hex((unsigned char *) rxbuffer, total_count);
                  rig_debug(RIG_DEBUG_ERR,"read_block: select error after %d chars: "
                                          "%s\n", total_count, strerror(errno));
                        return -RIG_EIO;

             * grab bytes from the rig
             * The file descriptor must have been set up non blocking.
            rd_count = read(p->fd, rxbuffer+total_count, count);
            if (rd_count < 0) {
                        rig_debug(RIG_DEBUG_ERR, "read_block: read failed - %s\n",
                        return -RIG_EIO;
            total_count += rd_count;
            count -= rd_count;

  rig_debug(RIG_DEBUG_TRACE,"RX %d bytes\n",total_count);
  dump_hex((unsigned char *) rxbuffer, total_count);
  return total_count;               /* return bytes count read */

Here is the call graph for this function:

Generated by  Doxygen 1.6.0   Back to index