Classes | Enumerations | Functions
urg_connection.h File Reference

通信の処理 More...

#include "urg_c/urg_serial.h"
#include "urg_c/urg_tcpclient.h"
Include dependency graph for urg_connection.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  urg_connection_t
 通信リソース More...
 

Enumerations

enum  { URG_CONNECTION_TIMEOUT = -1 }
 定数定義 More...
 
enum  urg_connection_type_t { URG_SERIAL, URG_ETHERNET }
 通信タイプ More...
 

Functions

void connection_close (urg_connection_t *connection)
 切断 More...
 
int connection_open (urg_connection_t *connection, urg_connection_type_t connection_type, const char *device, long baudrate_or_port)
 接続 More...
 
int connection_read (urg_connection_t *connection, char *data, int max_size, int timeout)
 受信 More...
 
int connection_readline (urg_connection_t *connection, char *data, int max_size, int timeout)
 改行文字までの受信 More...
 
int connection_set_baudrate (urg_connection_t *connection, long baudrate)
 
int connection_write (urg_connection_t *connection, const char *data, int size)
 送信 More...
 

Detailed Description

通信の処理

Author
Satofumi KAMIMURA
Id
urg_connection.h,v 1d233c7a2240 2011/02/19 03:08:45 Satofumi

Definition in file urg_connection.h.

Enumeration Type Documentation

anonymous enum

定数定義

Enumerator
URG_CONNECTION_TIMEOUT 

タイムアウトが発生したときの戻り値

Definition at line 24 of file urg_connection.h.

通信タイプ

Enumerator
URG_SERIAL 

シリアル, USB 接続

URG_ETHERNET 

イーサーネット接続

Definition at line 32 of file urg_connection.h.

Function Documentation

void connection_close ( urg_connection_t connection)

切断

デバイスとの接続を切断する。

Parameters
[in,out]connection通信リソース
1 connection_close(&connection);
See also
connection_open()

Definition at line 33 of file urg_connection.c.

int connection_open ( urg_connection_t connection,
urg_connection_type_t  connection_type,
const char *  device,
long  baudrate_or_port 
)

接続

指定されたデバイスに接続する。

Parameters
[in,out]connection通信リソース
[in]connection_type接続タイプ
[in]device接続名
[in]baudrate_or_portボーレート / ポート番号
Return values
0正常
<0エラー

connection_type には

  • URG_SERIAL ... シリアル通信
  • URG_ETHERNET .. イーサーネット通信

を指定する。

device, baudrate_or_port の指定は connection_type により指定できる値が異なる。 例えば、シリアル通信の場合は以下のようになる。

Example

1 connection_t connection;
2 if (! connection_open(&connection, URG_SERIAL, "COM1", 115200)) {
3  return 1;
4 }

また、イーサーネット通信の場合は以下のようになる。

Example

1 connection_t connection;
2 if (! connection_open(&connection, URG_ETHERNET, "192.168.0.10", 10940)) {
3  return 1;
4 }
See also
connection_close()

Definition at line 13 of file urg_connection.c.

int connection_read ( urg_connection_t connection,
char *  data,
int  max_size,
int  timeout 
)

受信

データを受信する。

Parameters
[in,out]connection通信リソース
[in]data受信データを格納するバッファ
[in]max_size受信データを格納できるバイト数
[in]timeoutタイムアウト時間 [msec]
Return values
>=0受信データ数
<0エラー

timeout に負の値を指定した場合、タイムアウトは発生しない。

1 文字も受信しなかったときは URG_CONNECTION_TIMEOUT を返す。

Example

1 enum {
2  BUFFER_SIZE = 256,
3  TIMEOUT_MSEC = 1000,
4 };
5 char buffer[BUFFER_SIZE];
6 n = connection_read(&connection, buffer, BUFFER_SIZE, TIMEOUT_MSEC);
See also
connection_write(), connection_readline()

Definition at line 80 of file urg_connection.c.

int connection_readline ( urg_connection_t connection,
char *  data,
int  max_size,
int  timeout 
)

改行文字までの受信

改行文字までのデータを受信する。

Parameters
[in,out]connection通信リソース
[in]data受信データを格納するバッファ
[in]max_size受信データを格納できるバイト数
[in]timeoutタイムアウト時間 [msec]
Return values
>=0受信データ数
<0エラー

data には、'\0' 終端された文字列が max_size を越えないバイト数だけ格納される。 つまり、受信できる文字のバイト数は、最大で max_size - 1 となる。

改行文字は '\r' または '\n' とする。

受信した最初の文字が改行の場合は、0 を返し、1 文字も受信しなかったときは URG_CONNECTION_TIMEOUT を返す。

See also
connection_write(), connection_read()

Definition at line 95 of file urg_connection.c.

int connection_set_baudrate ( urg_connection_t connection,
long  baudrate 
)

ボーレートを設定する

Definition at line 47 of file urg_connection.c.

int connection_write ( urg_connection_t connection,
const char *  data,
int  size 
)

送信

データを送信する。

Parameters
[in,out]connection通信リソース
[in]data送信データ
[in]size送信バイト数
Return values
>=0送信データ数
<0エラー

Example

1 n = connection_write(&connection, "QT\n", 3);
See also
connection_read(), connection_readline()

Definition at line 65 of file urg_connection.c.



urg_c
Author(s): Satofumi Kamimura , Katsumi Kimoto, Adrian Boeing
autogenerated on Wed Jun 10 2020 03:48:10