2011-07-07 50 views
4

我發現了API here如何讓星級TSP100LAN收據打印機在Android上運行?

但是,當我運行AndroidSample測試應用程序時,出現錯誤。

當我按下「獲取打印機狀態」按鈕時,我得到「打印機在線」。看起來這個按鈕起作用。

但是:

  • 按「閱讀來自打印機的數據」產量「失敗的固件名稱無法讀取。」

  • 按下「Print Receipt」會導致應用程序掛起3秒鐘。然後沒有。

  • 按下「Print Checked Block Receipt」將產生「打印成功」或大掛起(有時強制關閉)。無論如何,什麼都不打印。

+0

有沒有人能夠解決這個問題?我有同樣的問題.thx – 2011-10-15 04:38:02

+0

你有沒有找到你的查詢解決方案?有沒有辦法解決這個問題。 –

回答

0

Did you add your Activity on AndroidManifest?並添加您的應用需要允許他們的權限?

+0

是的。應用程序啓動,顯示活動。 – esb

+0

所以也許它回到了你使用的代碼和方法。 –

+0

「AndroidSample」是如何使用API​​的示例。它與API文件捆綁在一起。該API的文檔非常少,而且該示例的評論很少。問題是我無法得到榜樣去工作,我不知道爲什麼。 – esb

3

通讀iOS和Android StarIO SDK的文檔我發現STAR TSP100LAN要求它處於「光柵模式」。不幸的是,與iPhone和Android SDK一起提供的示例僅適用於「行模式」打印。雖然這不是一個答案,但希望它會幫助你指向正確的方向:)

我要試着聯繫Star自己,看看我能否直接從他們那裏得到一些示例代碼,祝我好運,我會在這裏回覆我收到的任何迴應!

+0

這真的很有幫助。我不相信他們發送的演示程序不起作用!我試圖通過他們的iPhone之一,它可以正確地看到打印機狀態,(打開蓋等),但它不打印。 – sasquatch

+1

我能夠聯繫美國的STAR支持(我在澳大利亞,本地支持似乎只針對最終用戶而不是開發者),但是當我開始與他們取得一些進展時,他們發現我打電話來自並且關閉了支持會議並將我介紹給Star的澳大利亞辦公室!非常無益!回到繪圖板!除非美國有人在技術支持方面有更多的運氣。 – happs

+0

當前SDK中提供的演示程序使用光柵打印(屏幕上的倒數第二個按鈕)。它看起來非常簡單,基本上只是在位圖畫布上繪製一些文本。 「PrinterFunctions」類的文檔現在狀態爲「TSP100不支持行模式打印」。 – bensnider

0

Star增加了一個新的Android SDK包,其功能比本主題中提到的舊版本更多(我相信它是V1.0)。新的可用here

如上所述,TSP100LAN需要接收光柵命令,因爲它本身就是一個圖形打印機。最新的SDK包有一個更新的示例應用程序,它可以讓您測試許多不同的打印機功能,包括一些光柵命令。

在撰寫本答案時可下載的SDK包是V2.3。手冊(README_StarIO_POSPrinter_Android_SDK.pdf)指出TSP100LAN可以使用開放式錢箱,獲取狀態,打印光柵圖形文本(裝飾文本/將其發送到打印機)和圖像文件打印(優惠券)功能。

星也有一個編程手冊,其中包含詳細說明其他功能的光柵命令。請參閱section 3.4

6

我花了很長時間才弄清楚如何使其工作。我會盡我所能讓你開始。我對android相當陌生,所以請隨時指出我所做的不正確的事情。它通過將內容向上移動而偶爾會錯誤地進行打印,從而切斷頂部並在底部添加大量空間。如果任何人都可以弄清楚,我會非常感激。

在這裏你去:

需要從APK這些文件:不要相信我修改他們無論如何: 1. RasterDocument.java 2. StarBitmap。的java

主要印刷方法:

