PlanetSquires Forums

Please login or register.

Login with username, password and session length
Advanced search  

Author Topic: EAN 128 Barcodes  (Read 2327 times)

Petrus Vorster

  • Senior Member
  • ***
  • Posts: 451
EAN 128 Barcodes
« on: November 15, 2015, 05:02:22 AM »

Hi all

In VB.Net there is a tool to create EAN128 Barcodes.
Code: [Select]
   Imports OnBarcode.Barcode


   Dim barcode As Linear = New Linear
   
   ' Code 128 Barcode Basic Settings
   barcode.Type = BarcodeType.CODE128
   
   '   Code 128 Valid data char set:
   '        all 128 ASCII characters (Char from 0 to 127)
   barcode.Data = "112233445566"
   
   '  Set the ProcessTilde property to true, if you want use the tilde character "~"
   '  to specify special characters in the input data. Default is false.
   '
   '  1) 1-byte character: ~0dd/~1dd/~2dd (character value from 000 ~ 255);
   '         Strings from "~256" to "~299" are unused
   '  2) 2-byte character (Unicode): ~6ddddd (character value from 00000 ~ 65535)
   '       ASCII character '~' is presented by ~126;Strings from "~665536" to "~699999" are unused
   barcode.ProcessTilde = True
   
   ' Barcode Size Related Settings
   barcode.UOM = UnitOfMeasure.PIXEL
   barcode.X = 1
   barcode.Y = 80
   barcode.LeftMargin = 0
   barcode.RightMargin = 0
   barcode.TopMargin = 0
   barcode.BottomMargin = 0
   barcode.Resolution = 96
   barcode.Rotate = Rotate.Rotate0
   
   ' Barcode Text Settings
   barcode.ShowText = True
   barcode.TextFont = New Drawing.Font("Arial", 9.0F, Drawing.FontStyle.Regular)
   barcode.TextMargin = 6
   
   ' Image format setting
   barcode.Format = System.Drawing.Imaging.ImageFormat.Gif()
   
   barcode.drawBarcode("c://code-128.gif")

Has anyone done similar work in PB or Fb?
I need to create a little app that can create its own EAN 128 Barcodes on the fly.
I have the company's sequencing code and so forth to create the numbers, but the conversion to an actual bar-code i still cannot do.
It will eventually generate a standard postal bar-code and print it to a label printer.

Isn't there a Dll or something out there that you perhaps know about. I want to do this in FB if possibe.
There are some EAN128 Bar-code fonts out there, but it doesn't seem to work properly.
Sometimes triggers in the barcode is necessary like "*" and the makers of the original barcode stickers we use ROTOLABEL obviously wont share the secret.

Anyone perhaps have done more work on this?

Thanks!
« Last Edit: November 15, 2015, 06:18:59 AM by Petrus Vorster »
Logged

Nathan Durland

  • Junior Member
  • **
  • Posts: 83
Re: EAN 128 Barcodes
« Reply #1 on: November 15, 2015, 11:55:17 AM »

Here is some ancient code that we used to use to create bar code on print streams when we were using Don Dickinson's DDOC printing system.  We switched to Virtual Print Engine quite some time ago.  This is mostly code that I um, "borrowed" from somewhere else.  It probably wouldn't be terribly hard to convert it to use XPRINT, or whatever is native to FreeBASIC.

Code: [Select]
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
' Function to print a 128 code Barcode on a DDOC output
' stream.
'
'  hPrt       = DDOC print doc handle
'  Victim     = String to barcode
'  xLoc,yLoc  = x (horiz) & y (vert) corrdinate of barcode
'  bcScale      = multiplier for size; std heigh is 0.315
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

%START_A = 103     'Checksum Modulus

