Dutch
Something like the following - FT_BYTEXOR() is in the Nanforum library
available on the OASIS
Untested code so use with care.
-------------------------------------------------------------------------
function checksum( cString )
local xValue1
local xValue2
local nLen := len( cString )
local i
for i := 1 to nLen
xValue1 := substring( cString, i, 1 )
xValue2 := ft_bytexor( xValue1, xValue2 )
next
Return := Dec2Hex( ASC( xValue2 ) )
--
HTH
Steve Quinn
Born free........Taxed to death.
I used to have a handle on life, but it broke.
WANTED: Meaningful Overnight Relationship.
BEER: It's not just for breakfast anymore.
Quote:
> Dear All,
> I have a problem with another program. They need me to send a protocal to
> their program. But I don't understand their document. They need to send
> the protocal and ending with "Check Characters" I can send all data to
> comm port but I cannot send the Check Characters and the end of protocal.
> If any know pls describe and give me an example.
> Thanks in advance,
> Example
> if (com_open( 1 , 4000 , 4000 )) // Open comm port
> if com_init( 1 , 9600 , 'N' , 8 , 1 ) // Initial com port
> com_init(comport,baudrate,'N', 8 , 1 )
> do while com_dtr( 1 ,.F.) // set DTR is inactive
> end
> inkey(1)
> do while !com_dtr( 1 ,.T.) // set DTR is active
> end
> else
> WarnMsg(' Port not initialize ! ')
> com_close( 1 ) // comm close
> end
> end
> InOut := chr(2)+'0130G'+chr(30);
> 'R201'+chr(30)+;
> 'TSingle'+chr(30)+;
> 'D199705251630'+chr(30)+;
> 'O199705301300'+chr(30)+;
> 'UGuest 2nd Floor'+chr(30)+;
> chr(3)+?? <=== My problem
> if (x:= com_send( 1 , InOut )) = 0 // Send Protocal
> else
> end
> com_close(1)
> close all
> return
> The document is in below;
> -----------------------------------------------------------
> Check Characters "cc"
> Check Characters ensure that a message received by either the PMS has
> arrived intact. The Check Characters is an LRC using exclusive OR (XOR)
> starting with 0x00 as seed. On transmission all characters after the STX
> including ETX are XORed. The result is expanded to ASCII characters,
stored
> in two bytes, and sent as the Check Characters.
> The example below issustrates how to compute the Check Characters. The
> example message is not an valid message as described in this protocal
> Message:
> --------------------------------------------------------------------------
--
> ------
> | STX | 0x41 | 0x52 | 0x6F | ETX | C | C
> |
> --------------------------------------------------------------------------
--
> ------
> first byte 0x00
> XOR 0x41 =0x41
> second byte 0x41
XOR
> 0x52 =0x13
> third byte 0x13
> XOR 0x6F =0x7C
> forth byte 0x7C
> XOR 0x03 =0x7F = hex check character
> first Check Character in ASCII 0x7
> =0x37
> second Check Character in ASCII 0xF
> =0x46
> On reception all bytes following the STX up to the two bytes following the
> ETX are XORed. The two bytes following the ETX are contracted from ASCII
to
> hex value. The result is 0x00 if the message is received correctly.
> --------------------------------------------------------------------------
--
> -------------
> | STX | 0x41 | 0x52 | 0x6F | ETX | 0x37 |
> 0x46 |
> --------------------------------------------------------------------------
--
> -------------
> first byte
> 0x00 XOR 0x41 =0x41
> second byte
0x41
> XOR 0x52 =0x13
> third byte
> 0x13 XOR 0x6F =0x7C
> forth byte
> 0x7C XOR 0x03 =0x7F
> first Check Character 0x37 => 0x7 0x7F XOR
0x70
> =0x0F
> second Check Character 0x46 => 0xF 0x0F XOR 0x0F
> =0x00
> These Check Characters are not applicable in error correction. Instead,
the
> sending device should retry a message RTM times when it receives an NAK
from
> the receiveing device.
> Thanks very big for any idea.... : )