2. Basic Recipes
The following recipes demonstrate some of the capabilities of the “Python API for Lanner PSP”. Please note that all recipes are written assuming Python 3.6+.
2.1. Importing Lanner PSP
In Python, libraries and functions used in a script must be imported by name at the top of the file, with the exception of the functions built into Python by default.
For example, to use the HWM
interface from Lanner PSP, it
should be explicitly imported:
from lannerpsp import HWM
Now HWM
is available directly in your script:
hwm = HWM()
Alternatively, the whole Lanner PSP library can be imported:
import lannerpsp
In this case, all references to items within Lanner PSP must be prefixed:
hwm = lannerpsp.HWM()
2.2. Hardware Configuration
The Hardware Configuration Diagram, Block Diagram and Motherboard Layout can be found in the user manual on Lanner’s official website product page.
2.3. GPIO
Example for LEC-2290:
LEC-2290 has 1x 20 pin terminal block 8 DI (12V) & 8 DO (12V,100mA) Isolation, you can get
or set the GPIO
status according to your needs:
from lannerpsp import GPIO
gpio = GPIO()
# Get GPIO information.
gpio_info = gpio.get_info()
# Get the number of GPI/DI pins on LEC-2290:
print(gpio_info.number_of_di_pins) # It should print 8.
# Get the number of GPO/DO pins on LEC-2290:
print(gpio_info.number_of_do_pins) # It should print 8.
# Get GPI/DI status (LSB is DI_0).
print(gpio.get_digital_in())
# Set the values of (DO_7 to DO_0) to (1101 0011) signal,
# you can use your preferred integer representation (LSB is DO_0).
# 1. Use binary integer:
gpio.set_digital_out(0b11010011)
# 2. Use octal integer:
gpio.set_digital_out(0o323)
# 3. Use decimal integer:
gpio.set_digital_out(211)
# 4. Use hexadecimal integer:
gpio.set_digital_out(0xD3)
2.4. GPS
Example for V6S:
Connect the GPS antenna and place it in an open and unshaded place to ensure that the GPS can receive satellite signals normally.
Search for the port of the GPS
on V6S:
from lannerpsp import GPS
gps = GPS()
print(gps.search_port()) # It should print '/dev/ttyS5'.
2.5. LCD Module
Example for NCA-2510:
NCA-2510 has a LCD Module with a keypad, you can write string to the LCM
or get the keypad status:
from lannerpsp import LCM
lcm = LCM()
# Clear LCM display.
lcm.clear()
# Move the cursor to the initial position.
lcm.set_cursor(1, 1)
# Write string to LCD module.
lcm.write("Hello World")
2.6. COM Port
Example for LEC-7230M:
LEC-7230M has 2x DB9 Serial COM ports supporting RS232/422/485, you can set
the COMPort
mode according to your needs:
from lannerpsp import COMPort
com1 = COMPort(1)
# Set COM port mode to RS-485.
com1.set_mode(485)
# Get COM port information.
com1_info = com1.get_info()
print(com1_info.mode) # It should print 485.
print(com1_info.mode_str) # It should print 'RS-485'.
2.7. PoE
Example for IIoT-I530:
IIoT-I530 SKU A has 6x GbE RJ45 for PoE+ (Total PoE budget of 120W), you can set
the PoE
power status according to your needs:
from lannerpsp import PoE
# Get PoE information.
poe_info = PoE.get_info()
# Get the number of PoE ports on IIoT-I530:
print(poe_info.number_of_poe_ports) # It should print 6.
# Get the power status of all PoE ports on IIoT-I530:
print(poe_info.power_status)
# Use PoE port-1:
poe1 = PoE(1)
# Enable the PoE port-1 power (power on by auto):
poe1.enable()
# Get the PoE port-1 power status:
print(poe1.get_power_status()) # It should print True.
# Disable the PoE port-1 power (power off):
poe1.disable()
# Get the PoE port-1 power status:
print(poe1.get_power_status()) # It should print False.
2.8. RF Module
Example for LEC-7242:
2.8.1. Installation for SIM Card
Locate the SIM card slot. Unsecure the screw and remove the cover from the front panel.
Insert the SIM card into the slot with the gold contacts facing side.
SIM1, SIM2 for M.2 LTE module, SIM3, SIM4 for mini-PCIe LTE module:
Note
No need to shut down the system while installing/exchanging the SIM card. The Cover-Remove-detect I/O will deliver the GPO signal and cut off the Power of m.2 and mini PCIe while uninstalls the cover.
LEC-7242 is pre-installed with a mini-PCIe LTE module. Suppose a SIM card is installed in each of the SIM3 and SIM4 slots, and SIM3 is enabled. If you want to switch the SIM card from SIM3 slot to SIM4 slot:
from time import sleep
from lannerpsp import RFM
rfm = RFM()
print(rfm.get_sim_status()) # It should print 0.
# Power off the mini-PCIe LTE module.
# 01: mPCIe -> off, M.2 -> on
rfm.set_power_status(1)
# Switch to SIM4 slot.
# 10: mPCIe -> second sim (SIM4), M.2 -> first sim (SIM1)
rfm.set_sim_status(2)
# Power on the mini-PCIe LTE module.
# 11: mPCIe -> on, M.2 -> on
rfm.set_power_status(3)
# It will take about 15 seconds for the SIM card to be switched successfully.
sleep(15)
2.9. System LED
Example for LEC-7242:
LEC-7242 has a Yellow LED for Alarm, you can set the SystemLED
light mode according to your needs:
from time import sleep
from lannerpsp import SystemLED
led = SystemLED()
while True:
led.red()
sleep(1)
led.off()
sleep(1)
2.10. GPS Status LED
Example for LEC-7242:
LEC-7242 has 1x Blue LED for GPS status, you can set the GPSStatusLED
light mode according to your needs:
from time import sleep
from lannerpsp import GPSStatusLED
led = GPSStatusLED()
while True:
led.on()
sleep(2)
led.blink()
sleep(2)
led.off()
sleep(2)
2.11. LTE Status LED
Example for LEC-7242:
LEC-7242 has 1x Yellow/Green/Red LED for LTE status, you can set the LTEStatusLED
light mode according to your needs:
from time import sleep
from lannerpsp import LTEStatusLED
led = LTEStatusLED()
led.red()
sleep(2)
led.red_blink()
sleep(2)
led.green()
sleep(2)
led.green_blink()
sleep(2)
led.yellow()
sleep(2)
led.yellow_blink()
sleep(2)
led.off()
2.12. LTE Stress LED
Example for LEC-7242:
LEC-7242 has 4x Blue LED for LTE signal level status, you can set the LTEStressLED
signal strength from 1% to 100%:
from lannerpsp import LTEStressLED
led = LTEStressLED()
led.set_strength(87)