libmodbus"ERROR communication time out -12)
Hi,
Im running a C program for capturing a modbus data from a charge controller. The program works when I connected it to a local network but when I connected it through Internet I got this error message "ERROR Communication time out (-12)" and the value of results is much more different from the result when it was connected to a local network. Im wondering if there's a way to change the communication time out from modbus.h that will solve this problem? Here's the part of the program:
#include <stdio.h>
#include <stdlib.h>
#include <modbus/modbus.h>
#define SUNSAVERMPPT 0x01 /* MODBUS Address of the SunSaver MPPT */
int main(void)
{
modbus_param_t mb_param;
int ret;
float adc_vb_
float V_lvd, Ahl_r, Ahl_t, Power_out, Sweep_Vmp, Sweep_Pmax, Sweep_Voc, Vb_min_daily;
float Vb_max_daily, Ahc_daily, Ahl_daily, vb_min, vb_max;
short T_hs, T_batt, T_amb, T_rts;
unsigned short charge_state, load_state, led_state;
unsigned int hourmeter;
unsigned short array_fault, load_fault, dip_switch, array_fault_daily, load_fault_daily;
unsigned int alarm, alarm_daily;
uint16_t data[50];
/* Setup the serial port parameters */
modbus_
/* Open the MODBUS connection */
if (modbus_
printf("ERROR Connection failed\n");
exit(1);
}
/* Read the RAM Registers */
ret = read_input_
/* Close the MODBUS connection */
modbus_
/* Convert the results to their proper values and print them out */
printf("RAM Registers\n\n");
adc_vb_
printf("adc_vb_f = %.2f V\n",adc_vb_f);
adc_va_
printf("adc_va_f = %.2f V\n",adc_va_f);
adc_vl_
printf("adc_vl_f = %.2f V\n",adc_vl_f);
adc_ic_
printf("adc_ic_f = %.2f A\n",adc_ic_f);
adc_il_
printf("adc_il_f = %.2f A\n",adc_il_f);
T_hs=data[5];
printf("T_hs = %d °C\n",T_hs);
T_batt=data[6];
printf("T_batt = %d °C\n",T_batt);
T_amb=data[7];
printf("T_amb = %d °C\n",T_amb);
T_rts=data[8];
printf("T_rts = %d °C\n",T_rts);
Question information
- Language:
- English Edit question
- Status:
- Solved
- For:
- libmodbus Edit question
- Assignee:
- No assignee Edit question
- Solved by:
- jeffrey
- Solved:
- Last query:
- Last reply: