Skip to content
Snippets Groups Projects
Commit dd70ec81 authored by Erik Strand's avatar Erik Strand
Browse files

Updates for linux

And testing my new USB-equipped board (currently virtual serial).
parent 22d6fd49
No related branches found
No related tags found
No related merge requests found
......@@ -26,8 +26,10 @@ 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)
#set_target_properties(serialport PROPERTIES IMPORTED_LOCATION /usr/local/Cellar/libserialport/0.1.1/lib/libserialport.dylib)
set_target_properties(serialport PROPERTIES IMPORTED_LOCATION /usr/lib/x86_64-linux-gnu/libserialport.so.0.1.0)
#target_include_directories(serialport INTERFACE /usr/local/Cellar/libserialport/0.1.1/include)
target_include_directories(serialport INTERFACE /usr/include)
add_executable(serial_cpp main.cpp)
target_link_libraries(serial_cpp serialport)
......
......@@ -22,7 +22,9 @@ int main() {
std::cout << "Searching for serial ports.\n";
list_ports();
const char* desired_port = "/dev/cu.usbserial-AC01YB5P";
//const char* desired_port = "/dev/cu.usbserial-AC01YB5P";
//const char* desired_port = "/dev/ttyUSB0";
const char* desired_port = "/dev/ttyACM0";
constexpr uint32_t baud_rate = 115200;
constexpr uint32_t byte_buffer_size = 512;
char byte_buffer[byte_buffer_size];
......@@ -40,23 +42,44 @@ int main() {
std::cout << bytes_waiting << " bytes in the buffer: ";
int byte_num = 0;
byte_num = sp_nonblocking_read(port, byte_buffer, byte_buffer_size);
bool button_pressed = false;
//bool button_pressed = false;
for (decltype(byte_num) i = 0; i < byte_num; ++i){
if (byte_buffer[i] == '1') {
button_pressed = true;
}
//if (byte_buffer[i] == '1') {
// button_pressed = true;
//}
std::cout << byte_buffer[i];
}
std::cout << '\n';
/*
if (button_pressed) {
std::cout << " the button is pressed!";
}
std::cout << std::endl;
*/
}
}
// Execution can never make it here, but I'll close the port on principle.
sp_close(port);
} else {
std::cout << "Error opening serial device\n";
switch(error) {
case SP_ERR_ARG:
std::cout << "Bad arguments\n";
break;
case SP_ERR_FAIL:
std::cout << "OS reported failure\n";
std::cout << sp_last_error_code() << '\n';
std::cout << sp_last_error_message() << '\n';
break;
case SP_ERR_SUPP:
std::cout << "Not supported\n";
break;
case SP_ERR_MEM:
std::cout << "OOM\n";
break;
default:
std::cout << "No idea\n";
}
}
} else {
std::cout << "Error finding serial device\n";
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment