private void SearchDevices()
{
// Получаем реальные COM-порты
var ports = System.IO.Ports.SerialPort.GetPortNames().ToList();
// Добавляем фиктивные для теста
ports.Add("COM10");
ports.Add("COM18");
if (ports.Count == 0)
{
MessageBox.Show("COM-порты не найдены.", "Поиск касс", MessageBoxButtons.OK, MessageBoxIcon.Warning);
return;
}
string checkedPorts = "";
string foundDevices = "";
foreach (var port in ports)
{
Debug.WriteLine($"Проверяю порт: {port}");
checkedPorts += port + " ";
try
{
var testFptr = new Fptr();
// Указываем тип соединения: 0 = COM-порт
testFptr.setParam(1024, 0); // LIBFPTR_PARAM_CONNECTION_TYPE
testFptr.setParam(1031, port); // LIBFPTR_PARAM_COM_FILE
testFptr.setParam(1032, 115200); // LIBFPTR_PARAM_COM_BAUDRATE
var res = testFptr.open();
if (res == 0 && testFptr.isOpened())
{
// Запрашиваем статус
testFptr.setParam(1204, 0); // LIBFPTR_PARAM_DATA_TYPE
testFptr.queryData();
string serial = testFptr.getParamString(1049); // LIBFPTR_PARAM_SERIAL_NUMBER
string model = testFptr.getParamString(1050); // LIBFPTR_PARAM_MODEL_NAME
foundDevices += $"Найдена ККТ:\nПорт: {port}\nМодель: {model}\nСерийный номер: {serial}\n\n";
}
testFptr.close();
}
catch (Exception ex)
{
Debug.WriteLine($"Ошибка при проверке порта {port}: {ex.Message}");
}
}
if (string.IsNullOrEmpty(foundDevices))
{
MessageBox.Show($"ККТ не найдены.\nПорты, по которым был поиск:\n{checkedPorts}", "Поиск касс", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
else
{
MessageBox.Show($"{foundDevices}\nПорты, по которым был выполнен поиск:\n{checkedPorts}", "Результаты поиска", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
Проблема в том, что на любом порту обёртка от Атол видит кассу, хотя касса на одном порту