2016-04-08 8 views
0

私は2つのStarIOプリンタ(TSP100 USBとLAN)を扱っています。 "usbprn:Cashier"と "tcp:192.168.1.xxx"のポート名を使用して、StarIO Line Mode C#SDKを使用してオンラインで検出できます。StarIO Line Mode C#SDKは印刷されません

ただし、[サンプル印刷の印刷]機能ではプリンタに何も印刷されません。デバッグでは何も表示されません。

他のSDK(iOS、Android)でも同じことが起こります(オンラインで検出されますが、印刷時には表示されません)。

これはプリンタに関する問題ですか(アプリケーション "Configuration Utility TSP100"からのサンプル印刷でプリンタがうまく機能している場合)。

本当にありがとうございます!

+0

コードを入力しなくても、ログは記録されず、印刷されないという説明は難しいです。私はあなたに助けになるより多くの情報が必要と思うと思う – dman2306

+0

ありがとう@ dman2306。私はこのリンクからダウンロードしたC#SDKを試しました(http://www.starmicronics.com/support/zipfile.aspx?sat2=122&id=122&type=4&referrer=http://www.starmicronics.com/support/sdkdocumentation .aspx&tabText)。コードは変更されません。 SDKアプリケーションを実行した後、ポート名を "usbprn:Cashier"(すでにキャッシャーにプリンターキュー名を設定している)として入力しました。アプリケーションはオンラインでプリンタを検出しますが、印刷は何もしません。早速のお返事ありがとうございます。 –

+0

Chinh、私はあなたがここで説明しているのと同じ問題にぶつかりました。私はあなたが解決策を見つけたかどうか疑問に思っていた – Sleette

答えて

0

@Sleette、遅く応答して申し訳ありませんが、通知は一連の通知メールで深刻です。

FAQサイトからの一時的な解決策がありましたが、Q & Aがたくさんあり、元のリンクが見つかりませんでした。しかし、「何らかの形で」働くコードがあります。

これはSDKを経由せず、もちろん「吸う」ウィンドウの印刷キューですが、今のところ私にとってはうまくいきます。

制限:プリンタキューにLANプリンタを手動で追加し、名前でアクセスする必要があります。

public class RawPrinterHelper 
    { 
    // Structure and API declarions: 
    [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)] 
    public class DOCINFOA 
    { 
     [MarshalAs(UnmanagedType.LPStr)] 
     public string pDocName; 
     [MarshalAs(UnmanagedType.LPStr)] 
     public string pOutputFile; 
     [MarshalAs(UnmanagedType.LPStr)] 
     public string pDataType; 
    } 
    [DllImport("winspool.Drv", EntryPoint = "OpenPrinterA", SetLastError = true, CharSet = CharSet.Ansi, ExactSpelling = true, CallingConvention = CallingConvention.StdCall)] 
    public static extern bool OpenPrinter([MarshalAs(UnmanagedType.LPStr)] string szPrinter, out IntPtr hPrinter, IntPtr pd); 

    [DllImport("winspool.Drv", EntryPoint = "ClosePrinter", SetLastError = true, ExactSpelling = true, CallingConvention = CallingConvention.StdCall)] 
    public static extern bool ClosePrinter(IntPtr hPrinter); 

    [DllImport("winspool.Drv", EntryPoint = "StartDocPrinterA", SetLastError = true, CharSet = CharSet.Ansi, ExactSpelling = true, CallingConvention = CallingConvention.StdCall)] 
    public static extern bool StartDocPrinter(IntPtr hPrinter, Int32 level, [In, MarshalAs(UnmanagedType.LPStruct)] DOCINFOA di); 

    [DllImport("winspool.Drv", EntryPoint = "EndDocPrinter", SetLastError = true, ExactSpelling = true, CallingConvention = CallingConvention.StdCall)] 
    public static extern bool EndDocPrinter(IntPtr hPrinter); 

    [DllImport("winspool.Drv", EntryPoint = "StartPagePrinter", SetLastError = true, ExactSpelling = true, CallingConvention = CallingConvention.StdCall)] 
    public static extern bool StartPagePrinter(IntPtr hPrinter); 

    [DllImport("winspool.Drv", EntryPoint = "EndPagePrinter", SetLastError = true, ExactSpelling = true, CallingConvention = CallingConvention.StdCall)] 
    public static extern bool EndPagePrinter(IntPtr hPrinter); 

    [DllImport("winspool.Drv", EntryPoint = "WritePrinter", SetLastError = true, ExactSpelling = true, CallingConvention = CallingConvention.StdCall)] 
    public static extern bool WritePrinter(IntPtr hPrinter, IntPtr pBytes, Int32 dwCount, out Int32 dwWritten); 

    // SendBytesToPrinter() 
    // When the function is given a printer name and an unmanaged array 
    // of bytes, the function sends those bytes to the print queue. 
    // Returns true on success, false on failure. 
    public static bool SendBytesToPrinter(string pDocName, string szPrinterName, IntPtr pBytes, Int32 dwCount) 
    { 
     Int32 dwError = 0, dwWritten = 0; 
     IntPtr hPrinter = new IntPtr(0); 
     DOCINFOA di = new DOCINFOA(); 
     bool bSuccess = false; // Assume failure unless you specifically succeed. 

     di.pDocName = pDocName; 
     di.pDataType = "RAW"; 

     // Open the printer. 
     if (OpenPrinter(szPrinterName.Normalize(), out hPrinter, IntPtr.Zero)) 
     { 
     // Start a document. 
     if (StartDocPrinter(hPrinter, 1, di)) 
     { 
      // Start a page. 
      if (StartPagePrinter(hPrinter)) 
      { 
      // Write your bytes. 
      bSuccess = WritePrinter(hPrinter, pBytes, dwCount, out dwWritten); 
      EndPagePrinter(hPrinter); 
      } 
      EndDocPrinter(hPrinter); 
     } 
     ClosePrinter(hPrinter); 
     } 
     // If you did not succeed, GetLastError may give more information 
     // about why not. 
     if (bSuccess == false) 
     { 
     dwError = Marshal.GetLastWin32Error(); 
     } 
     return bSuccess; 
    } 

    public static bool SendStringToPrinter(string pDocName, string szPrinterName, string szString) 
    { 
     IntPtr pBytes; 
     Int32 dwCount; 
     // How many characters are in the string? 
     dwCount = szString.Length; 
     // Assume that the printer is expecting ANSI text, and then convert 
     // the string to ANSI text. 
     pBytes = Marshal.StringToCoTaskMemAnsi(szString); 
     // Send the converted ANSI string to the printer. 
     var result = SendBytesToPrinter(pDocName, szPrinterName, pBytes, dwCount); 
     Marshal.FreeCoTaskMem(pBytes); 
     return result; 
    } 
    } 
関連する問題