问题
For some interop with a legacy POS application, I was wondering if it was possible to implement a phony OPOS device in C#.
Basically I would implement a phony keyboard that took web requests and passed on key presses to the legacy application.
Does anyone know if this is possible or where to get documentation? I figured OPOS just called COM objects which are configured by registry keys. All of which should be implementable in C#.
回答1:
Yes it's certainly possible.
You can develop an OPOS SO (Service Object) which implements the COM interface expected by OPOS in C#. This can then implement the API in any way you want.
I suggest you download Curtiss Monroe's OPOS Common Control Objects from http://monroecs.com/oposccos.htm.
This will give you the type libraries you need to implement for your Service object(s), and probably has some links to the OPOS documentation. NB I think OPOS uses late-binding so you will need to implement a dual interface.
A caveat: IMHO OPOS is technically a horrible API, designed by a committee peripheral vendors to expose the capabilities of their peripherals rather than to provide a useful abstraction for POS application developers.
A particularly striking example of this is the so-called ToneIndicator device, which exposes the capabilities of a tone generator in a Fujitsu keyboard to sound a repeated sequence of two tones of different pitch and volume.
UPDATE
I have implemented OPOS Service Objects before, but it's been a long time. Here's some more info to get you started on a POSKeyboard SO.
The Control object (CO) will load your Service Object (SO) using late-binding. So in fact there is no COM IID or type library that you implement. Instead you need to implement all the required methods and events defined in the appropriate version of the OPOS specs (e.g. one of the docs on this page: http://monroecs.com/oposreleases.htm). The info below is based on the 1.6 Control Programer's Guide (CPG) linked on this page.
Chapter 2 of the CPG describes what you need to implement. Note that OPOS uses a weird method for getting/setting properties. Whereas the Control Object (CO) exposes properties with sensible names (e.g. DeviceEnabled, DeviceName, DeviceDescription), these all call into the same methods GetPropertyString (for string properties) or GetPropertyNumber (for integer properties), passing an integer "property index" as an argument that defines which property is to be retrieved. The "property indexes" are all defined in header files supplied with the OPOS standard.
From a quick glance at the CCO PosKeyboard source, the method names you need to implement are listed in s_SOMethodNames in the source file POSKeyboardImpl.cpp.
The registry entries you need to set up are defined in the OPOS Application Programmer's Guide (APG) appendix "OPOS Registry Usage". In your case you will need to create a registry key HKLM\OleForRetail\ServiceOPOS\POSKeyboard\DefaultPOSKeyboard (where DefaultPOSKeyboard is the device name you are passing the Open method). This registry key needs to have a default value which is the ProgId of your SO class. You can also store other values there (e.g. configuration information used by your SO).
Good luck with this - it will be a painful process with plenty of WTF's.
来源:https://stackoverflow.com/questions/1076068/implement-opos-device-in-c-sharp