Can anyone explain how the function 15
FORCE_MULTIPLE_COILS
Works
i have been running some test on this
and cant figure out how to use the
local_start_address
is this the data to read from
or
is it a pointer to another File
modbus_construct(&packets[PACKET1], 1, 15, 1, 8, 1021);
dec 8 = (no_of_registers = packet->data) // number of coils
so frame 6 = 1 (frame[6] = no_of_bytes;) // number of bytes more
dec 1021 = (packet->local_start_address)
the dec 1021 and 65565 seams to work
but makes no sense to me in binary format ?
part of CPP file:
unsigned char construct_F15()
{
// function 15 coil information is packed LSB first until the first 16 bits are completed
// It is received the same way..
unsigned char no_of_registers = packet->data / 16;
unsigned char no_of_bytes = no_of_registers * 2;
// if the number of points dont fit in even 2byte amounts (one register) then use another register and pad
if (packet->data % 16 > 0)
{
no_of_registers++;
no_of_bytes++;
}
frame[6] = no_of_bytes;
unsigned char bytes_processed = 0;
unsigned char index = 7; // user data starts at index 7
unsigned int temp;
for (unsigned char i = 0; i < no_of_registers; i++)
{
temp = register_array[packet->local_start_address + i]; // get the data
frame[index] = temp & 0xFF;
bytes_processed++;
if (bytes_processed < no_of_bytes)
{
frame[index + 1] = temp >> 8;
bytes_processed++;
index += 2;
}
}
unsigned char frameSize = (9 + no_of_bytes); // first 7 bytes of the array + 2 bytes CRC + noOfBytes
return frameSize;
}