#define SLAVE_ID 1
#define START_ADDRESS 0
#define NUMBER_REGISTERS 14
#define DEBUG 1
void minute_check(int signum){
alarm(60);
}
int main(int argc, char *argv[])
{
const char *CONFIG_FILE = "modbuslog.cfg";
config_t cfg;
//config_setting_t *setting;
const char *modbus_device_address;
int modbus_baud_rate;
int modbus_data_bits;
const char *modbus_parity;
int modbus_stop_bits;
config_init(&cfg);
if(!config_read_file(&cfg, CONFIG_FILE))
{
fprintf(stderr, "%s:%d - %s\n", config_error_file(&cfg),
config_error_line(&cfg), config_error_text(&cfg));
config_destroy(&cfg);
fprintf(stderr, "Unable to find CONFIG_FILE.\n");
return -1;
}
if(!(config_lookup_string(&cfg, "modbus.device", &modbus_device_address)
&& config_lookup_int(&cfg, "modbus.baud", &modbus_baud_rate)
&& config_lookup_int(&cfg, "modbus.data_bits", &modbus_data_bits)
&& config_lookup_string(&cfg, "modbus.parity", &modbus_parity)
&& config_lookup_int(&cfg, "modbus.stop_bits", &modbus_stop_bits))
){
fprintf(stderr, "Incomplete modbus configuration. Check configuration file.\n");
return -1;
}
if(DEBUG){
printf("%s %d %c %d %d\n",modbus_device_address, modbus_baud_rate, modbus_parity[0], modbus_data_bits, modbus_stop_bits);
}
modbus_t *ctx;
uint16_t tab_reg[64];
int rc;
int i;
signal(SIGALRM, minute_check);
alarm(60);
for (;;){
select(0, NULL, NULL, NULL, NULL);
time_t t = time(NULL);
//int unixtime_min = (((int) t)/60*60);
int unixtime = (int) t;
printf("%d\n", unixtime);
config_setting_t *registers;
registers = config_lookup(&cfg, "register");
unsigned int num_registers = config_setting_length(registers);
int i;
for(i = 0; i < num_registers; ++i){
config_setting_t *register_element = config_setting_get_elem(registers, i);
int slaveid;
config_setting_lookup_int(register_element, "slaveid", &slaveid);
printf("%d ", slaveid);
}
printf("\n");
}
}
/*
ctx = modbus_new_rtu(modbus_device_address, modbus_baud_rate, modbus_parity[0], modbus_data_bits, modbus_stop_bits);
modbus_set_slave(ctx, SLAVE_ID);
modbus_set_debug(ctx, DEBUG);
if (ctx == NULL) {
fprintf(stderr, "Unable to create libmodbus object.\n");
return -1;
}
if (modbus_connect(ctx) == -1) {
fprintf(stderr, "Connection failed: %s\n", modbus_strerror(errno));
modbus_free(ctx);
return -1;
}
rc = modbus_read_input_registers(ctx, START_ADDRESS, NUMBER_REGISTERS, tab_reg);
if (rc == -1) {
fprintf(stderr, "ERROR: %s\n", modbus_strerror(errno));
return -1;
}
for (i=0; i < rc; i=i+2) {
printf("reg[%d]=%d\n", i, tab_reg[i]+tab_reg[i+1]);
}
modbus_close(ctx);
modbus_free(ctx);
return 0;
}
*/
aaa145390dc7e221e7828&follow=1'>Add details to patch.Jonathan McCrohan | 1 | -0/+5 |
2012-02-06 | Promote myself to maintainer. | Jonathan McCrohan | 3 | -9/+8 |
2012-02-05 | Change to dpkg-source 3.0 | Jonathan McCrohan | 1 | -2/+2 |
2012-02-05 | Update broken handcrafted patch | Jonathan McCrohan | 1 | -2/+2 |
2012-02-05 | Use 3.0 (quilt) | Jonathan McCrohan | 2 | -2/+2 |
2012-02-05 | Use 3.0 (quilt) | Jonathan McCrohan | 3 | -0/+13 |
2012-02-05 | Use quilt | Jonathan McCrohan | 3 | -6/+9 |
2012-02-05 | Update changelog | Jonathan McCrohan | 1 | -1/+6 |
2012-02-05 | clean up packaging | Jonathan McCrohan | 2 | -2/+1 |
2012-02-05 | fix errors | Jonathan McCrohan | 3 | -10/+3 |
2012-02-05 | Undo accidental source changes | Jonathan McCrohan | 2 | -9/+9 |
2012-02-05 | Add patch to remove copying | Jonathan McCrohan | 2 | -1/+9 |