This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision | ||
en:libschsat-py [2019/12/30 17:06] golikov |
en:libschsat-py [2020/03/25 16:28] (current) |
||
---|---|---|---|
Line 1: | Line 1: | ||
+ | ====== Python Function Libraries ====== | ||
+ | |||
**Description of Python Function Libraries** | **Description of Python Function Libraries** | ||
Line 7: | Line 9: | ||
Here is what you need to create a bare-bones Python project: | Here is what you need to create a bare-bones Python project: | ||
- | 1. Place your Python into a separate file with the .py extension (Do not use the following reserved filenames: main.py and schsat.py). | + | 1. Place your Python into a separate file with the ''.py'' extension (Do not use the following reserved filenames: ''main.py'' and ''schsat.py''). |
- | 2. Implement a function named control in Python (The control() function is an entry point into your Python code. View it in the same manner as the main() function). | + | |
+ | 2. Implement a function named ''control'' in Python (The ''control()'' function is an entry point into your Python code. View it in the same manner as the ''main()'' function). | ||
Example of a simple project in Python | Example of a simple project in Python | ||
Line 30: | Line 33: | ||
hyro_request_reset(num) -> err | hyro_request_reset(num) -> err | ||
- | The preceding example describes an interface named ''hyro_request_reset'' – this is the name of a Python function; the function accepts a single argument ''num'' (sensor number) and returns a single value err (error code). | + | The preceding example describes an interface named ''hyro_request_reset'' – this is the name of a Python function; the function accepts a single argument ''num'' (sensor number) and returns a single value ''err'' (error code). |
- | Most functions expect device ID (sensor number or the number of a particular actuator of given type) as their first argument. Devices are commonly numbered 0 to 3. Furthermore, most function return the execution status of the function being invoked (the error code). The foregoing example denotes this fact with the symbol pair -> err. | + | Most functions expect ''device ID'' (sensor number or the number of a particular actuator of given type) as their first argument. Devices are commonly numbered 0 to 3. Furthermore, most function return the execution status of the function being invoked (the error code). The foregoing example denotes this fact with the symbol pair -> ''err''. |
- | When using functions it is important to analyze the return code (the err value). When the function being called completes without an error it returns zero (0), otherwise a nonzero value is returned. Sample handling of the return value of the function: | + | When using functions it is important to analyze the return code (the ''err'' value). When the function being called completes without an error it returns zero (0), otherwise a nonzero value is returned. Sample handling of the return value of the function: |
<code python> | <code python> | ||
Line 44: | Line 47: | ||
There are common functions named ''interface_request_reset'', ''interface_get_state'', ''interface_turn_on()'' and ''interface_turn_off'', where ''interface'' , where interface is the interface name. | There are common functions named ''interface_request_reset'', ''interface_get_state'', ''interface_turn_on()'' and ''interface_turn_off'', where ''interface'' , where interface is the interface name. | ||
- | These functions are generally used as follows. This example is for the interface named hyro: | + | These functions are generally used as follows. This example is for the interface named ''hyro'': |
<code python> | <code python> |