Updates:

Click here to visit our store! https://www.auberins.com

SYL-2381 Using the Modbus feature to get values from the PID

Started by chakahamilton, March 30, 2022, 05:01:48 PM

Previous topic - Next topic

chakahamilton

HI, I have the syl-2381 wired up and I am trying to take advantage of the Modbus feature After reading the supplemental Manual

My Setup
Arduinio Uno
Connected to Max485 Module: A&B are connected to A&B on the pid controller pin 13 & 14

I am using the ModbusMaster RS485_HalfDuplex Library

Things I know
Modbus Slave ID is 5
Baud Rate is set to 9600

What I don't know
1) The code mentions toggle the coil address which is currently set to 0x0002 (what is the right address if any for this device, its not immediately clear or different wording used in the supplemental manual)
2)  Read 16 registers starting at 0x3100) I changed it to 0x164 its unclear wether or not i need to add the 0164 after the 0x or not and is the H necessary, when I added it the Arduino would give an error.

MY Results
with all of that said, when I open the serial monitor I get a bunch of squares and question marks. I initially thought it might be the baud rate but I have made it 9600. It seems the data is being received I just cant read it.


with all that said, can anyone offer help with the Modbus  portion of this code example listed below?

Regards
// Modbus communication runs at 9600 baud
  Serial.begin(9600);

  // Modbus slave ID 5
  node.begin(5, Serial);
  // Callbacks allow us to configure the RS485 transceiver correctly
  node.preTransmission(preTransmission);
  node.postTransmission(postTransmission);
}

bool state = true;

void loop()
{
  uint8_t result;
  uint16_t data[6];
 
  // Toggle the coil at address 0x0002 (Manual Load Control)
  result = node.writeSingleCoil(0x0002, state);
  state = !state;

  // Read 16 registers starting at 0x0164)
  result = node.readInputRegisters(0164, 16);
  if (result == node.ku8MBSuccess)
  {
    Serial.print("PV: ");
    Serial.println(node.getResponseBuffer(0x0164));
    Serial.print("OUT: ");
    Serial.println(node.getResponseBuffer(0x0166));
    Serial.print("SV: ");
    Serial.println((node.getResponseBuffer(0x0000));
  }

Kkane

1. By my understanding, the data types used in modbus can be either "coil", or "register" type. "Coil" is for 1-bit register and "register" is for word or 16-bit. In SYL-2381, only the parameters AL1_STA (addr: 0005H)and AT (addr: 0000H) are 1-bit.

2. All the parameter addresses in its supplementary manual are HEX numbers. If I'm right, all the addresses like 0x3100 are HEX numbers as well. Please check if the numbers in your code or library are hex numbers or not.

chakahamilton

Kane,
I the numbers appear to be in hex but when I compile in arduino ide for example 0000H is for the set value. the arduino error states:
operator 'operator""H'
result = node.readInputRegisters(0000H=, 1);
^~~~~
RS485_HalfDuplex-March:84:42: error: expected primary-expression before ',' token
result = node.readInputRegisters(0000H=, 1);
^
RS485_HalfDuplex-March:88:43: error: unable to find numeric literal operator 'operator""H'
Serial.println(node.getResponseBuffer(0000H));
^~~~~


it doesnt like H.

it'd be helpful if the supplemental had better examples. I struggled to even get the simple modbus software to connect to the PID I kept getting errors. there are diagrams for wiring to a ftdi converter or Arduino  <shrug>

Kkane

I haven't used arduino before so I may not help further. Maybe you can just try to put the four digit number only in hex without "H" and see how it works. It depends on how this value/address is definied in the RS485 library you are using. Or you can google the error code directly.

The last several pages on the supplementary manual shows how to use Simply Modbus Software to communicate between the computer and 2381 controller. You can probably try it to make sure your controller and computer connection are all good at least. You can also use any serial port debugging tools/softwares to send the command to the controller to see if you can get the correct response.