ICP DAS
LinPAC-52xx Series XV-Board API User Manual
6
Example:
int RetValue, timeout=100, count=1, netid=1;
int comport=COM1;
/* Refer to [Remark 1] */
int function=1;
/* Refer to [Remark 2] */
int addr=33;
/*
Refer to [Remark 3] */
char szBuf[80];
DWORD baudrate=115200;
WORD wT;
/* Open the device file */
RetValue=Open_Com(comport, baudrate, Data8Bit, NonParity, OneStopBit);
if (RetValue > 0) {
printf("open
COM%d
failed!\n",comport);
return
FAILURE;
}
RetValue=modbusRequest(comport, netid, function, addr, count, szBuf, sizeof(szBuf),
timeout,
&wT);
Close_Com(comport);
if (RetValue==0) {
if((function==1)||(function==2))
printf("%d",
szBuf[0]);
else
{
RetValue=(szBuf[0]<<8)|szBuf[1];
printf("%ld",
RetValue);
}
}