Diagraph-ResmarkAPI 1.0.0

dotnet add package Diagraph-ResmarkAPI --version 1.0.0
                    
NuGet\Install-Package Diagraph-ResmarkAPI -Version 1.0.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Diagraph-ResmarkAPI" Version="1.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Diagraph-ResmarkAPI" Version="1.0.0" />
                    
Directory.Packages.props
<PackageReference Include="Diagraph-ResmarkAPI" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Diagraph-ResmarkAPI --version 1.0.0
                    
#r "nuget: Diagraph-ResmarkAPI, 1.0.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Diagraph-ResmarkAPI@1.0.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Diagraph-ResmarkAPI&version=1.0.0
                    
Install as a Cake Addin
#tool nuget:?package=Diagraph-ResmarkAPI&version=1.0.0
                    
Install as a Cake Tool

ResmarkAPI Demo

This is a simple C# program for interfacing with a Resmark printer using the ResmarkAPI. It demonstrates how to connect to a Resmark printer, retrieve information, handle printing tasks, and manage message variables.

Prerequisites

Before running this program, ensure you have the following prerequisites:

  • A Diagraph Resmark printer with a reachable IP address.
  • The .NET SDK installed.
  • Diagraph-ResmarkAPI NuGet package (e.g., Diagraph-ResmarkAPI.1.0.0.nupkg)

Getting Started

  1. Create a new C# project in your preferred development environment.

  2. Add the Diagraph-ResmarkAPI NuGet package to your project.

  3. Replace the default code in your project with the provided code.

  4. Build your program.

  5. Place a printer message "variable.next" in the bin Folder and run your program.

Content of the file "variable.next" could be

<?xml version="1.0"?>
<ProductObject Name="variable" GapBetweenPrint="1.000" PrintCount="1" TaskType="HighResTask" DPI="300">
	<Margin />
	<Box Width="10.000" Length="10.000" Height="18.000" />
	<Variables />
	<Panel Name="Front">
		<Head UID="0" Name="PrintHead1" Type="384" Offset="1.000" Enabled="True" DPI="300">
			<FieldObject xsi:type="VarFieldObject" X="1.708" Y="0.656" LockAspectRatio="True" Data="WWWWWWWWWW" Family="Arial" Style="Regular" Width="36" Height="36" Length="10" />
		</Head>
	</Panel>
	<Panel Name="Right" />
	<Panel Name="Back" />
	<Panel Name="Left" />
	<Panel Name="Top" />
	<Panel Name="Bottom" />
</ProductObject>

Usage

This program connects to a Resmark printer, retrieves printer status, and manages messages and variable data. It provides the following functionalities:

  • Search for available Resmark printers on the network and display their information.
  • Fetch information about the connected printer, including status and errors.
  • Retrieve and print XML messages.
  • Manage and print stored messages.
  • Set message variable data and message counts for printing.
  • Pause, resume, and cancel printing jobs.

Code Explanation

  • The program utilizes the ResmarkAPI class to interact with the Resmark printer.

  • It begins by searching for available printers on the network and connecting to the specified printer using its IP address and printer UID.

  • It fetches important information about the connected printer's status and provides options to handle messages, including printing XML-based messages or stored messages on the printer.

  • It allows you to set custom variable data for messages and set a specific message count for printing.

  • The program also includes error handling and printer job control features such as pausing, resuming, and canceling prints.

Example Code Snippets

Here are some important functions in the demo:

using System;
using System.Collections.Generic;
using System.IO;
using System.Threading.Tasks;
using Diagraph.ResmarkApi;

