Ethernet Getting Started

This guide provides basic instructions for working with Ethernet devices using the icsneopy library.

Prerequisites

  • Python 3.8 or higher

  • icsneopy installed (see Installation)

  • Intrepid Control Systems Device

Download complete example

Opening the Device

To begin working with an Ethernet device, you must first discover, open, and bring it online:

def setup_device():
	"""Initialize Ethernet device."""
	devices = icsneopy.find_all_devices()
	if not devices:
		raise RuntimeError("No devices found")

	device = devices[0]
	print(f"Using device: {device}")
	return device


def open_device(device):
	"""Open device connection."""
	try:
		if not device.open():
			raise RuntimeError("Failed to open device")

		if not device.go_online():
			device.close()
			raise RuntimeError("Failed to go online")

		print("Device initialized successfully")
		return True

	except Exception as e:
		print(f"Device setup failed: {e}")
		return False

Transmitting Ethernet Frames

Transmit Ethernet frames using the EthernetMessage class:

			f"Length: {len(frame.data)}")
	frame_filter = icsneopy.MessageFilter(icsneopy.Network.NetID.ETHERNET_02)
	callback = icsneopy.MessageCallback(frame_handler, frame_filter)
	device.add_message_callback(callback)

	print("Ethernet frame reception configured")
	return 0


def transmit_ethernet_frame(device):
	"""Transmit an Ethernet frame."""
	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

Monitoring Ethernet Status

Monitor Ethernet link status changes using message callbacks:

def on_status_message(message):
	print(f"info: network: {message.network}, state: {message.state}, speed: {message.speed}, duplex: {message.duplex}, mode: {message.mode}")

DoIP Ethernet Activation Control

Diagnostics over Internet Protocol (DoIP) can be controlled through digital I/O pins:

Download DoIP example

		initial_state = device.get_digital_io(icsneopy.IO.EthernetActivation, 1)
		print(f"Initial DoIP activation state: {initial_state}")

		print("Activating DoIP Ethernet...")
		device.set_digital_io(icsneopy.IO.EthernetActivation, 1, True)
		time.sleep(1)

		active_state = device.get_digital_io(icsneopy.IO.EthernetActivation, 1)
		print(f"DoIP activated: {active_state}")
		time.sleep(2)

		print("Deactivating DoIP Ethernet...")
		device.set_digital_io(icsneopy.IO.EthernetActivation, 1, False)
		time.sleep(1)

		final_state = device.get_digital_io(icsneopy.IO.EthernetActivation, 1)
		print(f"DoIP deactivated: {final_state}")

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


	return success

def cleanup_device(device):
	"""Close device connection."""
	if device:
		device.close()
		print("Device connection closed")

def main():
	"""Complete Ethernet example"""
	device = None

	try:
		# Initialize device
		device = setup_device()

		# Open device
		if not open_device(device):
			raise RuntimeError("Failed to initialize device")
		
		filter = icsneopy.MessageFilter(icsneopy.Message.Type.EthernetStatus)
		status_callback = icsneopy.MessageCallback(on_status_message, filter)
		device.add_message_callback(status_callback)

		#Setup Ethernet Callback
		setup_ethernet_reception(device)

		# Transmit an Ethernet frame
		transmit_result = transmit_ethernet_frame(device)
		if not transmit_result:
			print("Warning: Failed to transmit frame")

		# Monitor for a period
		print("Monitoring for 10 seconds...")
		time.sleep(10)

		print(f"Monitoring completed.")

	except Exception as e:
		print(f"Error: {e}")
		return 1