### Install BACpypes Library using easy_install Source: https://bacpypes.readthedocs.io/en/latest/gettingstarted/gettingstarted001 Installs the BACpypes library using the easy_install tool. This command requires superuser privileges to modify system-wide Python packages. ```Shell $ sudo easy_install bacpypes ``` -------------------------------- ### Clone BACpypes Project Repository from GitHub Source: https://bacpypes.readthedocs.io/en/latest/gettingstarted/gettingstarted001 Clones the BACpypes project repository from GitHub, which includes the library source code, sample applications, and documentation. This command requires Git to be installed on your system. ```Shell $ git clone https://github.com/JoelBender/bacpypes.git ``` -------------------------------- ### Install BACpypes Library using pip Source: https://bacpypes.readthedocs.io/en/latest/gettingstarted/gettingstarted001 Installs the BACpypes library using the pip package manager. This is the recommended method for Python package installation and requires superuser privileges. ```Shell $ sudo pip install bacpypes ``` -------------------------------- ### Install Wireshark on Linux using apt-get Source: https://bacpypes.readthedocs.io/en/latest/gettingstarted/gettingstarted001 Installs the Wireshark network protocol analyzer, a crucial tool for debugging network communications, using the apt-get package manager on Debian/Ubuntu-based systems. This operation requires superuser privileges. ```Shell $ sudo apt-get install wireshark ``` -------------------------------- ### Display Who-Is Command Syntax Help Source: https://bacpypes.readthedocs.io/en/latest/gettingstarted/gettingstarted001 This example illustrates how to access the help documentation for the `whois` command. It provides the BNF-like syntax, indicating optional parameters for BACnet device addresses and low/high address limits. ```Shell > help whois whois [ ] [ ] ``` -------------------------------- ### Prepare BACpypes Configuration File Source: https://bacpypes.readthedocs.io/en/latest/gettingstarted/gettingstarted001 This snippet provides shell commands to navigate to the BACpypes project directory and create a local copy of the sample configuration file (`BACpypes~.ini`) named `BACpypes.ini`. This is the first step before customizing the workstation's BACnet settings. ```Shell $ cd bacpypes $ cp BACpypes~.ini BACpypes.ini ``` -------------------------------- ### Display Help for BACpypes Application Commands Source: https://bacpypes.readthedocs.io/en/latest/gettingstarted/gettingstarted001 After launching a BACpypes sample application, typing 'help' at the interactive prompt displays a list of all available commands. This feature assists users in discovering and understanding the functionalities provided by the running application. ```BACpypes CLI > help Documented commands (type help ): ======================================== EOF buggers bugin bugout exit gc help iam shell whois ``` -------------------------------- ### Run BACpypes WhoIsIAm.py Sample Application Source: https://bacpypes.readthedocs.io/en/latest/gettingstarted/gettingstarted001 This command executes the `WhoIsIAm.py` sample application, which is part of the BACpypes library. This application is designed to send Who-Is and I-Am messages and display the results, serving as a fundamental example for understanding BACnet communication. ```Bash $ python samples/WhoIsIAm.py ``` -------------------------------- ### Install BACpypes from GitHub Source Source: https://bacpypes.readthedocs.io/en/latest/index This snippet outlines the process for installing BACpypes directly from its GitHub repository. It involves cloning the repository and then using Python's `setup.py` script to perform the installation, allowing access to the latest development version. ```Shell $ git clone https://github.com/JoelBender/bacpypes.git $ cd bacpypes $ python setup.py install ``` -------------------------------- ### Example BACpypes INI Configuration File Source: https://bacpypes.readthedocs.io/en/latest/gettingstarted/gettingstarted001 This snippet shows a typical structure and content of a `BACpypes.ini` file. It defines various BACnet parameters for a device, including its object name, IP address, unique identifier, maximum APDU length, segmentation support, and vendor information. These settings are crucial for the workstation's BACnet communication. ```INI [BACpypes] objectName: Betelgeuse address: 192.168.1.2/24 objectIdentifier: 599 maxApduLengthAccepted: 1024 segmentationSupported: segmentedBoth maxSegmentsAccepted: 1024 vendorIdentifier: 15 foreignPort: 0 foreignBBMD: 128.253.109.254 foreignTTL: 30 ``` -------------------------------- ### Discover BACnet Devices within an Address Range Source: https://bacpypes.readthedocs.io/en/latest/gettingstarted/gettingstarted001 This example demonstrates how to use the `whois` command to discover all BACnet devices within a specified address range. This is particularly useful for finding devices grouped by a numbering scheme, such as those within a specific building. ```Shell > whois 203000 203099 ``` -------------------------------- ### Install BACpypes from PyPI Source: https://bacpypes.readthedocs.io/en/latest/index This snippet demonstrates how to install the latest released version of the BACpypes library from the Python Package Index (PyPI). It provides commands for both `easy_install` and `pip`, requiring superuser privileges. ```Shell $ sudo easy_install bacpypes or $ sudo pip install bacpypes ``` -------------------------------- ### Get Command Line Help for BACpypes Application Source: https://bacpypes.readthedocs.io/en/latest/gettingstarted/gettingstarted002 This snippet demonstrates how to use the `--help` option to display usage information, available arguments, and a brief description of a BACpypes sample application like WhoIsIAm.py. ```Shell $ python samples/WhoIsIAm.py --help usage: WhoIsIAm.py [-h] [--buggers] [--debug [DEBUG [DEBUG ...]]] [--color] [--ini INI] This application presents a 'console' prompt to the user asking for Who-Is and I-Am commands which create the related APDUs, then lines up the corresponding I-Am for incoming traffic and prints out the contents. optional arguments: -h, --help show this help message and exit --buggers list the debugging logger names --debug [DEBUG [ DEBUG ... ]] DEBUG ::= debugger [ : fileName [ : maxBytes [ : backupCount ]]] add console log handler to each debugging logger --color use ANSI CSI color codes --ini INI device object configuration file ``` -------------------------------- ### Send a Generic BACnet Who-Is Request Source: https://bacpypes.readthedocs.io/en/latest/gettingstarted/gettingstarted001 This snippet demonstrates how to send an unconstrained BACnet Who-Is request to discover all devices on the network. It also shows the typical I-Am response received from a test device, including its source, device identifier, APDU length, segmentation support, and vendor ID. ```Shell > whois ``` ```Shell > whois > pduSource = iAmDeviceIdentifier = ('device', 1000) maxAPDULengthAccepted = 480 segmentationSupported = segmentedBoth vendorID = 8 ``` -------------------------------- ### Discover a Specific BACnet Device by ID Source: https://bacpypes.readthedocs.io/en/latest/gettingstarted/gettingstarted001 This snippet shows how to use the `whois` command to find a specific BACnet device by providing its device identifier as both the low and high limit. This is a common method for targeting a known device. ```Shell > whois 1000 1000 ``` -------------------------------- ### Generate BACnet I-Am Message from Application Source: https://bacpypes.readthedocs.io/en/latest/gettingstarted/gettingstarted001 This command, executed within the BACpypes application's command-line interface, instructs the application to generate and send a basic I-Am message. This message is typically a global broadcast and can be observed and verified using a network sniffer like Wireshark. ```BACpypes CLI > iam ``` -------------------------------- ### Debug a Specific BACpypes Module or Class Instance Source: https://bacpypes.readthedocs.io/en/latest/gettingstarted/gettingstarted002 This example shows how to debug the activity of a BACpypes module's class, like `bacpypes.udp.UDPActor`, including its initialization and response handling, by specifying the module path with the `--debug` flag. ```Shell $ python samples/WhoIsIAm.py --ini BAC0.ini --debug bacpypes.udp.UDPActor ``` -------------------------------- ### Get help for a specific command in console Source: https://bacpypes.readthedocs.io/en/latest/tutorial/tutorial006 Illustrates how to use the `help ` syntax within the console application to retrieve the specific documentation (docstring) for a given command, such as 'set'. ```Shell > help set set - change a cache value ``` -------------------------------- ### Example BACpypes Command Shell Interaction Source: https://bacpypes.readthedocs.io/en/latest/tutorial/tutorial006 This interactive shell session demonstrates basic commands and features of the BACpypes command shell. It covers handling unknown commands, accessing help, listing debug handlers ('buggers'), attaching and removing debuggers, and exiting the shell. ```Shell $ python Tutorial/SampleConsoleCmd.py > hi *** Unknown syntax: hi > help Documented commands (type help ): ======================================== EOF buggers bugin bugout exit gc help shell > buggers no handlers __main__ bacpypes bacpypes.apdu bacpypes.apdu.APCI ... bacpypes.vlan.Network bacpypes.vlan.Node > bugin bacpypes.task.OneShotTask handler to bacpypes.task.OneShotTask added > bugout bacpypes.task.OneShotTask handler to bacpypes.task.OneShotTask removed > exit Exiting... ``` -------------------------------- ### Instantiate, Bind, and Test Custom BACpypes Client Source: https://bacpypes.readthedocs.io/en/latest/tutorial/tutorial001 Re-instantiates the client with the custom `MyClient` class and re-binds it to the existing server. A request is then sent, demonstrating the complete communication flow where the custom client successfully receives and processes the server's response, confirming the setup works as intended. ```python c = MyClient() bind(c, s) c.request('hi') ``` -------------------------------- ### Add and dump cache entries in console Source: https://bacpypes.readthedocs.io/en/latest/tutorial/tutorial006 Shows a practical example of using the 'set' command to add two key-value pairs ('x': '12', 'y': '13') to the cache, followed by the 'dump' command to verify that the entries have been successfully stored. ```Shell > set x 12 > set y 13 > dump {'x': '12', 'y': '13'} ``` -------------------------------- ### Creating a PDU with initial content in Python Source: https://bacpypes.readthedocs.io/en/latest/tutorial/tutorial003 This example shows how to instantiate a `PDU` object, providing initial content. The content represents the raw data that the PDU will encapsulate for network transmission. It includes variations for Python 3 (bytes) and Python 2 (string). ```Python 3 pdu = PDU(b"hello") ``` ```Python 2 pdu = PDU("Hello") ``` -------------------------------- ### Specify BACpypes INI File on Command Line (BAC1.ini) Source: https://bacpypes.readthedocs.io/en/latest/gettingstarted/gettingstarted002 This command provides another example of overriding the default `BACpypes.ini` file by specifying `BAC1.ini` on the command line, illustrating the flexibility to switch between various BACnet communication parameter configurations. ```Shell $ python samples/WhoIsIAm.py --ini BAC1.ini ``` -------------------------------- ### Defining and Using a Custom BACpypes IOController Source: https://bacpypes.readthedocs.io/en/latest/tutorial/iocb This example defines SomeController, a custom subclass of IOController, overriding the process_io method to implement specific logic for an IOCB. It then demonstrates instantiating this controller and initiating an IOCB's processing via request_io. ```Python class SomeController(IOController): def process_io(self, iocb): self.complete_io(iocb, iocb.args[0] + iocb.args[1] * iocb.kwargs['a']) ``` ```Python some_controller = SomeController() some_controller.request_io(iocb) ``` -------------------------------- ### Send Unconstrained Who-Is to a Specific IP Address Source: https://bacpypes.readthedocs.io/en/latest/gettingstarted/gettingstarted001 This snippet illustrates how to send an unconstrained Who-Is request directly to a specific IP address. This method is useful for attempting to discover BACnet devices that may not be properly configured but are known to have an IP address. The output shows the I-Am response from the device at the specified IP. ```Shell > whois 192.168.0.10 ``` ```Shell > pduSource =
iAmDeviceIdentifier = ('device', 1000) maxAPDULengthAccepted = 1024 segmentationSupported = segmentedBoth vendorID = 15 ``` -------------------------------- ### Instantiate and Print RemoteBroadcast Address Source: https://bacpypes.readthedocs.io/en/latest/tutorial/addressing Demonstrates the creation of a `RemoteBroadcast` object by providing a network number. The example shows its string representation, which includes the network number followed by an asterisk, indicating any address on that remote network. ```Python from bacpypes.pdu import RemoteBroadcast print(RemoteBroadcast(17)) ``` -------------------------------- ### APIDOC: task._Task Base Class Reference Source: https://bacpypes.readthedocs.io/en/latest/modules/task API definition for the `_Task` base class, providing fundamental methods for task installation, processing, suspension, and resumption. ```APIDOC class task._Task: install_task(when: float) when: time task should be processed process_task() when: time task should be processed suspend_task() when: time task should be processed resume_task() when: time task should be processed ``` -------------------------------- ### Adding source and destination addressing to a PDU in Python Source: https://bacpypes.readthedocs.io/en/latest/tutorial/tutorial003 This example illustrates how to assign `pduSource` and `pduDestination` attributes to an existing PDU object. These attributes define the origin and intended recipient of the PDU, enabling proper routing within the network. ```Python pdu.pduSource = 1 pdu.pduDestination = 2 pdu.debug_contents() ``` -------------------------------- ### Conceptual IOCB Function Call Example Source: https://bacpypes.readthedocs.io/en/latest/modules/iocb This conceptual Python-like function call illustrates how an IOCB would encapsulate arguments and keyword arguments for a function (`some_function`). The `result` would then be stored within the IOCB upon completion, demonstrating the IOCB's role in managing function parameters and return values asynchronously. ```Python result = some_function(arg1, arg2, kwarg1=1) ``` -------------------------------- ### Initialize BACpypes Debug Instance Source: https://bacpypes.readthedocs.io/en/latest/tutorial/tutorial002 Initializes an instance of the `Debug` class, providing a unique name ('middle') as an argument. This naming convention helps distinguish output from multiple `Debug` instances, making it easier to trace messages in complex communication setups. ```python d = Debug("middle") ``` -------------------------------- ### Conditionally Instantiate ConsoleCmd in BACpypes Applications Source: https://bacpypes.readthedocs.io/en/latest/tutorial/tutorial006 This example illustrates how to conditionally instantiate `ConsoleCmd` based on command-line arguments. This allows the command shell to be enabled only when a specific flag (e.g., '--console') is provided at application startup. ```Python if '--console' in sys.argv: ConsoleCmd() ``` -------------------------------- ### Initiating Who-Is Request (Python) Source: https://bacpypes.readthedocs.io/en/latest/migration/migration001 This Python function simplifies the initiation of a BACnet Who-Is request within the WhoIsIAmServices class. It automatically handles parameter validation, the construction of the WhoIsRequest PDU, and sending the request downstream, abstracting these complexities from the user. ```Python def who_is(self, low_limit=None, high_limit=None, address=None): ... ``` -------------------------------- ### Python: Binding Algorithm Instance to Object Property Source: https://bacpypes.readthedocs.io/en/latest/modules/service/detect This Python code snippet shows how to instantiate `SomeAlgorithm` and bind its 'pValue' parameter to the `presentValue` attribute of an `AnalogValueObject` (avo). This setup allows the algorithm to monitor changes in the analog value object's present value. ```python some_algorithm = SomeAlgorithm() some_algorithm.bind(pValue = (avo, 'presentValue')) ``` -------------------------------- ### Run Sample Console Application and view help Source: https://bacpypes.readthedocs.io/en/latest/tutorial/tutorial006 Demonstrates how to execute the `SampleConsoleCmd.py` script from the command line and then use the built-in `help` command to list all available commands, including the newly added 'del', 'dump', and 'set'. ```Shell $ python Tutorial/SampleConsoleCmd.py > help Documented commands (type help ): ======================================== EOF bugin **del** exit help **set** something buggers bugout **dump** gc nothing shell ``` -------------------------------- ### Run BACpypes Tests with setup.py Source: https://bacpypes.readthedocs.io/en/latest/releasenotes Execute the BACpypes test suite using the setup.py script. This command leverages nose for running the tests and is part of the build process. ```bash $ python setup.py test ``` -------------------------------- ### Configure Wireshark for BACnet UDP Traffic Source: https://bacpypes.readthedocs.io/en/latest/gettingstarted/gettingstarted001 This snippet provides a Wireshark display filter to capture BACnet UDP traffic specifically on the standard port 47808. Applying this filter helps in monitoring and analyzing network communication related to BACnet devices. ```Wireshark Filter udp and port 47808 ``` -------------------------------- ### Initialize BIPNetworkApplication Class Source: https://bacpypes.readthedocs.io/en/latest/modules/app Initializes the `BIPNetworkApplication` class, inheriting from `NetworkServiceElement`. This constructor is used to set up network services and requires a `localAddress` string. ```APIDOC class app.BIPNetworkApplication(NetworkServiceElement): __init__(localAddress): localAddress: This is a long line of text. ``` -------------------------------- ### Decode PDU Data in BACpypes using Get Operations Source: https://bacpypes.readthedocs.io/en/latest/tutorial/tutorial003 This snippet demonstrates how to consume data from a BACpypes PDU object. It shows the creation of a PDU, followed by sequential calls to `get()`, `get_short()`, and `get_long()` to extract octets, short integers, and long integers, respectively. The `debug_contents()` method is used to visualize the PDU's remaining data after each operation. ```Python pdu=PDU(b'hello!!') pdu.debug_contents() ``` ```Python pdu.get() pdu.debug_contents() ``` ```Python pdu.get_short() pdu.debug_contents() ``` ```Python pdu.get_long() pdu.debug_contents() ``` -------------------------------- ### APIDOC: npdu.InitializeRoutingTable Class Source: https://bacpypes.readthedocs.io/en/latest/modules/npdu This is a message used to initialize the routing table of a router or get the contents of the current routing table. ```APIDOC class npdu.InitializeRoutingTable(NPCI): description: This is a message used to initialize the routing table of a router or get the contents of the current routing table. methods: encode(npdu): decode(npdu): parameters: pdu: NPDU buffer ``` -------------------------------- ### Initialize BIPForeignApplication Class Source: https://bacpypes.readthedocs.io/en/latest/modules/app Initializes the `BIPForeignApplication` class, inheriting from `Application`. This constructor is used for foreign device registration and requires `localDevice`, `localAddress`, `bbmdAddress`, and `bbmdTTL` parameters. ```APIDOC class app.BIPForeignApplication(Application): __init__(localDevice, localAddress, bbmdAddress, bbmdTTL): localDevice: This is a long line of text. localAddress: This is a long line of text. bbmdAddress: This is a long line of text. bbmdTTL: This is a long line of text. ``` -------------------------------- ### APIDOC: task.TaskManager Class Reference Source: https://bacpypes.readthedocs.io/en/latest/modules/task API definition for the `TaskManager` class, responsible for managing the lifecycle of tasks, including installation, suspension, resumption, and retrieval of the next task. ```APIDOC class task.TaskManager: install_task(task) task: task to be installed suspend_task(task) task: task to be suspended resume_task(task) task: task to be resumed get_next_task() process_task() ``` -------------------------------- ### Initialize BIPSimpleApplication Class Source: https://bacpypes.readthedocs.io/en/latest/modules/app Initializes the `BIPSimpleApplication` class, inheriting from `Application`. This constructor requires a `localDevice` object and a `localAddress` string to set up the simple BACnet/IP application. ```APIDOC class app.BIPSimpleApplication(Application): __init__(localDevice, localAddress): localDevice: This is a long line of text. localAddress: This is a long line of text. ``` -------------------------------- ### Test ExampleOne with PlusOne Transformation Source: https://bacpypes.readthedocs.io/en/latest/tutorial/capability This snippet demonstrates instantiating `ExampleOne` and calling its `transform` method. It shows that the `PlusOne` capability is successfully applied, incrementing the input value by one, confirming the mixed-in behavior. ```Python some_transformer = ExampleOne() some_transformer.transform(10) 11 ``` -------------------------------- ### BACpypes BVLL PDU Types API Source: https://bacpypes.readthedocs.io/en/latest/modules/bvll Documents various specific PDU types used within the BACnet Virtual Link Layer (BVLL), starting with the Result PDU. ```APIDOC Class: bvll.Result(BVLCI) ``` -------------------------------- ### Register Application Controller Source: https://bacpypes.readthedocs.io/en/latest/modules/iocb This function registers a controller instance within a module-level dictionary. This allows other parts of the application to discover and utilize the services provided by the registered controller, such as an HTTP GET service. ```APIDOC iocb.register_controller(controller) controller: controller to register ``` -------------------------------- ### Constructing RemoteStation Address (Byte String) in Python Source: https://bacpypes.readthedocs.io/en/latest/tutorial/addressing This example demonstrates constructing a 'RemoteStation' address using a network number and a byte string for the device address. The byte string is represented in hexadecimal in the output. ```python print(RemoteStation(15, b'123456')) ``` -------------------------------- ### Instantiate ConsoleCmd for BACpypes Command Shell Source: https://bacpypes.readthedocs.io/en/latest/tutorial/tutorial006 After importing, this code demonstrates how to create an instance of `ConsoleCmd`, which initializes and activates the command shell within your application. ```Python ConsoleCmd() ``` -------------------------------- ### IPv4 String Representation with Port for LocalStation in Python Source: https://bacpypes.readthedocs.io/en/latest/tutorial/addressing This example extends the IPv4 representation, demonstrating that if the address corresponds to a non-standard port, the port number will also be included in the string output for a 'LocalStation' object. ```python LocalStation(b'\1\2\3\4\xba\xc3') ``` -------------------------------- ### Import BACpypes Communication Classes Source: https://bacpypes.readthedocs.io/en/latest/tutorial/tutorial001 Imports the necessary `Client`, `Server`, and `bind` components from the `bacpypes.comm` module. These are fundamental for setting up communication channels within BACpypes applications, allowing for the creation and binding of communication endpoints. ```python from bacpypes.comm import Client, Server, bind ``` -------------------------------- ### Debug a Specific BACpypes Application or Class Source: https://bacpypes.readthedocs.io/en/latest/gettingstarted/gettingstarted002 This command demonstrates how to enable debug logging for a specific BACpypes application or class, such as `__main__.WhoIsIAmApplication`, to focus the debugging output and reduce verbosity. ```Shell $ python samples/WhoIsIAm.py --debug __main__.WhoIsIAmApplication ``` -------------------------------- ### Accessing Underlying Address Bytes in Python Source: https://bacpypes.readthedocs.io/en/latest/tutorial/addressing This example demonstrates how to access the underlying byte string components of a BACpypes address object using the 'addrAddr' attribute. It shows the raw byte representation of the address. ```python addr1.addrAddr addr1.addrAddr ``` -------------------------------- ### Constructing LocalStation Address from Bytes in Python Source: https://bacpypes.readthedocs.io/en/latest/tutorial/addressing This example shows how to create a 'LocalStation' address object by passing a byte string to its constructor. The address is internally stored as bytes, and its string representation is shown in hexadecimal. ```python addr1 = Address(b'123456') print(addr1) ``` -------------------------------- ### Instantiate and Bind BACpypes Client and Server Source: https://bacpypes.readthedocs.io/en/latest/tutorial/tutorial001 Creates instances of the generic `Client` and the custom `MyServer` classes. The `bind()` function is then used to establish a communication link between these two instances, allowing the client to send requests to the server and initiate the communication flow. ```python c = Client() s = MyServer() bind(c, s) ``` -------------------------------- ### Instantiating IOCB and Accessing Stored Arguments Source: https://bacpypes.readthedocs.io/en/latest/tutorial/iocb This code illustrates how to create an instance of an IOCB with both positional and keyword arguments. It then shows how to access these stored arguments using the iocb.args tuple and iocb.kwargs dictionary properties, which hold the parameters for the operation. ```Python iocb = IOCB(1, 2, a=3) ``` ```Python iocb.args ``` ```Python iocb.kwargs ``` -------------------------------- ### Stop BACpypes Application (core.stop) Source: https://bacpypes.readthedocs.io/en/latest/modules/core This function is called to stop a BACpypes application. It resets the `running` boolean value. It is also installed as a signal handler for the TERM signal, allowing background processes to be stopped via `kill -TERM`. ```APIDOC core.stop(*args) args: Optional signal handler arguments. ``` ```bash kill -TERM 12345 ``` -------------------------------- ### BACpypes Debug Command Line Argument Definition Source: https://bacpypes.readthedocs.io/en/latest/gettingstarted/gettingstarted002 This section defines the structure and parameters for the `--debug` command-line argument in BACpypes, detailing its positional arguments, optional `fileName`, `maxBytes`, and `backupCount` for log configuration. ```APIDOC positional arguments: --debug [DEBUG [ DEBUG ... ]] DEBUG ::= debugger [ : fileName [ : maxBytes [ : backupCount ]]] ``` -------------------------------- ### Debug a Specific Module in BACpypes Application Source: https://bacpypes.readthedocs.io/en/latest/gettingstarted/gettingstarted002 This snippet illustrates how to enable debugging for a specific module (e.g., __main__) in a BACpypes application using the `--debug` command-line option, showing the resulting debug output. ```Shell $ python WhoIsIAm.py --debug __main__ DEBUG:__main__:initialization DEBUG:__main__: - args: Namespace(buggers=False, debug=['__main__'], ini=) DEBUG:__main__.WhoIsIAmApplication:__init__ (, '128.253.109.40/24:47808') DEBUG:__main__:running > ``` -------------------------------- ### Observe Client Request and Reply Flow with Debug Source: https://bacpypes.readthedocs.io/en/latest/tutorial/tutorial002 Initiates a request from the client (`c`) with the message 'hi'. This action triggers a sequence where the `Debug` instance (`d`) intercepts and logs the message as it travels downstream to the server and then logs the reply as it travels upstream back to the client, demonstrating the full communication cycle. ```python c.request('hi') ``` -------------------------------- ### Mix BaseCollector with TimesTen Capability and Test Source: https://bacpypes.readthedocs.io/en/latest/tutorial/capability This snippet defines `ExampleTwo` by mixing `BaseCollector` with `TimesTen`. It then instantiates `ExampleTwo` and tests its `transform` method, demonstrating that the `TimesTen` capability correctly multiplies the input value by ten. ```Python class ExampleTwo(BaseCollector, TimesTen): pass some_transformer = ExampleTwo() some_transformer.transform(10) 100 ``` -------------------------------- ### Debugging Function Decorator: function_debugging Source: https://bacpypes.readthedocs.io/en/latest/modules/debugging Explains the `function_debugging` decorator, which automatically names buggers based on the function and module names. It facilitates structured debugging by providing a named access point for log handlers. Includes a Python example demonstrating its usage. ```APIDOC debugging.function_debugging() Description: This function decorates a function with instances of buggers that are named by the function name combined with the module name. ``` ```Python @function_debugging def some_function(arg): if _debug: some_function._debug("some_function %r", arg) # rest of code ``` -------------------------------- ### Mix Multiple Capabilities (PlusOne, TimesTen) and Test Order Source: https://bacpypes.readthedocs.io/en/latest/tutorial/capability This snippet defines `ExampleThree` by mixing `BaseCollector`, `PlusOne`, and `TimesTen`. It then tests the `transform` method, showing the combined effect of the capabilities, where `PlusOne` is applied before `TimesTen` due to method resolution order. ```Python class ExampleThree(BaseCollector, PlusOne, TimesTen): pass some_transformer = ExampleThree() some_transformer.transform(10) 110 ``` -------------------------------- ### Define Recurring Function with Python Decorator Source: https://bacpypes.readthedocs.io/en/latest/modules/task This Python decorator wraps a function in a task object, allowing it to be called at regular intervals and also as a regular function. The decorated function becomes a task object that can be installed, suspended, and resumed like any other task. ```Python @recurring_function(5000) def my_ping(arg=None): print "my_ping", arg ``` -------------------------------- ### Mix Multiple Capabilities (TimesTen, PlusOne) and Test Order Impact Source: https://bacpypes.readthedocs.io/en/latest/tutorial/capability This snippet defines `ExampleFour` by mixing `BaseCollector`, `TimesTen`, and `PlusOne` in a different order. It then tests the `transform` method, demonstrating that the order of mixed-in classes affects the method resolution order and thus the final transformation result. ```Python class ExampleFour(BaseCollector, TimesTen, PlusOne): pass some_transformer = ExampleFour() some_transformer.transform(10) 101 ``` -------------------------------- ### List Debugging Loggers for BACpypes Application Source: https://bacpypes.readthedocs.io/en/latest/gettingstarted/gettingstarted002 This snippet shows how to list the debugging loggers associated with a BACpypes application, specifically filtering for __main__ related loggers using grep to focus on application components. ```Shell $ python samples/WhoIsIAm.py --buggers | grep __main__ __main__ __main__.WhoIsIAmApplication __main__.WhoIsIAmConsoleCmd ``` -------------------------------- ### BACpypes DeviceInfoCache: Release Device Information Source: https://bacpypes.readthedocs.io/en/latest/modules/app This function is called by the application service layer when a device no longer has confirmed requests associated with it, indicating its DeviceInfo can be removed from the cache. Derived classes can override this to modify cache behavior, for example, by implementing a timed removal. ```APIDOC DeviceInfoCache.release_device_info(info: DeviceInfo) Parameters: info (DeviceInfo): Device information no longer being used. ``` -------------------------------- ### Get Datatype for Object Property Source: https://bacpypes.readthedocs.io/en/latest/modules/object Documents the `get_datatype` function, which requires both an `objectType` and a `property` identifier. This function retrieves the specific datatype class associated with a given property of a particular BACnet object type, crucial for validating and interpreting property values according to BACnet standards. ```APIDOC object.get_datatype(objectType, property) Parameters: objectType: something property: something Returns: datatype class Description: This is a long line of text. ``` -------------------------------- ### List available console commands Source: https://bacpypes.readthedocs.io/en/latest/modules/consolecmd This command displays a list of all documented console commands that can be executed within the BACpypes application. Users can type 'help ' for more specific information on a particular command. ```Shell > help Documented commands (type help ): ======================================== EOF buggers bugin bugout exit gc help nothing shell ``` -------------------------------- ### Instantiating a PDU with source and destination in Python Source: https://bacpypes.readthedocs.io/en/latest/tutorial/tutorial003 This snippet shows an alternative method for creating a PDU, where the source and destination addressing information is provided directly during the object's instantiation. This streamlines the PDU creation process for messages with predefined routing. ```Python pdu = PDU(b"hello", source=1, destination=2) pdu.debug_contents() ``` -------------------------------- ### Python: Example Usage of @monitor_filter Decorator Source: https://bacpypes.readthedocs.io/en/latest/modules/service/detect This Python code snippet demonstrates how to apply the `@monitor_filter` decorator to a method within a `DetectionAlgorithm` subclass. The `value_changed` method will only execute if the `new_value` for 'pValue' exceeds the `old_value` by more than 10, effectively filtering minor changes. ```python class SomeAlgorithm(DetectionAlgorithm): @monitor_filter('pValue') def value_changed(self, old_value, new_value): return new_value > old_value + 10 ``` -------------------------------- ### Python Class Initialization Refactoring with super() Source: https://bacpypes.readthedocs.io/en/latest/releasenotes This section illustrates the evolution of class initialization in Python within the Bacpypes project. It demonstrates the transition from directly calling parent class `__init__` methods to using `super()`, which resolves issues with multiple base class initializations in complex inheritance hierarchies. It also shows how to handle specific keyword arguments while passing others up the inheritance chain. ```Python class Foo(Bar): def __init__(self): Bar.__init__(self) self.foo = 12 ``` ```Python class Foo(Bar): def __init__(self, *args, **kwargs): super(Foo, self).__init__(*args, **kwargs) self.foo = 12 ``` ```Python class Foo(Bar): def __init__(self, foo_arg=None, *args, **kwargs): super(Foo, self).__init__(*args, **kwargs) self.foo = 12 ``` -------------------------------- ### BACpypes Comm Module API Reference Source: https://bacpypes.readthedocs.io/en/latest/modules/comm API documentation for the `comm` module's global variables and functions. It includes definitions for `client_map`, `server_map`, `service_map`, `element_map`, and the `bind` function, outlining their purpose and parameters. ```APIDOC comm.client_map: Description: This is ... comm.server_map: Description: This is ... comm.service_map: Description: This is ... comm.element_map: Description: This is ... comm.bind(*args): Parameters: args: Type: list Description: a list of clients and servers to bind together in a stack ``` -------------------------------- ### bvll.BTR Class API Reference Source: https://bacpypes.readthedocs.io/en/latest/modules/bvllservice Detailed API documentation for the `bvll.BTR` class, outlining its constructor (`__init__`) and methods such as `indication`, `confirmation`, `add_peer`, and `delete_peer`, along with their parameters and purpose within the BACnet Virtual Link Layer (BVLL). ```APIDOC bvll.BTR: __init__() Description: This is a long line of text. indication(pdu) pdu: message to process Description: This is a long line of text. confirmation(pdu) pdu: message to process Description: This is a long line of text. add_peer(peerAddr[, networks]) peerAddr: peer address networks: list of networks reachable by peer Description: This is a long line of text. delete_peer(peerAddr) peerAddr: peer address Description: This is a long line of text. ``` -------------------------------- ### Update LocalDeviceObject Import in BACpypes Python Source: https://bacpypes.readthedocs.io/en/latest/migration/migration001 This snippet demonstrates how to update the import statement for LocalDeviceObject in BACpypes applications. In version 0.15.0, LocalDeviceObject has moved from bacpypes.app to bacpypes.service.device, requiring an update to application code to reflect its new module location. ```Python from bacpypes.app import LocalDeviceObject, BIPSimpleApplication ``` ```Python from bacpypes.app import BIPSimpleApplication from bacpypes.service.device import LocalDeviceObject ``` -------------------------------- ### Configure BACpypes Debug Log File Rotation Source: https://bacpypes.readthedocs.io/en/latest/gettingstarted/gettingstarted002 This command shows how to configure log file rotation for BACpypes debug output by specifying both `maxBytes` and `backupCount` (e.g., 100 files), allowing control over the number of archived log files. ```Shell $ python samples/WhoIsIAm.py --debug __main__ bacpypes.udp:traffic.txt:1048576:100 ``` -------------------------------- ### Specify BACpypes INI File on Command Line (BAC0.ini) Source: https://bacpypes.readthedocs.io/en/latest/gettingstarted/gettingstarted002 This command demonstrates how to override the default `BACpypes.ini` file by specifying an alternative INI file, such as `BAC0.ini`, directly on the command line using the `--ini` option, useful for managing different configurations. ```Shell $ python samples/WhoIsIAm.py --ini BAC0.ini ``` -------------------------------- ### API Documentation for bacpypes.udp Classes Source: https://bacpypes.readthedocs.io/en/latest/modules/udp Detailed API documentation for the `UDPDirector`, `UDPActor`, and `UDPPickleActor` classes, outlining their constructors, methods, attributes, and parameters. ```APIDOC Class: udp.UDPDirector Inherits: asyncore.dispatcher, Server, ServiceAccessPoint, Logging Description: This is a long line of text. Methods: __init__(self, address, timeout=0, actorClass=UDPActor, sid=None, sapID=None) Description: This is a long line of text. Parameters: address: the initial source value timeout: the initial source value actorClass: the initial source value sid: the initial source value sapID: the initial source value AddActor(actor) Description: This is a long line of text. Parameters: actor: the initial source value RemoveActor(actor) Description: This is a long line of text. Parameters: actor: the initial source value GetActor(address) Description: This is a long line of text. Parameters: address: the initial source value handle_connect() Description: This is a long line of text. readable() Description: This is a long line of text. handle_read() Description: This is a long line of text. writable() Description: This is a long line of text. handle_write() Description: This is a long line of text. handle_close() Description: This is a long line of text. indication(pdu) Description: This is a long line of text. _response(pdu) Class: udp.UDPActor Inherits: Logging Description: This is a long line of text. Attributes: director: This is a long line of text. peer: This is a long line of text. timeout: This is a long line of text. timer: This is a long line of text. Methods: __init__(director, peer) Description: This is a long line of text. Parameters: director: the initial source value peer: the initial destination value IdleTimeout() Description: This is a long line of text. indication(pdu) Description: This is a long line of text. Parameters: pdu: the initial source value response(pdu) Description: This is a long line of text. Parameters: pdu: the initial source value Class: udp.UDPPickleActor Inherits: UDPActor, Logging Description: Methods: indication(pdu) Description: This is a long line of text. Parameters: pdu: the initial source value response(pdu) Description: This is a long line of text. Parameters: pdu: the initial source value ``` -------------------------------- ### Instantiate and Print GlobalBroadcast Address Source: https://bacpypes.readthedocs.io/en/latest/tutorial/addressing Illustrates the `GlobalBroadcast` class, which represents a PDU destination for all devices across all networks. It requires no constructor parameters. The string output `*:*` signifies any network and any address. ```Python from bacpypes.pdu import GlobalBroadcast print(GlobalBroadcast()) ``` -------------------------------- ### Migrate BACpypes Application Subclasses for Default Service Support in Python Source: https://bacpypes.readthedocs.io/en/latest/migration/migration001 This snippet shows how to update BACpypes application subclasses to retain default service behavior after the Application class no longer includes services by default. To maintain previous functionality, mix in WhoIsIAmServices and ReadWritePropertyServices from their respective service modules into your custom application class. ```Python class MyApplication(Application): ... ``` ```Python from bacpypes.service.device import WhoIsIAmServices from bacpypes.service.object import ReadWritePropertyServices class MyApplication(Application, WhoIsIAmServices, ReadWritePropertyServices): ... ``` -------------------------------- ### API Documentation for bvll._MultiplexServer Class Source: https://bacpypes.readthedocs.io/en/latest/modules/bvllservice This snippet provides documentation for the `_MultiplexServer` class, another internal component that interfaces with the UDP multiplexer. It describes its `multiplexer` attribute, its constructor, and the `confirmation` method for handling message confirmations. ```APIDOC Class: bvll._MultiplexServer multiplexer Description: This is a long line of text. __init__(mux) Parameters: mux: multiplexer reference Description: This is a long line of text. confirmation(pdu) Parameters: pdu: message to process Description: This is a long line of text. ``` -------------------------------- ### Define Custom BACpypes Server Class Source: https://bacpypes.readthedocs.io/en/latest/tutorial/tutorial001 Defines `MyServer`, a custom class inheriting from `Server`. It overrides the `indication` method to process incoming requests by printing the argument and returning its uppercase version as a response. This demonstrates basic server-side request handling and response generation. ```python class MyServer(Server): def indication(self, arg): print('working on', arg) self.response(arg.upper()) ``` -------------------------------- ### Importing BACpypes IOCB and IOController Classes Source: https://bacpypes.readthedocs.io/en/latest/tutorial/iocb This snippet demonstrates how to import the fundamental IOCB (IO Control Block) and IOController classes from the bacpypes.iocb module. These classes are essential for defining and managing asynchronous I/O operations within BACpypes applications. ```Python from bacpypes.iocb import IOCB, IOController ``` -------------------------------- ### API Documentation for tcp.TCPClient Class Source: https://bacpypes.readthedocs.io/en/latest/modules/tcp Documents the TCPClient class, an asyncore.dispatcher subclass, detailing its constructor and various handlers for connection, read, write, and close events, along with an indication method. ```APIDOC class tcp.TCPClient(asyncore.dispatcher): __init__(peer): Parameters: peer: This is a long line of text. Description: This is a long line of text. handle_connect(): Description: This is a long line of text. handle_expt(): Description: This is a long line of text. readable(): Description: This is a long line of text. handle_read(): Description: This is a long line of text. writable(): Description: This is a long line of text. handle_write(): Description: This is a long line of text. handle_close(): Description: This is a long line of text. indication(pdu): Parameters: pdu: data to send Description: This is a long line of text. ``` -------------------------------- ### API Documentation for bvll.BIPForeign Class Source: https://bacpypes.readthedocs.io/en/latest/modules/bvllservice Documents the bvll.BIPForeign class, extending BIPSAP, Client, Server, and OneShotTask. It provides methods for PDU handling, foreign device registration, unregistration, and task processing. ```APIDOC bvll.BIPForeign(BIPSAP, Client, Server, OneShotTask): indication(pdu): pdu: message to process confirmation(pdu): pdu: message to process register(addr, ttl): addr: message to process ttl: time-to-live unregister(): process_task(): ``` -------------------------------- ### BACpypes Capability Module API Reference Source: https://bacpypes.readthedocs.io/en/latest/modules/capability API documentation for the `capability` module, detailing the `Capability` and `Collector` classes, their attributes, and methods for managing object capabilities. ```APIDOC module: capability class: Capability description: Base class for defining capabilities. attributes: _zIndex: int description: Capability functions are ordered by this attribute. class: Collector description: Manages and collects Capability derived classes. attributes: capabilities: list[Capability] description: A list of Capability derived classes that are in the inheritance graph. methods: __init__(): description: Initializes the collector, searching through the inheritance graph to build the list of Capability derived classes and then calling the __init__() method for each of them. capability_functions(fn: string) -> generator description: A generator that yields all of the functions of the Capability classes with the given name, ordered by z-index. parameters: fn: string description: Name of a capability function. add_capability(cls: class) description: Adds a Capability derived class to the method resolution order of the object. This will give the object a new value for its __class__ attribute. The __init__() method will also be called with the object instance. This new capability will only be given to the object, not other objects of the same type. parameters: cls: class description: The Capability derived class to add. _search_capability(base) description: Private method that returns a flattened list of all of the Capability derived classes, including other Collector classes that might be in the inheritance graph, using recursion. ```