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.

prig port descriptor
txbuffercommand sequence to be sent
countnumber of bytes to send
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.


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

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

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

  int i, ret;

  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 
              p->post_write_date.tv_sec = 0;

  if (p->write_delay > 0) {
      for (i=0; i < count; i++) {
            ret = write(p->fd, 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;
  } else {
      ret = write(p->fd, 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) {

      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;
    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;

Here is the call graph for this function:

Here is the caller graph for this function:

Generated by  Doxygen 1.6.0   Back to index