From c0605b2398856d7ada33e19f80605d93e440dfdb Mon Sep 17 00:00:00 2001 From: zolliker Date: Fri, 23 Feb 2007 12:32:24 +0000 Subject: [PATCH] - various enhancements --- modbus.c | 13 ++++++++----- modbus.h | 16 ++++++++++++++-- 2 files changed, 22 insertions(+), 7 deletions(-) diff --git a/modbus.c b/modbus.c index 40c0bdc..bdb586d 100644 --- a/modbus.c +++ b/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) { - char buf[50]; + char buf[128]; int i; - if (length > 16) length = 16; + if (length > 40) length = 40; for (i=0; ians[1] == 3) { /* answer for read n words */ l = eab->ans[2]; /* bytes to read */ if (l<0 || l >= sizeof(eab->ans)-5) { - l=32; + l=64; } iret = readRS232TillTerm(eab->ser, eab->ans+5, &l); l+=5; @@ -294,7 +294,7 @@ void ModBusPutFloats(EaseBase *eab, int adr, int npar, float val[]) { ModBusWrite(eab, l); } /*----------------------------------------------------------------------------*/ -void ModBusRequestFloats(EaseBase *eab, int adr, int npar) { +void ModBusRequestValues(EaseBase *eab, int adr, int npar) { assert(npar <= 14); @@ -322,7 +322,7 @@ static double ModBus2double(char ieee[4]) { 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 i; @@ -334,6 +334,9 @@ float ModBusGetFloat(EaseBase *eab, int adr) { if (i < 0 || i >= word2uint(eab->cmd + 4)) { return 0.0; } + if (type == modBusTime) { + return quad2long(eab->ans + 3 + i * 4) * 0.001; + } return ieee2double(eab->ans + 3 + i * 4); } /*----------------------------------------------------------------------------*/ diff --git a/modbus.h b/modbus.h index 8655f25..1ea1b57 100644 --- a/modbus.h +++ b/modbus.h @@ -16,11 +16,23 @@ Markus Zolliker, Aug 2005 typedef enum {modBusFloat, modBusInt, modBusTime} ModBusType; int ModBusHandler(void *eab); + void ModBusPutFloats(EaseBase *eab, int adr, int npar, float val[]); -void ModBusRequestFloats(EaseBase *eab, int adr, int npar); -float ModBusGetFloat(EaseBase *eab, int adr); +/* put floats with contiguous adresses */ + +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); +/* request one value of arbitrary type */ + float ModBusGetValue(EaseBase *eab, int type); +/* get this value */ + void ModBusPutValue(EaseBase *eab, int adr, int type, float val); +/* put one value of arbitrary type */ #endif