ruida-laser
ruida-laser copied to clipboard
Receives ACK but nothing happens when I send commands
Hey guys! I've tried everything and nothing works. I tried using some of the ruida-laser code but what I want is a way to send simple commands like the 50207 port allows. Btw I got that to work. In the code below I call the "Start Process" using the D8 00 provided by the docs and I recieve ACK but my laser is not doing anything. What is the problem? I've tried swizzling but that wont work. Am I supposed to swizzle the checksum or put the unswizzled checksum togheter with the swizzled payload? Please take a look below and see if you can find a problem.
import os
import sys
import time
from socket import *
host = "192.168.68.163"
class RuidaUdp():
NETWORK_TIMEOUT = 4000
INADDR_ANY_DOTTED = '0.0.0.0' # bind to all interfaces
SOURCE_PORT = 40200 # used by rdworks in Windows
DEST_PORT = 50200 # Ruida Board
verbose = True # babble while working
retry_delay_sec = 0.2 # delay between retries
retry_delay_sec_max = 5.0 # maximum retry delay
def __init__(self, host, port=DEST_PORT, localport=SOURCE_PORT):
self.sock = socket(AF_INET, SOCK_DGRAM)
localport = os.environ.get("UDPSENDRUIDA_LOCALPORT", str(localport))
self.sock.bind((self.INADDR_ANY_DOTTED, int(localport)))
self.sock.connect((host, port))
self.sock.settimeout(self.NETWORK_TIMEOUT * 0.001)
def _checksum(self, data):
cs = sum(data)
b1 = cs & 0xff
b0 = (cs >> 8) & 0xff
return bytes([b0, b1])
def send(self, data):
# Add checksum to the payload
chksum = self._checksum(data)
buf = chksum + data
retry = True # Always retry if there is an error
while retry:
self.sock.send(buf)
try:
response = self.sock.recv(8) # timeout raises an exception
except Exception as e:
print(f"Error receiving data: {e}")
break
if len(response) == 0:
if self.verbose:
print("Received nothing (empty)")
break
if response[0] == 0x46: # 'F' indicates an error
if self.verbose:
print("Received error response, retrying...")
time.sleep(self.retry_delay_sec)
if self.retry_delay_sec < self.retry_delay_sec_max:
self.retry_delay_sec *= 2
elif response[0] == 0xc6: # 'C' indicates acknowledgment
if self.verbose:
print("Received ACK")
retry = False
else:
print(f"Unknown response: {response[0]:02x}")
break
payload = b"\xD8\x00" # The fixed data payload
laser = RuidaUdp(host)
laser.send(payload)