-
-
Save ivanrad/250f7c6c47ad13811cd928424b303ef2 to your computer and use it in GitHub Desktop.
linknlink emotion modbus
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// cc -Wall mb.c $(pkg-config --cflags --libs libmodbus) | |
// | |
#include <stdio.h> | |
#include <stdlib.h> | |
#include <modbus.h> | |
int main(int argc, char **argv) { | |
modbus_t *mb; | |
uint16_t motion, no_motion; | |
if (argc != 2) { | |
fprintf(stderr, "usage: %s IP_ADDRESS\n", argv[0]); | |
exit(2); | |
} | |
mb = modbus_new_tcp(argv[1], 502); | |
if (modbus_connect(mb) == -1) { | |
fprintf(stderr, "error connecting\n"); | |
exit(1); | |
} | |
modbus_read_registers(mb, 802, 1, &motion); | |
modbus_read_registers(mb, 832, 1, &no_motion); | |
modbus_close(mb); | |
modbus_free(mb); | |
printf("motion = %#x\n", motion); | |
printf("no motion = %#x\n", no_motion); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment