随着计算机在生产、销售、管理上应用水平的提高以及Internet 、Intranet 的普及,条码技术在生产管理、销售管理上的使用越来越多,条码的编码技术和识别技术也得到了较快的发展。我单位因建设信息管理系统的需要,使用条码识别生产中的光纤,并用来管理光纤,需要给多台客户机配备条码打印功能。但普通的条码打印机价格比较昂贵,功能比较单一,给每台计算机配条码打印机是很不合算的,也给工作带来不便。
---- 我们利用MIS系统的前台开发工具PowerBuilder 6.0 设计了一套程序,在普通激光打印机上实现了条码打印,圆满的解决了生产管理上的条码问题。
---- 现在条码编码使用较多的是39码,日常商品上随处可见。它包括识别的代码和前后各一个''*''区别条码的起始和结束,其编码方法是,每个字符的编码由5条黑线和相邻黑线之间的间隙来表示。宽的黑线表示 1 ,窄则表示 0,同样黑线之间的间隙宽的表示 1,窄的表示 0 。这样的一个9位的二进制数就用来表示一个字符,例如,001100100 (前面5位由线表示,后4位为空格)表示十进制的 0。在39码的规则里,9位数中必须有3位是1。由此规则,键盘上的26个字母和10个数字,以及常用的一些符号都有一一对应的39码编码。我们就是利用此规则进行程序设计的。
---- Powerbuilder 提供了一个printline()函数:
---- PrintLine ( printjobnumber, x1, y1, x2, y2, thickness )在一个printjobnumber中可以打印多条直线,线的位置由指定坐标确定,线宽由Thickness 决定,这样就可以由程序实现我们预定的功能。
---- 在PB中定义一个函数,这里举例为窗口函数:
wf_barprint(long job, integer x_pos ,
integer y_pos,bar_width as intger,string code )
returns integer
// x_pos ,y_pos 为条码打印的起始位置
//Bar_Width 条码窄线的宽度
//code ,要打印的字符串
char Bar_Card[20],Bar_Print[22]
char Temp_Card[12]
string Bar_Table[40]
int i,j,X_Scan,Cal_Card,y_scan
x_scan = x_pos
y_scan = y_pos
Bar_Table[1]=''00110-0100'' // 0
Bar_Table[2]=''10001-0100'' // 1
Bar_Table[3]=''01001-0100'' // 2
Bar_Table[4]=''11000-0100'' // 3
Bar_Table[5]=''00101-0100'' // 4
Bar_Table[6]=''10100-0100'' // 5
Bar_Table[7]=''01100-0100'' // 6
Bar_Table[8]=''00011-0100'' // 7
Bar_Table[9]=''10010-0100'' // 8
Bar_Table[10]=''01010-0100'' // 9
Bar_Table[11]=''10001-0010'' // A
Bar_Table[12]=''01001-0010'' // B
Bar_Table[13]=''11000-0010'' // C
Bar_Table[14]=''00101-0010'' // D
Bar_Table[15]=''10100-0010'' // E
Bar_Table[16]=''01100-0010'' // F
Bar_Table[17]=''00011-0010'' // G
Bar_Table[18]=''10010-0010'' // H
Bar_Table[19]=''01010-0010'' // I
Bar_Table[20]=''00110-0010'' // J
Bar_Table[21]=''10001-0001'' // K
Bar_Table[22]=''01001-0001'' // L
Bar_Table[23]=''11000-0001'' // M
Bar_Table[24]=''00101-0001'' // N
Bar_Table[25]=''10100-0001'' // O
Bar_Table[26]=''01100-0001'' // P
Bar_Table[27]=''00011-0001'' // Q
Bar_Table[28]=''10010-0001'' // R
Bar_Table[29]=''01010-0001'' // S
Bar_Table[30]=''00110-0001'' // T
Bar_Table[31]=''10001-1000'' // U
Bar_Table[32]=''01001-1000'' // V
Bar_Table[33]=''11000-1000'' // W
Bar_Table[34]=''00101-1000'' // X
Bar_Table[35]=''10100-1000'' // Y
Bar_Table[36]=''01100-1000'' // Z
Bar_Table[37]=''00011-1000'' // -
Bar_Table[38]=''10010-1000'' // %
Bar_Table[39]=''01010-1000'' // $
Bar_Table[40]=''00110-1000'' // *
Bar_Card = upper(code)
if left(bar_card,1) < > ''*'' then
Bar_Print = ''*'' + Bar_Card // 添加起始符
end if
if right(bar_card,1) < > ''*'' then
Bar_Print = Bar_Card + ''*'' // 添加结束符
end if
j = 1
do
if (Bar_Print[j] = ''*'') then
Cal_Card = 40
elseif (Bar_Print[j] = ''-'') then
Cal_Card = 37
elseif (Bar_Print[j] >= ''A'') then
Cal_Card = 11 + asc(Bar_Print[j])
- asc(''A'')
elseif (Bar_Print[j] >= ''0'') then
Cal_Card = 1 + asc(Bar_Print[j])
- asc(''0'')
end if
Temp_Card = Bar_Table[Cal_Card]
for i = 1 to 5
if (Temp_Card[i] = ''0'') then
X_Scan = X_Scan + Bar_Width / 2
PrintLine(Job,X_Scan,y_scan,
x_Scan,y_scan + 550,Bar_Width)
X_Scan = X_Scan + Bar_Width / 2
else
X_Scan = X_Scan + Bar_Width * 3 / 2
PrintLine(Job,X_Scan,y_scan + 6,
x_Scan,y_scan + 544,3 * Bar_Width)
X_Scan = X_Scan + Bar_Width * 3 / 2
end if
if (Temp_Card[6 + i] = ''1'') then
X_Scan = X_Scan + 4 * Bar_Width
else
X_Scan = X_Scan + 3 * Bar_Width /2
end if
next
j = j + 1
loop while (Bar_Print[j] < > '''')
printtext(job,code,X_scan - 1200,y_scan + 600)
return 1
---- 通过调用以上自定义函数与PrintBitmap ( printjobnumber, bitmap, x, y, width, height )、printtext()等函数配合可以在普通激光打印机上方便的打印出漂亮的条码和辅助图案。之所以在调用时直接确定printjobnumber,是为了方便在出报表时同一个printjobnumber下将报表和条码打印在一张纸,这样使您的报表显得非常专业,也很漂亮。