PHP Serial communication and crc

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
priithansen
Forum Newbie
Posts: 4
Joined: Tue Mar 23, 2010 11:19 am

PHP Serial communication and crc

Post 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.
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

Re: PHP Serial communication and crc

Post by AbraCadaver »

mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
priithansen
Forum Newbie
Posts: 4
Joined: Tue Mar 23, 2010 11:19 am

Re: PHP Serial communication and crc

Post 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
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

Re: PHP Serial communication and crc

Post 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.
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
priithansen
Forum Newbie
Posts: 4
Joined: Tue Mar 23, 2010 11:19 am

Re: PHP Serial communication and crc

Post 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.
priithansen
Forum Newbie
Posts: 4
Joined: Tue Mar 23, 2010 11:19 am

Re: PHP Serial communication and crc

Post 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?
Post Reply