Source code for pyupm_uartat

# This file was automatically generated by SWIG (http://www.swig.org).
# Version 3.0.8
#
# Do not make changes to this file unless you know what you are doing--modify
# the SWIG interface file instead.





from sys import version_info
if version_info >= (2, 6, 0):
    def swig_import_helper():
        from os.path import dirname
        import imp
        fp = None
        try:
            fp, pathname, description = imp.find_module('_pyupm_uartat', [dirname(__file__)])
        except ImportError:
            import _pyupm_uartat
            return _pyupm_uartat
        if fp is not None:
            try:
                _mod = imp.load_module('_pyupm_uartat', fp, pathname, description)
            finally:
                fp.close()
            return _mod
    _pyupm_uartat = swig_import_helper()
    del swig_import_helper
else:
    import _pyupm_uartat
del version_info
try:
    _swig_property = property
except NameError:
    pass  # Python < 2.2 doesn't have 'property'.


def _swig_setattr_nondynamic(self, class_type, name, value, static=1):
    if (name == "thisown"):
        return self.this.own(value)
    if (name == "this"):
        if type(value).__name__ == 'SwigPyObject':
            self.__dict__[name] = value
            return
    method = class_type.__swig_setmethods__.get(name, None)
    if method:
        return method(self, value)
    if (not static):
        if _newclass:
            object.__setattr__(self, name, value)
        else:
            self.__dict__[name] = value
    else:
        raise AttributeError("You cannot add attributes to %s" % self)


def _swig_setattr(self, class_type, name, value):
    return _swig_setattr_nondynamic(self, class_type, name, value, 0)


def _swig_getattr_nondynamic(self, class_type, name, static=1):
    if (name == "thisown"):
        return self.this.own()
    method = class_type.__swig_getmethods__.get(name, None)
    if method:
        return method(self)
    if (not static):
        return object.__getattr__(self, name)
    else:
        raise AttributeError(name)

def _swig_getattr(self, class_type, name):
    return _swig_getattr_nondynamic(self, class_type, name, 0)


def _swig_repr(self):
    try:
        strthis = "proxy of " + self.this.__repr__()
    except Exception:
        strthis = ""
    return "<%s.%s; %s >" % (self.__class__.__module__, self.__class__.__name__, strthis,)

try:
    _object = object
    _newclass = 1
except AttributeError:
    class _object:
        pass
    _newclass = 0



def getVersion():
    return _pyupm_uartat.getVersion()
getVersion = _pyupm_uartat.getVersion

_pyupm_uartat.UARTAT_FLOW_CONTROL_NONE_swigconstant(_pyupm_uartat)
UARTAT_FLOW_CONTROL_NONE = _pyupm_uartat.UARTAT_FLOW_CONTROL_NONE

_pyupm_uartat.UARTAT_FLOW_CONTROL_HARD_swigconstant(_pyupm_uartat)
UARTAT_FLOW_CONTROL_HARD = _pyupm_uartat.UARTAT_FLOW_CONTROL_HARD

_pyupm_uartat.UARTAT_FLOW_CONTROL_SOFT_swigconstant(_pyupm_uartat)
UARTAT_FLOW_CONTROL_SOFT = _pyupm_uartat.UARTAT_FLOW_CONTROL_SOFT

_pyupm_uartat.UARTAT_RESPONSE_CODE_OK_swigconstant(_pyupm_uartat)
UARTAT_RESPONSE_CODE_OK = _pyupm_uartat.UARTAT_RESPONSE_CODE_OK

_pyupm_uartat.UARTAT_RESPONSE_CODE_CONNECT_swigconstant(_pyupm_uartat)
UARTAT_RESPONSE_CODE_CONNECT = _pyupm_uartat.UARTAT_RESPONSE_CODE_CONNECT

_pyupm_uartat.UARTAT_RESPONSE_CODE_RING_swigconstant(_pyupm_uartat)
UARTAT_RESPONSE_CODE_RING = _pyupm_uartat.UARTAT_RESPONSE_CODE_RING

_pyupm_uartat.UARTAT_RESPONSE_CODE_NO_CARRIER_swigconstant(_pyupm_uartat)
UARTAT_RESPONSE_CODE_NO_CARRIER = _pyupm_uartat.UARTAT_RESPONSE_CODE_NO_CARRIER

