Commit 80c67da1 LN

IO模块增加重连

1 个父辈 7bdb0072
...@@ -7,21 +7,20 @@ ...@@ -7,21 +7,20 @@
<!--是否开机自动启动料仓--> <!--是否开机自动启动料仓-->
<add key="App_AutoRun" value="1"/> <add key="App_AutoRun" value="1"/>
<add key="App_Title" value="AC_SA_料仓_1"/> <add key="App_Title" value="AC_SA_料仓_1"/>
<!-- 开始吹气的判断值(配置值=服务器发送的湿度值-开始吹气值)--> <!-- 开始吹气的判断值(配置值=服务器发送的湿度值-开始吹气值)-->
<add key="StartBlowValue" value="4"/> <add key="StartBlowValue" value="4"/>
<!-- 停止吹气的判断值(配置值=服务器发送的湿度值-停止吹气值)--> <!-- 停止吹气的判断值(配置值=服务器发送的湿度值-停止吹气值)-->
<add key="StopBlowValue" value="4"/> <add key="StopBlowValue" value="4"/>
<!--Server address--> <!--Server address-->
<add key="http.server" value="http://192.168.201.68/myproject/" /> <add key="http.server" value="http://192.168.101.11/myproject/" />
<!--storeType--> <!--storeType-->
<add key="store_count" value="1"/> <add key="store_count" value="1"/>
<!--start one store config--> <!--start one store config-->
<add key="Store_Position_Config" value="\StoreConfig\AC\linePositions.csv"/> <add key="Store_Position_Config" value="\StoreConfig\AC\linePositions.csv"/>
<add key="Store_ConfigPath" value="\StoreConfig\AC\StoreConfig.csv"/> <add key="Store_ConfigPath" value="\StoreConfig\AC\StoreConfig.csv"/>
<add key="Store_Type" value="RC_AC_SA"/> <add key="Store_Type" value="RC_AC_SA"/>
<add key="Store_CID" value="rc1250ac-4"/> <add key="Store_CID" value="line-ac1"/>
<add key ="Store_ID" value ="4"/> <add key ="Store_ID" value ="1"/>
<!--end one store config--> <!--end one store config-->
<add key="ACBaudRate" value="115200" /> <add key="ACBaudRate" value="115200" />
<add key="InOutDefaultPosition" value="8000"/> <add key="InOutDefaultPosition" value="8000"/>
...@@ -32,7 +31,7 @@ ...@@ -32,7 +31,7 @@
<add key="HumitureControllerType" value="0"/> <add key="HumitureControllerType" value="0"/>
<add key="UseAIOBOX" value="1"/> <add key="UseAIOBOX" value="1"/>
<!--流水线地址和端口配置--> <!--流水线地址和端口配置-->
<add key ="LineServerIp" value ="192.168.1.114"/> <add key ="LineServerIp" value ="192.168.101.11"/>
<add key ="LineServerPort" value ="5246"/> <add key ="LineServerPort" value ="5246"/>
<!--是否调试状态--> <!--是否调试状态-->
<add key ="IsInDebug" value ="1"/> <add key ="IsInDebug" value ="1"/>
...@@ -40,7 +39,7 @@ ...@@ -40,7 +39,7 @@
</appSettings> </appSettings>
<log4net> <log4net>
<appender name="RollingLogFileAppender" type="log4net.Appender.RollingFileAppender"> <appender name="RollingLogFileAppender" type="log4net.Appender.RollingFileAppender">
<file value="logs/ACStore-RC1250-1.log"/> <file value="logs/ACStore-line-ac1.log"/>
<param name="Encoding" value="UTF-8" /> <param name="Encoding" value="UTF-8" />
<appendToFile value="true"/> <appendToFile value="true"/>
<rollingStyle value="Date"/> <rollingStyle value="Date"/>
......
using Asa.IOModule;
using OnlineStore.Common;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
namespace OnlineStore.DeviceLibrary
{
public abstract class AIManager
{
public bool NeedShow = false;
public static AIManager Instance = null;
public static void Init()
{
bool isAIOBox = ConfigAppSettings.GetIntValue(Setting_Init.UseAIOBOX).Equals(1);
if (isAIOBox)
{
Instance = new AIOAIManager();
}
else
{
Instance = new KNDAIManager();
}
}
public static double ConvertAI(double aiValue, double defaultValue)
{
double xishu = (double)StoreManager.Config.AI_ConvertPosition;
double result = Math.Round((aiValue - defaultValue) / xishu, 2);
return result;
}
public abstract void StartConnect(params string[] ioIp);
public abstract void CloseConnect();
public abstract double GetAIValue(string ioiP,int index);
}
}
using Asa.IOModule;
using OnlineStore.Common;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
namespace OnlineStore.DeviceLibrary
{
public class AIOAIManager:AIManager
{
private object AILock = "";
private List<int> AIValList = null;
private int AILength = 4;
private Asa.IOModule.AIOBOX AIBox = null;
private System.Timers.Timer conTimer = null;
private List<string> needConIp = new List<string>();
public override void StartConnect(params string[] ipList)
{
if (conTimer == null)
{
conTimer = new System.Timers.Timer();
conTimer.AutoReset = true;
conTimer.Interval = 60000;
conTimer.Elapsed += ConTimer_Elapsed;
}
conTimer.Enabled = false;
needConIp = new List<string>(ipList);
foreach (string ip in ipList)
{
bool result = ConnectionIP(ip);
}
if (needConIp.Count > 0)
{
//启动定时器,1一分钟重连一次
conTimer.Start();
}
}
private bool ConnectionIP(string ioIp)
{
int autoMS = 150;
try
{
AIValList = new List<int>();
AIBox = new Asa.IOModule.AIOBOX();
AIBox.IP = ioIp;
// bool rtn = AIBox.AutoIP(ioIp);
AIBox.SetInput(Asa.IOModule.Box_Type.AI, AILength);
AIBox.SetOutput(Asa.IOModule.Box_Type.DO, 0);
AIBox.AutoReadInput(true, autoMS);
AIBox.AI_Changed_Event += Box_AI_Changed_Event;
LogUtil.debug("开始连接AI模块[" + ioIp + "][" + autoMS + "],尝试重连三次");
for (int i = 1; i <= 3; i++)
{
bool result = AIBox.Connect();
if (result)
{
if (needConIp.Contains(ioIp))
{
needConIp.Remove(ioIp);
}
LogUtil.info("第【" + i + "】次连接IO模块[" + ioIp + "][" + autoMS + "]成功:" + AIBox.ErrInfo);
return true;
}
else
{
LogUtil.error("第【" + i + "】次连接IO模块[" + ioIp + "][" + autoMS + "]失败:" + AIBox.ErrInfo + "");
}
Thread.Sleep(10);
}
}
catch (Exception error)
{
LogUtil.error("连接IO模块[" + ioIp + "][" + autoMS + "]出错:" + error.ToString());
}
return false;
}
private void ConTimer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
{
try
{
List<string> list = new List<string>(needConIp);
if (list.Count > 0)
{
foreach (string ip in list)
{
LogUtil.info("重连AOI AI 模块 :" + ip);
ConnectionIP(ip);
}
}
}
catch (Exception ex)
{
LogUtil.error("AOI AI ConTimer_Elapsed 出错: " + ex.ToString());
}
}
public override void CloseConnect()
{
try
{
if (AIBox != null)
{
AIBox.Close();
}
}
catch (Exception ex)
{
LogUtil.error("断开AI连接出错:" + ex.ToString());
}
}
private void Box_AI_Changed_Event(AIOBOX box, int[] val)
{
try
{
if (val != null && val.Length >= AILength)
{
lock (AILock)
{
AIValList = new List<int>();
AIValList.AddRange(val);
}
}
}
catch (Exception ex)
{
LogUtil.error("Box_AI_Changed_Event出错:" + ex.ToString());
}
}
public override double GetAIValue(string ioiP,int index)
{
if (AIValList != null && AIValList.Count > index)
{
return AIValList[index];
}
return -1;
}
//public override double ConvertAI(double aiValue, double defaultValue)
//{
// double xishu = (double)ConfigAppSettings.GetNumValue(Setting_Init.AI_ConvertPosition);
// double result = Math.Round((aiValue - defaultValue) / xishu, 2);
// return result;
//}
}
}
...@@ -27,6 +27,52 @@ namespace OnlineStore.DeviceLibrary ...@@ -27,6 +27,52 @@ namespace OnlineStore.DeviceLibrary
private object DILock = ""; private object DILock = "";
private object DOLock = ""; private object DOLock = "";
private List<string> IoIPLIst = new List<string>();
private System.Timers.Timer conTimer = null;
public override void ConnectionIOList(List<string> DIONameList)
{
if (conTimer == null)
{
conTimer = new System.Timers.Timer();
conTimer.AutoReset = true;
conTimer.Interval = 60000;
conTimer.Elapsed += ConTimer_Elapsed;
}
conTimer.Enabled = false;
IoIPLIst = new List<string>(DIONameList);
foreach (string ip in DIONameList)
{
ConnectionIP(ip);
}
if (IoIPLIst.Count > 0)
{
//启动定时器,1一分钟重连一次
conTimer.Start();
}
}
private void ConTimer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
{
try
{
List<string> list = new List<string>(IoIPLIst);
if (list.Count > 0)
{
foreach (string ip in list)
{
LogUtil.info("重连AOI :" + ip);
ConnectionIP(ip);
}
}
}
catch (Exception ex)
{
LogUtil.error("AOI ConTimer_Elapsed 出错: " + ex.ToString());
}
}
public void ConnectionIP(string ioIp) public void ConnectionIP(string ioIp)
{ {
AIOBOX aioBox = null; AIOBOX aioBox = null;
...@@ -49,11 +95,6 @@ namespace OnlineStore.DeviceLibrary ...@@ -49,11 +95,6 @@ namespace OnlineStore.DeviceLibrary
{ {
DOValueMap.Remove(ioIp); DOValueMap.Remove(ioIp);
} }
try
{
// Create new modbus master and add event functions
aioBox = new AIOBOX();
aioBox.IP = ioIp;
int DIMS = ConfigAppSettings.GetIntValue("DIMS"); int DIMS = ConfigAppSettings.GetIntValue("DIMS");
if (DIMS < 20) if (DIMS < 20)
{ {
...@@ -64,9 +105,17 @@ namespace OnlineStore.DeviceLibrary ...@@ -64,9 +105,17 @@ namespace OnlineStore.DeviceLibrary
{ {
DOMS = 200; DOMS = 200;
} }
// bool rtn = aioBox.AutoIP(ioIp);
int DILength = StoreManager.Config.GetDILength(ioIp); int DILength = StoreManager.Config.GetDILength(ioIp);
int DOLength = StoreManager.Config.GetDOLength(ioIp); int DOLength = StoreManager.Config.GetDOLength(ioIp);
string logName = "IO模块[" + ioIp + "] DI[" + DILength + "] DO[" + DOLength + "],[" + DIMS + "] [" + DOMS + "]";
try
{
// Create new modbus master and add event functions
aioBox = new AIOBOX();
aioBox.IP = ioIp;
// bool rtn = aioBox.AutoIP(ioIp);
aioBox.SetInput(Asa.IOModule.Box_Type.DI, DILength); aioBox.SetInput(Asa.IOModule.Box_Type.DI, DILength);
aioBox.SetOutput(Asa.IOModule.Box_Type.DO, DOLength); aioBox.SetOutput(Asa.IOModule.Box_Type.DO, DOLength);
aioBox.AutoReadInput(true, DIMS); aioBox.AutoReadInput(true, DIMS);
...@@ -78,29 +127,34 @@ namespace OnlineStore.DeviceLibrary ...@@ -78,29 +127,34 @@ namespace OnlineStore.DeviceLibrary
// aioBox.Log_Out_Event += AioBox_Log_Out_Event; // aioBox.Log_Out_Event += AioBox_Log_Out_Event;
//aioBox.Log_RxTx_Event += AioBox_Log_RxTx_Event; //aioBox.Log_RxTx_Event += AioBox_Log_RxTx_Event;
AIOMap.Add(ioIp, aioBox); AIOMap.Add(ioIp, aioBox);
LogUtil.info("开始连接IO模块[" + ioIp + "][" + DIMS + "][" + DOMS + "],尝试重连三次");
LogUtil.debug("开始连接" + logName + ",尝试重连5次");
for (int i = 1; i <= 3; i++) for (int i = 1; i <= 3; i++)
{ {
bool result = aioBox.Connect(); bool result = aioBox.Connect();
if (result) if (result)
{ {
LogUtil.info("第【" + i + "】次连接IO模块【" + ioIp + "】成功:" + aioBox.ErrInfo); LogUtil.info("第【" + i + "】次连接 " + logName + " 成功:" + aioBox.ErrInfo);
Thread.Sleep(10); Thread.Sleep(10);
//读取所有的DO //读取所有的DO
ReadAllDI(ioIp, 0); ReadAllDI(ioIp, 0);
if (IoIPLIst.Contains(ioIp))
{
IoIPLIst.Remove(ioIp);
}
break; break;
} }
else else
{ {
LogUtil.error("第【" + i + "】次连接IO模块【" + ioIp + "】失败:" + aioBox.ErrInfo + ""); LogUtil.error("第【" + i + "】次连接 " + logName + " 失败:" + aioBox.ErrInfo + "");
} }
Thread.Sleep(10); Thread.Sleep(2);
} }
} }
catch (Exception error) catch (Exception error)
{ {
LogUtil.error(LOGGER, "连接IO模块[" + ioIp + "]出错:" + error.ToString()); LogUtil.error(LOGGER, "连接IO模块 " + logName + " 出错:" + error.ToString());
} }
} }
...@@ -123,7 +177,7 @@ namespace OnlineStore.DeviceLibrary ...@@ -123,7 +177,7 @@ namespace OnlineStore.DeviceLibrary
{ {
foreach (string str in s) foreach (string str in s)
{ {
LogUtil.AIOLog.Debug("[" + box.IP + "]" + str); // LogUtil.AIOLog.Debug("[" + box.IP + "]" + str);
} }
} }
...@@ -155,6 +209,7 @@ namespace OnlineStore.DeviceLibrary ...@@ -155,6 +209,7 @@ namespace OnlineStore.DeviceLibrary
{ {
if (sta != null && sta.Length >= StoreManager.Config.GetDILength(ip)) if (sta != null && sta.Length >= StoreManager.Config.GetDILength(ip))
{ {
string updateDi = "[" + ip + "]:";
bool needUpdate = false; bool needUpdate = false;
List<Box_Sta> newList = new List<Box_Sta>(); List<Box_Sta> newList = new List<Box_Sta>();
newList.AddRange(sta); newList.AddRange(sta);
...@@ -166,6 +221,14 @@ namespace OnlineStore.DeviceLibrary ...@@ -166,6 +221,14 @@ namespace OnlineStore.DeviceLibrary
} }
else else
{ {
//foreach(Box_Sta s in sta)
//{
// updateDi += s.ToString() + ",";
//}
//if (ip.Equals("192.168.201.61"))
//{
// LogUtil.info(updateDi);
//}
for (int i = 0; i < newList.Count; i++) for (int i = 0; i < newList.Count; i++)
{ {
if (!(oldList[i].Equals(newList[i]))) if (!(oldList[i].Equals(newList[i])))
...@@ -245,13 +308,6 @@ namespace OnlineStore.DeviceLibrary ...@@ -245,13 +308,6 @@ namespace OnlineStore.DeviceLibrary
} }
public override void ConnectionIOList(List<string> DIONameList)
{
foreach (string ip in DIONameList)
{
ConnectionIP(ip);
}
}
//关闭所有的DO //关闭所有的DO
public override void CloseAllDO() public override void CloseAllDO()
...@@ -451,11 +507,11 @@ namespace OnlineStore.DeviceLibrary ...@@ -451,11 +507,11 @@ namespace OnlineStore.DeviceLibrary
{ {
if (configIO.ProType.Equals(ConfigItemType.DI)) if (configIO.ProType.Equals(ConfigItemType.DI))
{ {
return GetDIValue(configIO.IO_IP, configIO.SlaveID, configIO.GetIOAddr()); return GetDIValue(configIO.DeviceName, configIO.SlaveID, configIO.GetIOAddr());
} }
else if (configIO.ProType.Equals(ConfigItemType.DO)) else if (configIO.ProType.Equals(ConfigItemType.DO))
{ {
return GetDOValue(configIO.IO_IP, configIO.SlaveID, configIO.GetIOAddr()); return GetDOValue(configIO.DeviceName, configIO.SlaveID, configIO.GetIOAddr());
} }
} }
catch (Exception ex) catch (Exception ex)
......
...@@ -15,22 +15,21 @@ namespace OnlineStore.DeviceLibrary ...@@ -15,22 +15,21 @@ namespace OnlineStore.DeviceLibrary
/// <summary> /// <summary>
/// 康奈德IO控制模块 /// 康奈德IO控制模块
/// </summary> /// </summary>
public class KNDAIManager public class KNDAIManager : AIManager
{ {
public static ushort DefaultAILength = 8; public ushort DefaultAILength = 8;
public static byte DefualtSlaveID = 255; public byte DefualtSlaveID = 255;
private static string AIStartAddress = "0258"; private string AIStartAddress = "0258";
public static readonly ILog LOGGER = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); public Dictionary<string, AITcpClient> mastMap = new Dictionary<string, AITcpClient>();
public static Dictionary<string, AITcpClient> mastMap = new Dictionary<string, AITcpClient>(); public Dictionary<string, List<KNDAI>> AIValueMap = new Dictionary<string, List<KNDAI>>();
public static Dictionary<string, List<KNDAI>> AIValueMap = new Dictionary<string, List<KNDAI>>(); private object AIMapLock = "";
private static object AIMapLock = "";
public static System.Timers.Timer timer = null; public System.Timers.Timer timer = null;
private static ushort port = 502; private ushort port = 502;
//public static bool IsNeedReadAI = true; //public static bool IsNeedReadAI = true;
public static void ConnectionIP(string ioIp) public override void StartConnect(params string[] ioIps)
{ {
if (timer == null) if (timer == null)
{ {
...@@ -41,6 +40,8 @@ namespace OnlineStore.DeviceLibrary ...@@ -41,6 +40,8 @@ namespace OnlineStore.DeviceLibrary
timer.Enabled = true; timer.Enabled = true;
} }
AITcpClient MBmaster = null; AITcpClient MBmaster = null;
foreach (string ioIp in ioIps)
{
if (mastMap.ContainsKey(ioIp)) if (mastMap.ContainsKey(ioIp))
{ {
MBmaster = mastMap[ioIp]; MBmaster = mastMap[ioIp];
...@@ -68,19 +69,21 @@ namespace OnlineStore.DeviceLibrary ...@@ -68,19 +69,21 @@ namespace OnlineStore.DeviceLibrary
MBmaster.OnException += new AITcpClient.ExceptionData(MBmaster_OnException); MBmaster.OnException += new AITcpClient.ExceptionData(MBmaster_OnException);
MBmaster.autoConnectOfBreak = false; MBmaster.autoConnectOfBreak = false;
mastMap.Add(ioIp, MBmaster); mastMap.Add(ioIp, MBmaster);
LogUtil.info(LOGGER, "连接AI模块[" + ioIp + "]成功"); LogUtil.info("连接AI模块[" + ioIp + "]成功");
Thread.Sleep(10); Thread.Sleep(10);
WriteAIScope(ioIp, 1); WriteAIScope(ioIp, 1);
Thread.Sleep(10); Thread.Sleep(10);
ReadAll(ioIp); ReadAll(ioIp);
} }
catch (Exception error) catch (Exception error)
{ {
LogUtil.error(LOGGER, "连接AI模块[" + ioIp + "]出错:" + error.ToString()); LogUtil.error("连接AI模块[" + ioIp + "]出错:" + error.ToString());
}
} }
} }
private static void ReadAll(string ioIp) private void ReadAll(string ioIp)
{ {
//读取所有的DO //读取所有的DO
ReadMultipleAI(ioIp, DefualtSlaveID, AIStartAddress, DefaultAILength); ReadMultipleAI(ioIp, DefualtSlaveID, AIStartAddress, DefaultAILength);
...@@ -89,7 +92,7 @@ namespace OnlineStore.DeviceLibrary ...@@ -89,7 +92,7 @@ namespace OnlineStore.DeviceLibrary
/// <summary> /// <summary>
/// 判断Io模块是否连接 /// 判断Io模块是否连接
/// </summary> /// </summary>
public static bool IsConnection(string ip) public bool IsConnection(string ip)
{ {
try try
{ {
...@@ -110,14 +113,14 @@ namespace OnlineStore.DeviceLibrary ...@@ -110,14 +113,14 @@ namespace OnlineStore.DeviceLibrary
} }
catch (Exception ex) catch (Exception ex)
{ {
LogUtil.error(LOGGER, "出错啦:" + ex.ToString()); LogUtil.error("出错啦:" + ex.ToString());
} }
return false; return false;
} }
private static DateTime PreCheckTime = DateTime.Now; private DateTime PreCheckTime = DateTime.Now;
private static bool isProcess = false; private bool isProcess = false;
public static bool NeedShow = false;
private static void timer_Elapsed(object sender, System.Timers.ElapsedEventArgs e) private void timer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
{ {
if (isProcess) if (isProcess)
{ {
...@@ -145,26 +148,26 @@ namespace OnlineStore.DeviceLibrary ...@@ -145,26 +148,26 @@ namespace OnlineStore.DeviceLibrary
} }
else if (span.TotalSeconds > 3) else if (span.TotalSeconds > 3)
{ {
LogUtil.error(LOGGER, "AI模块" + IP + "当前没有连上,重连" + IP); LogUtil.error("AI模块" + IP + "当前没有连上,重连" + IP);
ConnectionIP(IP); StartConnect(IP);
PreCheckTime = DateTime.Now; PreCheckTime = DateTime.Now;
} }
} }
} }
catch (Exception ex) catch (Exception ex)
{ {
LogUtil.error(LOGGER, "出错啦:" + ex.ToString()); LogUtil.error("出错啦:" + ex.ToString());
} }
Thread.Sleep(2); Thread.Sleep(2);
isProcess = false; isProcess = false;
} }
private static void WriteAIScope(string ioIp, int value) private void WriteAIScope(string ioIp, int value)
{ {
// 0 表示 0 - 10V, 1 表示 0 - 5V // 0 表示 0 - 10V, 1 表示 0 - 5V
WriteAIScope(ioIp, DefualtSlaveID, "03EA", value); WriteAIScope(ioIp, DefualtSlaveID, "03EA", value);
} }
private static void WriteAIScope(string ioIp, byte slaveId, string Adress, int value) private void WriteAIScope(string ioIp, byte slaveId, string Adress, int value)
{ {
// 写 AI 模块采样范围,可以往寄存器里面写入 0 或 1。 0 表示 0 - 10V, 1 表示 0 - 5V。默 // 写 AI 模块采样范围,可以往寄存器里面写入 0 或 1。 0 表示 0 - 10V, 1 表示 0 - 5V。默
//认 0,写 AI 模块采样范围为 0 - 5V //认 0,写 AI 模块采样范围为 0 - 5V
...@@ -177,10 +180,10 @@ namespace OnlineStore.DeviceLibrary ...@@ -177,10 +180,10 @@ namespace OnlineStore.DeviceLibrary
} }
else else
{ {
LogUtil.error(LOGGER, "WriteAIScope出错没有连接AI模块:" + ioIp); LogUtil.error("WriteAIScope出错没有连接AI模块:" + ioIp);
} }
} }
private static void ReadMultipleAI(string ioIp, byte slaveId, string StartAddress, int length) private void ReadMultipleAI(string ioIp, byte slaveId, string StartAddress, int length)
{ {
ushort ID = 1; ushort ID = 1;
AITcpClient MBmaster = null; AITcpClient MBmaster = null;
...@@ -191,10 +194,10 @@ namespace OnlineStore.DeviceLibrary ...@@ -191,10 +194,10 @@ namespace OnlineStore.DeviceLibrary
} }
else else
{ {
LogUtil.error(LOGGER, "ReadMultipleAI出错没有连接AI模块:" + ioIp); LogUtil.error("ReadMultipleAI出错没有连接AI模块:" + ioIp);
} }
} }
public static void CloseAllConnection() public override void CloseConnect()
{ {
List<AITcpClient> list = new List<AITcpClient>(); List<AITcpClient> list = new List<AITcpClient>();
foreach (AITcpClient tcp in list) foreach (AITcpClient tcp in list)
...@@ -203,20 +206,14 @@ namespace OnlineStore.DeviceLibrary ...@@ -203,20 +206,14 @@ namespace OnlineStore.DeviceLibrary
} }
mastMap.Clear(); mastMap.Clear();
} }
public static double ConvertAI(double aiValue, double defaultValue)
{ public override double GetAIValue(string ioiP, int index)
double xishu = (double)ConfigAppSettings.GetNumValue(Setting_Init.AI_ConvertPosition);
double result = Math.Round((aiValue - defaultValue) / xishu, 2);
return result;
}
public static double GetAIValue(string ioiP, int index)
{ {
double aiValue = GetAIValue(ioiP, DefualtSlaveID, index - 1); double aiValue = GetAIValue(ioiP, DefualtSlaveID, index - 1);
return Math.Round(aiValue, 2); return Math.Round(aiValue, 2);
} }
public static double GetAIValue(string ioIP, byte slaveId, int index) public double GetAIValue(string ioIP, byte slaveId, int index)
{ {
double value = 0; double value = 0;
try try
...@@ -240,7 +237,7 @@ namespace OnlineStore.DeviceLibrary ...@@ -240,7 +237,7 @@ namespace OnlineStore.DeviceLibrary
} }
return value; return value;
} }
private static void ClearAIData(string ioIp) private void ClearAIData(string ioIp)
{ {
byte[] datas = new byte[32]; byte[] datas = new byte[32];
for (int i = 0; i < datas.Length; i++) for (int i = 0; i < datas.Length; i++)
...@@ -249,7 +246,7 @@ namespace OnlineStore.DeviceLibrary ...@@ -249,7 +246,7 @@ namespace OnlineStore.DeviceLibrary
} }
SaveAIData(ioIp, 3, datas); SaveAIData(ioIp, 3, datas);
} }
private static void SaveAIData(string ioIp, ushort ID, byte[] values) private void SaveAIData(string ioIp, ushort ID, byte[] values)
{ {
try try
{ {
...@@ -322,18 +319,18 @@ namespace OnlineStore.DeviceLibrary ...@@ -322,18 +319,18 @@ namespace OnlineStore.DeviceLibrary
} }
catch (Exception ex) catch (Exception ex)
{ {
LogUtil.error(LOGGER, "SaveAIData出错:" + ex.ToString()); LogUtil.error("SaveAIData出错:" + ex.ToString());
} }
} }
private static float BitToFloat(string hexString) private float BitToFloat(string hexString)
{ {
uint num = uint.Parse(hexString, System.Globalization.NumberStyles.AllowHexSpecifier); uint num = uint.Parse(hexString, System.Globalization.NumberStyles.AllowHexSpecifier);
byte[] floatVals = BitConverter.GetBytes(num); byte[] floatVals = BitConverter.GetBytes(num);
float f = BitConverter.ToSingle(floatVals, 0); float f = BitConverter.ToSingle(floatVals, 0);
return f; return f;
} }
private static void MBmaster_OnResponseData(string ioIp, ushort ID, byte function, byte[] values, byte[] reviceData) private void MBmaster_OnResponseData(string ioIp, ushort ID, byte function, byte[] values, byte[] reviceData)
{ {
try try
{ {
...@@ -394,10 +391,10 @@ namespace OnlineStore.DeviceLibrary ...@@ -394,10 +391,10 @@ namespace OnlineStore.DeviceLibrary
} }
catch (Exception ex) catch (Exception ex)
{ {
LogUtil.error(LOGGER, "处理接受数据出错:" + ex.ToString()); LogUtil.error("处理接受数据出错:" + ex.ToString());
} }
} }
private static void MBmaster_OnException(string ioIp, ushort id, byte function, byte exception, byte[] reviceData) private void MBmaster_OnException(string ioIp, ushort id, byte function, byte exception, byte[] reviceData)
{ {
string exc = "Modbus says error: "; string exc = "Modbus says error: ";
switch (exception) switch (exception)
...@@ -415,7 +412,7 @@ namespace OnlineStore.DeviceLibrary ...@@ -415,7 +412,7 @@ namespace OnlineStore.DeviceLibrary
default: default:
break; break;
} }
LOGGER.Error("接收数据出错:" + exc); LogUtil.error("接收数据出错:" + exc);
} }
} }
......
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!