Drive a POS printer via USB in c# [closed]

匿名 (未验证) 提交于 2019-12-03 02:06:01

问题:

Any ideas how i can best drive a USB POS printer from c#. POS printers are usually serial, TCP/IP or USB based. I know how to accomplish serial and TCP/IP but have no idea about communications through USB in C#. I know that there is a layer available from Microsoft called POS.NET, but I want to try and avoid using this. Any ideas or any C# libraries that people can recomend would be really appreciated. Thanks

回答1:

You should really consider using POS for .NET and OPOS or .NET service objects (Epson, for example provides both). POS for .NET conforms to the UnifiedPOS industry standard for interfacing with these devices.



回答2:

If the printer registers itself as a Human Interface Device, you can P/INVOKE into the appropriate Win32 APIs. Here are the signatures:

    [ DllImport( "hid.dll", SetLastError=true ) ]     public static extern Boolean      HidD_FlushQueue( SafeFileHandle HidDeviceObject );              [ DllImport( "hid.dll", SetLastError=true ) ]     public static extern Boolean      HidD_FreePreparsedData( ref IntPtr PreparsedData );              [ DllImport( "hid.dll", SetLastError=true ) ]     public static extern Boolean      HidD_GetAttributes(  SafeFileHandle HidDeviceObject                        , ref HIDD_ATTRIBUTES Attributes );              [ DllImport( "hid.dll", SetLastError=true ) ]     public static extern Boolean      HidD_GetFeature(  SafeFileHandle HidDeviceObject                     , ref Byte lpReportBuffer                     , Int32 ReportBufferLength );              [ DllImport( "hid.dll", SetLastError=true ) ]     public static extern Boolean      HidD_GetInputReport( SafeFileHandle HidDeviceObject                         ,ref Byte lpReportBuffer                         ,Int32 ReportBufferLength );              [ DllImport( "hid.dll", SetLastError=true ) ]     public static extern void HidD_GetHidGuid( ref System.Guid HidGuid );      [ DllImport( "hid.dll", SetLastError=true ) ]     public static extern Boolean      HidD_GetNumInputBuffers(  SafeFileHandle HidDeviceObject                             , ref Int32 NumberBuffers );              [ DllImport( "hid.dll", SetLastError=true ) ]     public static extern Boolean      HidD_GetPreparsedData( SafeFileHandle HidDeviceObject                           ,ref IntPtr PreparsedData );      [ DllImport( "hid.dll", SetLastError=true ) ]     public static extern Boolean      HidD_SetFeature(  SafeFileHandle HidDeviceObject                     , ref Byte lpReportBuffer                     , Int32 ReportBufferLength );      [ DllImport( "hid.dll", SetLastError=true ) ]     public static extern Boolean      HidD_SetNumInputBuffers( SafeFileHandle HidDeviceObject                             ,Int32 NumberBuffers );      [ DllImport( "hid.dll", SetLastError=true ) ]     public static extern        
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!