};
/** 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 {
*/
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().
*/
#include "libserialport.h"
+struct sp_port {
+ char *name;
+#ifdef _WIN32
+ HANDLE hdl;
+#else
+ int fd;
+#endif
+};
+
struct port_data {
#ifdef _WIN32
DCB dcb;
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);