Search code examples
c#.netconnectionpos

The POS Device is not connecting, how can I undestand wether the cable or the code is wrong?


I want to connect to an Ingenico iCT250 POS device through a c# package. I am using this one . I followed the instructions on their readme and tried to connect. When I run, after a few seconds the program closes and I got this message.

C:\Users\User\Documents\c#\pos\pos\bin\Debug\net6.0\pos.exe (process 22480) exited with code 0.

I don't understand why I got this exit code. What is happening? Is the code wrong? Or there are problems with the cable? How can I research a solution? Or is it connected because I read that "Saying that the Process finished with exit code 0 means that everything worked ok."? But if everything was okay, the posDevice.IsConnected should have returned either true or false. I tried also with passing the port only in new POS. But same result. Here is the code:

class Program
{
    public static void Main(string[] args)
    {  
        POS posDevice = new POS("COM4", 115200);
         posDevice.Connect();
        Console.WriteLine("IsConnected??", posDevice.IsConnected);
    }
}

Solution

  • exited with code 0. means that nothing went wrong with your code (in terms of Exceptions).

    but there's two logical problems with your code:

    1 - you're not actually writing the result of your test, because you didn't include a placeholder in your format.

    so try changing it to:
    Console.WriteLine("IsConnected?? {0}", posDevice.IsConnected);

    2 - after your program is done, it immediately exits - closing the console window, and hiding the output from you.

    so add the following to the end of your Main:
    Console.ReadLine();

    that way, your program waits for your user input before exiting, keeping the console window open for you to read the result.

    the code in total:

    class Program
    {
        public static void Main(string[] args)
        {  
            POS posDevice = new POS("COM4", 115200);
            posDevice.Connect();
            Console.WriteLine("IsConnected?? {0}", posDevice.IsConnected);
            Console.ReadLine();
        }
    }