Revision 14688426 mainbox/tool.c

View differences:

mainbox/tool.c
8 8
modbus_t *ctx;
9 9

  
10 10
int tool_init_mb(const char *device) {
11
  struct timeval timeout;
12

  
11 13
  ctx = modbus_new_rtu(device, MB_BAUD, 'N', 8, 1);
12 14
  if (ctx == NULL) {
13 15
    fprintf(stderr, "modbus_new_rtu: %s\n", modbus_strerror(errno));
......
20 22
    return 1;
21 23
  }
22 24

  
25
  modbus_get_response_timeout(ctx, &timeout);
26
  printf("Response timeout is %lus %luus\n", timeout.tv_sec, timeout.tv_usec);
27

  
23 28
  return 0;
24 29
}
25 30

  
......
42 47

  
43 48
static void tool_read_user(struct tool_t *tool) {
44 49
  unsigned short serno[2];
45
  if (modbus_read_registers(ctx, MB_INP_SERNOL, 2, serno) == -1) {
50
  if (modbus_read_input_registers(ctx, MB_INP_SERNOL, 2, serno) == -1) {
46 51
    fprintf(stderr, "modbus_read_registers: %s\n", modbus_strerror(errno));
47 52
    tool->user = 0;
48 53
  } else {
......
68 73
void tool_poll(struct tool_t *tool) {
69 74
  unsigned char status[N_COILS];
70 75

  
71
  if (modbus_set_slave(ctx, SLAVE_ADDR) == -1) {
76
  if (modbus_set_slave(ctx, tool->address) == -1) {
72 77
    fprintf(stderr, "modbus_set_slave: %s\n", modbus_strerror(errno));
73 78
  }
74 79

  
80
  tool_read_user(tool);
81
  printf("%08x\n", tool->user);
82
  return;
83

  
75 84
  if (modbus_read_bits(ctx, 0, N_COILS, status) == -1) {
76 85
    fprintf(stderr, "modbus_read_bits: %s\n", modbus_strerror(errno));
77 86
    return;

Also available in: Unified diff