SimLink only sends what is in the config file, but the simulink driver on OpenPLC rewrites the whole buffer up to ANALOG_BUF_SIZE and DIGITAL_BUF_SIZE
while(1)
{
//printf("waiting for data...\n");
net_len = recvfrom(socket_fd, plc_data, sizeof(*plc_data), 0, (struct sockaddr *) &client, &cli_len);
//printf("data received!\n");
if (net_len < 0)
{
printf("Error receiving data on socket %d\n", socket_fd);
}
else
{
pthread_mutex_lock(&bufferLock); //lock mutex
for (int i = 0; i < ANALOG_BUF_SIZE; i++)
{
if (int_input[i] != NULL) *int_input[i] = plc_data->analogIn[i];
if (int_output[i] != NULL) plc_data->analogOut[i] = *int_output[i];
}
for (int i = 0; i < DIGITAL_BUF_SIZE; i++)
{
if (bool_input[i/8][i%8] != NULL) *bool_input[i/8][i%8] = plc_data->digitalIn[i];
if (bool_output[i/8][i%8] != NULL) plc_data->digitalOut[i] = *bool_output[i/8][i%8];
}
pthread_mutex_unlock(&bufferLock); //unlock mutex
//printf("sending data...\n");
net_len = sendto(socket_fd, plc_data, sizeof(*plc_data), 0, (struct sockaddr *) &client, cli_len);
if (net_len < 0)
{
printf("Error sending data on socket %d\n", socket_fd);
}
}
}
That's why I said you should be careful in isolating the address spaces for each driver:
thiagoralves wrote:
So you will have to be careful so that the ESP driver writes on a portion of the address space and the simulink driver writes on another portion. If they both write to the same address portion, they will be constantly overwriting each other.