public static void PrintReceipt(Context context, RelativeLayout layout){ 

     String portName = "tcp:10.1.250.20"; //ip address of your printer 
     String portSettings = ""; 

//have to measure the layout for it to print correctly, otherwise sizes are zero 
     layout.measure(View.MeasureSpec.makeMeasureSpec(layout.getLayoutParams().width, View.MeasureSpec.EXACTLY), 
       View.MeasureSpec.makeMeasureSpec(layout.getLayoutParams().height, View.MeasureSpec.EXACTLY)); 
     layout.layout(0, 0, layout.getMeasuredWidth(), layout.getMeasuredHeight()); 

     Bitmap bitmap = Bitmap.createBitmap(layout.getWidth(),layout.getHeight(), Bitmap.Config.RGB_565); 
     Canvas canvas = new Canvas(bitmap); 
     canvas.drawColor(Color.WHITE); 
     layout.draw(canvas); 


     int maxWidth = 576; //default width of tsp100 receipt 
     RasterDocument rasterDoc = new RasterDocument(RasterDocument.RasSpeed.Full, RasterDocument.RasPageEndMode.FeedAndFullCut, RasterDocument.RasPageEndMode.FeedAndFullCut, RasterDocument.RasTopMargin.Standard, 0, 0, 0); 
     StarBitmap starbitmap = new StarBitmap(bitmap, false, maxWidth); 

     StarIOPort port = null; 
     try 
     { 
      /* 
        using StarIOPort3.1.jar (support USB Port) 
        Android OS Version: upper 2.2 
       */ 
      port = StarIOPort.getPort(portName, portSettings, 10000, context); 
      /* 
        using StarIOPort.jar 
        Android OS Version: under 2.1 
        port = StarIOPort.getPort(portName, portSettings, 10000); 
       */ 

      try 
      { 
       Thread.sleep(500); 
      } 
      catch(InterruptedException e) {} 

      byte[] command = rasterDoc.BeginDocumentCommandData(); 
      port.writePort(command, 0, command.length); 
      command = starbitmap.getImageRasterDataForPrinting(); 
      port.writePort(command, 0, command.length); 
      command = rasterDoc.EndDocumentCommandData(); 
      port.writePort(command, 0, command.length); 

      try 
      { 
       Thread.sleep(1000); 
      } 
      catch(InterruptedException e) {} 
     } 
     catch (StarIOPortException e) 
     { 
      ShowAlertMessage(context, "Failure", "Failed to connect to printer. " + e.getMessage()); 
     } 
     finally 
     { 
      if(port != null) 
      { 
       try { 
        StarIOPort.releasePort(port); 
       } catch (StarIOPortException e) {} 
      } 
     } 

    } 

    private static void ShowAlertMessage(final Context context, final String alertTitle, final String message){ 
     try { 
      ((Activity)context).runOnUiThread(new Runnable() { 

       @Override 
       public void run() { 
        AlertDialog.Builder dialog = new AlertDialog.Builder(context); 
        dialog.setNegativeButton("Ok", null); 
        AlertDialog alert = dialog.create(); 
        alert.setTitle(alertTitle); 
        alert.setMessage(message); 
        alert.show(); 
       }}); 
     } catch (final Exception e) { 
      Log.e(PrinterFunctions.class.getName(), e.getMessage()); 
     } 
    } 

THEN: 在另一方法中,發送一個PrintReceipt RelativeLayout的。在類的構造函數中設置當前上下文。

Context currentContext; 
    RelativeLayout relativeLayout; 
    private final int receiptWidth = 576; 
    private Typeface typeFace = Typeface.DEFAULT; 
    private int normalFontSize = 23; 
    private int largeFontSize = 28; 

public SetupReceiptClass(Context context){ 
    currentContext = context; 
} 
public void SetupReceipt(String customerName){ 
     //Create layout for receipt 
     relativeLayout = new RelativeLayout(currentContext); 
     RelativeLayout.LayoutParams params; 
     params = new RelativeLayout.LayoutParams(receiptWidth,  ViewGroup.LayoutParams.MATCH_PARENT); 
     relativeLayout.setLayoutParams(params); 
     relativeLayout.setId(R.id.ReceiptLayout); 

//Create whatever views you want here and add them to the RelativeLayout to make up your receipt 
relativeLayout.addView(whateverViewsYouCreate); 

//Finally, Print the receipt. 
     new Thread(new Runnable() { 

      @Override 
      public void run() { 
       PrintReceipt(currentContext, relativeLayout); 
      } 
     }).start(); 

} 

再一次,我是新來的android的東西,這可能不是最好的方式,但它是打印。任何酷你發現我很想聽到他們。

+0

謝謝你.......你救了我們:)它的工作非常好。 – pioneerBhawna