我是一个刚入行的程序员,老板给的活让我十分苦恼.我不知该如何做这个程序,问题是这样的:公司是一个做手机的公司,而我是公司IT部的程序员,做一些小程序在公司内部使用.现在老板要在仓库里贴物料条形码,这个条形码由条形码打印机打出来,这个条形码打印程序由我来做,我要发疯了,我从来就没做过这样的程序.下面是我没来公司前一个跳槽走了的程序员用DELPHI写的代码:
function GetGraphyData(Img : TImage; var Data : String;var r_width_byte, r_total_byte : Integer) : Integer;
var
  l_i0, l_i1, l_j1, l_i, l_j, l_x, l_y, l_width, l_height, l_count : Integer;
  l_string0, l_string : String;
begin
  l_x := 0;
  l_y := 0;  with Img.Canvas do
  begin  l_width := img.Width;
  l_height := img.Height;  l_i0 := l_width div 4 + 1;
  if l_width mod 4 = 0 then
    begin
      l_i0 := l_width div 4;
    end;
  if l_i0 mod 2 = 1 then
    begin
    l_i0 := l_i0 + 1;
    end; l_string := '';
  for l_j := 1 to l_height do
    begin
      for l_i := 1 to l_i0 do
        begin
          l_i1 := l_x + (l_i - 1) * 4;
          l_j1 := l_y + l_j;
          l_count := 0;
          if Pixels[l_i1, l_j1] = clBlack then
            begin
              l_count := l_count + 8;
            end;
          if Pixels[l_i1+1, l_j1] = clBlack then
            begin
              l_count := l_count + 4;
            end;
          if Pixels[l_i1+2, l_j1] = clBlack then
            begin
              l_count := l_count + 2;
            end;
          if Pixels[l_i1+3, l_j1] = clBlack then
            begin
              l_count := l_count + 1;
            end;
          case l_count of
            15 : l_string0 := 'F';
            14 : l_string0 := 'E';
            13 : l_string0 := 'D';
            12 : l_string0 := 'C';
            11 : l_string0 := 'B';
            10 : l_string0 := 'A';
            9,8,7,6,5,4,3,2,1,0 : l_string0 := IntToStr(l_count);
            else l_string0 := '0';
          end;
          l_string := l_string + l_string0;
        end;
    end;
  end;  r_width_byte := l_i0 div 2;
  r_total_byte := r_width_byte * l_height;
  Data := l_string;
  Result := r_total_byte;
end;现在的硬件要求:
Connect to COM1/LPT1
Choose driver: Generic / Text only编码要求:
~DGlogo,180,6,003F00007E… ;define image
^XA ;start code
^LH10,10 ;left top margin
^FO0,0^A0,30,30^FD123abc^FS ;text
^FO0,40^BY2,2^BCN,20,N,N,N,A^FD123abc^FS ;barcode
^FO0,50^XGR:adsl,1,1^FS ;call image
^XZ ;end code
Instruction-~DG:~DGd,o,x,t,w,DATA
where
~DG = Set Printer to Download Graphic Mode
d = Destination Device to Store Image
o = Name of Image, 1-8 Alphanumeric Characters
x = Extension, 3 Alphanumeric Characters
{Fixed. Will always be .GRF}
t = Total Number of Bytes in Graphic
w = Number of Bytes Per Row
DATA = ASCII Hexadecimal String that Defines ImageInstruction-^LH:
^LHx,y
where
^LH = Set Label Home
x = Number of Dots along X-axis
Acceptable values: 0 - 9999
y = Number of Dots along Y-axis
Acceptable values: 0 - 9999
Instruction-^FO:
^FOx,y
where
^FO = Set Field Origin
x = Number of Dots along X-axis
Default value: = 0
Acceptable values: 0 - 9999
y = Number of Dots along Y-axis
Default value: = 0
Acceptable values: 0 - 9999
Instruction-^A:
^A#h,w
Where
^A# = Font size {0-9}
h = Character Height in Dots
w = Character Width in Dots
Instruction-^BC:
^BCo,h,f,g,e,m
where
^BC = Code 128 Bar Code
o = Orientation
h = Bar Code Height
f = Print Interpretation Line
Default value: Y = Yes
Other value: N = No
g = Print Interpretation Line Above Code
Default value: N = No
Other value: Y = Yes
NOTE: Default changes to Yes in UCC Case Mode
e = UCC Check Digit
Default value: N = No
Other value: Y = Yes
m = Mode
Default value: N = No mode selected
Other value: U = UCC Case Mode
Instruction-^BY:
^BYw,r,h
where
^BY = Change Bar Code Default Parameters
w = Module (Narrow Bar) Width
Initial power -up value: 2 dots
Acceptable values: 1-10 dots
r = Wide Bar to Narrow Bar Width Ratio
Initial power-up ratio: 3.0
Acceptable ratios: From 2.0 to 3.0 in .1 increments.
(No affect on Fixed Ratio bar codes.)
h = Height of Bars
Initial Power-up value: 10 dots,
Acceptable values: 1 dot to height of labelInstruction-^XG:
^XGd,o,x,x,y
where
^XG = Recall Graphic Image
d = Source Device where Image is Stored
{Optional. Default is Search Priority.}
o = Name of Stored Image, 1-8 Alphanumeric Characters
(Default, the name .UNKNOWN. is used.)
x = Extension, 3 Alphanumeric Characters
{Fixed. Will always be .GRF}
x = Magnification Factor Along X-axis
Default value: 1
Minimum value: 1, Maximum value: 10
y = Magnification Factor Along Y-axis
Default value: 1
Minimum value: 1, Maximum value: 10
Advanced ZPL:
Placeholder
Chinese wordUse placeholder separate ZPL from code:
^XA
^LH#x#,#y#
^FO0,0^A0,30,30^FD#sn#^FS
^FO0,40^BY2,2^BCN,20,N,N,N,A^FD#sn#^FS
^FO30,80^XGR:logo,1,1^FS
^XZChinese, Windows font:
Write Chinese on a image
Define image in ZPL
appendix:
Full sample
Source codeFull sample:
~DGlogo,180,6,003F00007E0001FF0001FE0003FF0007FE0007FF000FFE000FF0000FE0001F80001F80001F00003F00003E00003E00003C00007C00007C0000780000780000780000780000F00000780000FFF800780000FFF800780000FFF800780000FFF800780000F800007800007800007C00007800003E00007C00003E00003E00001F80001F00000FC0001FC0000FF8000FF80003FF0007FE0001FF0001FE00007F00007E00000F00000E00000000000000000000000000
^XA
^LH30,10
^FO0,0^A0,30,30^FD123abc^FS
^FO0,40^BY2,2^BCN,20,N,N,N,A^FD123abc^FS
^FO30,80^XGR:logo,1,1^FS
^XZ

解决方案 »

  1.   

    粗略的看了一下,觉得主要是操作串口的程序:给COM端口发指令。Full Sample 很重要。
    DGlogo +指令符号。
    你可以用串口调试助手试一试,找到条形码机的编码规则再编码。
      

  2.   

    你要学习ZPLII语言,才能看懂这些:
    ^XA;start code
    ^LH10,10;left top margin
    ^FO0,0^A0,30,30^FD123abc^FS;text
    ^FO0,40^BY2,2^BCN,20,N,N,N,A^FD123abc^FS;barcode
    ^FO0,50^XGR:adsl,1,1^FS;call image
    ^XZ;end code当然还有何com/lpt发送指令和连接的内容
    我现在在公司就是给公司做一个条码打印的程序(c#/vs2005eng),有兴趣可以一起研究。