locked
PosExplorer GetDevice returns null RRS feed

  • Question

  • Hey,

    I am currnetly developing a POS application in WPF/C# and have Pos for .Net 1.12 installed with Epson OPOS ADK for .Net 1.11.13. When calling GetDevice and passing the logical name of the epson printer, it returns null. If I run the same code in a windows forms application GetDevice returns the printer fine.

    I just tested my small test WPF application on a XP machine and it worked fine. My development machine runs on Vista and is the one not working.

    I have even created a seperate DLL targetted to .Net 2.0 which references the Pos for .Net dll and this still does not work on my Vista development machine.

    Only Epson POS printers are causing me problems, IBM ones are working fine. They are the only ones I have to deal with at this stage.

    The code i am using is below:

    //Create PosExplorer

     

    PosExplorer posExplorer = new PosExplorer();

     

    DeviceInfo deviceInfo = null;

    deviceInfo = posExplorer.GetDevice(

    DeviceType.PosPrinter, printerName);

     

    if (deviceInfo == null)

    {

     

    var deviceCollection = posExplorer.GetDevices();

     

    foreach (DeviceInfo dInfo in deviceCollection)

    {

     

    if (!dInfo.ServiceObjectName.Equals(printerName)) continue;

    deviceInfo = dInfo;

     

    break;

    }

    }

    PosPrinter = (

    PosPrinter)posExplorer.CreateInstance(deviceInfo);

     

    //Open the device

    PosPrinter.Open();

     

    //Get the exclusive control right for the opened device.

     

    //Then the device is disable from other application.

    PosPrinter.Claim(1000);

     

    //Enable the device.

    PosPrinter.DeviceEnabled = true;

    Any help with this would be greatly appreciated.

    Tuesday, July 27, 2010 12:05 AM

Answers

  • Here is a sample contents:

    <PointOfServiceConfig Version="1.0">

      <ServiceObject Name="Microsoft LineDisplay Simulator" Type="LineDisplay">
        <Device HardwarePath="" Enabled="yes" PnP="no" Default="no">
          <LogicalName Name="my_device" />
        </Device>
      </ServiceObject>
    </PointOfServiceConfig>

    In your case the Type attribute must be "POSPrinter" and the Name must be the name of your service object (as defined in the DLL). It is recommended to define LogicalName - you can use it later to access the device. HardwarePath attribute can be blank or contain some string you prefer. Note that the format of this XML is strictly defined and you cannot add extra attributes or omit the required elements. If you have 2 or more devices of the same type and you issue GetDevice() function without logical name (only device type) then you will get exception if there is not defined Default device. I think the best practice is to call GetDevices method, show the available devices in a combobox - then the user will choose which one to use. Then call GetDevice with the selected name.

    • Edited by ABC07 Friday, July 30, 2010 11:35 AM correction
    • Marked as answer by Dlongy Thursday, August 5, 2010 9:26 PM
    Friday, July 30, 2010 11:34 AM

