wind direction using RS845 - error

userHead John.Harrison 2023-11-02 22:50:59 333 Views2 Replies

I am using the following code to get the wind direction from a wind vane via a RS845 using the following code

 

import minimalmodbus


instrument = minimalmodbus.Instrument('/dev/ttyACM0', 2)  # Address 2 for your sensor

# Set the communication parameters (you may need to adjust these)
instrument.serial.baudrate = 9600
instrument.serial.timeout = 1  # Set the timeout value as needed

try:
   # Read wind direction data (replace 1 with the register address for wind direction)
   wind_direction = instrument.read_register(1, functioncode=3)
   print(f"Wind Direction: {wind_direction} degrees")

except Exception as e:
   print(f"Error reading sensor data: {e}")

finally:
   instrument.serial.close()
 

I get the following error and have no idea how to proceed

 

Error reading sensor data: Too short Modbus RTU response (minimum length 4 bytes). Response: b'\x00'

 

A point in the right direction would be helpful.

2023-11-03 14:38:46

Hello,

 

The error message you are seeing indicates that the response from the sensor is too short for a valid Modbus RTU frame. A Modbus RTU frame must have a minimum of 4 bytes - the slave address, the function code, a minimum of one byte of data, and the CRC check. Here are some steps you can take to troubleshoot this issue:

 

Check Wiring and Connections: Ensure that all connections are secure and correct. Issues with the RS485 network wiring, termination, or bias resistors can cause incomplete messages.

 

Verify Modbus Settings: Ensure that the Modbus slave ID, baud rate, data bits, parity, and stop bits settings match what the wind vane expects. Any mismatch in these settings can cause communication failure.

 

Confirm Register Address: Make sure the register address (1 in your code) is correct and that it corresponds to the wind direction data in the documentation for your wind vane.

 

Check for Support of Function Code: Verify that your wind vane supports the Modbus function code 3 (Read Holding Registers). Some devices may use different function codes or register addresses.

 

Inspect the Instrument's Initialization Parameters: Sometimes, different devices might require specific configurations during initialization. Check the wind vane's manual to see if there are any specific parameters you need to pass to minimalmodbus.Instrument().

 

Modbus Mode: The Modbus protocol has two modes, ASCII and RTU. Make sure you're using the correct mode. For minimalmodbus, the mode is set to RTU by default, but if your device uses ASCII mode, you'll need to change the mode using instrument.mode = minimalmodbus.MODE_ASCII.

 

Check for Noise or Interference: RS485 is generally robust, but in some environments, electrical noise can cause issues. Check if the environment has high electromagnetic interference (EMI) and try using shielded cables or moving the setup to a different location.

 

Check Power Supply: Ensure that the sensor is powered correctly. An underpowered sensor can sometimes fail to respond correctly.

 

Use a Modbus Master Simulator: You might want to use a Modbus master simulator software on a PC connected to the wind vane sensor through a USB-to-RS485 converter to ensure that the sensor is working and that you can communicate with it correctly.

 

Check for Device-Specific Issues: Consult the device's documentation or support channels to check if there are any known issues with Modbus communication.

 

Update the Library: There might be updates to the minimalmodbus library that fix bugs or improve compatibility. Make sure you are using the latest version.

 

Review Timeout: A timeout value of 1 second may be too short if the device takes longer to respond. Try increasing the timeout value.

If you have access to an oscilloscope, it would be beneficial to monitor the RS485 signals to ensure they are being transmitted and received correctly. If not, try connecting to a different device that you know communicates well to ensure your RS485 adapter and software setup are functioning correctly.

 

Best regards,

userHeadPic xingzhao.zhu
John.Harrison wrote:

thanks for your comprehensive reply, I will try and work through all your suggestions.

2023-11-03 21:09:32
1 Replies