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

int HAMLIB_API write_block ( hamlib_port_t p,
const char *  txbuffer,
size_t  count 
)

Write a block of characters to an fd.

Parameters:
p rig port descriptor
txbuffer command sequence to be sent
count number of bytes to send
Returns:
0 = OK, <0 = NOK
Write a block of count characters to port file descriptor, with a pause between each character if write_delay is > 0

The write_delay is for Yaesu type rigs..require 5 character sequence to be sent with 50-200msec between each char.

Also, post_write_delay is for some Yaesu rigs (eg: FT747) that get confused with sequential fast writes between cmd sequences.

input:

fd - file descriptor to write to txbuffer - pointer to a command sequence array count - count of byte to send from the txbuffer write_delay - write delay in ms between 2 chars post_write_delay - minimum delay between two writes post_write_date - timeval of last write

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 261 of file iofunc.c.

References dump_hex(), hamlib_port_t::post_write_date, hamlib_port_t::post_write_delay, rig_debug(), RIG_DEBUG_ERR, RIG_DEBUG_TRACE, RIG_EIO, RIG_OK, hamlib_port_t::tv_sec, hamlib_port_t::tv_usec, and hamlib_port_t::write_delay.

Referenced by tt565_set_mode(), tt565_set_ptt(), and tt565_transaction().

{
  int i, ret;

#ifdef WANT_NON_ACTIVE_POST_WRITE_DELAY
  if (p->post_write_date.tv_sec != 0) {
              signed int date_delay;      /* in us */
              struct timeval tv;

              /* FIXME in Y2038 ... */
              gettimeofday(&tv, NULL);
              date_delay = p->post_write_delay*1000 - 
                                    ((tv.tv_sec - p->post_write_date.tv_sec)*1000000 +
                                     (tv.tv_usec - p->post_write_date.tv_usec));
              if (date_delay > 0) {
                        /*
                         * optional delay after last write 
                         */
                        usleep(date_delay); 
              }
              p->post_write_date.tv_sec = 0;
  }
#endif

  if (p->write_delay > 0) {
      for (i=0; i < count; i++) {
            ret = port_write(p, txbuffer+i, 1);
            if (ret != 1) {
                  rig_debug(RIG_DEBUG_ERR,"%s():%d failed %d - %s\n", 
                        __FUNCTION__, __LINE__, ret, strerror(errno));
                  return -RIG_EIO;
      }
      usleep(p->write_delay*1000);
      }
  } else {
      ret = port_write(p, txbuffer, count);
      if (ret != count) {
            rig_debug(RIG_DEBUG_ERR,"%s():%d failed %d - %s\n", 
                  __FUNCTION__, __LINE__, ret, strerror(errno));
            return -RIG_EIO;
      }
  }
  
  if (p->post_write_delay > 0) {
#ifdef WANT_NON_ACTIVE_POST_WRITE_DELAY
#define POST_WRITE_DELAY_TRSHLD 10

      if (p->post_write_delay > POST_WRITE_DELAY_TRSHLD) {
            struct timeval tv;
            gettimeofday(&tv, NULL);
            p->post_write_date.tv_sec = tv.tv_sec;
            p->post_write_date.tv_usec = tv.tv_usec;
      }
      else
#endif
    usleep(p->post_write_delay*1000); /* optional delay after last write */
                           /* otherwise some yaesu rigs get confused */
                           /* with sequential fast writes*/
  }
  rig_debug(RIG_DEBUG_TRACE,"TX %d bytes\n",count);
  dump_hex((unsigned char *) txbuffer,count);
  
  return RIG_OK;
}


Generated by  Doxygen 1.6.0   Back to index