'------------------------------------------------------------------------------------------------------------------------
FUNCTION Code128( BYVAL TheSrc AS STRING) AS STRING
'-------------------------------------------------------
' This function encodes the given string into a string
' of 1's and 0's; this is the pattern for the bars in
' the bar code
'-------------------------------------------------------

  LOCAL CheckSum      AS LONG
  LOCAL z             AS STRING
  LOCAL xLoop         AS LONG
  LOCAL CurrChar      AS STRING
  LOCAL csNum         AS LONG


  CheckSum = %START_A
  TheSrc  = UCASE$(TRIM$(TheSrc))
  z = z + STRING$(10, "0")                             'Leading quiet zone
  z = z + "11010000100"                                '2 1 1 4 1 2  Start Class A

  FOR xLoop = 1 TO LEN(TheSrc)
    CurrChar = MID$(TheSrc, xLoop, 1)
    GOSUB Selectbar                                    'Get pattern & check value for current character
    CheckSum = CheckSum + (csNum * xLoop)              'Do checksum
  NEXT

  CheckSum = CheckSum MOD %START_A                       'Do mod
  GOSUB Getchkchar                                         'Get checksum pattern

  z = z + "1100011101011"                                '2 3 3 1 1 1 2 Stop (7 patts.)
  z = z + STRING$(10, "0")                               'Trailing quiet zone

  FUNCTION = z

EXIT FUNCTION
'
Selectbar:
    SELECT CASE CurrChar
        CASE " "
            z = z + "11011001100"
            csNum = 0
        CASE "!":
            z = z + "11001101100"
            csNum = 1
        CASE CHR$(34)
            z = z + "11001100110"
            csNum = 2
        CASE "#"
            z = z + "10010011000"
            csNum = 3
        CASE "$"
            z = z + "10010001100"
            csNum = 4
        CASE "%"
            z = z + "10001001100"
            csNum = 5
        CASE "&"
            z = z + "10011001000"
            csNum = 6
        CASE "'"
            z = z + "10011000100"
            csNum = 7
        CASE "("
            z = z + "10001100100"
            csNum = 8
        CASE ")"
            z = z + "11001001000"
            csNum = 9
        CASE "*"
            z = z + "11001000100"
            csNum = 10
        CASE "+"
            z = z + "11000100100"
            csNum = 11
        CASE ","
            z = z + "10110011100"
            csNum = 12
        CASE "-"
            z = z + "10011011100"
            csNum = 13
        CASE "."
            z = z + "10011001110"
            csNum = 14
        CASE "/"
            z = z + "10111001100"
            csNum = 15
        CASE "0"
            z = z + "10011101100"
            csNum = 16
        CASE "1"
            z = z + "10011100110"
            csNum = 17
        CASE "2"
            z = z + "11001110010"
            csNum = 18
        CASE "3"
            z = z + "11001011100"
            csNum = 19
        CASE "4"
            z = z + "11001001110"
            csNum = 20
        CASE "5"
            z = z + "11011100100"
            csNum = 21
        CASE "6"
            z = z + "11001110100"
            csNum = 22
        CASE "7"
            z = z + "11101101110"
            csNum = 23
        CASE "8"
            z = z + "11101001100"
            csNum = 24
        CASE "9"
            z = z + "11100101100"
            csNum = 25
        CASE ":"
            z = z + "11100100110"
            csNum = 26
        CASE ";"
            z = z + "11101100100"
            csNum = 27
        CASE "<"
            z = z + "11100110100"
            csNum = 28
        CASE "="
            z = z + "11100110010"
            csNum = 29
        CASE ">"
            z = z + "11011011000"
            csNum = 30
        CASE "?"
            z = z + "11011000110"
            csNum = 31
        CASE "@"
            z = z + "11000110110"
            csNum = 32
        CASE "A"
            z = z + "10100011000"
            csNum = 33
        CASE "B"
            z = z + "10001011000"
            csNum = 34
        CASE "C"
            z = z + "10001000110"
            csNum = 35
        CASE "D"
            z = z + "10110001000"
            csNum = 36
        CASE "E"
            z = z + "10001101000"
            csNum = 37
        CASE "F"
            z = z + "10001100010"
            csNum = 38
        CASE "G"
            z = z + "11010001000"
            csNum = 39
        CASE "H"
            z = z + "11000101000"
            csNum = 40
        CASE "I"
            z = z + "11000100010"
            csNum = 41
        CASE "J"
            z = z + "10110111000"
            csNum = 42
        CASE "K"
            z = z + "10110001110"
            csNum = 43
        CASE "L"
            z = z + "10001101110"
            csNum = 44
        CASE "M"
            z = z + "10111011000"
            csNum = 45
        CASE "N"
            z = z + "10111000110"
            csNum = 46
        CASE "O"
            z = z + "10001110110"
            csNum = 47
        CASE "P"
            z = z + "11101110110"
            csNum = 48
        CASE "Q"
            z = z + "11010001110"
            csNum = 49
        CASE "R"
            z = z + "11000101110"
            csNum = 50
        CASE "S"
            z = z + "11011101000"
            csNum = 51
        CASE "T"
            z = z + "11011100010"
            csNum = 52
        CASE "U"
            z = z + "11011101110"
            csNum = 53
        CASE "V"
            z = z + "11101011000"
            csNum = 54
        CASE "W"
            z = z + "11101000110"
            csNum = 55
        CASE "X"
            z = z + "11100010110"
            csNum = 56
        CASE "Y"
            z = z + "11101101000"
            csNum = 57
        CASE "Z"
            z = z + "11101100010"
            csNum = 58
        CASE "["
            z = z + "11100011010"
            csNum = 59
        CASE "\"
            z = z + "11101111010"
            csNum = 60
        CASE "]"
            z = z + "11001000010"
            csNum = 61
        CASE "^"
            z = z + "11110001010"
            csNum = 62
        CASE "_"
            z = z + "10100110000"
            csNum = 63
        CASE ELSE
    END SELECT
