0

Hi im trying to simply print "Hello World" but I get an error "The value of the 'DevicePath' property must be defined by the service object before Open() can be called." and it points to this line printer.Open();

I am using .NET 4.8 and I have referenced the Microsoft.PointOfService; already. TIA.

using Microsoft.PointOfService;
using System;

namespace PrinterTest
{
    class Program
    {
        static void Main(string[] args)
        {
            PosExplorer explorer = new PosExplorer();
            DeviceCollection devices = explorer.GetDevices(DeviceType.PosPrinter);

            Console.WriteLine("Checking for connected POS Printers...");
            foreach (DeviceInfo device in devices)
            {
                if (device.ServiceObjectName.IndexOf("TM-U220B", StringComparison.OrdinalIgnoreCase) >= 0)
                {
                    Console.WriteLine("TM-U220B printer is connected!");

                    PosPrinter printer = (PosPrinter)explorer.CreateInstance(device);

                    printer.Open();

                    printer.Claim(1000);

                    printer.DeviceEnabled = true;

                    printer.PrintNormal(PrinterStation.Receipt, "Hello World\n");

                    //printer.Cut(PosPrinterCutType.FullCut);

                    printer.Release();
                    printer.Close();

                    Console.WriteLine("Printed 'Hello World' successfully.");
                    break;
                }
            }

            Console.WriteLine("Press any key to exit...");
            Console.ReadKey();
        }
    }
}
6
  • Did you compile as 32-bit as described here? Commented Nov 25, 2024 at 4:27
  • Did you debug that devices getting null ? Commented Nov 25, 2024 at 6:35
  • s stackoverflow.com/questions/68278999/… any help? Commented Nov 25, 2024 at 16:07
  • Hi guys I wanna break it down 1 by 1 to figure out the problem. first the problem I encountered is regarding to the .NET version. I changed it to .NET 4.8 and it worked. now as I researched, it says to quickly know if everything works well I just need to run the TestApp.exe 'C:\Program Files (x86)\Microsoft Point Of Service\SDK\Samples\Sample Application\TestApp.exe' but in my case it doesnt work. and it just said, DevicePath' property must be defined by the service object before Open() can be called. Commented Nov 25, 2024 at 23:53
  • @TharukaDeshan the devices is not null. I have fetched the printers that are installed in my machine and when I attached the printer to my pc it says connected to printer. the issue is that the "Hello World" print doesnt work. Commented Nov 25, 2024 at 23:56

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.