esp-modbus icon indicating copy to clipboard operation
esp-modbus copied to clipboard

How to output detailed instruction logs? (IDFGH-12822)

Open yel-best opened this issue 9 months ago • 6 comments

Hi My Friend.

1. I am currently doing modbus connection with some PLC devices. I need to see some detailed logs. For example, the sent message "01 03 A0 80 00 01 A7 E2" and then the received message "01 03 02 03 E8 B8 FA", I need to print to the console for output,I have been searching for a long time but I have not found how to open this part of the log.

2. In addition, the example does not seem to explain how to convert the value. For example, I have a float & u16 type value. How should I extract it for subsequent logic? I now use a very stupid way to do it, and I will *(uint16_t ) temp_data_ptr for forced conversion, do you have any other suggestions?

 if (TEST_VERIFY_VALUES(param_descriptor, (uint16_t *)temp_data_ptr) == ESP_OK)
  {
      ESP_LOGI(TAG, "Characteristic #%d %s (%s) value = %u (0x%" PRIx16 ") read successful.",
               (int)param_descriptor->cid,
               (char *)param_descriptor->param_key,
               (char *)param_descriptor->param_units,
               *(uint16_t *)temp_data_ptr,
               *(uint16_t *)temp_data_ptr);
  }

uint16_t test_v =   *(uint16_t *)temp_data_ptr,

I assign the value to test_v and then I bring test_v into my business logic. There seems to be some problems and it doesn't feel optimal.

yel-best avatar May 15 '24 04:05 yel-best