Commit 6daccc87 authored by wangjunqiang's avatar wangjunqiang

修正信号值bug

parent d47f0f7d
......@@ -34,9 +34,17 @@ namespace GcDevicePc.Common
private uint hModbusHandle;
public GCModbusSlave()
{
try
{
this.hModbusHandle = fnLibModbusSlaveInit();
}
catch
{
}
}
~GCModbusSlave()
{
......@@ -84,35 +92,43 @@ namespace GcDevicePc.Common
static ushort slavereadhreg(ushort address)
{
ushort value = 0;
ushort baseaddress = 20;
address = (ushort)(address - 1);
ushort signalddress = 17;
ushort baseaddress = 23;
address = (ushort) (address - 1);
int listnum = SharedSpace.Data.listValue.Count;
int readnum = (address - baseaddress)/2;
if (readnum <= listnum - 1 && listnum > 0 && address >= 20)
{
// lock(CKVocAnalyzer.GlobalCKV.valueparamlist){
try
if (address >= 17)
{
ushort[] s = new ushort[2];
float[] f = new float[2];
if (address >= 17 && address <= 22)
{
if (address == 17 || address == 18)
f[0] = float.Parse(globaldata.m_dpbuffer.ShowList.showDet.fDetValue.ToString("0.000"));
if (address == 19 || address == 20)
f[0] = float.Parse(globaldata.m_dpbuffer.ShowList.showDet.iDetValue.ToString("0.000"));
if (address == 21 || address == 22)
f[0] = float.Parse(globaldata.m_dpbuffer.ShowList.showDet.bDetValue.ToString("0.000"));
Buffer.BlockCopy(f, 2, s, 0, 2);
Buffer.BlockCopy(f, 0, s, 2, 2);
value = s[(address - signalddress) % 2];
}
else if (address >= 23 && listnum > 0)
{
int readnum = (address - baseaddress) / 2;
f[0] = float.Parse(SharedSpace.Data.listValue[readnum].vale.ToString());
Buffer.BlockCopy(f, 2, s, 0, 2);
Buffer.BlockCopy(f, 0, s, 2, 2);
value = s[(address - baseaddress) % 2];
}
value = s[(address - baseaddress)%2];
}catch{
else
{
value = 0;
}
//}
}
if( address >=2 && address <20 )
if (address >= 2 && address < 20)
{
switch(address)
switch (address)
{
case 2:
{
......@@ -286,45 +302,9 @@ namespace GcDevicePc.Common
}
}
break;
case 17: //前检测器值
{
if (CProfileDevice.m_DevParam.syspara.u16DetFront == 1)
{
value = (ushort) (globaldata.m_dpbuffer.ShowList.showDet.fDetValue * 1000);
}
else
{
value = 0;
}
}
break;
case 18: //中检测器值
{
if (CProfileDevice.m_DevParam.syspara.u16DetInter == 1)
{
value = (ushort) (globaldata.m_dpbuffer.ShowList.showDet.iDetValue * 1000);
}
else
{
value = 0;
}
}
break;
case 19: //后检测器值
{
if (CProfileDevice.m_DevParam.syspara.u16DetBehind == 1)
{
value = (ushort) (globaldata.m_dpbuffer.ShowList.showDet.bDetValue * 1000);
}
else
{
value = 0;
}
}
break;
}
}
return value;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment