mirror of
https://github.com/intrepidcs/libicsneo.git
synced 2026-08-05 09:28:40 +02:00
Docs: Refactor icsneopy examples
This commit is contained in:
committed by
Kyle Schwarz
parent
cf2cf3e28b
commit
3c0c0dd44c
@@ -0,0 +1,56 @@
|
||||
===================
|
||||
CAN Getting Started
|
||||
===================
|
||||
|
||||
Prerequisites
|
||||
=============
|
||||
|
||||
- Python 3.8 or higher
|
||||
- icsneopy library installed
|
||||
- CAN hardware device connected
|
||||
|
||||
:download:`Download complete example <../../examples/python/can/can_complete_example.py>`
|
||||
|
||||
Basic Setup
|
||||
===========
|
||||
|
||||
1. Import the library and discover devices:
|
||||
|
||||
.. literalinclude:: ../../examples/python/can/can_complete_example.py
|
||||
:language: python
|
||||
:lines: 11-19
|
||||
|
||||
2. Configure and open the device:
|
||||
|
||||
.. literalinclude:: ../../examples/python/can/can_complete_example.py
|
||||
:language: python
|
||||
:lines: 22-37
|
||||
|
||||
Transmitting CAN Frames
|
||||
========================
|
||||
|
||||
.. literalinclude:: ../../examples/python/can/can_complete_example.py
|
||||
:language: python
|
||||
:lines: 40-53
|
||||
|
||||
Receiving CAN Frames
|
||||
=====================
|
||||
|
||||
.. literalinclude:: ../../examples/python/can/can_complete_example.py
|
||||
:language: python
|
||||
:lines: 56-72
|
||||
|
||||
Cleanup and Resource Management
|
||||
===============================
|
||||
|
||||
.. literalinclude:: ../../examples/python/can/can_complete_example.py
|
||||
:language: python
|
||||
:lines: 75-79
|
||||
|
||||
Complete Example with Error Handling
|
||||
====================================
|
||||
|
||||
.. literalinclude:: ../../examples/python/can/can_complete_example.py
|
||||
:language: python
|
||||
:lines: 82-125
|
||||
|
||||
@@ -0,0 +1,70 @@
|
||||
=========================
|
||||
Ethernet Getting Started
|
||||
=========================
|
||||
|
||||
This guide provides basic instructions for working with Ethernet devices using the icsneopy library.
|
||||
|
||||
Prerequisites
|
||||
=============
|
||||
|
||||
- Python 3.8 or higher
|
||||
- icsneopy library installed
|
||||
- Intrepid Control Systems Device
|
||||
|
||||
:download:`Download complete example <../../examples/python/ethernet/ethernet_complete_example.py>`
|
||||
|
||||
Opening the Device
|
||||
==================
|
||||
|
||||
To begin working with an Ethernet device, you must first discover, open, and bring it online:
|
||||
|
||||
.. literalinclude:: ../../examples/python/ethernet/ethernet_complete_example.py
|
||||
:language: python
|
||||
:lines: 11-37
|
||||
|
||||
Transmitting Ethernet Frames
|
||||
=============================
|
||||
|
||||
Transmit Ethernet frames using the EthernetMessage class:
|
||||
|
||||
.. literalinclude:: ../../examples/python/ethernet/ethernet_complete_example.py
|
||||
:language: python
|
||||
:lines: 61-78
|
||||
|
||||
Monitoring Ethernet Status
|
||||
==========================
|
||||
|
||||
Monitor Ethernet link status changes using message callbacks:
|
||||
|
||||
.. literalinclude:: ../../examples/python/ethernet/ethernet_complete_example.py
|
||||
:language: python
|
||||
:lines: 39-40
|
||||
|
||||
DoIP Ethernet Activation Control
|
||||
================================
|
||||
|
||||
Diagnostics over Internet Protocol (DoIP) can be controlled through digital I/O pins:
|
||||
|
||||
:download:`Download DoIP example <../../examples/python/doip/doip_activation_control.py>`
|
||||
|
||||
.. literalinclude:: ../../examples/python/doip/doip_activation_control.py
|
||||
:language: python
|
||||
:lines: 28-44
|
||||
|
||||
Network Configuration Reference
|
||||
===============================
|
||||
|
||||
Standard Ethernet network identifiers:
|
||||
|
||||
- ``icsneopy.Network.NetID.ETHERNET_01`` - Standard Ethernet Port 1
|
||||
|
||||
Automotive Ethernet network identifiers:
|
||||
|
||||
- ``icsneopy.Network.NetID.AE_01`` - Automotive Ethernet Port 1
|
||||
|
||||
Complete Example with Resource Management
|
||||
=========================================
|
||||
|
||||
.. literalinclude:: ../../examples/python/ethernet/ethernet_complete_example.py
|
||||
:language: python
|
||||
:lines: 86-127
|
||||
+32
-94
@@ -3,128 +3,66 @@ Python Examples
|
||||
===============
|
||||
|
||||
Transmit CAN frames on DW CAN 01
|
||||
============================
|
||||
=================================
|
||||
|
||||
.. code-block:: python
|
||||
:download:`Download example <../../examples/python/can/can_transmit_basic.py>`
|
||||
|
||||
import icsneopy
|
||||
|
||||
devices: list[icsneopy.Device] = icsneopy.find_all_devices()
|
||||
|
||||
# grab the first/only device found
|
||||
device: icsneopy.Device = devices[0]
|
||||
|
||||
message = icsneopy.CANMessage()
|
||||
message.network = icsneopy.Network(icsneopy.Network.NetID.DWCAN_01)
|
||||
message.arbid = 0x56
|
||||
message.data = (0x11, 0x22, 0x33)
|
||||
|
||||
device.open()
|
||||
|
||||
device.go_online()
|
||||
|
||||
device.transmit(message)
|
||||
.. literalinclude:: ../../examples/python/can/can_transmit_basic.py
|
||||
:language: python
|
||||
|
||||
Receive CAN frames on DW CAN 01
|
||||
===========================
|
||||
================================
|
||||
|
||||
.. code-block:: python
|
||||
:download:`Download example <../../examples/python/can/can_receive_basic.py>`
|
||||
|
||||
import icsneopy
|
||||
import time
|
||||
.. literalinclude:: ../../examples/python/can/can_receive_basic.py
|
||||
:language: python
|
||||
|
||||
devices: list[icsneopy.Device] = icsneopy.find_all_devices()
|
||||
Complete CAN Example
|
||||
====================
|
||||
|
||||
# grab the first/only device found
|
||||
device: icsneopy.Device = devices[0]
|
||||
:download:`Download example <../../examples/python/can/can_complete_example.py>`
|
||||
|
||||
def on_message(message: icsneopy.CANMessage):
|
||||
print(message.arbid, message.data)
|
||||
message_filter = icsneopy.MessageFilter(icsneopy.Network.NetID.DWCAN_01)
|
||||
callback = icsneopy.MessageCallback(on_message, message_filter)
|
||||
.. literalinclude:: ../../examples/python/can/can_complete_example.py
|
||||
:language: python
|
||||
|
||||
device.add_message_callback(callback)
|
||||
|
||||
device.open()
|
||||
device.go_online()
|
||||
Transmit Ethernet frames on Ethernet 01
|
||||
========================================
|
||||
|
||||
# rx for 10s
|
||||
time.sleep(10)
|
||||
:download:`Download example <../../examples/python/ethernet/ethernet_transmit_basic.py>`
|
||||
|
||||
.. literalinclude:: ../../examples/python/ethernet/ethernet_transmit_basic.py
|
||||
:language: python
|
||||
|
||||
Monitor Ethernet Status
|
||||
=======================
|
||||
|
||||
.. code-block:: python
|
||||
:download:`Download example <../../examples/python/ethernet/ethernet_monitor_status.py>`
|
||||
|
||||
import icsneopy
|
||||
import time
|
||||
.. literalinclude:: ../../examples/python/ethernet/ethernet_monitor_status.py
|
||||
:language: python
|
||||
|
||||
def main():
|
||||
devices = icsneopy.find_all_devices()
|
||||
if len(devices) == 0:
|
||||
print("error: no devices found")
|
||||
return False
|
||||
|
||||
device = devices[0]
|
||||
print(f"info: monitoring Ethernet status on {device}")
|
||||
|
||||
def on_message(message):
|
||||
print(f"info: network: {message.network}, state: {message.state}, speed: {message.speed}, duplex: {message.duplex}, mode: {message.mode}")
|
||||
|
||||
filter = icsneopy.MessageFilter(icsneopy.Message.Type.EthernetStatus)
|
||||
callback = icsneopy.MessageCallback(on_message, filter)
|
||||
device.add_message_callback(callback)
|
||||
|
||||
if not device.open():
|
||||
print("error: unable to open device")
|
||||
return False
|
||||
|
||||
if not device.go_online():
|
||||
print("error: unable to go online")
|
||||
return False
|
||||
|
||||
while True:
|
||||
time.sleep(1)
|
||||
|
||||
main()
|
||||
|
||||
TC10
|
||||
====
|
||||
TC10 Power Management
|
||||
=====================
|
||||
|
||||
:download:`Download example <../../examples/python/tc10/tc10.py>`
|
||||
|
||||
.. literalinclude:: ../../examples/python/tc10/tc10.py
|
||||
:language: python
|
||||
|
||||
DoIP Ethernet Activation
|
||||
========================
|
||||
|
||||
.. code-block:: python
|
||||
:download:`Download example <../../examples/python/doip/doip_activation_control.py>`
|
||||
|
||||
import icsneopy
|
||||
import time
|
||||
.. literalinclude:: ../../examples/python/doip/doip_activation_control.py
|
||||
:language: python
|
||||
|
||||
devs = icsneopy.find_all_devices()
|
||||
Complete Ethernet Example
|
||||
=========================
|
||||
|
||||
dev = devs[0]
|
||||
:download:`Download example <../../examples/python/ethernet/ethernet_complete_example.py>`
|
||||
|
||||
dev.open()
|
||||
|
||||
# the device must be online for digital I/O
|
||||
dev.go_online()
|
||||
|
||||
print(f"initial state: {dev.get_digital_io(icsneopy.IO.EthernetActivation, 1)}")
|
||||
|
||||
dev.set_digital_io(icsneopy.IO.EthernetActivation, 1, True)
|
||||
|
||||
print(f"after setting to true: {dev.get_digital_io(icsneopy.IO.EthernetActivation, 1)}")
|
||||
|
||||
# allow for observing the change
|
||||
time.sleep(2)
|
||||
|
||||
dev.set_digital_io(icsneopy.IO.EthernetActivation, 1, False)
|
||||
|
||||
print(f"after setting to false: {dev.get_digital_io(icsneopy.IO.EthernetActivation, 1)}")
|
||||
|
||||
# allow for observing the change
|
||||
time.sleep(2)
|
||||
.. literalinclude:: ../../examples/python/ethernet/ethernet_complete_example.py
|
||||
:language: python
|
||||
|
||||
@@ -5,6 +5,8 @@ icsneopy
|
||||
.. toctree::
|
||||
:maxdepth: 2
|
||||
|
||||
can_getting_started
|
||||
ethernet_getting_started
|
||||
examples
|
||||
api
|
||||
radepsilon
|
||||
|
||||
Reference in New Issue
Block a user