← Back to team overview

modbus team mailing list archive

Re: [Question #180855]: ERROR Invalid argument: select

 

Question #180855 on libmodbus changed:
https://answers.launchpad.net/libmodbus/+question/180855

    Status: Expired => Open

jeffrey is still having a problem:
Hi,

Im using Mac OS Lion version.  Here's some part of the code:

#include <stdio.h>
#include <stdlib.h>
#include <modbus/modbus-tcp.h>
#include <modbus/modbus.h>
#include <errno.h>
#include <unistd.h>

#define SUNSAVERMPPT    0x01    /* MODBUS Address of the SunSaver MPPT
*/

int main(void)
{
    modbus_t *ctx;
    int ret;
    int rc;
    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;
    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];
    struct timeval old_response_timeout;
    struct timeval response_timeout;



    ctx = modbus_new_tcp("161.30.190.246", 502);
    modbus_set_debug(ctx, TRUE);

/* Save original timeout */
modbus_get_response_timeout(ctx, &old_response_timeout);

/* Define a new and too short timeout! */
response_timeout.tv_sec = 600;
response_timeout.tv_usec = 5000000;
modbus_set_response_timeout(ctx, &response_timeout);
        

    
    if (modbus_connect(ctx) == -1) {
        fprintf(stderr, "Connection failed: %s\n", modbus_strerror(errno));
        modbus_free(ctx);
        return -1;
    
    }



    
    /* Read the RAM Registers */
    rc = modbus_set_slave(ctx,SUNSAVERMPPT);
    ret = modbus_read_input_registers(ctx, 0X0008, 45, data);

    
    /* Close the MODBUS connection */
    modbus_close(ctx);
    modbus_free(ctx);
    
    /* Convert the results to their proper values and print them out */
    printf("RAM Registers\n\n");
    
    adc_vb_f=data[0]*100.0/32768.0;
    printf("adc_vb_f = %.2f V\n",adc_vb_f);
    
    adc_va_f=data[1]*100.0/32768.0;
    printf("adc_va_f = %.2f V\n",adc_va_f);
    
    adc_vl_f=data[2]*100.0/32768.0;
    printf("adc_vl_f = %.2f V\n",adc_vl_f);
    
    adc_ic_f=data[3]*79.16/32768.0;
    printf("adc_ic_f = %.2f A\n",adc_ic_f);
    
    adc_il_f=data[4]*79.16/32768.0;
    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);
    
    charge_state=data[9];
    switch (charge_state) {
        case 0:
            printf("charge_state = %d START\n",charge_state);
            break;
        case 1:
            printf("charge_state = %d NIGHT_CHECK\n",charge_state);
            break;
        case 2:
            printf("charge_state = %d DISCONNECT\n",charge_state);
            break;
        case 3:
            printf("charge_state = %d NIGHT\n",charge_state);
            break;
        case 4:
            printf("charge_state = %d FAULT\n",charge_state);
            break;
        case 5:
            printf("charge_state = %d BULK_CHARGE\n",charge_state);
            break;
        case 6:
            printf("charge_state = %d ABSORPTION\n",charge_state);
            break;
        case 7:
            printf("charge_state = %d FLOAT\n",charge_state);
            break;
        case 8:
            printf("charge_state = %d EQUALIZE\n",charge_state);
            break;
    }


________________________________
 From: Stéphane Raimbault <question180855@xxxxxxxxxxxxxxxxxxxxx>
To: jep0815@xxxxxxxxx 
Sent: Saturday, January 28, 2012 7:45 AM
Subject: Re: [Question #180855]: ERROR Invalid argument: select
 
Your question #180855 on libmodbus changed:
https://answers.launchpad.net/libmodbus/+question/180855

Stéphane Raimbault posted a new comment:
I need Mac OS X testers so could indicate the version you've used and
code extract please ?

-- 
You received this question notification because you asked the question.

You received this question notification because you are a member of
Modbus Team, which is an answer contact for libmodbus.