0

I am currently trying out the VB.NET PrinterSample_Step1, "Hello OPOS for .Net" . I have installed the driver for TM-H6000III using EPSON advanced driver and set it up in the SetUpPOS for OPOS.NET . I am facing issues with these lines:

deviceInfo = posExplorer.GetDevice(DeviceType.PosPrinter, strLogicalName)
m_Printer = posExplorer.CreateInstance(deviceInfo)

posExplorer.CreateInstance(deviceInfo) returns nothing.

This is the full code:

Imports Microsoft.PointOfService


Public Class FrameStep1
    Inherits System.Windows.Forms.Form

    Private m_Printer As Microsoft.PointOfService.PosPrinter = Nothing


#Region " Windows Forms Designer generated code."

    Public Sub New()
        MyBase.New()

        ' The InitializeComponent() call is required for windows Forms designer support.
        InitializeComponent()

        ' TODO: Add counstructor code after the InitializeComponent() call.

    End Sub

    ' Rear treatment is carried out in the resource being used.
    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
        If disposing Then
            If Not (components Is Nothing) Then
                components.Dispose()
            End If
        End If
        MyBase.Dispose(disposing)
    End Sub

    ' Design  variable.
    Private components As System.ComponentModel.IContainer

    ' This method is required for Windows Forms designer support.
    'Do not change the method contents inside the source code editor.   
    ' The Forms designer might not be able to load this method if it was changed manually.
    Friend WithEvents btnPrint As System.Windows.Forms.Button
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Me.btnPrint = New System.Windows.Forms.Button
        Me.SuspendLayout()
        '
        'btnPrint
        '
        Me.btnPrint.Location = New System.Drawing.Point(84, 40)
        Me.btnPrint.Name = "btnPrint"
        Me.btnPrint.Size = New System.Drawing.Size(120, 32)
        Me.btnPrint.TabIndex = 0
        Me.btnPrint.Text = "Print"
        '
        'FrameStep1
        '
        Me.AutoScaleBaseSize = New System.Drawing.Size(5, 12)
        Me.ClientSize = New System.Drawing.Size(280, 125)
        Me.Controls.Add(Me.btnPrint)
        Me.MaximizeBox = False
        Me.Name = "FrameStep1"
        Me.Text = "Step1 Print ""Hello OPOS for .Net"""
        Me.ResumeLayout(False)

    End Sub

