How to open RJ11 cash drawer in wpf c# using .net 7 framework?

Jenish Patel 0 Reputation points
2023-08-29T11:08:34.8766667+00:00
			public static PosExplorer posExplorer = new PosExplorer();
 			DeviceCollection deviceCollection = Global.posExplorer.GetDevices("CashDrawer");
            CashDrawer cashDrawer;

            foreach (DeviceInfo deviceInfo in deviceCollection)
            {
                cashDrawer = Global.posExplorer.CreateInstance(deviceInfo) as CashDrawer;
                cashDrawer.Open();
                cashDrawer.Claim(1000);
                cashDrawer.DeviceEnabled = true;
                cashDrawer.OpenDrawer();
                cashDrawer.DeviceEnabled = false;
                cashDrawer.Release();
                cashDrawer.Close();
            }

I need to open a cash drawer in my WPF application, and I have used POSforDotNet V1.14.1 and it is working fine, but it is only supported in the.net 4.5 framework. My application is currently being used in .net 7. How can I achieve it with different library?

.NET
.NET
Microsoft Technologies based on the .NET software framework.
3,834 questions
Windows Presentation Foundation
Windows Presentation Foundation
A part of the .NET Framework that provides a unified programming model for building line-of-business desktop applications on Windows.
2,768 questions
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,904 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. niloufar kianfar 5 Reputation points
    2023-08-29T11:16:07.09+00:00

    hey try this code but first make sure your cash drawer connects through a USB port, serial (COM) port.

    using System.IO.Ports;
    
    // ...
    
    private void OpenCashDrawer(string comPort)
    {
        try
        {
            SerialPort serialPort = new SerialPort(comPort, 9600); // Adjust if needed
            serialPort.Open();
            serialPort.Write("\x07"); // This tells the drawer to open
            serialPort.Close();
        }
        catch (Exception ex)
        {
            // Handle any issues that might come up
        }
    }
    
    

  2. Castorix31 85,116 Reputation points
    2023-08-29T13:07:56.2633333+00:00

    You can use CashDrawer Class

    with the package Microsoft.Windows.CsWinRT

    In Project file,

    Change TargetFramework with a recent Windows 10 SDK version (that you must have installed), like

    <TargetFramework>net7.0-windows10.0.20348.0</TargetFramework>
    

    and add the Namespaces you want to use, like :

    <PropertyGroup>	
    	<CsWinRTIncludes>Windows.Devices.PointOfService;Windows.Devices.Enumeration</CsWinRTIncludes>	
    </PropertyGroup>
    

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.