internal class Program
{
    private static async Task Main(string[] args)
    {
        //Search Resmark printers
        var printers = PrinterSearch.Search();
        foreach (var message in printers.Result) Console.WriteLine(message);

        // Create an instance of the ResmarkAPI
        var printerUID = "02fd";
        var ipAddress = "192.168.174.225";
        var folderName = "/";
        var resmarkAPI = new ResmarkAPI(printerUID, ipAddress, folderName);

        // Demonstrating ResmarkAPI functions
        try
        {
            // 1. Retrieve printer status
            Console.WriteLine("\nRetrieving printer status...");
            var statusResult = await resmarkAPI.GetStatus();
            Console.WriteLine("Printer status: " + statusResult.Status);

            // 2. Retrieve messages
            Console.WriteLine("Retrieving messages...");
            var messagesResult = await resmarkAPI.GetMessages();
            if (messagesResult.Success)
            {
                Console.WriteLine("Messages:");
                foreach (var message in messagesResult.List) Console.WriteLine(message);
            }
            else
            {
                Console.WriteLine("Error retrieving messages: " + messagesResult.Message);
            }

            // 3. Print XML message
            Console.WriteLine("\nPrinting an .next message...");
            var messageXmlPath = "variable.next";
            if (File.Exists(messageXmlPath))
            {
                var messageXml = File.ReadAllText(messageXmlPath);
                var printXmlResult = await resmarkAPI.PrintMessageXML(messageXml);
                Console.WriteLine("Printed successfully: " + printXmlResult.Success);
            }
            else
            {
                Console.WriteLine("variable.next file not found.");
            }

            // 4. Cancel printing
            Console.WriteLine("\nCanceling print...");
            var cancelPrintResult = await resmarkAPI.CancelPrint();
            Console.WriteLine("Print canceled: " + cancelPrintResult.Success);

            // 5. Print stored message
            Console.WriteLine("\nPrinting a stored message...");
            var printStoredResult = await resmarkAPI.PrintStoredMessage("variable.next");
            Console.WriteLine("Printed successfully: " + printStoredResult.Success);

            // 6. Retrieve message variable data
            Console.WriteLine("\nRetrieving message variable data...");
            var messageVariablesResult = await resmarkAPI.GetMessageVariableData();
            if (messageVariablesResult.Success && messageVariablesResult.Dictionary != null)
                foreach (var variable in messageVariablesResult.Dictionary)
                    Console.WriteLine($"{variable.Key}: {variable.Value}");
            else
                Console.WriteLine("Error retrieving message variables: " + messageVariablesResult.Message);

            // 7. Set message variable data
            Console.WriteLine("\nSetting message variable data...");
            var newVariables = new Dictionary<string, string>
            {
                { "", DateTime.Now.ToLongTimeString() }
            };

            var setVariableDataResult = await resmarkAPI.SetMessageVariableData(newVariables);
            Console.WriteLine("Message variable data set: " + setVariableDataResult.Success);

            // 8. Set message count
            Console.WriteLine("\nSetting message count...");
            var messageCount = 1; // Example count
            var setMessageCountResult = await resmarkAPI.SetMessageCount(messageCount);
            Console.WriteLine("Message count set: " + setMessageCountResult.Success);

            // 9. Pause printing
            Console.WriteLine("\nPausing print...");
            var pausePrintResult = await resmarkAPI.PausePrinting();
            Console.WriteLine("Print paused: " + pausePrintResult.Success);

            // 10. Resume printing
            Console.WriteLine("\nResuming print...");
            var resumePrintResult = await resmarkAPI.ResumePrinting();
            Console.WriteLine("Print resumed: " + resumePrintResult.Success);
        }
        catch (Exception ex)
        {
            Console.WriteLine("Error: " + ex.Message);
        }

        Console.WriteLine("\nProgram completed. Press any key to exit.");
        Console.ReadKey();
    }
}

Features

  1. Retrieve Printer Information:

    • Get the current status and potential error details from the printer.
  2. Print Messages:

    • Print messages stored in XML files or predefined stored messages on the printer.
  3. Set Message Variables:

    • Dynamically set the variables for messages before printing using the SetMessageVariableData() method.
  4. Set Message Count:

    • Define how many times a specific message should be printed with the SetMessageCount() function.
  5. Job Control:

    • Control printing jobs by pausing, resuming, or canceling them.

How to Run

  1. Make sure the Resmark printer is connected to the network.
  2. Modify the printerUID, ipAddress, and folderName fields in the demo program to match your printer's configuration.
  3. Run the program and follow the prompts in the console to interact with the Resmark printer.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net is compatible.  net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios is compatible. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

This package has no dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.0 191 9/10/2024

Version 1.0.0 - Initial Release (September 2024)
Overview:

The first release of the ResmarkAPI provides core functionality for interacting with Resmark printers. This version includes basic API features for printer communication, message handling, variable data management, and job control.