Reputation: 1
I'm trying to write data to multiple chips located in different printers from Evolis (Primacy 2). Each printer has an embedded encoder, with both contact and contactless readers. After writing to the chip, I want to print a graphical design on the card.
When only one printer is connected, I can write to the card and print by simply calling getReaders to list the readers connected to the machine, then connecting to the reader containing the card. However, when multiple printers are connected, I can still call getReaders to list the readers, but I have no way of knowing which reader belongs to which printer.
I'm using the Elyctis SDK for this purpose. Below is the code I use to get the list of readers with the Elyctis SDK:
public static ISCardManager m_iResMan = null;
public static ISCardConnection m_iCard = null;
public static string m_strSelectedInterface = null;
public static SHARE m_connectionMode;
public static PROTOCOL m_protocol;
bool connected = false;
m_protocol = PROTOCOL.T0orT1;
m_connectionMode = SHARE.Shared;
// Establish context with the PCSC manager
try
{
m_iResMan = new SCardManager();
m_iResMan.EstablishContext(SCOPE.System);
}
catch (Exception exc)
{
MessageBox.Show("The PCSC Resource Manager is not available!\r\n" +
exc.Message, "PC/SC stack failure",
MessageBoxButtons.OK,
MessageBoxIcon.Exclamation,
MessageBoxDefaultButton.Button1);
}
string[] strArrays = null;
try
{
strArrays = m_iResMan.ListReaders();
}
catch (Exception ex)
{
MessageBox.Show("No reader found", "PC/SC stack failure",
MessageBoxButtons.OK,
MessageBoxIcon.Exclamation,
MessageBoxDefaultButton.Button1);
}
if (strArrays != null && strArrays.Length >= 1)
{
foreach (string reader in strArrays)
{
try
{
m_iCard = m_iResMan.CreateConnection(reader);
m_iCard.Connect(m_connectionMode, m_protocol);
if (m_iCard.Connected)
{
m_strSelectedInterface = reader;
connected = true;
break;
}
else
{
m_iCard.Disconnect(DISCONNECT.Leave);
m_iCard.EndTransaction(DISCONNECT.Leave);
m_iCard = null;
}
}
catch (Exception ex)
{
continue;
}
}
}
if (connected)
{
try
{
ReadService readService = new ReadService(m_iCard);
}
catch (Exception exc)
{
MessageBox.Show(exc.Message);
}
}
And here is the code for printing on the card after writing to the chip, using the Evolis SDK3 :
if (Printer.name != null && Printer.model.Equals("Evolis_Primacy_2"))
{
RunVersion(pathImage, Printer.name);
}
public static bool RunVersion(string url1, string printer)
{
Connection co = null;
bool isOk = false;
co = new Connection(printer);
if (co.IsOpen())
{
PrintSession ps = new PrintSession(ref co);
bool rep = co.GetStatus(out Status status);
ps.InitFromDriverSettings();
Console.WriteLine("Command sic " + rep + "status " + status.information);
co.InsertCard();
co.SetOutputTray(OutputTray.STANDARD);
co.SetErrorTray(OutputTray.ERROR);
if (!ps.SetImage(CardFace.FRONT, url1))
{
Console.WriteLine("> Error: can't load file resources/front.bmp");
isOk = false;
}
Console.WriteLine("> Start printing...");
ReturnCode r = ps.Print();
Console.WriteLine("> Print result: " + r);
if (r.ToString().Equals("OK"))
{
isOk = true;
}
else
{
Console.WriteLine(r.ToString());
co.SendCommand("Ser");
}
co.EjectCard();
co.Close();
}
else
{
Console.WriteLine("Failed to connect to printer: " + printer);
}
if (co == null)
{
MessageBox.Show("No Primacy printer found", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
return isOk;
}
My problem arises when multiple printers are connected and I need to identify the readers for each printer. If I always choose the first reader containing the card, I end up printing on only one printer. Does anyone have any suggestions on how I can map the readers to their corresponding printers?
Thank you in advance!
Upvotes: 0
Views: 38