This commit is contained in:
Nicola Carminati
2019-02-07 15:33:35 +00:00
parent efb5c1d44b
commit ce71658bd0
+36 -8
View File
@@ -872,39 +872,67 @@ namespace CMS_CORE_Library.Osai
public override CmsError PLC_RScadaValue(string memIndex, SCADA_MEM_TYPE memType, ref object value)
{
string[] index = memIndex.Split('.');
if(memType == SCADA_MEM_TYPE.BOOL )
{
if(memIndex.ToUpper() == "FALSE")
{
value = false;
return NO_ERROR;
}
else if (memIndex.ToUpper() == "TRUE")
{
value = true;
return NO_ERROR;
}
}
string[] index = memIndex.Split('_');
CmsError cmsError = NO_ERROR;
if (index.Count() == 0)
MEMORY_TYPE Type = MEMORY_TYPE.Osai_MW;
if (index.Count() != 2)
return INCORRECT_PARAMETERS_ERROR;
else if (index.Count() == 1)
switch (index[0].ToUpper())
{
case "GW": Type = MEMORY_TYPE.Osai_MW; break;
case "MW": Type = MEMORY_TYPE.Osai_MW; break;
case "M": Type = MEMORY_TYPE.Osai_MW; break;
case "MD": Type = MEMORY_TYPE.Osai_MD; break;
case "GD": Type = MEMORY_TYPE.Osai_GD; break;
};
index = index[1].Split('.');
if (index.Count() == 1)
{
if (memType == SCADA_MEM_TYPE.INT)
{
// read INT
int val = 0;
cmsError = MEM_RWInteger(R, 0, MEMORY_TYPE.Osai_MW, Convert.ToInt32(index[0]), ref val);
cmsError = MEM_RWInteger(R, 0, Type, Convert.ToInt32(index[0]), ref val);
value = val;
}
else if (memType == SCADA_MEM_TYPE.WORD)
{ // read WORD
ushort val = 0;
cmsError = MEM_RWWord(R, 0, MEMORY_TYPE.Osai_MW, Convert.ToInt32(index[0]), ref val);
cmsError = MEM_RWWord(R, 0, Type, Convert.ToInt32(index[0]), ref val);
value = val;
}
else if (memType == SCADA_MEM_TYPE.REAL)
{ // read DOUBLE
double val = 0;
cmsError = MEM_RWDouble(R, 0, MEMORY_TYPE.Osai_GD, Convert.ToInt32(index[0]), ref val);
cmsError = MEM_RWDouble(R, 0, Type, Convert.ToInt32(index[0]), ref val);
value = val;
}
else
{ // read BYTE
byte val = 0;
cmsError = MEM_RWByte(R, 0, MEMORY_TYPE.Osai_MW, Convert.ToInt32(index[0]), 0, ref val);
cmsError = MEM_RWByte(R, 0, Type, Convert.ToInt32(index[0]), 0, ref val);
value = val;
}
@@ -912,7 +940,7 @@ namespace CMS_CORE_Library.Osai
else if (index.Count() == 2 && memType == SCADA_MEM_TYPE.BOOL)
{ // read BOOL
bool val = false;
cmsError = MEM_RWBoolean(R, 0, MEMORY_TYPE.Osai_MW, Convert.ToInt32(index[0]), Convert.ToInt32(index[1]), ref val);
cmsError = MEM_RWBoolean(R, 0, Type, Convert.ToInt32(index[0]), Convert.ToInt32(index[1]), ref val);
value = val;
}