ReDucky呱呱網

    • 註冊
    • 登入
    • 版面
    • 最新
    • 標籤
    • 熱門
    • 使用者
    • 群組

    POS機列印

    Code頂區
    1
    1
    1009
    正在載入更多貼文
    • 從舊到新
    • 從新到舊
    • 最多點贊
    回覆
    • 在新貼文中回覆
    登入後回覆
    此主題已被刪除。只有擁有主題管理權限的使用者可以查看。
    • redeye
      redeye 最後由 redeye 編輯

      感印表機資訊
      目前使用的是WPT-800熱感印表機
       軟體支援
      (Windows、OPOS、Linux等驅動及 Android SDK)
      使用用型號
      T800系列

      安裝方式

      開啟裝置管理員:
      按 Win + X,選擇「裝置管理員」
      1.確認熱感印表機連接COM的位置
      一開始不知道是哪個就拔掉在插看哪裡有變化就是那個我這裡是USB Serial Port (COM6)
      6b9d4139-d243-4ed0-a3d5-f2e2f876b423-image.png
      許多 POS 機器透過 USB-to-Serial 轉換來連接電腦,因此需要相應的 USB-to-Serial 驅動程式來識別這類設備

      點擊右鍵內容查看裝置的晶片是使用哪個公司
      6903ca13-cdc5-4970-83fd-3d5e8906e8ac-image.png
      FTDI(Future Technology Devices International):廣泛使用於商業和工業,提供穩定的 USB-to-Serial 連接。FTDI 驅動程式可從其官網下載。

      Prolific:Prolific 的 USB-to-Serial 轉換晶片Prolific驅動也相當常見,特別是針對較低價位的設備。

      這裡用的是FDTI到官網下載對應的驅動:
      ftdichip drivers
      7aa06386-c345-4fb8-85f7-d6b6e6751c1d-image.png

      安裝驅動可能會無法安裝因為沒有數位簽章會被擋下
      0585c733-87df-461a-a0f1-615afd6f73fc-image.png
      取消數位簽證方式
      WIN-10.WIN-11-停止數位簽章方式
      取消後如果直接使用INF檔會出現問題是因為32位元與64位元問題
      3e41b459-2386-4146-93a3-86b28243975c-image.png
      所以這裡我就直接使用打包好的exe
      59eca669-f3b0-42f5-930c-265090f7a5bd-image.png
      用手動的方式新增
      aa7943f7-ada4-4799-8047-d0d2c072de4c-image.png
      選擇剛剛的COM6
      056f941a-c108-4aea-a597-5ee595c3207d-image.png
      直接點擊下一步
      626d1d5a-a135-470a-93bd-2df41c42c979-image.png
      會出現安全警告
      54ea34b0-8e92-47ce-892d-47789f876bdc-image.png
      0f7b6c41-1da8-439d-9ae4-9cbe4e328c1e-image.png
      安裝好可以點列印測試頁進行測試
      272bfe83-2ba5-41e5-9610-d006d39ade8a-image.png
      這樣就成功了
      IMG20241108105503.jpg

      安裝 OlePOS 驅動的步驟

      1. 執行 PPSO_T800_10020.exe 安裝 OlePOS 驅動。
      2. 使用 OPOSConfig.exe 設置邏輯設備名稱(Logical Device Name)。
      3. 在 C# 程式碼中透過 POS for .NET 的 API 使用該邏輯設備名稱來控制設備。

      OlePOS 驅動程式主要是為了提供 POS 設備的標準化控制,這樣您可以在應用程式中更簡單地調用列印功能和其他 POS 設備功能。
      3230cdbf-adb6-468a-89c6-c4e598d6c241-image.png

      OlePOS 是一種基於 OPOS(OLE for Retail POS)的驅動程式格式,通常由 POS 設備製造商提供,用來讓 POS 系統與設備(如收據印表機、條碼掃描器和顯示器等)進行溝通。它主要依賴 Microsoft 提供的 POS for .NET API,允許開發人員以標準化的方式與 POS 設備互動。

      OlePOS 的功能和用途

      1. 標準化 POS 設備控制:OlePOS 遵循 OPOS 標準,讓開發者可以使用一組統一的指令和 API 來控制不同品牌的 POS 設備。
      2. 支援 Microsoft POS for .NET:OlePOS 驅動程式可以與 Microsoft POS for .NET 結合,提供 C# 等 .NET 語言的開發人員標準的 API,用來開發 POS 應用程式。
      3. 簡化設備整合:使用 OlePOS 驅動程式後,開發人員只需設置一次設備配置(例如邏輯設備名稱),即可在應用程式中統一調用,無需深入了解設備的底層指令。

      WP-T800 中的 OlePOS 驅動

      在 WP-T800 列印機驅動的安裝檔案中,OlePOS 資料夾包含了安裝 OPOS 驅動程式的工具(例如 PPSO_T800_10020.exe 和 OPOSConfig.exe)。這些工具讓您能夠:

      • 安裝 OlePOS 驅動,將 WP-T800 設置為系統中的 OPOS 設備。
      • 配置邏輯設備名稱(Logical Device Name),以便在程式碼中識別和控制列印機。

      使用 OlePOS 驅動的好處

      1. 跨品牌相容性:使用 OlePOS 驅動程式時,即使更換品牌,只要新設備支援 OPOS,應用程式也可以無需修改或只做少量調整就能正常運行。
      2. 簡化的列印控制:OlePOS 支援 POS for .NET 中的 PosExplorer 和 PosPrinter 類,方便開發者控制列印機進行列印操作。
      3. 廣泛支援的 POS 功能:OlePOS 支援多種 POS 設備(如條碼掃描器、顯示器等)的控制和管理,適合開發完整的 POS 系統。

      這裡有兩個驅動檔案
      OPOSConfig.exe 通常是用來配置 OPOS 設備的工具,它可以幫助您在系統中註冊並設置 POS 列印機的邏輯設備名稱(Logical Device Name)。執行這個工具後,您可以為 WP-T800 列印機設定一個名稱(例如 T800Printer),這樣在 C# 程式中就可以透過該名稱來控制列印機。

      PPSO_T800_10020.exe 是 OPOS 驅動程式的安裝程序。所以要首先執行 PPSO_T800_10020.exe 安裝 OPOS 驅動,然後再使用 OPOSConfig.exe 來配置驅動並設定邏輯名稱。

      安裝和配置步驟

      1. 執行 PPSO_T800_10020.exe 安裝驅動:

        • 雙擊安裝程序,按照指示完成 OPOS 驅動的安裝。
      2. 執行 OPOSConfig.exe 配置設備:

        • 打開 OPOSConfig.exe。
        • 添加您的 WP-T800 列印機,並設定一個邏輯設備名稱(例如 T800Printer)。
        • 儲存配置後,這個名稱將用於您的 C# 程式碼中。
      3. 測試設備:

        • 在 OPOSConfig.exe 中設置完成後,可以測試一下是否能正常列印。若測試成功,您即可在 C# 中使用相同的名稱來控制列印機。

      完成這些步驟後,您應該就可以在 C# 程式中使用 POS for .NET 的 PosExplorer 和 PosPrinter 類來控制 WP-T800 列印機。

      安裝OPOSConfig.exe時會出現註冊檔登入錯誤

      044dd680-0c03-4d22-8c3f-5e00d8f9fcd0-image.png
      為什麼我收到「無法註冊類型庫:註冊 TypeLib 失敗」錯誤?
      在安裝打卡時鐘或其實用程式之一期間,可能會出現以下錯誤:
      C:\Windows\system32\STDOLE2.TLB無法註冊類型庫:RegisterTypeLib 失敗;代碼0x8002801C。存取 OLE 註冊表時發生錯誤。

      按一下「重試」重試,按一下「忽略」仍繼續(不
      建議),或按一下「中止」取消安裝。

      這是因為在 Windows Vista 及更高版本上,Windows 中實作了新的安全系統。 stdole2.tlb 函式庫是一個受 Windows 保護的文件,該文件被視為穩定文件,不會再更改。為了防止此檔案受到病毒或其他惡意軟體的攻擊,Windows 不允許任何人更改它。

      如果出現此錯誤訊息,只需忽略它即可完成安裝。該程式仍將按要求運行。

      引用DLL

      將DLL加入參考
      4fd9b63f-04af-403d-a32a-f9132f7f6ede-image.png

      測試

      using System;
      using System.Collections.Generic;
      using System.Linq;
      using System.Text;
      using System.Threading.Tasks;
      using Microsoft.PointOfService;
      
      namespace ConsoleApp5
      {
          class Program
          {
              static void Main(string[] args)
              {
      
                  PosExplorer explorer = new PosExplorer();
      
                  // 列出所有 POS 印表機
                  foreach (DeviceInfo device in explorer.GetDevices(DeviceType.PosPrinter))
                  {
                      Console.WriteLine("Printer Name: " + device.ServiceObjectName);
                      Console.ReadKey();
                  }
              }
          }
      }
      
      

      f0bb60bc-6ddb-490c-a5ab-76917052585e-image.png

      測試列印

      打開安裝的OPOSConfig.exe測試有沒有連上POS列印機
      584392ab-f6f7-4e2a-9f4a-126a46aaceb4-image.png
      a30e0d9c-0869-402f-a719-e1c9be406517-image.png

      因為要用C#開發要先安裝 PosForDotNet-1.14.1

      using System;
      using Microsoft.PointOfService;
      
      namespace ConsoleApp5
      {
          class Program
          {
              static void Main(string[] args)
              {
                  try
                  {
                      PosExplorer explorer = new PosExplorer();
      
                      // 查找所有已連接的 POS 印表機
                      DeviceInfo deviceInfo = explorer.GetDevice(DeviceType.PosPrinter, "WP-T800");
                      if (deviceInfo != null)
                      {
                          // 建立 POS 印表機裝置
                          PosPrinter posPrinter = (PosPrinter)explorer.CreateInstance(deviceInfo);
      
                          try
                          {
                              // 開啟裝置
                              posPrinter.Open();
                              // 要求控制權
                              posPrinter.Claim(1000);
                              // 啟用裝置
                              posPrinter.DeviceEnabled = true;
      
                              // 檢查是否支援收據列印
                              if (posPrinter.CapRecPresent)
                              {
                                  // 模擬發票列印
                                  posPrinter.PrintNormal(PrinterStation.Receipt, "=== 發票列印 ===\n");
                                  posPrinter.PrintNormal(PrinterStation.Receipt, $"日期: {DateTime.Now:yyyy-MM-dd}\n");
                                  posPrinter.PrintNormal(PrinterStation.Receipt, $"時間: {DateTime.Now:HH:mm:ss}\n");
                                  posPrinter.PrintNormal(PrinterStation.Receipt, "--------------------\n");
                                  posPrinter.PrintNormal(PrinterStation.Receipt, "品項       數量 單價  總價\n");
                                  posPrinter.PrintNormal(PrinterStation.Receipt, "--------------------\n");
      
                                  // 假設有三個商品品項
                                  posPrinter.PrintNormal(PrinterStation.Receipt, "商品A       1   100   100\n");
                                  posPrinter.PrintNormal(PrinterStation.Receipt, "商品B       2   200   400\n");
                                  posPrinter.PrintNormal(PrinterStation.Receipt, "商品C       3   150   4500\n");
                                  posPrinter.PrintNormal(PrinterStation.Receipt, "商品D       54  100   1000\n");
                                  posPrinter.PrintNormal(PrinterStation.Receipt, "商品E       20  200   4000\n");
                                  posPrinter.PrintNormal(PrinterStation.Receipt, "商品F       32  150   4501\n");
                                  posPrinter.PrintNormal(PrinterStation.Receipt, "--------------------\n");
      
                                  // 顯示總金額
                                  posPrinter.PrintNormal(PrinterStation.Receipt, "總金額:          14501\n");
                                  posPrinter.PrintNormal(PrinterStation.Receipt, "====================\n");
                                  posPrinter.PrintNormal(PrinterStation.Receipt, "\n");
                                  posPrinter.PrintNormal(PrinterStation.Receipt, "\n");
                                  posPrinter.PrintNormal(PrinterStation.Receipt, "\n");
                                  posPrinter.PrintNormal(PrinterStation.Receipt, "\n");
                                  posPrinter.PrintNormal(PrinterStation.Receipt, "\n");
                                  posPrinter.PrintNormal(PrinterStation.Receipt, "\n");
                                  posPrinter.PrintNormal(PrinterStation.Receipt, "\n");
      
                                  // 切紙
                                  //if (posPrinter.CapRecPaperCut)
                                  //{
                                  //    posPrinter.CutPaper(100);
                                  //}
                              }
                              else
                              {
                                  Console.WriteLine("裝置不支援收據列印功能。");
                              }
                          }
                          catch (PosControlException ex)
                          {
                              Console.WriteLine("POS 控制錯誤: " + ex.Message);
                          }
                          catch (Exception ex)
                          {
                              Console.WriteLine("一般錯誤: " + ex.Message);
                          }
                          finally
                          {
                              // 結束前進行切紙
                              if (posPrinter.CapRecPaperCut)
                              {
                                  posPrinter.CutPaper(100);
                              }
                              // 釋放裝置控制權並關閉
                              posPrinter.Release();
                              // posPrinter.Close();
                          }
                      }
                      else
                      {
                          Console.WriteLine("未找到指定的 POS 印表機。請確認印表機名稱。");
                      }
                  }
                  catch (Exception ex)
                  {
                      Console.WriteLine("一般錯誤: " + ex.Message);
                  }
                  Console.WriteLine("測試結束。按任意鍵退出。");
                  Console.ReadKey();
              }
          }
      }
      

      印出結果
      IMG20241112104629.jpg

      1 條回覆 最後回覆 回覆 引用 1
      • First post
        Last post
      Powered by NodeBB | Contributors