_pyupm_uartat.UARTAT_RESPONSE_CODE_ERROR_swigconstant(_pyupm_uartat)
UARTAT_RESPONSE_CODE_ERROR = _pyupm_uartat.UARTAT_RESPONSE_CODE_ERROR

_pyupm_uartat.UARTAT_RESPONSE_CODE_NO_DIALTONE_swigconstant(_pyupm_uartat)
UARTAT_RESPONSE_CODE_NO_DIALTONE = _pyupm_uartat.UARTAT_RESPONSE_CODE_NO_DIALTONE

_pyupm_uartat.UARTAT_RESPONSE_CODE_BUSY_swigconstant(_pyupm_uartat)
UARTAT_RESPONSE_CODE_BUSY = _pyupm_uartat.UARTAT_RESPONSE_CODE_BUSY

_pyupm_uartat.UARTAT_RESPONSE_CODE_NO_ANSWER_swigconstant(_pyupm_uartat)
UARTAT_RESPONSE_CODE_NO_ANSWER = _pyupm_uartat.UARTAT_RESPONSE_CODE_NO_ANSWER
[docs]class UARTAT(_object): """ API for a Generic AT command based UART device. ID: uartat Name: Generic AT Command Based UART Device Category: other Connection: uart This is a generic UART device driver for accessing UART based devices that utilize an "AT" command set. Typically these devices are Radios, Modems, and similar devices that are configured and controlled by emitting "AT" commands. C++ includes: uartat.hpp """ __swig_setmethods__ = {} __setattr__ = lambda self, name, value: _swig_setattr(self, UARTAT, name, value) __swig_getmethods__ = {} __getattr__ = lambda self, name: _swig_getattr(self, UARTAT, name) __repr__ = _swig_repr def __init__(self, *args): """ UARTAT(std::string uart_path, unsigned int baudrate) UARTAT object constructor for a UART specified by PATH (ex: /dev/ttyUSB0) Parameters: ----------- uart_path: Specify path of UART device. baudrate: Specify the baudrate to use. """ this = _pyupm_uartat.new_UARTAT(*args) try: self.this.append(this) except Exception: self.this = this __swig_destroy__ = _pyupm_uartat.delete_UARTAT __del__ = lambda self: None
[docs] def readStr(self, size): """ std::string readStr(size_t size) Read character data from the device. Parameters: ----------- size: The maximum number of characters to read. string containing the data read. """ return _pyupm_uartat.UARTAT_readStr(self, size)
[docs] def writeStr(self, buffer): """ int writeStr(std::string buffer) Write character data to the device. Parameters: ----------- buffer: The string containing the data to write. The number of bytes written. """ return _pyupm_uartat.UARTAT_writeStr(self, buffer)
[docs] def setBaudrate(self, baudrate): """ void setBaudrate(unsigned int baudrate) Set the baudrate of the device. Parameters: ----------- baudrate: The baud rate to set for the device. """ return _pyupm_uartat.UARTAT_setBaudrate(self, baudrate)
[docs] def setResponseWaitTime(self, wait_time): """ void setResponseWaitTime(unsigned int wait_time) Set the default time, in milliseconds, to wait for data to arrive after sending a command. Parameters: ----------- wait_time: The response delay to set, in milliseconds. """ return _pyupm_uartat.UARTAT_setResponseWaitTime(self, wait_time)
[docs] def dataAvailable(self, millis): """ bool dataAvailable(unsigned int millis) Determine whether there is data available to be read. In the case of a UART, this function will wait up to "millis" milliseconds for data to become available. In the case of an I2C device, the millis argument is ignored and the function will return immediately, indicating whether data is available. Parameters: ----------- millis: The number of milliseconds to wait for data to become available. true if data is available to be read, false otherwise. """ return _pyupm_uartat.UARTAT_dataAvailable(self, millis)
[docs] def commandMode(self, cmd_chars, guard_ms): """ bool commandMode(const std::string cmd_chars, unsigned int guard_ms) Place the device in AT command mode. Many devices operate in a transparent mode and an AT command mode. Command mode is required to issue AT based commands. When in transparent mode, the device will usually listen for a special sequence of characters and delays, indicating that AT command mode should be entered. On most devices, the sequence is: <wait 1 second>+++<wait 1 second> For most devices, the wait time is 1 second (1000 ms) and the character sequence is "+++". These options can often be configured on the device. This function will wait millis milliseconds, write the command characters (typically "+++"), then wait millis milliseconds again. At this time a read will be attempted, looking for the "OK" response indicating command mode was successfully entered. Parameters: ----------- cmd_chars: The character sequence to write, typically "+++". guard_ms: The number of milliseconds to delay before and after the cmd_chars are written. true if AT command mode ("OK" detected) was successfully entered, false otherwise. """ return _pyupm_uartat.UARTAT_commandMode(self, cmd_chars, guard_ms)
[docs] def inCommandMode(self): """ bool inCommandMode() Check to see if the device is in command mode. This is accomplished by sending an "AT\\r" command and seeing if "OK" or "0" is returned. true if AT command mode was detected, false otherwise. """ return _pyupm_uartat.UARTAT_inCommandMode(self)
[docs] def drain(self): """ void drain() Read and throw away any data currently available to be read. This is useful to avoid reading data that might have been the result of a previous command interfering with data you currently want to read. This function is automatically called by commandWithResponse(), command(), and commandWaitfor() prior to writing the requested command to the device. """ return _pyupm_uartat.UARTAT_drain(self)
[docs] def commandWithResponse(self, cmd, resp_len): """ string commandWithResponse(const std::string cmd, size_t resp_len) Send an AT command and optionally return a response. Parameters: ----------- cmd: A character string containing the AT command to send, including the "AT" prefix and a terminating carriage return ("\\r"). resp_len: The maximum number of characters to read from the device. The device response string, if any. """ return _pyupm_uartat.UARTAT_commandWithResponse(self, cmd, resp_len)
[docs] def commandWaitFor(self, cmd, resp_len, waitString, millis): """ string commandWaitFor(const std::string cmd, size_t resp_len, const std::string waitString, unsigned int millis) Send an AT command and return a response, while waiting for a specific string. If the string isn't found the returned string will be empty. If the string is found, the function will return immediately. Parameters: ----------- cmd: A character string containing the AT command to send, including the "AT" prefix and a terminating carriage return ("\\r"). resp_len: The maximum number of characters to read from the device. waitString: The string to look for. If found, the response will be returned immediately regardless of the timeout setting. millis: The maximum number of milliseconds to wait for the string. A string containing the response if the search string was found, otherwise and empty string is returned. """ return _pyupm_uartat.UARTAT_commandWaitFor(self, cmd, resp_len, waitString, millis)
[docs] def command(self, cmd): """ void command(const std::string cmd) Send an AT command and ignore any response. Parameters: ----------- cmd: The AT command to send, including the "AT" prefix and a terminating carriage return ("\\r"). """ return _pyupm_uartat.UARTAT_command(self, cmd)
[docs] def stringCR2LF(self, str): """ string stringCR2LF(std::string str) This is a convenience method that converts each CR () in a string to a LF ( ) and returns it. This is useful for outputting the response to an AT command for instance, which is often CR terminated. Parameters: ----------- str: The string to convert The converted string """ return _pyupm_uartat.UARTAT_stringCR2LF(self, str)
[docs] def setFlowControl(self, fc): """ void setFlowControl(UARTAT_FLOW_CONTROL_T fc) Set a flow control method for the UART. By default, during initialization, flow control is disabled. Parameters: ----------- fc: One of the UARTAT_FLOW_CONTROL_T values. """ return _pyupm_uartat.UARTAT_setFlowControl(self, fc)
[docs] def find(self, buffer, str): """ bool find(const std::string buffer, const std::string str) Look for a string in a buffer. This is a utility function that can be used to indicate if a given string is present in a supplied buffer. The search is case sensitive. Parameters: ----------- buffer: The string buffer in which to search. str: The string to search for. true if the string was found, false otherwise. """ return _pyupm_uartat.UARTAT_find(self, buffer, str)
[docs] def filterCR(self, enable): """ void filterCR(bool enable) Filter out carriage returns (CR) from response buffers if enabled. This operates only on the response buffers returned from commandWithResponse(), command(), and commandWaitfor(). Parameters: ----------- enable: true to filter out CR's, false otherwise """ return _pyupm_uartat.UARTAT_filterCR(self, enable)
UARTAT_swigregister = _pyupm_uartat.UARTAT_swigregister UARTAT_swigregister(UARTAT) # This file is compatible with both classic and new-style classes.