empecemos
This commit is contained in:
Vendored
+3
-1
@@ -4,7 +4,9 @@
|
|||||||
"name": "macos-clang-x64",
|
"name": "macos-clang-x64",
|
||||||
"includePath": [
|
"includePath": [
|
||||||
"${workspaceFolder}/**",
|
"${workspaceFolder}/**",
|
||||||
"${workspaceFolder}"
|
"${workspaceFolder}",
|
||||||
|
"${workspaceFolder}/class",
|
||||||
|
"${workspaceFolder}/class"
|
||||||
],
|
],
|
||||||
"compilerPath": "/usr/bin/clang",
|
"compilerPath": "/usr/bin/clang",
|
||||||
"cStandard": "${default}",
|
"cStandard": "${default}",
|
||||||
|
|||||||
Vendored
+1
-1
@@ -4,7 +4,7 @@
|
|||||||
"C_Cpp_Runner.debuggerPath": "lldb",
|
"C_Cpp_Runner.debuggerPath": "lldb",
|
||||||
"C_Cpp_Runner.cStandard": "",
|
"C_Cpp_Runner.cStandard": "",
|
||||||
"C_Cpp_Runner.cppStandard": "",
|
"C_Cpp_Runner.cppStandard": "",
|
||||||
"C_Cpp_Runner.msvcBatchPath": "C:/Program Files/Microsoft Visual Studio/VR_NR/Community/VC/Auxiliary/Build/vcvarsall.bat",
|
"C_Cpp_Runner.msvcBatchPath": "",
|
||||||
"C_Cpp_Runner.useMsvc": false,
|
"C_Cpp_Runner.useMsvc": false,
|
||||||
"C_Cpp_Runner.warnings": [
|
"C_Cpp_Runner.warnings": [
|
||||||
"-Wall",
|
"-Wall",
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
#include "SMARTComm70.h"
|
#include "SMARTComm70.h"
|
||||||
#include "SmartErrcodes.h"
|
#include "SmartErrcodes.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
+173
-11
@@ -1,14 +1,176 @@
|
|||||||
// Ejemplo de conexión básica
|
#include <string>
|
||||||
HSMART70 printerHandle;
|
#include <vector>
|
||||||
SMART70_PRINTER_LIST printerList;
|
#include <mutex>
|
||||||
|
#include <memory>
|
||||||
|
#include <unordered_map>
|
||||||
|
#include "SmartComm2.h" // Incluir el SDK
|
||||||
|
|
||||||
// Obtener lista de impresoras disponibles
|
class Smart70Printer {
|
||||||
Smart70_GetDeviceList(&printerList);
|
public:
|
||||||
|
// Singleton para manejar múltiples instancias de impresoras
|
||||||
|
static Smart70Printer& getInstance() {
|
||||||
|
static Smart70Printer instance;
|
||||||
|
return instance;
|
||||||
|
}
|
||||||
|
|
||||||
// Conectar con la primera impresora encontrada (modo DCL)
|
// Estructura para información de la impresora
|
||||||
Smart70DCL_OpenDevice(&printerHandle, printerList.item[0].desc,
|
struct PrinterInfo {
|
||||||
SMART70_OPENDEVICE_BYDESC, DMORIENT_LANDSCAPE);
|
std::string id;
|
||||||
|
std::string description;
|
||||||
|
std::string ipAddress;
|
||||||
|
int port;
|
||||||
|
bool isConnected;
|
||||||
|
};
|
||||||
|
|
||||||
// Verificar módulos conectados
|
// Conectar a una impresora por dirección IP
|
||||||
SMART70_DEVCONNLIST moduleList;
|
bool connect(const std::string& ipAddress, int port = 9100) {
|
||||||
Smart70_GetConnectedModules(printerHandle, &moduleList);
|
std::lock_guard<std::mutex> lock(m_mutex);
|
||||||
|
|
||||||
|
// Verificar si ya estamos conectados a esta impresora
|
||||||
|
auto it = m_connectedPrinters.find(ipAddress);
|
||||||
|
if (it != m_connectedPrinters.end() && it->second.isConnected) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Obtener lista de dispositivos
|
||||||
|
SMART70_PRINTER_LIST printerList;
|
||||||
|
if (Smart70_GetDeviceList(&printerList) != SM_SUCCESS) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Buscar la impresora por dirección IP
|
||||||
|
for (int i = 0; i < printerList.n; i++) {
|
||||||
|
SMART70_PRINTER_INFO info;
|
||||||
|
if (Smart70_GetDeviceInfo(&info, printerList.item[i].desc,
|
||||||
|
SMART70_OPENDEVICE_BYDESC) == SM_SUCCESS) {
|
||||||
|
if (info.dev_type == 2 && std::string(info.net.ip) == ipAddress) {
|
||||||
|
// Conectar en modo DCL
|
||||||
|
HSMART70 handle;
|
||||||
|
if (Smart70DCL_OpenDevice(&handle, printerList.item[i].desc,
|
||||||
|
SMART70_OPENDEVICE_BYDESC,
|
||||||
|
DMORIENT_LANDSCAPE) == SM_SUCCESS) {
|
||||||
|
|
||||||
|
PrinterInfo printerInfo;
|
||||||
|
printerInfo.id = printerList.item[i].id;
|
||||||
|
printerInfo.description = printerList.item[i].desc;
|
||||||
|
printerInfo.ipAddress = ipAddress;
|
||||||
|
printerInfo.port = port;
|
||||||
|
printerInfo.isConnected = true;
|
||||||
|
|
||||||
|
m_handles[ipAddress] = handle;
|
||||||
|
m_connectedPrinters[ipAddress] = printerInfo;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Desconectar una impresora
|
||||||
|
bool disconnect(const std::string& ipAddress) {
|
||||||
|
std::lock_guard<std::mutex> lock(m_mutex);
|
||||||
|
|
||||||
|
auto it = m_handles.find(ipAddress);
|
||||||
|
if (it != m_handles.end()) {
|
||||||
|
int result = Smart70DCL_CloseDevice(it->second);
|
||||||
|
m_handles.erase(it);
|
||||||
|
m_connectedPrinters[ipAddress].isConnected = false;
|
||||||
|
return result == SM_SUCCESS;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Obtener información de impresoras conectadas
|
||||||
|
std::vector<PrinterInfo> getConnectedPrinters() {
|
||||||
|
std::lock_guard<std::mutex> lock(m_mutex);
|
||||||
|
std::vector<PrinterInfo> result;
|
||||||
|
|
||||||
|
for (const auto& pair : m_connectedPrinters) {
|
||||||
|
if (pair.second.isConnected) {
|
||||||
|
result.push_back(pair.second);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Obtener el estado de los módulos
|
||||||
|
std::vector<SMART70_DEVICE_STATUS> getModuleStatus(const std::string& ipAddress) {
|
||||||
|
std::lock_guard<std::mutex> lock(m_mutex);
|
||||||
|
|
||||||
|
auto it = m_handles.find(ipAddress);
|
||||||
|
if (it != m_handles.end()) {
|
||||||
|
SMART70_DEVCONNLIST moduleList;
|
||||||
|
if (Smart70_GetConnectedModules(it->second, &moduleList) == SM_SUCCESS) {
|
||||||
|
return std::vector<SMART70_DEVICE_STATUS>(
|
||||||
|
moduleList.dev,
|
||||||
|
moduleList.dev + moduleList.n
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
|
// Solicitar preempción (con manejo de concurrencia)
|
||||||
|
bool requestPreemption(const std::string& ipAddress, WORD& preemptionId) {
|
||||||
|
std::lock_guard<std::mutex> lock(m_mutex);
|
||||||
|
|
||||||
|
auto it = m_handles.find(ipAddress);
|
||||||
|
if (it != m_handles.end()) {
|
||||||
|
return Smart70_RequestPreemption(it->second, &preemptionId) == SM_SUCCESS;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Liberar preempción
|
||||||
|
bool releasePreemption(const std::string& ipAddress, WORD preemptionId) {
|
||||||
|
std::lock_guard<std::mutex> lock(m_mutex);
|
||||||
|
|
||||||
|
auto it = m_handles.find(ipAddress);
|
||||||
|
if (it != m_handles.end()) {
|
||||||
|
return Smart70_ReleasePreemption(it->second, preemptionId) == SM_SUCCESS;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Método para crear un nuevo trabajo (Job Descriptor)
|
||||||
|
bool createJob(const std::string& ipAddress, HJOBD& jobDescriptor) {
|
||||||
|
std::lock_guard<std::mutex> lock(m_mutex);
|
||||||
|
|
||||||
|
auto it = m_handles.find(ipAddress);
|
||||||
|
if (it != m_handles.end()) {
|
||||||
|
return Smart70_NewJobDescriptor(it->second, &jobDescriptor, nullptr) == SM_SUCCESS;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Método para enviar un trabajo a la impresora
|
||||||
|
bool submitJob(const std::string& ipAddress, HJOBD jobDescriptor, int& jobId) {
|
||||||
|
std::lock_guard<std::mutex> lock(m_mutex);
|
||||||
|
|
||||||
|
auto it = m_handles.find(ipAddress);
|
||||||
|
if (it != m_handles.end()) {
|
||||||
|
return Smart70_InsertJob(it->second, jobDescriptor, &jobId) == SM_SUCCESS;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
Smart70Printer() {} // Constructor privado para singleton
|
||||||
|
~Smart70Printer() {
|
||||||
|
// Limpiar todas las conexiones al destruir
|
||||||
|
for (auto& pair : m_handles) {
|
||||||
|
Smart70DCL_CloseDevice(pair.second);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Eliminar copias
|
||||||
|
Smart70Printer(const Smart70Printer&) = delete;
|
||||||
|
Smart70Printer& operator=(const Smart70Printer&) = delete;
|
||||||
|
|
||||||
|
std::mutex m_mutex;
|
||||||
|
std::unordered_map<std::string, HSMART70> m_handles;
|
||||||
|
std::unordered_map<std::string, PrinterInfo> m_connectedPrinters;
|
||||||
|
};
|
||||||
Reference in New Issue
Block a user