- various enhancements
This commit is contained in:
13
modbus.c
13
modbus.c
@ -150,10 +150,10 @@ static int calc_crc(char *inp, int inpLen, int addCrc) {
|
|||||||
}
|
}
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
void ModBusDump(EaseBase *eab, int iout, char *fmt, char *buffer, int length) {
|
void ModBusDump(EaseBase *eab, int iout, char *fmt, char *buffer, int length) {
|
||||||
char buf[50];
|
char buf[128];
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
if (length > 16) length = 16;
|
if (length > 40) length = 40;
|
||||||
for (i=0; i<length; i++) {
|
for (i=0; i<length; i++) {
|
||||||
snprintf(buf+i*3, 4, " %2.2X", (unsigned char)buffer[i]);
|
snprintf(buf+i*3, 4, " %2.2X", (unsigned char)buffer[i]);
|
||||||
}
|
}
|
||||||
@ -221,7 +221,7 @@ int ModBusHandler(void *object) {
|
|||||||
} else if (eab->ans[1] == 3) { /* answer for read n words */
|
} else if (eab->ans[1] == 3) { /* answer for read n words */
|
||||||
l = eab->ans[2]; /* bytes to read */
|
l = eab->ans[2]; /* bytes to read */
|
||||||
if (l<0 || l >= sizeof(eab->ans)-5) {
|
if (l<0 || l >= sizeof(eab->ans)-5) {
|
||||||
l=32;
|
l=64;
|
||||||
}
|
}
|
||||||
iret = readRS232TillTerm(eab->ser, eab->ans+5, &l);
|
iret = readRS232TillTerm(eab->ser, eab->ans+5, &l);
|
||||||
l+=5;
|
l+=5;
|
||||||
@ -294,7 +294,7 @@ void ModBusPutFloats(EaseBase *eab, int adr, int npar, float val[]) {
|
|||||||
ModBusWrite(eab, l);
|
ModBusWrite(eab, l);
|
||||||
}
|
}
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
void ModBusRequestFloats(EaseBase *eab, int adr, int npar) {
|
void ModBusRequestValues(EaseBase *eab, int adr, int npar) {
|
||||||
|
|
||||||
assert(npar <= 14);
|
assert(npar <= 14);
|
||||||
|
|
||||||
@ -322,7 +322,7 @@ static double ModBus2double(char ieee[4]) {
|
|||||||
return (t * 65536 + word2uint(ieee+2)) * 0.001;
|
return (t * 65536 + word2uint(ieee+2)) * 0.001;
|
||||||
}
|
}
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
float ModBusGetFloat(EaseBase *eab, int adr) {
|
float ModBusGet(EaseBase *eab, int adr, int type) {
|
||||||
int startAdr;
|
int startAdr;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
@ -334,6 +334,9 @@ float ModBusGetFloat(EaseBase *eab, int adr) {
|
|||||||
if (i < 0 || i >= word2uint(eab->cmd + 4)) {
|
if (i < 0 || i >= word2uint(eab->cmd + 4)) {
|
||||||
return 0.0;
|
return 0.0;
|
||||||
}
|
}
|
||||||
|
if (type == modBusTime) {
|
||||||
|
return quad2long(eab->ans + 3 + i * 4) * 0.001;
|
||||||
|
}
|
||||||
return ieee2double(eab->ans + 3 + i * 4);
|
return ieee2double(eab->ans + 3 + i * 4);
|
||||||
}
|
}
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
|
16
modbus.h
16
modbus.h
@ -16,11 +16,23 @@ Markus Zolliker, Aug 2005
|
|||||||
typedef enum {modBusFloat, modBusInt, modBusTime} ModBusType;
|
typedef enum {modBusFloat, modBusInt, modBusTime} ModBusType;
|
||||||
|
|
||||||
int ModBusHandler(void *eab);
|
int ModBusHandler(void *eab);
|
||||||
|
|
||||||
void ModBusPutFloats(EaseBase *eab, int adr, int npar, float val[]);
|
void ModBusPutFloats(EaseBase *eab, int adr, int npar, float val[]);
|
||||||
void ModBusRequestFloats(EaseBase *eab, int adr, int npar);
|
/* put floats with contiguous adresses */
|
||||||
float ModBusGetFloat(EaseBase *eab, int adr);
|
|
||||||
|
void ModBusRequestValues(EaseBase *eab, int adr, int npar);
|
||||||
|
/* request floats or time (not int) with contiguous adresses */
|
||||||
|
|
||||||
|
float ModBusGet(EaseBase *eab, int adr, int type);
|
||||||
|
/* get value from the ModBusRequestValues command (no int!) */
|
||||||
|
|
||||||
void ModBusRequestValue(EaseBase *eab, int adr, int type);
|
void ModBusRequestValue(EaseBase *eab, int adr, int type);
|
||||||
|
/* request one value of arbitrary type */
|
||||||
|
|
||||||
float ModBusGetValue(EaseBase *eab, int type);
|
float ModBusGetValue(EaseBase *eab, int type);
|
||||||
|
/* get this value */
|
||||||
|
|
||||||
void ModBusPutValue(EaseBase *eab, int adr, int type, float val);
|
void ModBusPutValue(EaseBase *eab, int adr, int type, float val);
|
||||||
|
/* put one value of arbitrary type */
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
Reference in New Issue
Block a user