Create and Delete an Object
Tobias Müller, M. Eng edited this page 5 years ago

📜 Table of Contents


Create and Delete an Object

Import Xcom-API-Class:

To use the Xcom-API, either you need to import the class into your python-script, or you write your code directly inside the "Xcom_API.py" file. If you want to import the "Xcom_API.py" into your own python script, make sure, that the "Xcom_API.py" file is located inside the python-module search path. This is either the folder/directory where your script is located or under Microsoft Windows the path:

<drive>:\<install_path_to_python>\<python_folder_with_version>\Lib\site-packages

for example:

C:\Program Files\Python34-64\Lib\site-packages

or under Linux the path:

/usr/local/lib/<python_folder_with_version>

for example:

/usr/local/lib/python3.4

To import the class use the python-code:

>>> # import module
>>> from Xcom_API import Xcom_API

or:

>>> # import module
>>> from Xcom_API import *
Create an Object:

Now you are able to create an object of the Xcom-API-Class. For example with the code:

>>> # create object of the Xcom-API-Class
>>> object = Xcom_API()

If you create an object, the "__init__" method of the class will be called. It checks the passed arguments and store them. There are predefined arguments for this object, if you generate an objects without the relevant arguments, such like in the shown code-example before. The predefined arguments are:

crc         = True
source      = 1
destination = 101

The "crc" value indicates, whether the CRC check for this object in active or not. The "source" value indicates the address of the Xcom-232i, which is the CAN-RS232-Bridge. Normally the standard address is "1", if you have only one Xcom-232i in your configuration. The "destination" value is the address of the Xtender-Module, which you want to communicate with. If you want to change one or more of these arguments, then change it's value. For example:

>>> # create object of the Xcom-API-Class with CRC-Check disable and
>>> # destination address = 103
>>> object = Xcom_API(crc=False,destination=103)

For each Xtender-Module you want to communicate with, you must create an own object for it. You can't change any arguments after creating an object. This is a safety aspect, which prevents you against confusing code, because each object represents a Xtender-Module. So make sure, that the object name is well chosen.

Delete an Object:

To delete an object, just use the "del" expression.

>>> # delete an object
>>> del object

This calls the "__del__" method of the class, which delete the object specific arguments such like: "crc", "source" and "destination", and the object itself.


Hochschule Anhalt | Anhalt University of Applied Sciences | Department 6 EMW
Xcom-API

Tobias Müller, M. Eng.
📧 Tobias.Mueller@HS-Anhalt.de

© es-lab.de, 31.10.2017