Closed ElectricRCAircraftGuy closed 4 years ago
I too would like to see this. I subscribed to the mailing list and sent a message. Before I got an answer though, I sent another message to who I believe is the author. I got a response from the mailing list. I just had to wait a little bit longer. Anyway, I can share with you ElectricRCAircraftGuy what was shared with me.
I only asked for an example on how to enumerate serial ports, you know, have the OS report a list of serial ports found. This is the example they shared:
#include <stdio.h>
#include <libserialport.h>
int main(void)
{
int i;
struct sp_port **ports;
sp_list_ports(&ports);
for (i = 0; ports[i]; i++)
printf("Found port: '%s'.\n", sp_get_port_name(ports[i]));
sp_free_port_list(ports);
}
Although I would love to take credit for this sample, this information was provided by the very nice and very talented Mr. Uwe Hermann. So any credit should go to him. If I can get the library compiled for Windows 7, I'll share more examples as I learn them if you'd like.
Hey thanks! And that sounds great. By the way, I'm brand-new to C++ on a computer (I've done Arduino and AVR microcontroller C and C++ code though), and I have the library running on Windows 8.1 just fine. I just copied and pasted the "libserialport.h" and "serialport.c" files into my working directory, and it all compiles and runs just fine. I'm using Code::Blocks, running a C++ Console Project. I imagine this would work fine for Windows 7 too.
We are working on a new release and as part of that, I have finally started writing up some examples and integrating them into the documentation. The first two (list_ports and port_info) are now included in the API docs and can also be found in the examples directory in the repository. I plan to add more soon, to cover all the main functions and use cases.
Thanks! Glad to have this in there. Note that I've progressed a bit since originally posting this request. :) In 2015 I didn't know what opaque pointers/structs were, for instance, but now I do. That being said, any complex level of abstraction is always benefited with thorough examples and comments. And in C, virtually all abstraction is complex.
Hi, can you make an example folder and include a few basic examples, please? I'm trying to use this library and I'm struggling with it. Having to google a lot. I"m not familiar with "opaque structs" for instance.
A basic read/write example, list ports example, etc, would be really helpful.
Many thanks,
Gabriel.