Page 1 of 1

PHP Serial communication and crc

Posted: Tue Mar 23, 2010 11:44 am
by priithansen
Hello,

First of I'm rather inexperienced PHP programmer but I have decided to get my head around this.

What I want to achieve is make PHP communicate with a security system from Satel that has a special rs232 module just for that purpose.

Finds so far:
PHP class for communicating with serial port: http://phpclasses.fonant.com/browse/package/3679.html
Article about using mentioned php class: http://www.communitymx.com/content/arti ... &cid=8658A
The manual for the rs232 module: http://www.priithansen.com/INT-RS_v1.01_EN.pdf

I have not actually ordered the module just yet because I would like to figure it out in theory first. The part that I just can't seem to understand is on the module manual page 2 about calculating the crc sum for data integrity.
Could anyone Please guide me to some manual about crc or explain to a dummy how it's done?

Thank You in advance and sorry for the language as English is not my mother tongue.

Re: PHP Serial communication and crc

Posted: Tue Mar 23, 2010 1:16 pm
by AbraCadaver

Re: PHP Serial communication and crc

Posted: Tue Mar 23, 2010 1:30 pm
by priithansen
Thank You still not sure as of how to use it in this situation.

Image
As it shows in the manual in 1) and 2) a, b and c

Re: PHP Serial communication and crc

Posted: Tue Mar 23, 2010 1:42 pm
by AbraCadaver
Since it is a 16 bit CRC you'll need this:

Code: Select all

function crc16($data) {
   $crc = 0xFFFF;
   for ($i = 0; $i < strlen($data); $i++) {
      $x = (($crc >> 8) ^ ord($data[$i])) & 0xFF;
      $x ^= $x >> 4;
      $crc = (($crc << 8) ^ ($x << 12) ^ ($x << 5) ^ $x) & 0xFFFF;
   }
   return $crc;
}
Other than that I'm not much help.

Re: PHP Serial communication and crc

Posted: Tue Mar 23, 2010 2:17 pm
by priithansen
Thank you for the 16bit crc calculation sciprt.

Though still if anyones willing to explain the crc stuff going on in the manual I would appriciate it greatly.

Re: PHP Serial communication and crc

Posted: Tue Mar 23, 2010 4:46 pm
by priithansen
Hello again

As a neebie to binary and hex and XOR don't laugh too hard if what I'm saying is completly off but heres my go on the thing.

So in the manual it says set crc = 0x147A (could this be the Satel configured basis for calculating crc's?)

In the manual there's example frames:
Exemplary frames: FE FE 09 D7 EB FE 0D

The first two are sync frames and last two as well. As far as I can make out the 09 should be b aka data and D7 EB the checksum.
What I could come up with is as follows.
0x147A Rotate left = 0x28F4
0x28F4 XOR 0xFFFF = 0xD70B
0xD70B + 0xD7 + 0x09 = 0xD7EB

Could anyone clarify if I'm on the right tracks here or completly off?