Autonics TM4

Hello,

I am trying to communicate with Autonics TM4 temperature controller using Modbus RTU.
I used this ModbusRtu library.

I can read temperature value of controller using below code.
That means there are no any hardware error on my setup.
This is a modified code of a sample program. This code use Function code 4 to read holding register.
I want to use Function code 6 for write single register to change Set value of the controller.

I replace elegram.u8fct = 0x04; to telegram.u8fct = 0x06; and register address telegram.u16RegAdd = 0x03E8; to correct register address.
But, couldn’t set Set value of the controller. :frowning:

How can I use Function code 6 ?
If someone can give a example, greatly appreciated.

/*
    Modbus master example 1:
    The purpose of this example is to query an array of data
    from an external Modbus slave device.
    The link media can be USB or RS232.

    Recommended Modbus slave:
    diagslave http://www.modbusdriver.com/diagslave.html

    In a Linux box, run
    "./diagslave /dev/ttyUSB0 -b 19200 -d 8 -s 1 -p none -m rtu -a 1"
   This is:
   serial port /dev/ttyUSB0 at 19200 baud 8N1
 RTU mode and address @1
*/

#include <ModbusRtu.h>

// data array for modbus network sharing
uint16_t au16data[16];
uint8_t u8state;

/**
    Modbus object declaration
    u8id : node id = 0 for master, = 1..247 for slave
    u8serno : serial port (use 0 for Serial)
    u8txenpin : 0 for RS-232 and USB-FTDI
                 or any pin number > 1 for RS-485
*/
//TRANSMISSION CONTROL PIN - 8
//HADWARE SERIAL NUMBER - 2
Modbus master(0, 2, 8); // this is master and RS-232 or USB-FTDI

/*
   This is an structe which contains a query to an slave device
*/
modbus_t telegram;

unsigned long u32wait;

void setup() {
  Serial.begin(9600);
  master.begin(9600); // baud-rate at 9600
  master.setTimeOut( 2000 ); // if there is no answer in 2000 ms, roll over
  u32wait = millis() + 1000;
  u8state = 0;
}

void loop() {
  switch ( u8state ) {
    case 0:
      if (millis() > u32wait) u8state++; // wait state
      break;
    case 1:
      telegram.u8id = 0x01; // slave address
      telegram.u8fct = 0x04; // function code (this one is registers read)
      telegram.u16RegAdd = 0x03E8; // start address in slave [CHANNEL 1 PV]
      telegram.u16CoilsNo = 0x01; // number of elements (coils or registers) to read
      telegram.au16reg = au16data; // pointer to a memory array in the Arduino

      master.query( telegram ); // send query (only once)
      u8state++;
      break;
    case 2:
      master.poll(); // check incoming messages
      if (master.getState() == COM_IDLE) {
        u8state = 0;
        u32wait = millis() + 100;
        Serial.println(au16data[0]);//PRINT TEMPARATURE VALUE
      }
      break;
  }
}

Thank in advance

I am trying to communicate with Autonics TM4 temperature controller using Modbus TCP. I used this ModbusRtu library.

Modbus TCP and Modbus RTU doesn't have the same physical layer and the actual protocol differs substantially. You cannot use a Modbus RTU library to do Modbus TCP.

Im sorry. Its a mistake. It should be Modbus RTU. Controller supports Modbus RTU and I used Modbus RTU library.

I replace elegram.u8fct = 0x04; to telegram.u8fct = 0x06; and register address telegram.u16RegAdd = 0x03E8; to correct register address. But, couldn't set Set value of the controller.

Why didn't you post that code?

You have to set the value somewhere. If you did just change above stuff, you have to set au16data[0] to that value.

How can I use Function code 6 ? If someone can give a example, greatly appreciated.

The examples/advanced_master sketch provides such an example.