Commit a20d39d36c7052281294e648c65e39db8b33182f

Authored by Stéphane Raimbault
1 parent 3948142c

Write the values in force_multiple_coils and preset_multiple_registers (SLAVE)

Showing 1 changed file with 10 additions and 0 deletions
modbus/modbus.c
@@ -873,6 +873,9 @@ void manage_query(modbus_param_t *mb_param, uint8_t *query, @@ -873,6 +873,9 @@ void manage_query(modbus_param_t *mb_param, uint8_t *query,
873 resp_length = response_exception(mb_param, &sft, 873 resp_length = response_exception(mb_param, &sft,
874 ILLEGAL_DATA_ADDRESS, response); 874 ILLEGAL_DATA_ADDRESS, response);
875 } else { 875 } else {
  876 + /* 6 = byte count, 7 = first byte of data */
  877 + set_bits_from_bytes(mb_mapping->tab_coil_status, address, nb, &query[offset + 7]);
  878 +
876 resp_length = build_response_basis(mb_param, &sft, response); 879 resp_length = build_response_basis(mb_param, &sft, response);
877 /* 4 to copy the coil address (2) and the quantity of coils */ 880 /* 4 to copy the coil address (2) and the quantity of coils */
878 memcpy(response + resp_length, query + resp_length, 4); 881 memcpy(response + resp_length, query + resp_length, 4);
@@ -889,6 +892,13 @@ void manage_query(modbus_param_t *mb_param, uint8_t *query, @@ -889,6 +892,13 @@ void manage_query(modbus_param_t *mb_param, uint8_t *query,
889 resp_length = response_exception(mb_param, &sft, 892 resp_length = response_exception(mb_param, &sft,
890 ILLEGAL_DATA_ADDRESS, response); 893 ILLEGAL_DATA_ADDRESS, response);
891 } else { 894 } else {
  895 + int i, j;
  896 + for (i = address, j = 0; i < address + nb; i++, j += 2) {
  897 + /* 6 = byte count, 7 and 8 = first value */
  898 + mb_mapping->tab_holding_registers[i] =
  899 + (query[offset + 7 + j] << 8) + query[offset + 8 + j];
  900 + }
  901 +
892 resp_length = build_response_basis(mb_param, &sft, response); 902 resp_length = build_response_basis(mb_param, &sft, response);
893 /* 4 to copy the address (2) and the no. of registers */ 903 /* 4 to copy the address (2) and the no. of registers */
894 memcpy(response + resp_length, query + resp_length, 4); 904 memcpy(response + resp_length, query + resp_length, 4);