mirror of
https://github.com/intrepidcs/libicsneo.git
synced 2026-08-05 01:18:36 +02:00
Docs: Refactor icsneopy examples
This commit is contained in:
committed by
Kyle Schwarz
parent
cf2cf3e28b
commit
3c0c0dd44c
@@ -0,0 +1,45 @@
|
||||
"""
|
||||
Basic Ethernet frame transmission example using icsneopy library.
|
||||
|
||||
Demonstrates how to transmit Ethernet frames on Ethernet 01.
|
||||
"""
|
||||
|
||||
import icsneopy
|
||||
|
||||
|
||||
def transmit_ethernet_frame():
|
||||
"""Transmit an Ethernet frame."""
|
||||
devices = icsneopy.find_all_devices()
|
||||
if not devices:
|
||||
raise RuntimeError("No devices found")
|
||||
|
||||
device = devices[0]
|
||||
|
||||
try:
|
||||
if not device.open():
|
||||
raise RuntimeError("Failed to open device")
|
||||
|
||||
if not device.go_online():
|
||||
raise RuntimeError("Failed to go online")
|
||||
|
||||
frame = icsneopy.EthernetMessage()
|
||||
frame.network = icsneopy.Network(icsneopy.Network.NetID.ETHERNET_01)
|
||||
frame.data = [
|
||||
0x00, 0xFC, 0x70, 0x00, 0x01, 0x02,
|
||||
0x00, 0xFC, 0x70, 0x00, 0x01, 0x01,
|
||||
0x08, 0x00,
|
||||
0x01, 0xC5, 0x01, 0xC5
|
||||
]
|
||||
|
||||
success = device.transmit(frame)
|
||||
if success:
|
||||
print("Frame transmitted successfully")
|
||||
else:
|
||||
print("Failed to transmit frame")
|
||||
|
||||
finally:
|
||||
device.close()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
transmit_ethernet_frame()
|
||||
Reference in New Issue
Block a user