
QD1 IO Expansion Module User Manual
48 Document Version V3.0 (2020-08-18)
You can create a thread for management.
Example:
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <time.h>
#include <winsock2.h>
#include <windows.h>
#include <process.h>
#include "modbus.h"
/* This can be any input, just to keep connection alive */
#define HEART_BEAT_BIT0
#define HEART_BEAT_RATE30000/* 30s */
unsigned __stdcall HeartBeat(void *pParam) { /* create the thread
named HeartBeat */
unsigned char dest;
modbus_t *connection = pParam;
while (1) {modbus_read_input_bits(connect, HEART_BEAT_BIT, 1,
dest);
Sleep(HEART_BEAT_RATE); }
return;}
int main(int argc, char **argv) {
modbus_t *ctx;
HANDLE hThread;