Page 2 of 2

Re: PLCBUS polling

Posted: Sun Dec 19, 2010 8:04 am
by vdoucet
So ... I'm doing my first steps in Gambas and there is probably a "nicer" answer to this issue but I modified line 304 in CPLCBUS.class as follows :

Code: Select all

  '--- check if valid frame ---
  IF RecBuf[0] = STX AND IF RecBuf[1] = &H6 AND IF (RecBuf[8] = ETX OR (RecBuf[0] + RecBuf[1] + RecBuf[2] + RecBuf[3] + RecBuf[4] + RecBuf[5] + RecBuf[6] + RecBuf[7] + RecBuf[8]) = 0) THEN
and I think it solved the issue :P . At least it works with addresses A and B, I didn't check further for the time being.
Ron, if you agree this could be integrated in the next release.

PS. As I said, I'm just starting with Gambas ... I don't quite understand why summing only positive values different from 0 would end up with 0 but ... The tests I did with gambas seems to indicate that RecBuf being defined as a Byte, it is limited to 255. That is to say if the sum ends up as 255 it will remain 255, if it ends up as 258 for example, it will be converted to 2 (&H02 + &H06 + &HFA = 258 (dec) => 2).

Re: PLCBUS polling

Posted: Sun Dec 19, 2010 12:47 pm
by RDNZL
I have added your code to revision http://domotiga.nl/changeset/506 but shouldn't it be more like this:

Code: Select all

IF (RecBuf[0] = STX AND IF RecBuf[1] = &H6 AND IF RecBuf[8] = ETX) OR (RecBuf[0] + RecBuf[1] + RecBuf[2] + RecBuf[3] + RecBuf[4] + RecBuf[5] + RecBuf[6] + RecBuf[7] + RecBuf[8] = 0) THEN 
So not having a ( around the RecBuf[8] = ETX

Needs more testing/checking...