RETURN
'
Getchkchar:
    SELECT CASE CheckSum
        CASE 0
            z = z + "11011001100"
        CASE 1
            z = z + "11001101100"
        CASE 2
            z = z + "11001100110"
        CASE 3
            z = z + "10010011000"
        CASE 4
            z = z + "10010001100"
        CASE 5
            z = z + "10001001100"
        CASE 6
            z = z + "10011001000"
        CASE 7
            z = z + "10011000100"
        CASE 8
            z = z + "10001100100"
        CASE 9
            z = z + "11001001000"
        CASE 10
            z = z + "11001000100"
        CASE 11
            z = z + "11000100100"
        CASE 12
            z = z + "10110011100"
        CASE 13
            z = z + "10011011100"
        CASE 14
            z = z + "10011001110"
        CASE 15
            z = z + "10111001100"
        CASE 16
            z = z + "10011101100"
        CASE 17
            z = z + "10011100110"
        CASE 18
            z = z + "11001110010"
        CASE 19
            z = z + "11001011100"
        CASE 20
            z = z + "11001001110"
        CASE 21
            z = z + "11011100100"
        CASE 22
            z = z + "11001110100"
        CASE 23
            z = z + "11101101110"
        CASE 24
            z = z + "11101001100"
        CASE 25
            z = z + "11100101100"
        CASE 26
            z = z + "11100100110"
        CASE 27
            z = z + "11101100100"
        CASE 28
            z = z + "11100110100"
        CASE 29
            z = z + "11100110010"
        CASE 30
            z = z + "11011011000"
        CASE 31
            z = z + "11011000110"
        CASE 32
            z = z + "11000110110"
        CASE 33
            z = z + "10100011000"
        CASE 34
            z = z + "10001011000"
        CASE 35
            z = z + "10001000110"
        CASE 36
            z = z + "10110001000"
        CASE 37
            z = z + "10001101000"
        CASE 38
            z = z + "10001100010"
        CASE 39
            z = z + "11010001000"
        CASE 40
            z = z + "11000101000"
        CASE 41
            z = z + "11000100010"
        CASE 42
            z = z + "10110111000"
        CASE 43
            z = z + "10110001110"
        CASE 44
            z = z + "10001101110"
        CASE 45
            z = z + "10111011000"
        CASE 46
            z = z + "10111000110"
        CASE 47
            z = z + "10001110110"
        CASE 48
            z = z + "11101110110"
        CASE 49
            z = z + "11010001110"
        CASE 50
            z = z + "11000101110"
        CASE 51
            z = z + "11011101000"
        CASE 52
            z = z + "11011100010"
        CASE 53
            z = z + "11011101110"
        CASE 54
            z = z + "11101011000"
        CASE 55
            z = z + "11101000110"
        CASE 56
            z = z + "11100010110"
        CASE 57
            z = z + "11101101000"
        CASE 58
            z = z + "11101100010"
        CASE 59
            z = z + "11100011010"
        CASE 60
            z = z + "11101111010"
        CASE 61
            z = z + "11001000010"
        CASE 62
            z = z + "11110001010"
        CASE 63
            z = z + "10100110000"
        CASE 64
            z = z + "10100001100"
        CASE 65
            z = z + "10010110000"
        CASE 66
            z = z + "10010000110"
        CASE 67
            z = z + "10000101100"
        CASE 68
            z = z + "10000100110"
        CASE 69
            z = z + "10110010000"
        CASE 70
            z = z + "10110000100"
        CASE 71
            z = z + "10011010000"
        CASE 72
            z = z + "10011000010"
        CASE 73
            z = z + "10000110100"
        CASE 74
            z = z + "10000110010"
        CASE 75
            z = z + "11000010010"
        CASE 76
            z = z + "11001010000"
        CASE 77
            z = z + "11110111010"
        CASE 78
            z = z + "11000010100"
        CASE 79
            z = z + "10001111010"
        CASE 80
            z = z + "10100111100"
        CASE 81
            z = z + "10010111100"
        CASE 82
            z = z + "10010011110"
        CASE 83
            z = z + "10111100100"
        CASE 84
            z = z + "10011110100"
        CASE 85
            z = z + "10011110010"
        CASE 86
            z = z + "11110100100"
        CASE 87
            z = z + "11110010100"
        CASE 88
            z = z + "11110010010"
        CASE 89
            z = z + "11011011110"
        CASE 90
            z = z + "11011110110"
        CASE 91
            z = z + "11110110110"
        CASE 92
            z = z + "10101111000"
        CASE 93
            z = z + "10100011110"
        CASE 94
            z = z + "10001011110"
        CASE 95
            z = z + "10111101000"
        CASE 96
            z = z + "10111100010"
        CASE 97
            z = z + "11110101000"
        CASE 98
            z = z + "11110100010"
        CASE 99
            z = z + "10111011110"
        CASE 100
            z = z + "10100001000"
        CASE 101
            z = z + "11101011110"
        CASE 102
            z = z + "11110101110"
        CASE 103
            z = z + "11010000100"
        CASE 104
            z = z + "11010010000"
        CASE ELSE
    END SELECT
