首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >vb6,ZPL,套接字打印

vb6,ZPL,套接字打印
EN

Stack Overflow用户
提问于 2010-08-03 20:58:17
回答 3查看 6K关注 0票数 2

我用java做过这个编程,它可以工作,但不能让它在vb6中运行(我需要)。

基本上,我需要通过网络将数据发送到zebra打印机。整个过程正常工作(未报告错误,但打印机不打印。在Java中,我使用了:

代码语言:javascript
复制
 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:

代码语言:javascript
复制
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

EN

回答 3

Stack Overflow用户

发布于 2010-08-03 22:57:07

你发送了一个由unicode字符组成的字节数组,也就是说,如果ZPLString是"X“,你的缓冲区包含2个字节;88 00

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

票数 2
EN

Stack Overflow用户

发布于 2010-08-03 21:57:55

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

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

票数 1
EN

Stack Overflow用户

发布于 2018-11-05 21:57:57

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

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/3396656

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档