Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
serial_cpp
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Erik Strand
serial_cpp
Commits
b8400081
Commit
b8400081
authored
6 years ago
by
Erik Strand
Browse files
Options
Downloads
Patches
Plain Diff
Add working serial port enumeration test
parent
24628e01
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
CMakeLists.txt
+37
-0
37 additions, 0 deletions
CMakeLists.txt
main.cpp
+27
-0
27 additions, 0 deletions
main.cpp
with
64 additions
and
0 deletions
CMakeLists.txt
0 → 100644
+
37
−
0
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
()
This diff is collapsed.
Click to expand it.
main.cpp
0 → 100644
+
27
−
0
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
;
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment