Когда подключен только один принтер, я могу записать на карту и распечатать, просто вызвав getReaders, чтобы получить список считыватели подключаются к машине, а затем подключаются к считывателю, содержащему карту. Однако, когда подключено несколько принтеров, я все равно могу вызвать getReaders для получения списка читателей, но у меня нет возможности узнать, какое устройство чтения принадлежит какому принтеру.
Я использую Elyctis SDK для этой цели. Ниже приведен код, который я использую для получения списка читателей с помощью 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);
}
}
Код: Выделить всё
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;
}
Заранее спасибо!
Подробнее здесь: https://stackoverflow.com/questions/791 ... lis-primac