Python

from socket import socket, AF_INET, SOCK_DGRAM, IPPROTO_UDP
 
 
reader_ip: str = "192.168.1.190"
reader_port: int = 65_535
 
udp_client = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP)
udp_client.connect((reader_ip.encode(), reader_port))
udp_client.settimeout(5)
 
 
def request(command: str) -> str:
    udp_client.send(command.encode())
    response = udp_client.recv(4096).decode()
    if response.startswith("C"):
        raise Exception(f"Command error, request command: {command}")
    elif response.startswith("R"):
        raise Exception(f"Device refuses to execute command, request command: {command}")
    elif response.startswith("D"):
        raise Exception(f"Can't connect to the device, request command: {command}")
    elif response.startswith("F"):
        raise Exception(f"Command execution failed, request command: {command}")
    return response[1:]  # Remove the first character which is a status code
 
 
# Send echo
echo: str = request("X")
print(f"Echo: {echo}")
 
# Send login
request("L")
 
# Get - Network command parameter
print(f"Username: {request("GON")}")
print(f"Device name: {request("GDN")}")
print(f"MAC address: {request("GFE")}")
print(f"DHCP enable? {True if bool(int(request("GDH"))) else False}")
print(f"IP address: {request("GIP")}")
print(f"Port number: {request("GPN")}")
print(f"Transmission protocol: {request("GTP")}")
print(f"Connection timeout: {request("GCT")}")
print(f"Working mode: {request("GRM")}")
print(f"Connection mode: {request("GCM")}")
print(f"Destination port number: {request("GDP")}")
print(f"Gateway IP address: {request("GGI")}")
print(f"Network mask: {request("GNM")}")
 
# Get - Serial command parameter
print(f"Serial working mode: {request("GSI")}")
print(f"Flow direction control (RTS / CTS signal setting): {'Used' if bool(int(request("GFC"))) else 'Not used'}")
print(f"DTR setting: {'Used' if bool(int(request("GDT"))) else 'Not used'}")
print(f"Baud rate setting: {request("GBR")}")
print(f"Parity bit setting: {request("GPR")}")
print(f"Bit setting: {request("GBB")}")
 
# Set
username: str = "electron" # Username
request(f"SON{username}")
device_name: str = "hw-vx" # Device name
request(f"SDN{device_name}")
# ip_address: str = "192.168.1.191" # IP address
# request(f"SIP{ip_address}")
 
# Restart
request("E")
 
udp_client.close()