06-22-2023, 06:48 PM
I was following this video
how to control VFD (Variable Frequency Drive) inverter by KC868-COLB - YouTube
And wrote this code to control my H100 Inverter ( How to: H100 VFD & 1.5KW Air-Cooled Spindle Setup - Zhong Hua Jiang - How To - Carbide 3D Community Site)
import serial
def calculate_crc(data):
reg_crc = 0xFFFF
for byte in data:
reg_crc ^= byte
for _ in range(8):
if reg_crc & 0x0001:
reg_crc = (reg_crc >> 1) ^ 0xA001
else:
reg_crc >>= 1
return reg_crc
# RS485 port settings
rs485_port = 'COM12'
rs485_baud_rate = 115200
rs485_parity = serial.PARITY_NONE
rs485_stop_bits = serial.STOPBITS_ONE
rs485_data_bits = serial.EIGHTBITS
try:
# Open the RS485 serial port
ser = serial.Serial(
port=rs485_port,
baudrate=rs485_baud_rate,
parity=rs485_parity,
stopbits=rs485_stop_bits,
bytesize=rs485_data_bits,
timeout=1
)
# Send a command via RS485 in RTU mode
command = [0x64, 0x01, 0x02, 0x20, 0x00, 0x00, 0x01, 0x43, 0xCA] # Modify the command in hexadecimal format
crc = calculate_crc(command)
command.append(crc & 0xFF) # Low byte
command.append((crc >> 8) & 0xFF) # High byte
ser.write(bytes(command))
# Read the RS485 response
response_rs485 = ser.readline()
hex_response_rs485 = ' '.join(hex(byte) for byte in response_rs485)
print("RS485 Response:", hex_response_rs485)
# Close the RS485 serial port
ser.close()
except serial.SerialException as e:
print("Error opening or accessing the serial port:", str(e))
This is the code I wrote. The checksum passes, and everything else is fine. But when I run the code, it doesn't reflect any changes on the Inverter/ Motor. Please help.
The connections on the RS485 can be found in the images attached below.
Please help! Thanks in advance.
how to control VFD (Variable Frequency Drive) inverter by KC868-COLB - YouTube
And wrote this code to control my H100 Inverter ( How to: H100 VFD & 1.5KW Air-Cooled Spindle Setup - Zhong Hua Jiang - How To - Carbide 3D Community Site)
import serial
def calculate_crc(data):
reg_crc = 0xFFFF
for byte in data:
reg_crc ^= byte
for _ in range(8):
if reg_crc & 0x0001:
reg_crc = (reg_crc >> 1) ^ 0xA001
else:
reg_crc >>= 1
return reg_crc
# RS485 port settings
rs485_port = 'COM12'
rs485_baud_rate = 115200
rs485_parity = serial.PARITY_NONE
rs485_stop_bits = serial.STOPBITS_ONE
rs485_data_bits = serial.EIGHTBITS
try:
# Open the RS485 serial port
ser = serial.Serial(
port=rs485_port,
baudrate=rs485_baud_rate,
parity=rs485_parity,
stopbits=rs485_stop_bits,
bytesize=rs485_data_bits,
timeout=1
)
# Send a command via RS485 in RTU mode
command = [0x64, 0x01, 0x02, 0x20, 0x00, 0x00, 0x01, 0x43, 0xCA] # Modify the command in hexadecimal format
crc = calculate_crc(command)
command.append(crc & 0xFF) # Low byte
command.append((crc >> 8) & 0xFF) # High byte
ser.write(bytes(command))
# Read the RS485 response
response_rs485 = ser.readline()
hex_response_rs485 = ' '.join(hex(byte) for byte in response_rs485)
print("RS485 Response:", hex_response_rs485)
# Close the RS485 serial port
ser.close()
except serial.SerialException as e:
print("Error opening or accessing the serial port:", str(e))
This is the code I wrote. The checksum passes, and everything else is fine. But when I run the code, it doesn't reflect any changes on the Inverter/ Motor. Please help.
The connections on the RS485 can be found in the images attached below.
Please help! Thanks in advance.