Block Check Character (BCC)

Discuss anything else that does not suite other forums.

Moderator: Rathinagiri

User avatar
Roberto Lopez
HMG Founder
Posts: 3873
Joined: Wed Jul 30, 2008 6:43 pm
Has thanked: 6 times
Been thanked: 99 times

Block Check Character (BCC)

Post by Roberto Lopez » Wed Mar 08, 2017 5:56 pm

Hi All,

According Wikipedia, In telecommunications, a block check character (BCC) is a character added to a transmission block to facilitate error detection.

I need to communicate with a fiscal printer and I must send BCC with each command string.

Here is an example from the printer manual:

Code: Select all

[STX]1[ESC]*[FS]0000[FS]0000[FS]0004[FS]3[FS]83[FS]81[FS]2[FS]0[FS]0
[ETX]0054
Where BCC is the last value (0054 in this example)

Has anybody any idea about how to obtain it with Harbour?

Any help is welcome.

TIA.
Regards/Saludos,

Roberto


(Veritas Filia Temporis)

edk
Posts: 34
Joined: Thu Oct 16, 2014 11:35 am
Location: Poland
Has thanked: 4 times
Been thanked: 12 times

Re: Block Check Character (BCC)

Post by edk » Wed Mar 08, 2017 8:45 pm

Hi Roberto.
Way of calculating the checksum should be described in the programmer's documentation. What's a model of fiscal printer?

Code: Select all

[STX]1[ESC]*[FS]0000[FS]0000[FS]0004[FS]3[FS]83[FS]81[FS]2[FS]0[FS]0
[ETX]0054
is similar to polish Posnet protocol.

Edward.

User avatar
Roberto Lopez
HMG Founder
Posts: 3873
Joined: Wed Jul 30, 2008 6:43 pm
Has thanked: 6 times
Been thanked: 99 times

Re: Block Check Character (BCC)

Post by Roberto Lopez » Thu Mar 09, 2017 2:43 am

edk wrote:
Wed Mar 08, 2017 8:45 pm
Hi Roberto.
Way of calculating the checksum should be described in the programmer's documentation. What's a model of fiscal printer?

Code: Select all

[STX]1[ESC]*[FS]0000[FS]0000[FS]0004[FS]3[FS]83[FS]81[FS]2[FS]0[FS]0
[ETX]0054
is similar to polish Posnet protocol.

Edward.
Edward,

The fiscal printer is not of an international brand.

The description of BCC in the manual (translated from original Spanish) is as follows:
BCC = Four hexadecimales. Binary sum of all prior bytes
Regards/Saludos,

Roberto


(Veritas Filia Temporis)

User avatar
CalScot
Posts: 226
Joined: Thu Mar 21, 2013 12:22 am
Location: California
Been thanked: 1 time

Re: Block Check Character (BCC)

Post by CalScot » Thu Mar 09, 2017 3:14 am

I've heard of it referred to as a check digit, or in the old telecom days, as the CRC - Cyclic Redundancy Check. Interesting that there are so many names for essentially the same thing - a crude validation of the integrity of the value string that preceded it.
I don't have easy access to documentation right now (brand new computer!!) but it should be possible to write a function to return the binary sum of all prior bytes as a four-hexadecimal string. Checking Harbour's HexaToDec() or DecToHexa() might help, or at least give inspiration that would lead to a solution?
Hope that helps!

User avatar
andyglezl
Posts: 794
Joined: Fri Oct 26, 2012 7:58 pm
Location: Guadalajara Jalisco, MX
Has thanked: 7 times
Been thanked: 11 times
Contact:

Re: Block Check Character (BCC)

Post by andyglezl » Thu Mar 09, 2017 1:45 pm

Maybe someting like this...

DecToHexa( BIntODEC( DecToBin( asciisum( "123" ) ) ) )
Andrés González López
Desde Guadalajara, Jalisco. México.

User avatar
Roberto Lopez
HMG Founder
Posts: 3873
Joined: Wed Jul 30, 2008 6:43 pm
Has thanked: 6 times
Been thanked: 99 times

Re: Block Check Character (BCC)

Post by Roberto Lopez » Thu Mar 09, 2017 6:41 pm

Thanks for the answers.

The manual is plenty of examples of commands with numbers ()like the one I've already posted) but not programming examples.

