mirror of
git://sigrok.org/libserialport
synced 2023-08-10 21:13:24 +03:00
Make port structure opaque.
This commit is contained in:
parent
70cd37def2
commit
1c5aae9dc5
@ -226,18 +226,7 @@ enum sp_signal {
|
||||
};
|
||||
|
||||
/** A serial port. */
|
||||
struct sp_port {
|
||||
/** Name used to open the port. */
|
||||
char *name;
|
||||
/** @cond 0 */
|
||||
/** OS-specific port handle. */
|
||||
#ifdef _WIN32
|
||||
HANDLE hdl;
|
||||
#else
|
||||
int fd;
|
||||
#endif
|
||||
/** @endcond */
|
||||
};
|
||||
struct sp_port;
|
||||
|
||||
/** Configuration for a serial port. */
|
||||
struct sp_port_config {
|
||||
@ -281,6 +270,21 @@ struct sp_port_config {
|
||||
*/
|
||||
enum sp_return sp_get_port_by_name(const char *portname, struct sp_port **port_ptr);
|
||||
|
||||
/**
|
||||
* Get the name of a port.
|
||||
*
|
||||
* The name returned is whatever is normally used to refer to a port on the
|
||||
* current operating system; e.g. for Windows it will usually be a "COMn"
|
||||
* device name, and for Unix it will be a device path beginning with "/dev/".
|
||||
*
|
||||
* @param port Pointer to port structure.
|
||||
*
|
||||
* @return The port name, or NULL if an invalid port is passed. The name
|
||||
* string is part of the port structure and may not be used after the
|
||||
* port structure has been freed.
|
||||
*/
|
||||
char *sp_get_port_name(const struct sp_port *port);
|
||||
|
||||
/**
|
||||
* Free a port structure obtained from sp_get_port_by_name() or sp_copy_port().
|
||||
*/
|
||||
|
19
serialport.c
19
serialport.c
@ -58,6 +58,15 @@
|
||||
|
||||
#include "libserialport.h"
|
||||
|
||||
struct sp_port {
|
||||
char *name;
|
||||
#ifdef _WIN32
|
||||
HANDLE hdl;
|
||||
#else
|
||||
int fd;
|
||||
#endif
|
||||
};
|
||||
|
||||
struct port_data {
|
||||
#ifdef _WIN32
|
||||
DCB dcb;
|
||||
@ -184,6 +193,16 @@ enum sp_return sp_get_port_by_name(const char *portname, struct sp_port **port_p
|
||||
RETURN_OK();
|
||||
}
|
||||
|
||||
char *sp_get_port_name(const struct sp_port *port)
|
||||
{
|
||||
TRACE("%p", port);
|
||||
|
||||
if (!port)
|
||||
return NULL;
|
||||
|
||||
RETURN_VALUE("%s", port->name);
|
||||
}
|
||||
|
||||
enum sp_return sp_copy_port(const struct sp_port *port, struct sp_port **copy_ptr)
|
||||
{
|
||||
TRACE("%p, %p", port, copy_ptr);
|
||||
|
Loading…
Reference in New Issue
Block a user