USBUART
A library for reading/wring data via USB-UART adapters
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Modules
capi.cpp
Go to the documentation of this file.
1 
5 /* This file is part of USBUART Library. http://usbuart.info/
6  *
7  * Copyright (C) 2016 Eugene Hutorny <eugene@hutorny.in.ua>
8  *
9  * The USBUART Library is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU Lesser General Public License v2
11  * as published by the Free Software Foundation;
12  *
13  * The USBUART Library is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
16  * See the GNU Lesser General Public License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public License
19  * along with the USBUART Library; if not, see
20  * <http://www.gnu.org/licenses/gpl-2.0.html>.
21  */
22 
23 #include "usbuart.hpp"
24 
25 
26 /******************************************************************************
27  * C-style API forwarders
28  */
29 using namespace usbuart;
30 
32  struct channel* ch, const struct eia_tia_232_info* pi) {
33  return context::instance().pipe(ba, *ch, pi ? *pi : _115200_8N1n);
34 }
35 
36 int usbuart_pipe_bydevid(struct device_addr id,
37  struct channel* ch, const struct eia_tia_232_info* pi) {
38  return usbuart::context::instance().pipe(id, *ch, pi ? *pi : _115200_8N1n);
39 }
40 
41 int usbuart_attach_byaddr(struct device_addr ba, struct channel ch,
42  const struct eia_tia_232_info* pi) {
43  return usbuart::context::instance().attach(ba, ch, pi ? *pi : _115200_8N1n);
44 }
45 
46 int usbuart_attach_bydevid(struct device_addr id, struct channel ch,
47  const struct eia_tia_232_info* pi) {
48  return usbuart::context::instance().attach(id, ch, pi ? *pi : _115200_8N1n);
49 }
50 
52 void usbuart_close(struct channel ch) {
54 }
55 
57 int usbuart_reset(struct channel ch) {
58  return context::instance().reset(ch);
59 }
60 
62 int usbuart_break(struct channel ch) {
63  return context::instance().sendbreak(ch);
64 }
66 int usbuart_loop(int timeout) {
67  return context::instance().loop(timeout);
68 }
69 
70 int usbuart_isgood(struct channel ch) {
71  return context::instance().status(ch);
72 }
struct channel usbuart_pipe_bydevid(struct device_id, struct channel *ch, const struct eia_tia_232_info *)
Create two pipes and attach their ends to the USB device using VID/PID.
int sendbreak(channel) noexcept
Send RS232 break signal to the USB device.
Definition: core.cpp:985
void close(channel) noexcept
Close channel, detaches files from USB device.
Definition: core.cpp:955
Device address in terms bus ID, device number.
Definition: usbuart.h:84
I/O channel, represented by a pair of file descriptors.
Definition: usbuart.h:70
implementation header USBUART Library
int loop(int timeout) noexcept
Run libusb and async I/O message loops.
Definition: core.cpp:996
void usbuart_reset(struct channel)
Resets USB device.
Definition: capi.cpp:57
USBUART namespace.
Definition: usbuart.h:29
void usbuart_close(struct channel)
Close pipes and detach USB device.
Definition: capi.cpp:52
int usbuart_attach_bydevid(struct device_id id, struct channel ch, const struct eia_tia_232_info *pi)
Attach pair of file descriptors to the USB device using VID/PID.
int reset(channel) noexcept
Reset USB device.
Definition: core.cpp:964
int usbuart_loop(int timeout)
Run libusb and async I/O message loops.
Definition: capi.cpp:66
int attach(device_id id, channel ch, const eia_tia_232_info &pi) noexcept
Attach pair of file descriptors to the USB device using VID/PID.
Definition: core.cpp:935
int status(channel) noexcept
Returns combination of status_t bit or negative on error.
Definition: core.cpp:975
static context & instance() noexcept
Returns a singleton context instance.
Definition: core.cpp:1021
int usbuart_pipe_byaddr(struct device_addr ba, struct channel *ch, const struct eia_tia_232_info *pi)
Create two pipes and attach their ends to the USB device using BUS/ADDR.
Definition: capi.cpp:31
int pipe(device_id id, channel &ch, const eia_tia_232_info &pi) noexcept
Create two pipes and attach their ends to the USB device using VID/PID.
Definition: core.cpp:944
void usbuart_break(struct channel)
Send RS232 break signal to the USB device.
Definition: capi.cpp:62
int usbuart_attach_byaddr(struct device_addr, struct channel, const struct eia_tia_232_info *)
Attach pair of file descriptors to the USB device using BUS/ADDR.
Definition: capi.cpp:41