Communication timeout
Hi all, for the following very simple code (just write data to two registers), for some reason, I need to put the sleep(2) before I call preset_
Starting...
Opening /dev/tty.
[01][10]
Waiting for a message (8 bytes)...
ERROR Communication time out (-12)
ret: -12
Why do I need to wait before I write into the registers?
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include "modbus.h"
#define SLAVE 1
#define START_ADDRESS 0
#define NB 1
int ret;
int addr;
int nb;
uint16_t val;
int main (int argc, const char * argv[]) {
printf(
modbus_param_t mb_param;
modbus_
modbus_
modbus_
if (modbus_
printf("ERROR Connection failed\n");
return 0;
}
sleep(2);
val = 2;
ret = preset_
val = 100;
ret = preset_
printf("ret: %d\n", ret);
printf("\n\n");
sleep(4);
modbus_
return 0;
}
Question information
- Language:
- English Edit question
- Status:
- Answered
- For:
- libmodbus Edit question
- Assignee:
- No assignee Edit question
- Last query:
- Last reply:
Can you help with this problem?
Provide an answer of your own, or ask solarwind for more information if necessary.