RETURN
'
END FUNCTION

'------------------------------------------------------------------------------------------------------------------------
FUNCTION Code39(BYVAL Number AS STRING) AS STRING

  LOCAL NumberA       AS STRING
  LOCAL BCString      AS STRING
  LOCAL xLoop         AS LONG


  Number = UCASE$(Number)
  NumberA = "*" + Number + "*"
  BCString = ""
  FOR xLoop = 1 TO LEN(NumberA)
    SELECT CASE MID$(NumberA, xLoop, 1)
      CASE "1"
        BCString = BCString + "110100101011"
      CASE "2"
        BCString = BCString + "101100101011"
      CASE "3"
        BCString = BCString + "110110010101"
      CASE "4"
        BCString = BCString + "101001101011"
      CASE "5"
        BCString = BCString + "110100110101"
      CASE "6"
        BCString = BCString + "101100110101"
      CASE "7"
        BCString = BCString + "101001011011"
      CASE "8"
        BCString = BCString + "110100101101"
      CASE "9"
        BCString = BCString + "101100101101"
      CASE "0"
        BCString = BCString + "101001101101"
      CASE "A"
        BCString = BCString + "110101001011"
      CASE "B"
        BCString = BCString + "101101001011"
      CASE "C"
        BCString = BCString + "110110100101"
      CASE "D"
        BCString = BCString + "101011001011"
      CASE "E"
        BCString = BCString + "110101100101"
      CASE "F"
        BCString = BCString + "101101100101"
      CASE "G"
        BCString = BCString + "101010011011"
      CASE "H"
        BCString = BCString + "110101001101"
      CASE "I"
        BCString = BCString + "101101001101"
      CASE "J"
        BCString = BCString + "101011001101"
      CASE "K"
        BCString = BCString + "110101010011"
      CASE "L"
        BCString = BCString + "101101010011"
      CASE "M"
        BCString = BCString + "110110101001"
      CASE "N"
        BCString = BCString + "101011010011"
      CASE "O"
        BCString = BCString + "110101101001"
      CASE "P"
        BCString = BCString + "101101101001"
      CASE "Q"
        BCString = BCString + "101010110011"
      CASE "R"
        BCString = BCString + "110101011001"
      CASE "S"
        BCString = BCString + "101101011001"
      CASE "T"
        BCString = BCString + "101011011001"
      CASE "U"
        BCString = BCString + "110010101011"
      CASE "V"
        BCString = BCString + "100110101011"
      CASE "W"
        BCString = BCString + "110011010101"
      CASE "X"
        BCString = BCString + "100101101011"
      CASE "Y"
        BCString = BCString + "110010110101"
      CASE "Z"
        BCString = BCString + "100110110101"
      CASE "-"
        BCString = BCString + "100101011011"
      CASE "."
        BCString = BCString + "110010101101"
      CASE " "
        BCString = BCString + "100110101101"
      CASE "*"
        BCString = BCString + "100101101101"
      CASE "$"
        BCString = BCString + "100100100101"
      CASE "/"
        BCString = BCString + "100100100101"
      CASE "+"
        BCString = BCString + "100101001001"
      CASE "%"
        BCString = BCString + "101001001001"
      CASE ELSE
        BEEP
        EXIT FUNCTION
    END SELECT
    BCString = BCString + "0"
  NEXT xLoop

  FUNCTION = BCString

