]> mj.ucw.cz Git - home-hw.git/commitdiff
Modbus: More testing...
authorMartin Mares <mj@ucw.cz>
Tue, 9 Jul 2019 07:00:54 +0000 (09:00 +0200)
committerMartin Mares <mj@ucw.cz>
Tue, 9 Jul 2019 07:00:54 +0000 (09:00 +0200)
test-modbus/client/try.c
test-modbus/test.c

index ca02c5b4443d8f4e8ae833fe55f752bbff365748..eb975b99002368e1c64b66f9b307127a686b5a4c 100644 (file)
@@ -18,12 +18,32 @@ int main(void)
        if (modbus_set_slave(mb, 42) < 0)
                die("Cannot set slave address");
 
+       modbus_set_debug(mb, 1);
+
+#if 1
        u16 dest;
        rc = modbus_read_registers(mb, 0, 1, &dest);
        if (rc < 0)
                die("Cannot read: %s", modbus_strerror(errno));
-
        printf("%04x\n", dest);
+#endif
+
+#if 0
+       byte rr[] = { 42, 0x2b, 0x0e, 0x04, 0x00 };
+       // byte rr[] = { 42, 0x03, 0x00, 0x00, 0x00, 0x10 };
+       rc = modbus_send_raw_request(mb, rr, sizeof(rr));
+       if (rc < 0)
+               die("Cannot send raw request: %s", modbus_strerror(errno));
+
+       byte rp[256];
+       rc = modbus_receive_confirmation(mb, rp);
+       if (rc < 0)
+               die("Cannot receive confirmation: %s", modbus_strerror(errno));
+
+       for (int i=0; i<rc; i++)
+               printf("%02x ", rp[i]);
+       putchar('\n');
+#endif
 
        modbus_close(mb);
        modbus_free(mb);
index 16ae1ac9d24b46ae2a279964e8c5007f4845ee02..e8909987baef0d4d2b9cda74929b72daf7f4b349 100644 (file)
@@ -153,7 +153,7 @@ u16 modbus_get_input_register(u16 addr UNUSED)
 
 bool modbus_check_holding_register(u16 addr UNUSED)
 {
-       return (addr == 0);
+       return (addr < 16);
 }
 
 u16 modbus_get_holding_register(u16 addr UNUSED)