Interfaz/API de comunicación serial

-Wrapper Tmapp_IPOS.cs

public class Tmapp_IPOS
{
  // Constantes de error
  const uint MYDLL_OK = 0;
  const uint MYDLL_SETUP_ERROR = 1;
	// ... otros códigos

  // Estructura de resultado
  public struct Struct_result
  {
    public uint result; // Código de error
    public string message; // Mensaje descriptivo
    public string request; // Request enviado
    public string response; // Response recibido
  }
  // Método principal
  public static Struct_result WriteRead(string strrequest, uint uTimeout)
  {
  	// Implementación...
  }
}

-P/Invoke Declarations

`csharp
[DllImport("MiDLL.dll", CharSet = CharSet.Auto)]
public static extern uint WRITEREADX(
  byte[] strRequest, // Request como bytes
  byte[] strResponse, // Buffer para respuesta
  uint length, // Tamaño buffer
  uint timeout, // Timeout en segundos
  ref uint osError // Error del sistema
);
[DllImport("MiDLL.dll", CharSet = CharSet.Auto)]
public static extern uint GETERRORMESSAGE(
  uint dwError, // Código de error
  byte[] errorMsg, // Buffer para mensaje
  uint maxChars // Tamaño máximo
);

-Flujo de Comunicación

```csharp
// 1. Serializar JSON a bytes UTF-8
byte[] request = Encoding.ASCII.GetBytes(jsonRequest);

// 2. Preparar buffer de respuesta
byte[] response = new byte[MAX_BUFFER_SIZE]; // 200,000 bytes

// 3. Llamar a DLL nativa
uint osError = 0;
uint result = WRITEREADX(request, response, MAX_BUFFER_SIZE, timeout, ref
osError);

// 4. Procesar respuesta
if (result == MYDLL_OK)
{
  string jsonResponse = Encoding.UTF8.GetString(response);
  jsonResponse = jsonResponse.Substring(0, jsonResponse.IndexOf('\0'));
}
```

-Manejo de Buffer

```csharp
const int MAX_BUFFER_SIZE = 200000; // 200KB suficiente para reportes
detallados

// Consideraciones:
// - Reportes detallados pueden ser grandes
// - Buffer debe limpiarse entre transacciones
// - UTF-8 encoding garantiza compatibilidad con caracteres especiales

What’s Next