All replies

  • Try GetDevices to see whether the device is in the collection. Maybe it is not defined in Configuration.xml
    Wednesday, July 28, 2010 2:44 PM
  • As you see in the code snippet I try to find the deveice from the GetDevices collection after I can't find the device using GetDevice. Where is the Configuration.xml you speak of?

    Thanks for your help

    Wednesday, July 28, 2010 9:46 PM
  • Get the path from the Registry - HKEY_LOCAL_MACHINE\SOFTWARE\POSfor.Net - Configuration value. Also open "Logging" subkey, set Enabled = 1, then look in "Location" for "Name" log file. It contains useful log information for all POSforNet operations.
    Thursday, July 29, 2010 2:18 PM
  • I have now turned on Logging and will test it soon. The configuration file has nothing in it but the following:

    <PointOfServiceConfig Version="1.0">

    </PointOfServiceConfig>

    What am I missing if I have the epson drivers installed and have a Epson TM-T88IV connected?

    Thursday, July 29, 2010 9:25 PM
  • I tested the logging and I got the following for the POS printer I am using (TM-T88IV):

    [7/30/2010 7:36:42 AM     9 INFO    AssemblyLoader] Type: ElectronicJournal, Name: TM-T88IV, Description: EPSON TM-T88IV, Compatibility: CompatibilityLevel1, UPOS version: 1.11
    [7/30/2010 7:36:42 AM     9 INFO    AssemblyLoader] Enumerating hardware ids...
    [7/30/2010 7:36:42 AM     9 INFO    AssemblyLoader] Type: jp.co.epson.upos.ej.EJErrorStringConst
    [7/30/2010 7:36:42 AM     9 INFO    AssemblyLoader] SO attribute not found. Skipping the type.
    [7/30/2010 7:36:42 AM     9 INFO    AssemblyLoader] Type: jp.co.epson.upos.ej.cmd.QueryContentImplementor
    [7/30/2010 7:36:42 AM     9 INFO    AssemblyLoader] SO attribute not found. Skipping the type.
    [7/30/2010 7:36:42 AM     9 INFO    AssemblyLoader] Type: jp.co.epson.upos.ej.cmd.PrinterLockFactory
    [7/30/2010 7:36:42 AM     9 INFO    AssemblyLoader] SO attribute not found. Skipping the type.
    [7/30/2010 7:36:42 AM     9 INFO    AssemblyLoader] Type: jp.co.epson.upos.drw.StandardService
    [7/30/2010 7:36:42 AM     9 INFO    AssemblyLoader] SO attribute is found.

    [7/30/2010 7:36:42 AM     9 INFO    AssemblyLoader] Type: PosPrinter, Name: TM-T88IV, Description: EPSON TM-T88IV, Compatibility: CompatibilityLevel1, UPOS version: 1.11
    [7/30/2010 7:36:42 AM     9 INFO    AssemblyLoader] Enumerating hardware ids...
    [7/30/2010 7:36:42 AM     9 INFO    AssemblyLoader] Type: jp.co.epson.upos.pntr.T81Service
    [7/30/2010 7:36:42 AM     9 INFO    AssemblyLoader] SO attribute is found.

    [7/30/2010 7:36:42 AM     9 INFO    Explorer] Service object: name= TM-T88IV, type=ElectronicJournal, compatibility=CompatibilityLevel1
    [7/30/2010 7:36:42 AM     9 INFO    Explorer] The device type does not match. Skipping the service object.

    [7/30/2010 7:36:42 AM     9 INFO    Explorer] Service object: name= TM-T88IV, type=PosPrinter, compatibility=CompatibilityLevel1
    [7/30/2010 7:36:42 AM     9 INFO    Explorer] No NonPnPAliasMapping aliases defined. Adding one device for the service object.

    [7/30/2010 7:36:42 AM     9 INFO    Explorer] Service object: name= TM-T88IV, type=ElectronicJournal, compatibility=CompatibilityLevel1
    [7/30/2010 7:36:42 AM     9 INFO    Explorer] No NonPnPAliasMapping aliases defined. Adding one device for the service object.

    [7/30/2010 7:36:42 AM     9 INFO    Explorer] Service object: name= TM-T88IV, type=PosPrinter, compatibility=CompatibilityLevel1
    [7/30/2010 7:36:42 AM     9 INFO    Explorer] No NonPnPAliasMapping aliases defined. Adding one device for the service object.

    Thursday, July 29, 2010 9:43 PM
  • Here is a sample contents:

    <PointOfServiceConfig Version="1.0">

      <ServiceObject Name="Microsoft LineDisplay Simulator" Type="LineDisplay">
        <Device HardwarePath="" Enabled="yes" PnP="no" Default="no">
          <LogicalName Name="my_device" />
        </Device>
      </ServiceObject>
    </PointOfServiceConfig>

    In your case the Type attribute must be "POSPrinter" and the Name must be the name of your service object (as defined in the DLL). It is recommended to define LogicalName - you can use it later to access the device. HardwarePath attribute can be blank or contain some string you prefer. Note that the format of this XML is strictly defined and you cannot add extra attributes or omit the required elements. If you have 2 or more devices of the same type and you issue GetDevice() function without logical name (only device type) then you will get exception if there is not defined Default device. I think the best practice is to call GetDevices method, show the available devices in a combobox - then the user will choose which one to use. Then call GetDevice with the selected name.

    • Edited by ABC07 Friday, July 30, 2010 11:35 AM correction
    • Marked as answer by Dlongy Thursday, August 5, 2010 9:26 PM
    Friday, July 30, 2010 11:34 AM
  • Sorry I have been helping with another project and haven't had time to check back here.

    Thank you for the information. We will try again looking into this issue this week and I'll get back to you with any success or failures.

    Wednesday, August 4, 2010 4:27 AM
  • Hi,

    I'm afraid I can't help any more with your specific problem, but I can let you know that I did all our POS .Net printer development under Windows Vista and had no problems with the Epson drivers. I did have problems with the TPG (HP) ones, as they require the software to have administrative priviledges in order to use the printer, but the Epson ones worked fine. So in short, the problem shouldn't relate to the OS.

    I take it, since you have a logical name setup, you have run the SetupPOS application that came with the Epson service objects to configure the printer type, port settings and additional features (like using nvram for setbitmap etc) ? The Epson service objects don't seem to work unless they've been configured with SetupPOS first.

     

    Wednesday, August 4, 2010 11:12 PM
    Answerer
  • We have solved the issue. The epson drivers needed to be installed with administrator privilleges to be able to modify the Configuration.xml file. One we did this the printer could be found.

     

    Thanks for all the information

    Thursday, August 5, 2010 9:26 PM