END FUNCTION

'------------------------------------------------------------------------------------------------------------------------
FUNCTION PrintBarCode(_
        BYVAL hPrt AS INTEGER, _   '  DDOC print Stream
        BYVAL Victim AS STRING, _ ' string to print
        BYVAL xLoc AS SINGLE, _    ' where to put the barcode
        BYVAL yLoc AS SINGLE, _
        BYVAL bcScale AS SINGLE,
        BYVAL IncludeText AS STRING, _ ' human readable text under code
        BYVAL CodeType AS STRING)      ' Type of barcode
        AS LONG


  LOCAL bc        AS STRING
  LOCAL Lincr     AS SINGLE
  LOCAL xLoop     AS LONG
  LOCAL yLoop     AS LONG
  LOCAL bcHgt     AS SINGLE
  LOCAL lwd       AS SINGLE
  LOCAL x1, y1    AS SINGLE
  LOCAL x2, y2    AS SINGLE

  IF hPrt < 1 THEN
    FUNCTION = %False
    EXIT FUNCTION
  END IF

  IF CodeType = "39" THEN
    bc = Code39(Victim)
  ELSE
    bc = Code128(Victim)
  END IF
  ' Line spacing
  lincr = (3 / 300) * bcScale
  ' height
  bcHgt = 0.315  * bcScale

  ' Line width gives intensity
  ' 0.7 seems to work best
  lwd = (0.7 * bcScale)
  'lwd = 1
 
  x1 = xLoc
  bc = ltrim$(bc, "0")
 
  FOR xLoop = 1 TO LEN(bc)
    IF MID$(bc, xLoop, 1) = "1" THEN
      x1 = xLoc + (xLoop * lincr)
      y1 = yLoc
      x2 = xLoc + (xLoop * lincr) 
      y2 = yLoc + bcHgt
     
      DPRECT hPrt, x1, y1, x2+(lincr), y2, 0, %BLACK, %BLACK
     
    END IF
  NEXT

  IF LEN(IncludeText) > 0 THEN
    xLoc = xLoc + ((LEN(bc) * lincr) / 2)
    yLoc = yLoc + bchgt
    DPFONT hPrt,%DDOC_FONTBOLD,FIX(8*bcScale),%VBBLACK, "Courier New"
    DPTEXT hPrt,xLoc,yLoc,%DDOC_CENTER,(IncludeText)
  END IF


