Skip to content

Instantly share code, notes, and snippets.

@ivanrad
Created February 3, 2024 15:15
Show Gist options
  • Save ivanrad/250f7c6c47ad13811cd928424b303ef2 to your computer and use it in GitHub Desktop.
Save ivanrad/250f7c6c47ad13811cd928424b303ef2 to your computer and use it in GitHub Desktop.
linknlink emotion modbus
// 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