Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
Erik Strand
serial_cpp
Commits
b8400081
Commit
b8400081
authored
Nov 28, 2018
by
Erik Strand
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add working serial port enumeration test
parent
24628e01
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
64 additions
and
0 deletions
+64
-0
CMakeLists.txt
CMakeLists.txt
+37
-0
main.cpp
main.cpp
+27
-0
No files found.
CMakeLists.txt
0 → 100644
View file @
b8400081
cmake_minimum_required
(
VERSION 3.1
)
# Meta information about the project
set
(
META_PROJECT_NAME
"serial_cpp"
)
set
(
META_PROJECT_DESCRIPTION
"Interfacing with a microcontroller over a serial connection"
)
project
(
htmaa_shelves LANGUAGES CXX
)
set
(
CMAKE_CXX_STANDARD 11
)
set
(
CMAKE_CXX_STANDARD_REQUIRED ON
)
set
(
CMAKE_CXX_FLAGS
"
${
CMAKE_CXX_FLAGS
}
-Wall -Wextra -pedantic"
)
if
(
CMAKE_COMPILER_IS_GNUCXX
)
set
(
CMAKE_CXX_FLAGS
"
${
CMAKE_CXX_FLAGS
}
-Og"
)
else
()
set
(
CMAKE_CXX_FLAGS
"
${
CMAKE_CXX_FLAGS
}
-O1"
)
endif
()
# Let the compiler decide what to inline at link time.
cmake_policy
(
SET CMP0069 NEW
)
include
(
CheckIPOSupported
)
check_ipo_supported
(
RESULT ipo_supported OUTPUT error
)
if
(
ipo_supported
)
message
(
STATUS
"IPO / LTO enabled"
)
else
()
message
(
STATUS
"IPO / LTO not supported: <
${
error
}
>"
)
endif
()
add_library
(
serialport SHARED IMPORTED
)
# You can define two import-locations: one for debug and one for release.
set_target_properties
(
serialport PROPERTIES IMPORTED_LOCATION /usr/local/Cellar/libserialport/0.1.1/lib/libserialport.dylib
)
target_include_directories
(
serialport INTERFACE /usr/local/Cellar/libserialport/0.1.1/include
)
add_executable
(
serial_cpp main.cpp
)
target_link_libraries
(
serial_cpp serialport
)
if
(
ipo_supported
)
set_property
(
TARGET serial_cpp PROPERTY INTERPROCEDURAL_OPTIMIZATION TRUE
)
endif
()
main.cpp
0 → 100644
View file @
b8400081
// Use of libserialport based on https://gist.github.com/Nixes/78e401234e66aa131547d7b78135271c
#include <iostream>
#include <libserialport.h>
void
list_ports
()
{
int32_t
i
;
struct
sp_port
**
ports
;
sp_return
error
=
sp_list_ports
(
&
ports
);
if
(
error
==
SP_OK
)
{
for
(
i
=
0
;
ports
[
i
];
i
++
)
{
std
::
cout
<<
"Found port: "
<<
sp_get_port_name
(
ports
[
i
])
<<
'\n'
;
}
sp_free_port_list
(
ports
);
}
else
{
std
::
cout
<<
"No serial devices detected
\n
"
;
}
}
int
main
()
{
std
::
cout
<<
"Searching for serial ports.
\n
"
;
list_ports
();
return
0
;
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment