/* * sunsaver.c - This program reads all the RAM registers on a Moringstar SunSaver MPPT and prints the results. * */ /* Compile with: cc sunsaver.c -o sunsaver -lmodbus */ #include #include #include #define SUNSAVERMPPT 0x01 /* MODBUS Address of the SunSaver MPPT */ int main(void) { modbus_param_t mb_param; int ret; float adc_vb_f,adc_va_f,adc_vl_f,adc_ic_f,adc_il_f, Vb_f, Vb_ref, Ahc_r, Ahc_t, kWhc; 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, V_PU, I_PU; 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[150]; /* Setup the serial port parameters */ // modbus_init_rtu(&mb_param, "/dev/tty.voltmeter", 9600, "none", 8, 2); /* Add the appropriate path to your serial port */ modbus_init_tcp(&mb_param, "192.168.0.57", 502);/* Add the appropriate path to your serial port */ /* Open the MODBUS connection */ if (modbus_connect(&mb_param) == -1) { printf("ERROR Connection failed\n"); exit(1); } /* Read the RAM Registers */ ret = read_input_registers(&mb_param, SUNSAVERMPPT, 0x0000, 75, data); /* Close the MODBUS connection */ modbus_close(&mb_param); /* Convert the results to their proper values and print them out */ V_PU=((data[1] << 16) + data[0]); // printf("%.2f\n",V_PU); I_PU=((data[3] << 16) + data[2]); printf("%.2f\n%.2f\n",data[59]*V_PU*I_PU/131072,data[58]*V_PU*I_PU/131072); //max P // printf("%.2f\n",data[60]*V_PU*I_PU/131072); //array V, batteryV printf("%.2f\n%.2f\n",data[27]*V_PU/32768,data[38]*V_PU/32768); printf("%d\n",data[55]); return(0); }