Example #1
0
/*
 * Our main function
 */
int
main(void)
{
    GMainLoop *loop;
    AXHttpHandler *handler;
    guint timer = 0;

    loop    = g_main_loop_new(NULL, FALSE);
    handler = ax_http_handler_new(request_handler, &timer);

    g_message("Created a HTTP handler: %p", handler);

    struct modbus *modbus = NULL;

    lily_init_modbus(&modbus);

    /* Periodically call 'on_timeout()' every second */
    g_timeout_add(500, on_timeout, &modbus);

    /* start the main loop */
    g_main_loop_run(loop);

    /* free up resources */
    modbus_close_device(&modbus);
    g_main_loop_unref(loop);
    ax_http_handler_free(handler);

    return 0;
}
Example #2
0
modbus_t* GetModbus_Client(int deviceAddress)
{
	if (deviceAddress > MaxDeviceCount)
	{
		return NULL;
	}

	if (P_Modbus_device[deviceAddress] == NULL)
	{
		// close last device first
		if (LastDeviceId >=0 && P_Modbus_device[LastDeviceId] != NULL)
		{
			modbus_close_device(P_Modbus_device[LastDeviceId]);			
			P_Modbus_device[LastDeviceId] = NULL;
		}

		//TODO: Put the serial port to configuration file. 
#ifdef _WIN32
		P_Modbus_device[deviceAddress] = modbus_new_rtu_device("COM2", deviceAddress);
#else
		P_Modbus_device[deviceAddress] = modbus_new_rtu_device("/dev/ttyO1", deviceAddress);
#endif
		LastDeviceId = deviceAddress;
		
	}

	return P_Modbus_device[deviceAddress];
}
Example #3
0
static int lily_init_modbus(struct modbus **modbus)
{
    g_assert(modbus);

    if (*modbus) {
        modbus_close_device(modbus);
    }

    g_message("------------REINIT SERIAL PORT------------------------");

    *modbus = modbus_init_device("/dev/ttyS1",
                                 0x01,
                                 PARITY_EVEN,
                                 B9600,
                                 0 /* No stop bit */);

    return 0;
}