- various enhancements in drivers

This commit is contained in:
zolliker
2009-02-19 13:28:52 +00:00
parent a0e7c9782b
commit f6e5826e19
6 changed files with 193 additions and 47 deletions

View File

@@ -296,6 +296,7 @@ int ModBusHandler(void *object)
eab->cmd[3] = 0;
eab->cmd[4] = 44;
eab->cmd[5] = 55;
ParPrintf(eab, -2, "loopback");
ModBusWrite(eab, 6);
eab->state = EASE_lost;
}
@@ -324,6 +325,11 @@ void ModBusPutFloats(EaseBase * eab, int adr, int npar, float val[])
double2ieee(val[n], eab->cmd + l);
l += 4;
}
if (npar == 1) {
ParPrintf(eab, -1, "write #%d %.5g", adr, val[0]);
} else {
ParPrintf(eab, -1, "write #%d %.5g %.5g ... (%d)", adr, val[0], val[1], npar);
}
ModBusWrite(eab, l);
}
@@ -337,6 +343,7 @@ void ModBusRequestValues(EaseBase * eab, int adr, int npar)
eab->cmd[1] = 3; /* read n words */
fadr2word(adr, eab->cmd + 2);
uint2word(npar * 2, eab->cmd + 4);
ParPrintf(eab, -2, "read #%d (%d values)", adr, npar);
ModBusWrite(eab, 6);
}
@@ -363,14 +370,16 @@ static double ModBus2double(char ieee[4])
float ModBusGet(EaseBase * eab, int adr, int type)
{
int startAdr;
int i;
int i, n;
if (eab->state != EASE_read) {
return 0.0;
}
n = word2uint(eab->cmd + 4);
if (n <= 2) return ModBusGetValue(eab, type);
startAdr = word2fadr(eab->cmd + 2);
i = adr - startAdr;
if (i < 0 || i >= word2uint(eab->cmd + 4)) {
if (i < 0 || i >= n) {
return 0.0;
}
if (type == modBusTime) {
@@ -392,6 +401,7 @@ void ModBusRequestValue(EaseBase * eab, int adr, int type)
fadr2word(adr, eab->cmd + 2);
uint2word(2, eab->cmd + 4);
}
ParPrintf(eab, -2, "read #%d", adr);
ModBusWrite(eab, 6);
}
@@ -407,6 +417,7 @@ void ModBusPutValue(EaseBase * eab, int adr, int type, float val)
uint2word(1, eab->cmd + 4);
eab->cmd[6] = 2;
uint2word((int) (val), eab->cmd + 7);
ParPrintf(eab, -1, "write #%d %.5g", adr, val);
ModBusWrite(eab, 9);
return;
}
@@ -422,6 +433,7 @@ void ModBusPutValue(EaseBase * eab, int adr, int type, float val)
eab->cmd[9] = 0;
eab->cmd[10] = 0;
}
ParPrintf(eab, -1, "write #%d %.5g", adr, val);
ModBusWrite(eab, 11);
}