Fix lettura modbus x registri estesi
This commit is contained in:
@@ -4688,30 +4688,6 @@ namespace IOB_WIN_NEXT
|
||||
// banchi in array Int16 --> scompongo
|
||||
for (int i = 0; i < item.size / 2; i++)
|
||||
{
|
||||
#if false
|
||||
// verifico se usare LUT
|
||||
bool useLUT = memSetR != null && memSetR.Count > 0;
|
||||
if (useLUT)
|
||||
{
|
||||
int lutAddress = 40000 + item.index;
|
||||
if (HoldingRegisterLUT.ContainsKey(lutAddress))
|
||||
{
|
||||
try
|
||||
{
|
||||
listInt = HoldingRegisterLUT[lutAddress];
|
||||
}
|
||||
catch (Exception exc)
|
||||
{
|
||||
lgError($"Errore in lettura da HoldingRegisterLUT per indirizzo {lutAddress} | item {item.memAddr}{Environment.NewLine}{exc}");
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
listInt = readInputReg(item.index, item.size);
|
||||
}
|
||||
currStatus = ModbusClient.ConvertRegistersToInt(listInt);
|
||||
#endif
|
||||
currStatus = getAlarmStatus(item);
|
||||
|
||||
// aggiornamento blink counters dato nuovo valore
|
||||
|
||||
@@ -575,16 +575,15 @@ namespace IOB_WIN_NEXT
|
||||
/// </summary>
|
||||
/// <param name="startAddr"></param>
|
||||
/// <param name="currRegVal">Valore in formato INT da registri</param>
|
||||
/// <param name="baseAddr">Indirizzo di base dei registri</param>
|
||||
/// <returns></returns>
|
||||
public bool writeHoldingReg(int startAddr, int[] currRegVal, int baseAddr)
|
||||
public bool writeHoldingReg(int startAddr, int[] currRegVal)
|
||||
{
|
||||
bool answ = false;
|
||||
if (currPLC.Connected)
|
||||
{
|
||||
try
|
||||
{
|
||||
currPLC.WriteMultipleRegisters(startAddr + deltaBase + indexLutCorr + (40000 - baseAddr), currRegVal);
|
||||
currPLC.WriteMultipleRegisters(startAddr + deltaBase + indexLutCorr, currRegVal);
|
||||
answ = true;
|
||||
}
|
||||
catch
|
||||
@@ -772,7 +771,7 @@ namespace IOB_WIN_NEXT
|
||||
CurrVal = ModbusClient.ConvertIntToRegisters(valInt);
|
||||
}
|
||||
|
||||
fatto = writeHoldingReg(currMem.index, CurrVal, parametri.holdRegBaseAddr);
|
||||
fatto = writeHoldingReg(currMem.index, CurrVal);
|
||||
break;
|
||||
|
||||
case plcDataType.IntLH:
|
||||
@@ -787,20 +786,20 @@ namespace IOB_WIN_NEXT
|
||||
Array.Reverse(CurrVal);
|
||||
}
|
||||
|
||||
fatto = writeHoldingReg(currMem.index, CurrVal, parametri.holdRegBaseAddr);
|
||||
fatto = writeHoldingReg(currMem.index, CurrVal);
|
||||
break;
|
||||
|
||||
case plcDataType.DInt:
|
||||
valUInt = getScaledUInt(currMem, true);
|
||||
CurrVal = ModbusClient.ConvertLongToRegisters(valInt);
|
||||
fatto = writeHoldingReg(currMem.index, CurrVal, parametri.holdRegBaseAddr);
|
||||
fatto = writeHoldingReg(currMem.index, CurrVal);
|
||||
break;
|
||||
|
||||
case plcDataType.DIntLH:
|
||||
valUInt = getScaledUInt(currMem, true);
|
||||
CurrVal = ModbusClient.ConvertLongToRegisters(valInt);
|
||||
Array.Reverse(CurrVal);
|
||||
fatto = writeHoldingReg(currMem.index, CurrVal, parametri.holdRegBaseAddr);
|
||||
fatto = writeHoldingReg(currMem.index, CurrVal);
|
||||
break;
|
||||
|
||||
//case plcDataType.Word:
|
||||
@@ -817,14 +816,14 @@ namespace IOB_WIN_NEXT
|
||||
case plcDataType.RealHL:
|
||||
valDouble = getScaledDouble(currMem);
|
||||
CurrVal = ModbusClient.ConvertFloatToRegisters((float)valDouble, ModbusClient.RegisterOrder.HighLow);
|
||||
fatto = writeHoldingReg(currMem.index, CurrVal, parametri.holdRegBaseAddr);
|
||||
fatto = writeHoldingReg(currMem.index, CurrVal);
|
||||
break;
|
||||
|
||||
case plcDataType.FloatBADC:
|
||||
case plcDataType.RealLH:
|
||||
valDouble = getScaledDouble(currMem);
|
||||
CurrVal = ModbusClient.ConvertFloatToRegisters((float)valDouble, ModbusClient.RegisterOrder.LowHigh);
|
||||
fatto = writeHoldingReg(currMem.index, CurrVal, parametri.holdRegBaseAddr);
|
||||
fatto = writeHoldingReg(currMem.index, CurrVal);
|
||||
break;
|
||||
|
||||
case plcDataType.String:
|
||||
@@ -833,7 +832,7 @@ namespace IOB_WIN_NEXT
|
||||
Array.Copy(regLen, 0, CurrVal, CurrVal.Length - regLen.Length, regLen.Length);
|
||||
//CurrVal[CurrVal.Length - 2] = regLen[1];
|
||||
//CurrVal[CurrVal.Length - 1] = regLen[0];
|
||||
fatto = writeHoldingReg(currMem.index, CurrVal, parametri.holdRegBaseAddr);
|
||||
fatto = writeHoldingReg(currMem.index, CurrVal);
|
||||
break;
|
||||
|
||||
default:
|
||||
@@ -1603,7 +1602,7 @@ namespace IOB_WIN_NEXT
|
||||
case modBusAddrType.HoldingRegister:
|
||||
if (useLUT)
|
||||
{
|
||||
int lutAddress = 40000 + item.Value.index + deltaBase + indexLutCorr;
|
||||
int lutAddress = parametri.holdRegBaseAddr + item.Value.index + deltaBase + indexLutCorr;
|
||||
// se size = 1 --> devo cambiare modo recupero
|
||||
if (item.Value.size == 1)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user