vb6,ZPL,socket打印

时间:2010-08-03 12:58:17

标签: sockets vb6 zebra-printers zpl

我在java中完成了这个编程并且它可以工作但不能使它在vb6中运行(我需要)

基本上我需要通过网络向斑马打印机发送数据。 整个过程有效(没有报告错误,但打印机不打印。 在Java中我使用过:

 public void printOnions(ArrayList<String> DataArr){
        // LH is x,y coordinates for starting position
        // FO is x,y coordinates to start current print
        // BY sets the barcode size
        // BC is code128 then orientation, height,
        //    print interpretation line, print above barcode,
        //    check digit
        // A is font type, height and width
        // FD data start, FS data end
        String BarCode = DataArr.get(2) + "-" + DataArr.get(3);
        transferType = "^MTT";  // use thermal transfer
        String ZPLString = "^LH5,5" + transferType + // Sets the type to thermal transfer
            "^BY2" + "^MNM" +
            "^FO50,30" + "^ADN,96,20^FD" + DataArr.get(0) + "     " + DataArr.get(1) + "^FS" +
            "^FO250,130" + "^BCN,70,N,N,N"  + "^FD" + BarCode + "^FS" +
            "^FO50,230" + "^ADN,96,20^FD" + BarCode +  "      " + DataArr.get(4) + "^FS";

        PrtTags(ZPLString);

    }

    public void initializeZPL(String printerIn) throws IOException {
        try {
            //create stream objs
            int port = 9100;
            Socket sock = new Socket(printerIn, port);
            ostream = new FileOutputStream(printerIn);
            pstream = new PrintStream(sock.getOutputStream() );
        } catch (UnknownHostException ex) {
            Logger.getLogger(ZebraZPLView.class.getName()).log(Level.SEVERE, null, ex);
        } catch (IOException ex) {
            Logger.getLogger(ZebraZPLView.class.getName()).log(Level.SEVERE, null, ex);
//        } catch (FileNotFoundException e) {
//            e.printStackTrace();
        }
    }
    public void PrtTags(String ZPLString){
    try{
       ZPLString = "^XA" + ZPLString + "^XZ";
       char[] chars = ZPLString.toCharArray();
       pstream.print(chars);
           // pstream.close();
       pstream.flush();
       }
       catch (Exception e) {
           e.printStackTrace();
       }

    }

这是vb6:

Dim Buffer() As Byte

Dim printer As String
printer = "ZBR3677984"
If sock.State = sckClosed Then
   sock.RemoteHost = printer
   sock.RemotePort = 9100
   sock.Connect

   Me.txtPrice.Text = "connected" & vbNewLine & sock.LocalHostName _
                       & vbNewLine & CStr(sock.RemotePort) _
                       & vbNewLine & CStr(sock.RemoteHost)
   Dim ZPLString As String
   ZPLString = "^LH10,10" & "^MTT" & "^BY2" & "^MNM" & _
            "^FO15,0" & "^ADN,36,20^FD" & "Line-1 " & "   Line 2 " & "^FS" & _
            "^FO15,50" & "^ADN,56,40^FD" & "line-3 " & "^FS" & _
            "^FO100,100" & "^BCN,70,N,N,N" & "^FD" & "line-4" & "^FS" & _
            "^FO15,190" & "^ADN,56,40" & "^FD" & "line-5" & "^FS" & _
            "^FO15,250" & "^BCN,70,N,N,N" & "^FD" & "line-6" & "^FS"

    ZPLString = "^XA" + ZPLString + "^XZ"
    ZPLString = "^XA" + "test" + "^XZ"

    ReDim Buffer(Len(ZPLString)) As Byte

    Buffer = ZPLString
    sock.SendData Buffer
End If

我想念一些NetworkStream之王打印。 有人有想法吗? 非常感谢

Dallag

3 个答案:

答案 0 :(得分:2)

你发送一个字节数组的unicode字符,即如果ZPLString是“X”你的缓冲区包含2个字节; 88 00

我怀疑您不希望使用CharArray,因此您应该使用:buffer = StrConv(ZPLString, vbFromUnicode)从unicode转换。

答案 1 :(得分:1)

我在VB6中编写代码打印到斑马标签打印机,并且能够通过安装正确的斑马打印机驱动程序来完成此操作。完成此操作后,您只需使用VB6打印机对象即可将文本发送到打印机。

http://www.nodevice.com/driver/company/Zebra.html

答案 2 :(得分:0)

我发现您必须已经设置了端口。添加用于RAW的通用文本打印机集,并将其指向您的打印机,无论是COM1:,USB1 :、网络名称还是IP地址。端口存在后,即可使用它。