Example #1
0
/* ���M */
int serial_send(serial_t *serial, const char *data, int data_size)
{
  if (! serial_isConnected(serial)) {
    return SerialConnectionFail;
  }
  return write(serial->fd_, data, data_size);
}
Example #2
0
/* ��M */
int serial_recv(serial_t *serial, char* data, int data_size_max, int timeout)
{
  int filled;
  int read_n;
  int buffer_size;

  if (data_size_max <= 0) {
    return 0;
  }

  /* �����߂����P����������΁A�����o�� */
  filled = 0;
  if (serial->has_last_ch_ != False) {
    data[0] = serial->last_ch_;
    serial->has_last_ch_ = False;
    ++filled;
  }

  if (! serial_isConnected(serial)) {
    if (filled > 0) {
      return filled;
    }
    return SerialConnectionFail;
  }

  buffer_size = ring_size(&serial->ring_);
  read_n = data_size_max - filled;
  if (buffer_size < read_n) {
    // �����O�o�b�t�@���̃f�[�^�ő���Ȃ���΁A�f�[�^��ǂݑ���
    char buffer[RingBufferSize];
    int n = internal_receive(buffer,
                             ring_capacity(&serial->ring_) - buffer_size,
                             serial, 0);
    ring_write(&serial->ring_, buffer, n);
  }
  buffer_size = ring_size(&serial->ring_);

  // �����O�o�b�t�@���̃f�[�^��Ԃ�
  if (read_n > buffer_size) {
    read_n = buffer_size;
  }
  if (read_n > 0) {
    ring_read(&serial->ring_, &data[filled], read_n);
    filled += read_n;
  }

  // �f�[�^���^�C���A�E�g�t���œǂݏo��
  filled += internal_receive(&data[filled],
                             data_size_max - filled, serial, timeout);
  return filled;
}
Example #3
0
int serial_recv(serial_t *serial, char* data, int data_size_max, int timeout)
{
  int filled = 0;
  int buffer_size;
  int read_n;

  if (data_size_max <= 0) {
    return 0;
  }


  if (serial->has_last_ch_) {
    data[0] = serial->last_ch_;
    serial->has_last_ch_ = False;
    ++filled;
  }

  if (! serial_isConnected(serial)) {
    if (filled > 0) {
      return filled;
    }
    return SerialConnectionFail;
  }

  buffer_size = ring_size(&serial->ring_);
  read_n = data_size_max - filled;
  if (buffer_size < read_n) {

    char buffer[RingBufferSize];
    int n = internal_receive(buffer,
                             ring_capacity(&serial->ring_) - buffer_size,
                             serial, 0);
    ring_write(&serial->ring_, buffer, n);
  }
  buffer_size = ring_size(&serial->ring_);


  if (read_n > buffer_size) {
    read_n = buffer_size;
  }
  if (read_n > 0) {
    ring_read(&serial->ring_, &data[filled], read_n);
    filled += read_n;
  }


  filled += internal_receive(&data[filled],
                             data_size_max - filled, serial, timeout);
  return filled;
}
Example #4
0
int serial_send(serial_t *serial, const char *data, int data_size)
{
  DWORD n;

  if (data_size < 0) {
    return 0;
  }

  if (! serial_isConnected(serial)) {
    return SerialConnectionFail;
  }

  WriteFile(serial->hCom_, data, (DWORD)data_size, &n, NULL);
  return n;
}
Example #5
0
int urg_isConnected(const urg_t *urg)
{
  /* Return 0, if serial connectionis valid */
  return serial_isConnected(&urg->serial_);
}