test
serial_interface
SVHReceiveTest.cpp
Go to the documentation of this file.
1
//
3
// © Copyright 2022 SCHUNK Mobile Greifsysteme GmbH, Lauffen/Neckar Germany
4
// © Copyright 2022 FZI Forschungszentrum Informatik, Karlsruhe, Germany
5
//
6
// This file is part of the Schunk SVH Library.
7
//
8
// The Schunk SVH Library is free software: you can redistribute it and/or
9
// modify it under the terms of the GNU General Public License as published by
10
// the Free Software Foundation, either version 3 of the License, or (at your
11
// option) any later version.
12
//
13
// The Schunk SVH Library is distributed in the hope that it will be useful,
14
// but WITHOUT ANY WARRANTY; without even the implied warranty of
15
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
16
// Public License for more details.
17
//
18
// You should have received a copy of the GNU General Public License along with
19
// the Schunk SVH Library. If not, see <https://www.gnu.org/licenses/>.
20
//
22
23
//----------------------------------------------------------------------
30
//----------------------------------------------------------------------
31
32
#include <
schunk_svh_library/serial/ByteOrderConversion.h
>
33
#include <
schunk_svh_library/serial/Serial.h
>
34
35
using
driver_svh::ArrayBuilder
;
36
using
driver_svh::serial::Serial
;
37
using
driver_svh::serial::SerialFlags
;
38
39
// testing serial interface of svh driver
40
int
main
(
int
argc,
const
char
* argv[])
41
{
42
std::string serial_device_name =
"/dev/ttyUSB1"
;
43
44
Serial
* serial_device =
45
new
Serial
(serial_device_name.c_str(),
SerialFlags
(SerialFlags::BR_921600, SerialFlags::DB_8));
46
serial_device->
open
();
47
48
uint8_t data = 0;
49
while
(
true
)
50
{
51
if
(serial_device->
read
(&data,
sizeof
(uint8_t)))
52
{
53
std::cout <<
"0x"
<< std::setw(2) << std::setfill(
'0'
) << std::hex << static_cast<int>(data)
54
<<
" "
<< std::flush;
55
}
56
else
57
{
58
std::cout <<
"."
<< std::flush;
59
}
60
}
61
62
serial_device->
close
();
63
}
driver_svh::ArrayBuilder
Definition:
ByteOrderConversion.h:146
ByteOrderConversion.h
driver_svh::serial::Serial::open
bool open(const SerialFlags &flags)
Definition:
Serial.h:123
driver_svh::serial::Serial::close
void close()
Definition:
Serial.cpp:759
main
int main(int argc, const char *argv[])
Definition:
SVHReceiveTest.cpp:40
Serial.h
Contains a class that enables access to serial devices.
driver_svh::serial::Serial
Enables acces to serial devices.
Definition:
Serial.h:68
driver_svh::serial::SerialFlags
Short description of tSerialFlags.
Definition:
SerialFlags.h:52
driver_svh::serial::Serial::read
ssize_t read(void *data, ssize_t size, unsigned long time=100, bool return_on_less_data=true)
Definition:
Serial.cpp:492
schunk_svh_library
Author(s): Georg Heppner, Lars Pfotzer, Felix Exner, Johannes Mangler, Stefan Scherzinger, Pascal Becker
autogenerated on Fri Apr 14 2023 02:53:52