END FUNCTION  ' Print BarCode

Logged

Petrus Vorster

  • Senior Member
  • ***
  • Posts: 451
Re: EAN 128 Barcodes
« Reply #2 on: November 16, 2015, 04:30:53 PM »

Cool, thanks Nathan, i will give this a shot.
Logged

Klaas Holland

  • Junior Member
  • **
  • Posts: 106
  • FF3 User
Re: EAN 128 Barcodes
« Reply #3 on: November 16, 2015, 05:35:43 PM »

Hi Petrus,

I'am interested too.
Do you try to get it working in PB or in FreeBasic?

BTW I got the FB printing working, thanks to Paul.
When you are still interested I can send you an example.

Klaas
Logged

Petrus Vorster

  • Senior Member
  • ***
  • Posts: 451
Re: EAN 128 Barcodes
« Reply #4 on: November 17, 2015, 04:32:34 PM »

Hi Klaas.

I am looking at a few options here.
EAN128 is unlike Code39 not simply a case of using a font and type the numbers...
Nathan's code and some other i found also shows there is a definite start and end character, then a checksum calculation on each character according to its position, a division by 103 and then its assembled into a bunch of lines.
I found a codeEAN128 font which you can use with Xprint, but you still need to do the calculations it seems. I am talking to its creator about the methods.
He only has examples in C.net.
I will play around and let you know. I want to draw how the actual label will look like on my form before the person prints to the label printer.
Will keep you posted.
Logged

Chris Maher

  • Little Newbie
  • *
  • Posts: 24
  • New FF3 User
Re: EAN 128 Barcodes
« Reply #5 on: November 18, 2015, 04:43:09 PM »

Hi Petrus,

This link has some relevant detail that I found helpful: http://www.barcodeisland.com/code128.phtml

I don't think you would need to use a font resource. The code to draw the barcode looks like this on my preview graphic target but it could go directly to the printer using XPRINT commands instead.

Code: [Select]
    '--------------------------Draw the barcode

    LOCAL BinaryCodeString, BarcodeNumber AS STRING
    LOCAL ModuleWidth, BXpos, BYpos, BYDepth, i AS DOUBLE

    BarcodeNumber="02078010888284400068"
    ModuleWidth=.35      'Note: Scale was set to mm in earlier code
    BXpos=43
    BYpos=20.5
    BYdepth=10.5

    GRAPHIC WIDTH 1

    BinaryCodeString=Code128CBinary(BarcodeNumber)   '20 digits passed to barcode binary code string function
    FOR i=1 TO LEN(BinaryCodeString)
        BXpos=BXpos + ModuleWidth
        IF MID$(BinaryCodeString, i, 1)="1" THEN
            GRAPHIC BOX (BXpos, BYpos) - (BXpos+ModuleWidth, BYpos+BYdepth),0,-1,-1,0
        END IF
    NEXT i


I hope this helps - sorry it is not the complete solution..

Chris.
Logged

Petrus Vorster

  • Senior Member
  • ***
  • Posts: 451
Re: EAN 128 Barcodes
« Reply #6 on: November 19, 2015, 08:07:44 AM »

Thanks Chris!

I will play  with the code next week when I return.
I am certain we will be able to make it work.
Logged

Petrus Vorster

  • Senior Member
  • ***
  • Posts: 451
Re: EAN 128 Barcodes
« Reply #7 on: February 01, 2016, 02:37:23 PM »

Nope, still havent managed to get this working.

Do we have means to translate a DLL for .NET to something we can use either in FB or FF?
They have a simple DLL and all you need to do is give it the text and it returns the Barcode with the test figures and formulas inside, and then draws it too.

ONE line of code.

I really need to crack this EAN128 code thing.
Logged

Petrus Vorster

  • Senior Member
  • ***
  • Posts: 451
Re: EAN 128 Barcodes
« Reply #8 on: February 01, 2016, 03:50:09 PM »

Some progress made...
Calculation of the modulo 103 checksum for the barcode seems ok.
Now to try and make this auto calculate and create the actual barcode is a whole different story...
Logged