Ya pude resolver hace un ratito lo de leer, lo que no puedo solucionar es escribir.
Paso el codigo:
// -------------------------------------------------------------------------
// Funcion: PlcMain ()
// Funcion principal.
// -------------------------------------------------------------------------
// Crear variable que indica si esperamos una respuesta del Servidor.
new WaitResponse = 0
// Variable para almacenar datos.
new RxData[4]
// Crear variable para almacenar estado.
new MbStat
PlcMain()
{
// Inicializar display.
LcdClear()
LcdPrintf(0,1, "ModBus RTU")
// Inicializar Cliente ModBus RTU.
MbRtuClInit(19200, SERIAL_8E1, 10, MB_RTU_INTERFACE_RS485)
// Activar evento "OnMbRtuClientRx" para determinar respuesta
// del servidor.
if(MbRtuClSetRxEvent() < 0)
{
LcdClear()
LcdPrintf(0,1, "Error, Evento")
DelayS(5)
}
for(;;)
{
DelayS(5)
if( MbRtuClSendWriteSingle (247, 40140, 11) < 0 )
{
// Error.
}
}
}
// -------------------------------------------------------------------------
// Funcion: @OnMbRtuClientRx()
// Procesa una respuesta del servidor ModBus RTU (escritura/lectura).
// -------------------------------------------------------------------------
@OnMbRtuClientRx()
{
new MbStat
// Obtener Estado de Libreria.
MbStat = MbRtuClGetLibStatus()
// Mostrar Estado de Libreria.
LcdPrintf(0,0, "Stat = %03d", MbStat)
LcdPrintf(0,1, "Exception: %03d", MbRtuClGetExceptionCode())
// Leer registros recibidos si no hay error.
if(MbStat == 0)
{
// Leer Registros.
MbRtuClGetRxReg(RxData, 0, 4, 1)
// Mostrar valores de registros en LCD.
LcdPrintf(0,1, "%04d %04d %04d", RxData[0], RxData[1], RxData[2])
// Respuesta recibida, no esperar más.
WaitResponse = 0
}
}
Me responde error 7 excepción 001, (libreria ocupada).
Y despues de un ratito me pone:
PLC RETURN CODE C:7 R:500