Author Topic: AdvancedHMI not correct .NET framework for nugget.  (Read 50 times)

paintman

  • Newbie
  • *
  • Posts: 8
    • View Profile
AdvancedHMI not correct .NET framework for nugget.
« on: May 08, 2024, 04:41:45 PM »
Is there a way to add AdvancedHMI to a project or does it have to be started using the blank project? Reason being, I am trying to add a Zebra nugget package to a project and keep getting these errors:
Quote
  CACHE https://api.nuget.org/v3/registration5-gz-semver2/zebra.printer.sdk/index.json
Resolved actions to install package 'Zebra.Printer.SDK.3.0.3271'
Install failed. Rolling back...
Package 'Zebra.Printer.SDK.3.0.3271' does not exist in project 'AdvancedHMI'
Package 'Zebra.Printer.SDK.3.0.3271' does not exist in folder 'C:\Users\ashquinn\Desktop\PrintTest\packages'
Executing nuget actions took 1.18 sec
Could not install package 'Zebra.Printer.SDK 3.0.3271'. You are trying to install this package into a project that targets '.NETFramework,Version=v4.8', but the package does not contain any assembly references or content files that are compatible with that framework. For more information, contact the package author.
Time Elapsed: 00:00:01.8759248
========== Finished ==========

I am not sure how to get around this, or if there is even a way to. I am trying to print a tag element from my PLC to a Zebra zt410/411 without using the PLC. I was opting for VB to be in control. Has anyone one worked on something similiar to this?

*Edited title to be more accurate*

Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5268
    • View Profile
    • AdvancedHMI
Re: AdvancedHMI not correct .NET framework for nugget.
« Reply #1 on: May 08, 2024, 05:29:36 PM »
Several years ago I did a project that needed to print to a Zebra label printer. I installed the printer driver into Windows and set the zebra as the default printer. From there I send a raw string of data directly to the printer that was in the ZPL format.

Attached is a helper class I used for sending the data to the printer.

The code to send a string to the printer using the helper class:
Code: [Select]
        RawPrinterHelper.SendStringToPrinter(RawPrinterHelper.DefaultPrinterName(), s)

I created a label using the Zebra software and saved it to be used as a template file. I then edited the label file to insert markers where I wanted to substitute data from the PLC. For example, [BatchNumber]

I wrote code to read that template, searched for the markers, then substituted the real data. And finally sending the string directly to the printer.

I can share more of the code, if you are interested

paintman

  • Newbie
  • *
  • Posts: 8
    • View Profile
Re: AdvancedHMI not correct .NET framework for nugget.
« Reply #2 on: Today at 09:34:02 AM »
I think I found a thread on plctalk refering to the project you mentioned. It said you used brackets [] as the container to look for in the zpl, but how did you get the bracket in to the file? Did you just prefill the text with [Variable] and then just replaced the inner string, or you just altered the actual zpl file?

I am very interested on seeing the code for this, I am not well versed on printer communications nor how I can link it to AHMI

Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5268
    • View Profile
    • AdvancedHMI
Re: AdvancedHMI not correct .NET framework for nugget.
« Reply #3 on: Today at 10:01:40 AM »
After creating the file using the Zebra designer software, I manually edited with Notepad. Attached is the file.

The first thing my code does is to read data from the PLC and put it in a local variable:
Code: [Select]
        Dim RecipeName As String = ""
        Try
            RecipeName = EthernetIPforCLXCom1.Read("Batch1RecipeName")
        Catch ex As Exception
            MsgBox("Failed to read Batch1RecipeName from PLC. " & ex.Message)
            Exit Sub
        End Try

It then reads the file and stores it in a string:
Code: [Select]
        Dim s As String
        Using sw As New System.IO.StreamReader("BatchTicketLabelFormat.prn")
            s = sw.ReadToEnd()
        End Using

Using Regular Expression, the string is parsed looking for the brackets
Code: [Select]
        Dim x As System.Text.RegularExpressions.Match = System.Text.RegularExpressions.Regex.Match(s, "\[(.*?)\]")
        Dim Substitue As String
        While Not String.IsNullOrEmpty(x.Value)
            If x.Value.IndexOf("Batch1RecipeName") >= 0 Then
                Substitue = RecipeName
             Else
                Substitue = "ZZZZZZ"
            End If
            s = s.Substring(0, x.Index) & Substitue & s.Substring(x.Index + x.Length)
            x = System.Text.RegularExpressions.Regex.Match(s, "\[(.*?)\]")
        End While

And finally send the string directly to the printr:
Code: [Select]
        RawPrinterHelper.SendStringToPrinter(RawPrinterHelper.DefaultPrinterName(), s)

paintman

  • Newbie
  • *
  • Posts: 8
    • View Profile
Re: AdvancedHMI not correct .NET framework for nugget.
« Reply #4 on: Today at 02:24:29 PM »
Okay that seems fairly simple. The rawprinterhelper is a tad confusing for me.

Is the rawprinterhelper just placed in a separate module and called when needed? I am looking at the class and trying to understand some segments of the code. 
Would I just change this to what ever I name the ZPL file as, and the data type I assume would remain the same since its send a direct ZPL file?
Code: [Select]
        ' Set up the DOCINFO structure.
        With di
            .pDocName = "Mix Room Label Printer"
            .pDataType = "RAW"
        End With

And as far as the printer name goes, I figure it wouldn't really matter as long as it is the default.

Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5268
    • View Profile
    • AdvancedHMI
Re: AdvancedHMI not correct .NET framework for nugget.
« Reply #5 on: Today at 06:39:53 PM »
The RawPrinterHelper.vb file is added to the project by right clicking the AdancedHMI project and selecting Add->Existing Item.

You are correct, the printer name does not matter as long as it is default.