Diagraph-MLIAPI
1.0.0
dotnet add package Diagraph-MLIAPI --version 1.0.0
NuGet\Install-Package Diagraph-MLIAPI -Version 1.0.0
<PackageReference Include="Diagraph-MLIAPI" Version="1.0.0" />
<PackageVersion Include="Diagraph-MLIAPI" Version="1.0.0" />
<PackageReference Include="Diagraph-MLIAPI" />
paket add Diagraph-MLIAPI --version 1.0.0
#r "nuget: Diagraph-MLIAPI, 1.0.0"
#:package Diagraph-MLIAPI@1.0.0
#addin nuget:?package=Diagraph-MLIAPI&version=1.0.0
#tool nuget:?package=Diagraph-MLIAPI&version=1.0.0
Diagraph MLi Printer Demo
This is a simple C# program for interfacing with a Diagraph MLi Printer using the Diagraph-MLIAPI library. It demonstrates how to search for MLi printers on the network, connect to one, retrieve device information, and interact with the printer.
Prerequisites
Before running this program, ensure you have the following prerequisites:
- Diagraph MLi Printer
- .NET SDK installed
- Diagraph-MLIAPI NuGet package (e.g., Diagraph-MLIAPI.1.0.0.nupkg)
Getting Started
Create a new C# project in your preferred development environment.
Add the Diagraph-MLIAPI NuGet package to your project.
Replace the default code in your project with the provided code.
Build and run the program.
Usage
This program searches for Diagraph MLi printers on the network, connects to the first one found, and performs the following actions:
- Retrieves device information including version, status, errors, device info, and configuration.
- Lists files stored on the printer, such as label files and font files.
- Handles various notifications from the printer, including errors, warnings, and information messages.
Code Explanation
The program uses the
MLIAPI.MLIAPI
class from the Diagraph-MLIAPI library to interact with the Diagraph MLi Printer.It searches for available MLi printers on the network using the
SearchMLis
method and connects to the first printer found.The program then retrieves device information, such as version, status, errors, device info, and configuration settings, and displays them.
It lists the files stored on the printer, including label files and font files.
The program handles various notifications received from the printer, providing details about initialization, errors, warnings, information messages, and more.
using System.Text;
using MLIAPI;
using MLIAPI.Messages;
namespace MLI_DemoApp;
public class Program
{
private static readonly MLI _api = new();
public static void Main(string[] args)
{
//Search MLi printers on the network
var foundMLiPrinters = _api.SearchMLis();
//connect to first printer
foreach (var ip in foundMLiPrinters.Keys)
{
if (ConnectToDevice(ip))
{
GetDeviceInformation();
ListFiles("Label", _api.Methods.FILE_STORAGE_LIST().FILE_NAMES);
ListFiles("Font", _api.Methods.FONT_STORAGE_LIST().FILE_NAMES);
}
else
{
Console.WriteLine("Not connected: " + _api.ConnectionString);
}
Console.WriteLine("Press ESC to stop");
while (Console.ReadKey(true).Key != ConsoleKey.Escape)
{
}
_api.CloseDevice();
}
}
private static bool ConnectToDevice(string ip)
{
_api.Open("tcpip://" + ip + ":" + MLI.DefaultTcpPort);
if (_api.IsConnected)
{
Console.WriteLine("Connected to: " + _api.ConnectionString);
_api.OnNotificationRecieved += NotificationReceived;
return true;
}
return false;
}
private static void GetDeviceInformation()
{
// Get and print device information
var versionInfo = _api.Methods.GET_VERSION_INFORMATION(true);
Console.WriteLine("Version: " + versionInfo);
var deviceStatus = _api.Methods.GET_DEVICE_STATUS();
Console.WriteLine("Status: " + deviceStatus);
var errors = _api.Methods.GET_PENDING_ERRORS();
if (errors.Length == 0)
Console.WriteLine("Error: no error");
else
foreach (var error in errors)
Console.WriteLine("Error: " + error.ERROR_TEXT);
var deviceInfoKeys = _api.Methods.DEVICE_INFO_LISTKEYS();
foreach (var deviceInfoKey in deviceInfoKeys)
{
var info = _api.GetColumnInfo(deviceInfoKey.ToString());
var value = _api.GetStringFromBytes(info, _api.Methods.DEVICE_INFO_GET(deviceInfoKey));
Console.WriteLine("DeviceInfo: " + deviceInfoKey + ": " + value);
}
var configKeys = _api.Methods.CONFIG_LISTKEYS();
foreach (var configKey in configKeys)
{
var info = _api.GetColumnInfo(configKey.ToString(), true);
var value = _api.GetStringFromBytes(info, _api.Methods.CONFIG_GET(configKey));
Console.WriteLine("Config: " + configKey + ": " + value);
}
}
private static void ListFiles(string fileType, string[] fileNames)
{
foreach (var fileName in fileNames) Console.WriteLine($"{fileType}: {fileName}");
}
private static void NotificationReceived(object sender, IMessage eventData)
{
if (eventData is not NotificationMessage notification) return;
var notificationId = (MLI.NOTIFICATIONID) notification.Notification.NOTIFICATION_ID;
switch (notificationId)
{
case MLI.NOTIFICATIONID.NOTIFY_INIT:
Console.WriteLine(notificationId + Environment.NewLine);
break;
case MLI.NOTIFICATIONID.NOTIFY_HELLO:
Console.WriteLine(notificationId + Environment.NewLine);
break;
case MLI.NOTIFICATIONID.NOTIFY_BOOTCOMPLETE:
Console.WriteLine(notificationId + Environment.NewLine);
break;
case MLI.NOTIFICATIONID.NOTIFY_READY:
Console.WriteLine(notificationId + Environment.NewLine);
break;
case MLI.NOTIFICATIONID.NOTIFY_IDLE:
Console.WriteLine(notificationId + Environment.NewLine);
break;
case MLI.NOTIFICATIONID.NOTIFY_ERROR:
int errorModule = notification.Notification.DATA.ToArray()[0];
int errorCode = notification.Notification.DATA.ToArray()[1];
var errorText = Encoding.UTF8.GetString(notification.Notification.DATA.ToArray().Skip(2).ToArray());
Console.WriteLine(notificationId + " " + errorModule + " " + errorCode + " " + errorText +
Environment.NewLine);
break;
case MLI.NOTIFICATIONID.NOTIFY_WARN:
int warningModule = notification.Notification.DATA.ToArray()[0];
int warningCode = notification.Notification.DATA.ToArray()[1];
var warningText = Encoding.UTF8.GetString(notification.Notification.DATA.ToArray().Skip(2).ToArray());
Console.WriteLine(notificationId + " " + warningModule + " " + warningCode + " " + warningText +
Environment.NewLine);
break;
case MLI.NOTIFICATIONID.NOTIFY_INFO:
int infoModule = notification.Notification.DATA.ToArray()[0];
int infoCode = notification.Notification.DATA.ToArray()[1];
var infoText = Encoding.UTF8.GetString(notification.Notification.DATA.ToArray().Skip(2).ToArray());
Console.WriteLine(notificationId + " " + infoModule + " " + infoCode + " " + infoText +
Environment.NewLine);
break;
case MLI.NOTIFICATIONID.NOTIFY_USERMESSAGE:
Console.WriteLine(notificationId + Encoding.ASCII.GetString(notification.Notification.DATA) +
Environment.NewLine);
break;
case MLI.NOTIFICATIONID.NOTIFY_PRINTED:
Console.WriteLine(notificationId + Environment.NewLine);
Console.WriteLine("Print Counter: " + notification.Notification.DATA[0]);
break;
case MLI.NOTIFICATIONID.NOTIFY_PRINT_LOST:
Console.WriteLine(notificationId + Environment.NewLine);
break;
case MLI.NOTIFICATIONID.NOTIFY_CASECOVER_CLOSE:
Console.WriteLine(notificationId + Environment.NewLine);
break;
case MLI.NOTIFICATIONID.NOTIFY_NEED_VARIABLE_DATA:
Console.WriteLine(notificationId + Environment.NewLine);
break;
}
}
}
License
This project follows the licensing terms of the Diagraph-MLIAPI library. Be sure to review the license associated with the library for details.
If you encounter any issues or have questions, please refer to the library's documentation or contact the library's support resources.
Enjoy working with your Diagraph MLi Printer!
Product | Versions 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. |
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 | 306 | 10/18/2023 |
Initial release