#End Region

    ''' <summary>
    '''  A method "Print" calls some another method.
    '''  They are method for printing.
    ''' </summary>
    ''' <param name="sender"></param>
    ''' <param name="e"></param>
    Private Sub btnPrint_Click(ByVal sender As System.Object _
    , ByVal e As System.EventArgs) Handles btnPrint.Click

        '<<<step1>>> Start
        Try
            'As using the PrintNormal method, send strings to a printer, and print it
            '[vbCrLf] is the standard code for starting a new line.
            m_Printer.PrintNormal(PrinterStation.Receipt, "Hello OPOS for .Net" + vbCrLf)

        Catch ex As PosControlException

        End Try
        '<<<step2>>> End

    End Sub
    ''' <summary>
    ''' When the method "changeButtonStatus" was called,
    ''' all buttons other than a button "closing" become invalid.
    ''' </summary>
    Private Sub ChangeButtonStatus()

        'Disable control.
        btnPrint.Enabled = False
    End Sub
    ''' <summary>
    ''' The processing code required in order to enable to use of service is written here.
    ''' </summary>
    ''' <param name="sender"></param>
    ''' <param name="e"></param>
    Private Sub FrameStep1_Load(ByVal sender As System.Object _
    , ByVal e As System.EventArgs) Handles MyBase.Load

        '<<<step1>>>--Start
        'Use a Logical Device Name which has been set on the SetupPOS.
        Dim strLogicalName As String
        Dim deviceInfo As DeviceInfo
        Dim posExplorer As PosExplorer

        strLogicalName = "PosPrinter"

        'Create PosExplorer
        posExplorer = New PosExplorer

        m_Printer = Nothing

        Try

            deviceInfo = posExplorer.GetDevice(DeviceType.PosPrinter, strLogicalName)
            m_Printer = posExplorer.CreateInstance(deviceInfo)

        Catch ex As Exception
            ChangeButtonStatus()
            Return
        End Try

        Try

            'Open the device
            m_Printer.Open()

            'Get the exclusive control right for the opened device.
            'Then the device is disable from other application.
            m_Printer.Claim(1000)

            'Enable the device.
            m_Printer.DeviceEnabled = True

        Catch ex As PosControlException

            ChangeButtonStatus()

        End Try
        '<<<step1>>>--End
    End Sub
    ''' <summary>
    ''' When the method "closing" is called,
    ''' the following code is run.
    ''' </summary>
    ''' <param name="sender"></param>
    ''' <param name="e"></param>
    Private Sub FrameStep1_Closing(ByVal sender As Object _
    , ByVal e As System.ComponentModel.CancelEventArgs) Handles MyBase.Closing

        '<<<step1>>>--Start
        If m_Printer Is Nothing Then
            Return
        End If

        Try
            'Cancel the device
            m_Printer.DeviceEnabled = False

            'Release the device exclusive control right.
            m_Printer.Release()


        Catch ex As Exception

        Finally
            'Finish using the device.
            m_Printer.Close()

        End Try
        '<<<step1>>>--End

    End Sub
End Class

I have tried the answer from I can't get instance of pos printer , but it does not seem to work in Visual Studio 2019.

The form button will be grayed out as there is an exception.

Is there anyway to solve this issue?

mmm000
  • 89
  • 8

1 Answers1

1

Please make sure you get valid results at the first stage of deviceInfo = posExplorer.GetDevice(DeviceType.PosPrinter, strLogicalName).
For example, there is this in a Japanese article.
GetDevice の返り値が null ( Nothing )

In addition, please check the following items.


These are scanner articles, but they cover similar topics.
Why isn't my scanner in the PosExplorer.GetDevices() list?
Why does Honeywell POS4NET fire the same event for two different scanners?
pos explorer is not finding any device connected to the system in C#


Added after receiving the information of the comment:

A complete installation of the Microsoft POS for.NET SDK installs a sample application that you can use to test your device, so why not try it out and see if you can use your printer?

C:\Program Files (x86)\Microsoft Point Of Service\SDK\Samples\Sample Application\TestApp.exe

If you can use the printer in the sample application, there may be some problem in how to make your application.

If you cannot use the printer even with the sample application, there may be a problem with the printer's own hardware settings, hardware connection method, device driver installation, SetupPOS for OPOS.NET settings, etc.

kunif
  • 4,060
  • 2
  • 10
  • 30
  • Hi, Thank you for the reply. Both are compatible versions. I am using EPSON OPOS ADK for .NET https://download.epson-biz.com/modules/pos/index.php?page=single_soft&cid=6630&scat=39&pcat=3 . SetUpPOS is started as an administrator. Visual Studio is not running as an administrator. – mmm000 Jul 07 '21 at 03:07
  • The deviceInfo = posExplorer.GetDevice(DeviceType.PosPrinter, strLogicalName) returns {Service Object Name: TM-H6000IIILogical Names: PosPrinterDescription: EPSON TM-H6000IIIManufacturer: SEIKO EPSONType: PosPrinterService Object Version: 1.14.7620.27547UPOS Version: 1.14Compatibility: CompatibilityLevel1Hardware Description: Hardware Id: Hardware Path: TM-H6000IIIDefault: False} – mmm000 Jul 07 '21 at 03:23
  • Hi, I cannot use the printer with the sample application. It will return this error : POSControlException ErrorCode(Illegal) ExtendedErrorCode(0) occurred: The value of the 'DevicePath' property must be defined by the service object before Open() can be called. Created instance of device: TM-H6000IV . The other POS Printer, TM-H6000III, that I set up is not in the list in the sample application. – mmm000 Jul 07 '21 at 04:16
  • Perhaps, as the message says, the device information settings by SetupPOS for OPOS.NET are incorrect or missing. For example, if you have another type of printer from EPSON, try it there, or if you don't have another one, ask EPSON how to investigate and solve the problem. – kunif Jul 07 '21 at 04:29
  • Hi, now it seems that the printers can be used with the sample application, it will return ```Opened device: TM-H6000IV Created instance of device: TM-H6000IV``` Here is a screenshot: https://imgur.com/57f3Rcd – mmm000 Jul 07 '21 at 06:22
  • When I press the "claim" button, this error will occur: https://imgur.com/AB8G68y. I attached a screenshot as there is character limit in the comments. – mmm000 Jul 07 '21 at 07:03
  • Probably it is occurring because it is not opened with the information of TM-H6000III. Looking at the first screenshot, TM-H6000III does not exist. Please add the TM-H6000III information in SetupPOS for OPOS.NET and open it. – kunif Jul 07 '21 at 07:37
  • Hi, I added the TM-H6000III : https://imgur.com/hy552P4 , but the error will still occur. I have attached a screenshot: https://imgur.com/5xRzVEB – mmm000 Jul 07 '21 at 07:45
  • For example, please check if you can communicate with the printer with Setting/Logo/ Other utilities. [TM-H6000III](https://download.epson-biz.com/modules/pos/index.php?page=prod&pcat=1&pid=5) – kunif Jul 07 '21 at 07:53
  • Hi, now I will face the exception: {"The printer is currently being initialized."} – mmm000 Jul 07 '21 at 08:41
  • Was it possible to communicate with the printer using the tool? In such a situation, it is better to contact EPSON's support desk for instructions on how to deal with it. – kunif Jul 07 '21 at 08:51
  • I am currently testing using PosPrinter2, TM-H6000IV, but when I run the CheckHealthTest, it will be stuck at Interactive HCheck: Error Code -Offline ,```The printer is currently being initialized.``` and after I close it, this is the error message: ```Interactive HCheck: Error - The printer is currently being initialized.``` – mmm000 Jul 07 '21 at 08:56
  • Is it a check of the correct procedure? It happened to be displayed on the screen, so did you try it? It is better to contact EPSON for correct confirmation and setting method. – kunif Jul 07 '21 at 09:05
  • Hi, it is to for checking of errors. It is to check whether ServiceObjects are registered correctly. – mmm000 Jul 07 '21 at 09:26
  • By the way, if you could call the CheckHealth method, I think you've solved the problem of not being able to create an instance, which is the subject of this question. If you have any other problems, please ask a new question. – kunif Jul 07 '21 at 21:38
  • Hi, there is still some issues with creating the instance for the other printer TM-H6000III. – mmm000 Jul 08 '21 at 00:03
  • As far as you can see in the screenshot, it looks like the CreateInstance is done and the Open method after that is also done. It seems that the Claim method is causing the error. Please check the details of the step-by-step procedure, have the correct understanding, and add the description to the question if necessary. And if the Open method is successful, isn't the problem of the question solved? – kunif Jul 08 '21 at 00:32
  • Hi, the test app from MicrosoftPointOfService can open the printer, but when I test it with the CheckHealthTest from the ADK and their sample program, the error: ```{"The port name is illegal, or couldn't be connected to the device."}``` will still persist. – mmm000 Jul 08 '21 at 00:47
  • Again, the fact that you can call the CheckHealth method means that the problem you asked has been solved. Unsuccessful results of the CheckHealth method (the contents of CheckHealthText are not successful) is a completely different issue. Please ask another question. – kunif Jul 08 '21 at 00:59