To generate bar code from a number

This is a discussion on To generate bar code from a number within the C Programming forums, part of the General Programming Boards category; Necessary to generate a bar code in the format 128b, I will go to pass a number 1254896587 and necessary ...

  1. #1
    Registered User
    Join Date
    Dec 2007
    Posts
    13

    To generate bar code from a number

    Necessary to generate a bar code in the format 128b, I will go to pass a number 1254896587 and necessary that is generated in hexadecimal format therefore I will go to need to better print the bar code in a equipament POS which way to make this?

    example image in hexa:

    Code:
    static const byte bmp[] = {0xFF, 0xF0, 0x00, 0xCC, 0x3C, 0x3C, 0xCC, 0x00, 0xF0,0xFF,
                               0xFF, 0xF0, 0x00, 0xCC, 0x3C, 0x3C, 0xCC, 0x00, 0xF0,0xFF,
                               0xFF, 0xF0, 0x00, 0xCC, 0x3C, 0x3C, 0xCC, 0x00, 0xF0,0xFF,
                               0xFF, 0xF0, 0x00, 0xCC, 0x3C, 0x3C, 0xCC, 0x00, 0xF0,0xFF,
                               0xFF, 0xF0, 0x00, 0xCC, 0x3C, 0x3C, 0xCC, 0x00, 0xF0,0xFF,
                               0xFF, 0xF0, 0x00, 0xCC, 0x3C, 0x3C, 0xCC, 0x00, 0xF0,0xFF,
                               0xFF, 0xF0, 0x00, 0xCC, 0x3C, 0x3C, 0xCC, 0x00, 0xF0,0xFF,
                               0xFF, 0xF0, 0x00, 0xCC, 0x3C, 0x3C, 0xCC, 0x00, 0xF0,0xFF,
                               0xFF, 0xF0, 0x00, 0xCC, 0x3C, 0x3C, 0xCC, 0x00, 0xF0,0xFF,
                               0xFF, 0xF0, 0x00, 0xCC, 0x3C, 0x3C, 0xCC, 0x00, 0xF0,0xFF,
                               0xFF, 0xF0, 0x00, 0xCC, 0x3C, 0x3C, 0xCC, 0x00, 0xF0,0xFF,
                               0xFF, 0xF0, 0x00, 0xCC, 0x3C, 0x3C, 0xCC, 0x00, 0xF0,0xFF,
                               0xFF, 0xF0, 0x00, 0xCC, 0x3C, 0x3C, 0xCC, 0x00, 0xF0,0xFF,
                               0xFF, 0xF0, 0x00, 0xCC, 0x3C, 0x3C, 0xCC, 0x00, 0xF0,0xFF,
                               0xFF, 0xF0, 0x00, 0xCC, 0x3C, 0x3C, 0xCC, 0x00, 0xF0,0xFF,
                               0xFF, 0xF0, 0x00, 0xCC, 0x3C, 0x3C, 0xCC, 0x00, 0xF0,0xFF,
                               0xFF, 0xF0, 0x00, 0xCC, 0x3C, 0x3C, 0xCC, 0x00, 0xF0,0xFF,
                               0xFF, 0xF0, 0x00, 0xCC, 0x3C, 0x3C, 0xCC, 0x00, 0xF0,0xFF,
                               0xFF, 0xF0, 0x00, 0xCC, 0x3C, 0x3C, 0xCC, 0x00, 0xF0,0xFF,
                               0xFF, 0xF0, 0x00, 0xCC, 0x3C, 0x3C, 0xCC, 0x00, 0xF0,0xFF
                              };

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,500
    How about details such as
    - your operating system and compiler
    - your printer
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  3. #3
    Registered User
    Join Date
    Dec 2007
    Posts
    13
    Compiler: hcarm_4.5a
    Printer POS nurit 8320 http://www.paytec.com.br/nurit8320.html
    www.verifone.com

    it only prints bitmap in the hexadecinal format, then necessary to generate the image in the hexadecimal format, from a number "4879542145878" to be able to print!

    example function of help:


    Printer_PrintBitMap


    NAME OF FUNCTION:

    Printer_PrintBitMap



    DESCRIPTION:

    Before calling the function, the ExGraphicsDescriptor structure type application buffer must be declared and intialized.

    Use the function to print a Bitmap picture on the paper. The egd argument is a pointer to the ExGraphicsDescriptor structure type application buffer. The data argumnet points to the to-be-printed data. The function returns the number of bytes inserted to the buffer or 0 in case of an error.



    SYNTAX:

    sint Printer_PrintBitMap
    (
    ExGraphicsDescriptor* egd,
    byte* data
    )


    ARGUMENTS:

    ExGraphicsDescriptor* egd

    byte* data



    INPUT:

    byte* data - pointer to the data to be printed

    ExGraphicsDescriptor* egd - a structure defined in



    The following fields are included in the ExGraphicsDescriptor structure:
    byte Mode - Graphical Modes enumerated in

    The valid values for Mode are as follows:
    1 - EX_DOUBLE_VERTICAL - 192 bytes per 16 lines. This mode resembles the EX_SINGLE_VERTICAL mode except: Each Pixel is doubled and each Line is doubled as well.

    2 - EX_SINGLE_LINEAR - up to 48 bytes per Line (384) Pixels. 1 byte contains 8 bits where each bit represents a Pixel in the same line.

    3 - EX_DOUBLE_LINEAR - up to 24 bytes (192 Pixels). This mode resembles the EX_SINGLE_LINEAR mode, except: each byte in a Line is doubled and every Line is doubled too.

    4 - EX_SINGLE_VERTICAL - 384 bytes per 8 lines. 1byte equals to 1 Pixel muliplied by 8 Lines.



    byte InBuff - place the bitmap data into the buffer. Should use one of the following modes:

    0 - EX_DIRECT - places a Poiner to the data into the buffer. More than one line can be sent. This mode can be used with Static arrays only. The data cannot be modified in the application's code.

    1 - EX_BUFFERED - places the data into an internal buffer. This mode requires one line per call and Dynamic arrays can be used. The data can be modified in the application's code.



    usint Pixels - number of bytes per line, should be used in accordance with the mode. Can be less or equal to the number valid for the mode field of the structure.

    usint Lines - number of lines to print, in accordance with the Inbuff field value.

    InBuff = EX_DIRECT - prints more than 1 line

    InBuff = EX_BUFFERED - prints one line only.

    usint Allign - picture allignment. One of the following values defined in

    EX_ALLIGN_LEFT - alligns to the left.

    EX_ALLIGN_RIGHT - alligns to the right.

    EX_ALLIGN_CENTRE - alligns to the center.

    byte Reserved[ 8 ] - reserved space for future use - must be 0.



    OUTPUT:

    None



    RETURN VALUE:

    0 - in case of an Error

    OUT_O_PAPER - when the printer is out of paper

    Other value - okay.

    USAGE / EXAMPLE:

    Printer Demo6

    Printer Demo7

    Printer Demo8





    NOTES:

    If InBuf == 0 - the data must be in the static area, where the bitmap data can not be modified. See Printer Demo6 for example

    If InBuf == 1 - the data can be in the dynamic area, where the bitmap data can be modified. See Printer Demo7 for example.
    Last edited by Salem; 01-11-2008 at 09:23 AM. Reason: Remove unnecesary code tags, which prevented line wrapping

  4. #4
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    Is your question how to generate the byte array from a number, or how to send the byte array to the printer?

  5. #5
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,500
    Hex has nothing to do with it, that's just a convenient representation.

    When compiled, both these things are EXACTLY the same
    Code:
    char data [ ] = { 1, 2, 4, 8, 16, 32 };
    char data [ ] = { 0x1, 0x2, 0x4, 0x8, 0x10, 0x20 };
    However, the next question would seem to be how to convert a digit (Say '2') into the corresponding pixel data (hex as you put it) to output to the printer.

    To me, this seems like such a common thing to have to do with a PoS system that there should be an API already available to you.

    If not, then it would be what is in essence a lookup table to convert a character ('2') into some kind of bitmap representation of that character (as a barcode character).

    My first suggestion would be to explore the API documentation you have for more information.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  6. #6
    Registered User
    Join Date
    Dec 2007
    Posts
    13
    Quote Originally Posted by tabstop View Post
    Is your question how to generate the byte array from a number, or how to send the byte array to the printer?
    to generate and to send for the printer

  7. #7
    Registered User
    Join Date
    Dec 2007
    Posts
    13
    Quote Originally Posted by Salem View Post
    Hex has nothing to do with it, that's just a convenient representation.

    When compiled, both these things are EXACTLY the same
    Code:
    char data [ ] = { 1, 2, 4, 8, 16, 32 };
    char data [ ] = { 0x1, 0x2, 0x4, 0x8, 0x10, 0x20 };
    However, the next question would seem to be how to convert a digit (Say '2') into the corresponding pixel data (hex as you put it) to output to the printer.

    To me, this seems like such a common thing to have to do with a PoS system that there should be an API already available to you.

    If not, then it would be what is in essence a lookup table to convert a character ('2') into some kind of bitmap representation of that character (as a barcode character).

    My first suggestion would be to explore the API documentation you have for more information.
    I did not find nothing in help on this, only on catching the bar code of a reader, more necessary to generate of a number that this in an variable!

    if you it will be able to give one looked at in help, and to help me with this question he would be very been thankful!

    link download help ->

    http://www.megaupload.com/?d=12NY3HXF

    ---------------------------------------------------------------------------------------

    Summarizing, necessary to generate one bitmap of a bar code in the Code128 format from a text (String), to send for printer already I know as to make!
    Last edited by darkducke; 01-11-2008 at 10:35 AM.

  8. #8
    Registered User
    Join Date
    Dec 2007
    Posts
    13
    I found this, more I do not know as to use for mine case!

    http://idautomation.com/fonts/code128/

  9. #9
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    Do you have that font package? If so, then look through their docs; if not, then so what.

    It looks like there's two parts to this problem: 1) generating the pattern of black-and-white that makes up the barcode and 2) generating the bitmap equivalent in whatever format your printer expects.

    (1) looks pretty easy, based on thirty seconds of Google. You'll need to be able to peel off digits one at a time. For (2), based on what you posted above, your printer expects a pretty straightforward 1=black 0=white bit pattern, so whenever you figure out a black-and-white pattern you can add it into your bitfield.

  10. #10
    Registered User
    Join Date
    Mar 2005
    Location
    Mountaintop, Pa
    Posts
    1,059
    Here's my interpretation of the translation based on the Code 128 specs. You'll still have to feed it to the printer. There a a few free Windows code 128 fonts on the net. I don't know if the Windows font files will be of any use to you since I'm not familiar with POS hardware you're using.

    Code:
    #include <stdio.h>
    #include <stdlib.h>
    
    #define START 104
    #define STOP 106
    #define LENGTH 10
    
    int main(void)
    {
        char cInputArray[LENGTH+1] =  {"1254896587"}; 
        unsigned char ucOutputArray[LENGTH+3] = {0};
        unsigned long ulAccumulator = 0l;
        unsigned int uiCheckDigit = 0;
        int iIndex;
    
        ucOutputArray[0] = START;
        ulAccumulator = START;
        for(iIndex = 0; iIndex < LENGTH; iIndex++)
        {
            if( (int)cInputArray[iIndex] == 128)
                ucOutputArray[iIndex+1] = 0;
            else if( (int)cInputArray[iIndex] > 32 &&  (int)cInputArray[iIndex] < 127)
            {
                ucOutputArray[iIndex+1] = (int)cInputArray[iIndex] - 32;
                ulAccumulator += (iIndex+1) * ((int)cInputArray[iIndex] - 32);
            }
            else if( (int)cInputArray[iIndex] > 126 &&  (int)cInputArray[iIndex] !=  128)
            {
                ucOutputArray[iIndex+1] = (int)cInputArray[iIndex] - 50;
                ulAccumulator += (iIndex+1) * ((int)cInputArray[iIndex] - 50);
            }
            else printf("Questionable character = %c\n",cInputArray[iIndex]); 
        }
        uiCheckDigit = ulAccumulator % 103;
        ucOutputArray[iIndex+1] = uiCheckDigit;
        ucOutputArray[iIndex+2] = STOP;
        return 0;
    }

  11. #11
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,500
    "Building Language and Font Blocks using the Font Builder" in your help RAR file would seem to be a place to start.

    But it seems to only have features for scanning bar codes, not generating them.

    tabstop is right, you need to work on those two separate stages independently (initially at least) to get a feel for how each works in practice.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  12. #12
    Registered User
    Join Date
    Mar 2005
    Location
    Mountaintop, Pa
    Posts
    1,059
    The above code I posted is incorrect based on Barcode 128 symbology and other dated barcode ISO docs I have.

    I should have used a START of 105, the "C" character set instead of 104 which is the "B" character set. Also, I should have processed the digits in pairs. For instance, starting with 12 next 54 then 89 and 65 and finally 87. What is in ucOutputArray should be the binary representation of each pair that will be used for printing.

    Unfortunately, I don't have access to a barcode reader until Monday morning. So, this is theory until I actually verify it.

  13. #13
    Registered User
    Join Date
    Dec 2007
    Posts
    13

    Thumbs up

    Quote Originally Posted by BobS0327 View Post
    The above code I posted is incorrect based on Barcode 128 symbology and other dated barcode ISO docs I have.

    I should have used a START of 105, the "C" character set instead of 104 which is the "B" character set. Also, I should have processed the digits in pairs. For instance, starting with 12 next 54 then 89 and 65 and finally 87. What is in ucOutputArray should be the binary representation of each pair that will be used for printing.

    Unfortunately, I don't have access to a barcode reader until Monday morning. So, this is theory until I actually verify it.

    I thank the aid very, thus that you it will be able to test speaks to me with using so that I can test here and for in practical.
    while this I go trying to understand the code

    thanks!!!

  14. #14
    Ex scientia vera
    Join Date
    Sep 2007
    Posts
    478
    Man, you guys are better men than I am, I can't even understand what this guy is saying. I have a feeling he's using an online translator, by the looks of his english.

  15. #15
    Registered User
    Join Date
    Mar 2005
    Location
    Mountaintop, Pa
    Posts
    1,059
    I've had some very limited success using 128 barcodes created entirely via code. My test environment consisted of a Lexmark T634 laser printer, an old IBM "pen" type bar code reader, Type 7695, Model 265 and an industry standard Metrologic scanner model MS9520.

    The easy part was using the variant C as a starting point to print the bar codes. I just used a lookup table to handle all three variants, A,B and C.

    The hard part was printing the barcode correctly so that it can be successfully scanned by any bar code reader/scanner. The only way I could successfully print 128 barcodes was to use PCL.

    The standards state:

    Symbol Size:
    According to GS1-128 specifications, the height of the bar code should be 15% of the length or 0.50 inch (1.3 CM), whichever is greater. The X dimension may range from 10 mils (.025 cm) to 40 mils (.1 cm). When the X dimension used is between 10 and 16 mils, the symbol should be 0.50" tall. When the X dimension used is between 16 and 40 mils, the symbol should be 1.25" tall. The X dimension of 10 mils (0.10") is recommended for use with most hand-held scanners
    The only way I could accomplish such precise printing was to use PCL5. There are also a few other "standards" requirements that have to be addressed.

    So, my question is, does your target printer support PCL or postscript?

Page 1 of 2 12 LastLast
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 16
    Last Post: 11-23-2007, 12:48 PM
  2. Please Explain Count the number of bits in an int code
    By dnysveen in forum C++ Programming
    Replies: 36
    Last Post: 12-23-2006, 09:39 PM
  3. generate a random number
    By waxydock in forum C++ Programming
    Replies: 5
    Last Post: 06-05-2005, 07:43 PM
  4. how to deals with Bar Code
    By moemen ahmed in forum C++ Programming
    Replies: 6
    Last Post: 06-11-2003, 05:07 PM
  5. Random Number problem in number guessing game...
    By -leech- in forum Windows Programming
    Replies: 8
    Last Post: 01-15-2002, 04:00 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21