I've already attempted something using Harbour conversion functions, but I was not able to match the results as shown in manual examples.
Regards/Saludos,

Roberto


(Veritas Filia Temporis)

User avatar
Roberto Lopez
HMG Founder
Posts: 3873
Joined: Wed Jul 30, 2008 6:43 pm
Has thanked: 6 times
Been thanked: 99 times

Re: Block Check Character (BCC)

Post by Roberto Lopez » Thu Mar 09, 2017 6:47 pm

andyglezl wrote:
Thu Mar 09, 2017 1:45 pm
Maybe someting like this...

DecToHexa( BIntODEC( DecToBin( asciisum( "123" ) ) ) )
I've missed asciisum() when searched Harbour guides.

I'll try asciisum and Checksum functions.

http://harbour.edu.pl/lib/tools/ng3ef0c.html

http://harbour.edu.pl/lib/tools/ng4c464.html

By the way... harbour.edu.pl is a very nice site. The style / format is wonderful.

Thanks!
Regards/Saludos,

Roberto


(Veritas Filia Temporis)

User avatar
serge_girard
Posts: 1521
Joined: Sun Nov 25, 2012 2:44 pm
Location: Belgium
Has thanked: 142 times
Been thanked: 21 times
Contact:

Re: Block Check Character (BCC)

Post by serge_girard » Thu Mar 09, 2017 6:54 pm

Hello,


http://harbour.edu.pl/index.html


Is indeed a great site! However (like our DOCS-page) it contains many � TAB chars which need a STRTRAN because HTML doesn't recognize TAB char.

Serge

edk
Posts: 34
Joined: Thu Oct 16, 2014 11:35 am
Location: Poland
Has thanked: 4 times
Been thanked: 12 times

Re: Block Check Character (BCC)

Post by edk » Fri Mar 10, 2017 10:06 am

Hi again.
Sorry for the delay, but I was in the delegation.
The description of BCC in the manual (translated from original Spanish) is as follows:

BCC = Four hexadecimales. Binary sum of all prior bytes
In my opinion the binary sum of all bytes is nothing but the sum of the ASCII codes of each character in the string.
From a mathematical point of view, it does not matter if we add up the number of binary, hexadecimal or decimal notation. The sum should always be the same.
For example:
the sum in binary notation : 101 + 110 = 1011; decimal = 11
the sum in decimal notation: 5 + 6 = 11

I'm surprised the given example, because the sum of all bytes (from [STX] to [ETX]) results in a hexadecimal notation 0554, not 0054.

Example according to andyglezl
DecToHexa (BIntODEC (DecToBin (asciisum ("123"))))
is OK, but shorter is NTOC( AsciiSum ( cSent ), 16, 4, '0' )

Code: Select all

STX:=CHR(2)
ESC:=CHR(27)
FS:=CHR(28)
ETX:=CHR(3)
cSent:=STX+'1'+ESC+'*'+FS+'0000'+FS+'0000'+FS+'0004'+FS+'3'+FS+'83'+FS+'81'+FS+'2'+FS+'0'+FS+'0'+ETX

BCC:=NTOC( AsciiSum ( cSent ), 16, 4, '0' )  // => '0554'
Manufacturer fiscal printer does not provide any libraries to operate the device?

Edward.

User avatar
mol
Posts: 2631
Joined: Thu Sep 11, 2008 5:31 am
Location: Myszków, Poland
Has thanked: 59 times
Been thanked: 23 times
Contact:

Re: Block Check Character (BCC)

Post by mol » Sun Mar 12, 2017 6:21 am

I'm using such a function with communication with Polish fiscal printers to calculate CRC:

Code: Select all

function CalculateCRC
	param cString
	local nResult := 0xff
	local nChar
	local i
	local cRetValue
	for i:=1 to len(cString)
		nChar := asc(substr(cString,i,1))
		nResult := numxor(nResult, nChar)
	next i
	
	// conversion to required format - change hex to string
	nChar := nResult % 16
	if nChar > 9
		cRetValue := chr(55+nChar)
	else
		cRetValue := str(nChar,1)
	endif
	nChar := (nResult-nChar)/16
	if nChar > 9
		cRetValue := chr(55+nChar) + cRetValue
	else
		cRetValue := str(nChar,1) + cRetValue
	endif
 return cRetValue

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest