PDA

View Full Version : calculate SQ and CHK for mbus command



Zandis
22-03-2004, 02:44 PM
Please somebody explain me how to calculate SQ and CHK for mbus command.
Thanx.

NokDoc
22-03-2004, 08:13 PM
Hi,

One of them was a bytewised xor:

Chk = QS(1)
For Ih = 2 To 12
Chk = Chk Xor QS(Ih)
Next

NokDoc

Ice Draagon
23-03-2004, 04:09 AM
In Delphi (initialize MBUS):

cmdStr:=#$1F#$00#$1D#$D0#$00#$01#$04#$01#$CB
//#$CB (last byte) is the check byte, before that (#$01) is the seqNo

//seqNo (Sequence number) is always incremented by 1 everytime you
//compose an MBUS frame. Therefore, declare the variable as public.

inc(seqNo);
cmdLen:=Length(cmdStr);
cmdStr[cmdLen-1]:=Chr(seqNo); //Seq No.

//compute checksum/checkbyte from the beginning of frame upto
// the seqNo
chkByte:=0;
For i:=1 to cmdLen-1 do chkByte:=chkByte XOR Ord(cmdStr[i]);

//Store the checksum to end of the string
cmdStr[cmdLen]:=Chr(chkByte); //Checksum

You now have the InitializeMBUS ready to be sent to the COM port.

Zandis
23-03-2004, 03:08 PM
Hi,

One of them was a bytewised xor:

Chk = QS(1)
For Ih = 2 To 12
Chk = Chk Xor QS(Ih)
Next

NokDoc

NokDoc.
Thanks for replaying, but can you explain more detailted? (QS, xor, what is that?)
Thanx.

pico
23-03-2004, 06:35 PM
try searching
slikmik has a tool to calculate your check
sq is just any numner you like..

Zandis
23-03-2004, 07:34 PM
Finally i got that.
If somebody need this:
open windows calculator in scienfist mode.
choose hex.
Type each byte step by step and after each byte press xor.
Thats easy. :)

slikmik
23-03-2004, 07:46 PM
Finally i got that.
If somebody need this:
open windows calculator in scienfist mode.
choose hex.
Type each byte step by step and after each byte press xor.
Thats easy. :)


Here it is, thanks goes to some other dude who half wrote it but ive forgot who it was

NokDoc
23-03-2004, 09:23 PM
NokDoc.
Thanks for replaying, but can you explain more detailted? (QS, xor, what is that?)
Thanx.

Hi,

QS is just a name of an array of bytes.

Dim QS(13) As byte
QS(1) = &h1F

I think Mr. Zandis explained quite good.

NokDoc