Commit a1225610 几米阳光

添加康奈德AI模块代码

1 个父辈 d7299a86
......@@ -1178,6 +1178,7 @@ namespace OnlineStore.ACSingleStore
KNDManager.CloseAllDO();
StoreOpenStatus(false);
KNDManager.CloseAllConnection();
KNDAIManager.CloseAllConnection();
//WCFControl.CloseWCF();
System.Environment.Exit(System.Environment.ExitCode);
}
......
......@@ -60,6 +60,8 @@
<Compile Include="acSingleStore\AC_SA_BoxBean_Partial.cs" />
<Compile Include="acSingleStore\ACStoreManager.cs" />
<Compile Include="halcon\HDevelopExport.cs" />
<Compile Include="KangNaiDe\AITcpClient.cs" />
<Compile Include="KangNaiDe\KNDAIManager.cs" />
<Compile Include="KangNaiDe\KNDManager.cs" />
<Compile Include="KangNaiDe\MasterTcpClient.cs" />
<Compile Include="PanasonicServo\ACCMDManager.cs" />
......
using System;
using System.Collections;
using System.Text;
using System.IO;
using System.Net;
using System.Net.Sockets;
using System.Threading;
using System.Diagnostics;
using log4net;
using System.Reflection;
using OnlineStore.Common;
namespace OnlineStore.DeviceLibrary
{
public class AITcpClient
{
public static readonly ILog LOGGER = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
// ------------------------------------------------------------------------
// Constants for access
private const byte fctReadCoil = 1;
private const byte fctReadDiscreteInputs = 2;
private const byte fctReadHoldingRegister = 3;
private const byte fctReadInputRegister = 4;
private const byte fctWriteSingleCoil = 5;
private const byte fctWriteSingleRegister = 6;
private const byte fctWriteMultipleCoils = 15;
private const byte fctWriteMultipleRegister = 16;
private const byte fctReadWriteMultipleRegister = 23;
/// <summary>Constant for exception illegal function.</summary>
public const byte excIllegalFunction = 1;
/// <summary>Constant for exception illegal data address.</summary>
public const byte excIllegalDataAdr = 2;
/// <summary>Constant for exception illegal data value.</summary>
public const byte excIllegalDataVal = 3;
/// <summary>Constant for exception slave device failure.</summary>
public const byte excSlaveDeviceFailure = 4;
/// <summary>Constant for exception acknowledge.</summary>
public const byte excAck = 5;
/// <summary>Constant for exception slave is busy/booting up.</summary>
public const byte excSlaveIsBusy = 6;
/// <summary>Constant for exception gate path unavailable.</summary>
public const byte excGatePathUnavailable = 10;
/// <summary>Constant for exception not connected.</summary>
public const byte excExceptionNotConnected = 253;
/// <summary>Constant for exception connection lost.</summary>
public const byte excExceptionConnectionLost = 254;
/// <summary>Constant for exception response timeout.</summary>
public const byte excExceptionTimeout = 255;
/// <summary>Constant for exception wrong offset.</summary>
private const byte excExceptionOffset = 128;
/// <summary>Constant for exception send failt.</summary>
private const byte excSendFailt = 100;
// ------------------------------------------------------------------------
// Private declarations
private static ushort _timeout = 500;
private static ushort _refresh = 10;
private static bool _connected = false;
private static bool _autoConnectOfBreak = false;
private Socket socketClient;
private int M281_A_Len = 0;
private byte[] tcpSocketReviceBuffer = new byte[2048];
//private Socket tcpSynCl;
//private byte[] tcpSynClBuffer = new byte[2048];
// ------------------------------------------------------------------------
/// <summary>Response data event. This event is called when new data arrives</summary>
public delegate void ResponseData(string ip, ushort id, byte function, byte[] data,byte[] reviceData);
/// <summary>Response data event. This event is called when new data arrives</summary>
public event ResponseData OnResponseData;
/// <summary>Exception data event. This event is called when the data is incorrect</summary>
public delegate void ExceptionData(string ip, ushort id, byte function, byte exception, byte[] reviceData);
/// <summary>Exception data event. This event is called when the data is incorrect</summary>
public event ExceptionData OnException;
/// <summary>
/// autoConnectOfBreak
/// </summary>
public bool autoConnectOfBreak
{
get { return _autoConnectOfBreak; }
set { _autoConnectOfBreak = value; }
}
public static ushort timeout
{
get { return _timeout; }
set { _timeout = value; }
}
public ushort refresh
{
get { return _refresh; }
set { _refresh = value; }
}
public bool connected
{
get { return _connected; }
}
public AITcpClient()
{
}
public string IP = "";
public int Port = 0;
public int TimeOutTime = 0;
public AITcpClient(string ip, ushort port)
{
TimeOutTime = 2000;
connect(ip, port);
}
private System.Timers.Timer reviceTimer = new System.Timers.Timer();
public void connect(string ip, ushort port)
{
try
{
this.IP = ip;
this.Port = port;
OnResponseData = null;
// Connect asynchronous client
socketClient = new Socket(IPAddress.Parse(ip).AddressFamily, SocketType.Stream, ProtocolType.Tcp);
if (TimeOutTime <= 0)
{
socketClient.Connect(new IPEndPoint(IPAddress.Parse(ip), port));
socketClient.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.SendTimeout, _timeout);
socketClient.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReceiveTimeout, _timeout);
socketClient.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.NoDelay, 1);
}
else
{
socketClient.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.SendTimeout, _timeout);
socketClient.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReceiveTimeout, _timeout);
socketClient.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.NoDelay, 1);
IAsyncResult connResult = socketClient.BeginConnect(ip, port, null, null);
connResult.AsyncWaitHandle.WaitOne(this.TimeOutTime, true); //等待2秒
if (!connResult.IsCompleted)
{
LogUtil.info(LOGGER, "Connect to " + ip + ":" + port + " fail!");
return;
}
else
{
_connected = true;
LogUtil.info(LOGGER, "Connect to " + ip + ":" + port + " success!");
}
}
//Thread threadReceive = new Thread(new ThreadStart(ReceiveHandle));
//threadReceive.Start();
reviceTimer.AutoReset = true;
reviceTimer.Elapsed += reviceTimer_Elapsed;
reviceTimer.Interval = 130;
reviceTimer.Enabled = true;
_connected = true;
}
catch (Exception error)
{
LogUtil.info(LOGGER, "Connect to " + ip + ":" + port + " fail!");
_connected = false;
}
}
public void WriteAIScope(ushort id, byte slaveId, string address, int value)
{
//0x000100000006FF0603EA0001
byte function = 0x06;
byte[] data = new byte[12];
byte[] _id = BitConverter.GetBytes((short)id);
data[0] = _id[0]; // Slave id high byte
data[1] = _id[1]; // Slave id low byte
data[2] = 0x00;
data[3] = 0x00;
data[4] = 0x00;
data[5] = 6; // Message size
data[6] = slaveId; // Slave address //必须设置为"1": 2012.04-24 覃发光;
data[7] = function; ; // Function code
byte[] _adr = SerialBean.StringToByte(address);
data[8] = _adr[0]; // Start address
data[9] = _adr[1]; // Start address
byte[] _length = BitConverter.GetBytes((short)1);
data[10] = _length[0]; // Number of data to read
data[11] = _length[1]; // Number of data to read
WriteAsyncData( data,id);
}
public void ReadAllAI(ushort id, string startAddress, int length, byte slaveId)
{
//0x 000100000006FF0302580010
byte function = 0x03;
byte[] data = CreateData(id, startAddress,(ushort) length, function, slaveId);
WriteAsyncData(data, id);
}
private byte[] CreateData(ushort id, string startAddress, ushort length, byte function, byte SlaveID)
{
byte[] data = new byte[12];
byte[] _id = BitConverter.GetBytes((short)id);
data[0] = _id[0]; // Slave id high byte
data[1] = _id[1]; // Slave id low byte
data[5] = 6; // Message size
data[6] = SlaveID; // Slave address //必须设置为"1": 2012.04-24 覃发光;
data[7] = function; // Function code
byte[] _adr = SerialBean.StringToByte(startAddress);
if (_adr.Length .Equals( 2))
{
data[8] = _adr[0]; // Start address
data[9] = _adr[1]; // Start address
}else if (_adr.Length.Equals(1))
{
data[8] = 0x00;
data[9] = _adr[0]; // Start address
}
else
{
data[8] = 0x00;
data[9] = 0x00;
}
byte[] _length = BitConverter.GetBytes((short)IPAddress.HostToNetworkOrder((short)length));
data[10] = _length[0]; // Number of data to read
data[11] = _length[1]; // Number of data to read
return data;
}
void reviceTimer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
{
try
{
ReviceDataProcess();
Thread.Sleep(10);
}
catch (Exception ex)
{
LOGGER.Error("出错:" + ex.ToString());
}
}
private void ReviceDataProcess()
{
int lengthIndex = 5;
byte[] rdata = Receive();
if (rdata != null)
{
string str = "";
foreach (byte by in rdata)
{
str = str + " " + by;
//if (str.Length > 200)
//{
// break;
//}
}
//这里rdata就是接收到的数据,
IPEndPoint clientipe = (IPEndPoint)socketClient.RemoteEndPoint;
//ushort id = BitConverter.ToUInt16(rdata, 0);
//byte function = rdata[7];
byte dataLength = rdata[lengthIndex];
int allLength = lengthIndex + 1 + dataLength;
if (rdata.Length > allLength)
{
//LogUtil.info(clientipe.ToString() + "收到数据(需要分包):" + str);
int currStartIndex = 0;
for (int i = 0; i < 100; i++)
{
try
{
if (rdata.Length < currStartIndex + lengthIndex)
{
LogUtil.error(clientipe.ToString() + "收到数据:" + str + "分包出错 [" + currStartIndex + "]");
}
dataLength = rdata[currStartIndex + lengthIndex];
allLength = lengthIndex + 1 + dataLength ;
byte[] thisData = new byte[allLength];
Array.Copy(rdata, currStartIndex, thisData, 0, allLength);
ushort id = BitConverter.ToUInt16(thisData, 0);
byte function = thisData[7];
DataProcess(clientipe.ToString(), id, function, thisData);
//剩余的数据处理
if (rdata.Length <= currStartIndex + allLength)
{
break;
}
currStartIndex = currStartIndex + allLength;
}
catch (Exception ex)
{
LogUtil.error(clientipe.ToString() + "收到数据:" + str + "分包出错 [" + currStartIndex + "]:" + ex.ToString());
}
}
}
else
{
LogUtil.debug(LOGGER, clientipe.ToString() + "收到数据(无需分包):" + str);
ushort id = BitConverter.ToUInt16(rdata, 0);
byte function = rdata[7];
DataProcess(clientipe.ToString(),id,function,rdata);
}
}
}
private void DataProcess(string clientIp, ushort id, byte function, byte[] rdata)
{
byte[] data;
if ((function >= fctWriteSingleCoil) && (function != fctReadWriteMultipleRegister))
{
data = new byte[2];
Array.Copy(rdata, 10, data, 0, 2);
}
// ------------------------------------------------------------
// Read response data
else
{
data = new byte[rdata[8]];
Array.Copy(rdata, 9, data, 0, rdata[8]);
}
// ------------------------------------------------------------
// Response data is slave exception
if (function > excExceptionOffset)
{
function -= excExceptionOffset;
CallException(id, function, rdata[8], rdata);
}
// ------------------------------------------------------------
// Response data is regular data
else if (OnResponseData != null)
{ //收到的数据打印出来
OnResponseData(clientIp, id, function, data, rdata);
}
}
private byte[] Receive()
{
try
{
if (socketClient == null || !socketClient.Connected || socketClient.Available < 1)
{
return null;
}
int size = socketClient.Available;
byte[] rData = new byte[size];
socketClient.Receive(rData, size, SocketFlags.None);
return rData;
}
catch (SocketException e)
{
if (socketClient != null)
{
socketClient.Close();
socketClient = null;
}
return null;
}
}
public void disconnect()
{
Dispose();
}
~AITcpClient()
{
Dispose();
}
public void Dispose()
{
reviceTimer.Enabled = false;
if (socketClient != null)
{
if (socketClient.Connected)
{
try { socketClient.Shutdown(SocketShutdown.Both); }
catch { }
socketClient.Close();
}
socketClient = null;
}
}
internal void CallException(ushort id, byte function, byte exception, byte[] rdata)
{
reviceTimer.Enabled = false;
if ((socketClient == null))
{
return;
}
if (exception == excExceptionConnectionLost)
{
//tcpSynCl = null;
socketClient = null;
return;
}
if (OnException != null)
{
OnException(socketClient.RemoteEndPoint.AddressFamily.ToString(), id, function, exception, rdata);
}
}
public void WriteAsyncData(byte[] write_data, ushort id)
{
try
{
if (socketClient == null)
{
LOGGER.Error("发送数据时发现socketClient=null");
return;
}
IPEndPoint clientipe = (IPEndPoint)socketClient.RemoteEndPoint;
if ((socketClient != null) && (socketClient.Connected))
{
try
{
//发送的数据打印出来
string str = "";
foreach (byte by in write_data)
{
str = str + " " + by;
}
//LogUtil.info( clientipe.ToString()+"发送数据:" + str);
socketClient.BeginSend(write_data, 0, write_data.Length, SocketFlags.None, new AsyncCallback(OnSend), null);
//socketClient.BeginReceive(tcpSocketReviceBuffer, 0, tcpSocketReviceBuffer.Length, SocketFlags.None, new AsyncCallback(OnReceive), socketClient);
ReviceDataProcess();
}
catch (SystemException error)
{
CallException(id, write_data[7], excExceptionConnectionLost, tcpSocketReviceBuffer);
}
}
else CallException(id, write_data[7], excExceptionConnectionLost, tcpSocketReviceBuffer);
}
catch (Exception ex)
{
LOGGER.Error("出错:"+ex.ToString());
}
}
// ------------------------------------------------------------------------
// Write asynchronous data acknowledge
private void OnSend(System.IAsyncResult result)
{
if (result.IsCompleted == false) CallException(0xFFFF, 0xFF, excSendFailt, tcpSocketReviceBuffer);
}
internal bool ISConnection()
{
if (socketClient == null)
{
return false;
}
if (socketClient.Connected == false)
{
return false;
}
return true;
}
}
}
using log4net;
using OnlineStore.Common;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading;
//using FuBaRobot.LoadCSVLibrary;
namespace OnlineStore.DeviceLibrary
{
/// <summary>
/// 康奈德IO控制模块
/// </summary>
public class KNDAIManager
{
public static ushort DefaultAILength = 8;
public static byte DefualtSlaveID = 255;
private static string AIStartAddress = "0258";
public static readonly ILog LOGGER = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
public static Dictionary<string, AITcpClient> mastMap = new Dictionary<string, AITcpClient>();
public static Dictionary<string, List<KNDAI>> AIValueMap = new Dictionary<string, List<KNDAI>>();
private static object AIMapLock = "";
public static System.Timers.Timer timer = null;
private static ushort port = 502;
public static bool IsNeedReadAI = true;
public static void ConnectionIP(string ioIp)
{
if (timer == null)
{
timer = new System.Timers.Timer();
timer.Interval = 100;
timer.AutoReset = true;
timer.Elapsed += timer_Elapsed;
timer.Enabled = true;
}
AITcpClient MBmaster = null;
if (mastMap.ContainsKey(ioIp))
{
MBmaster = mastMap[ioIp];
if (null != MBmaster)
{
MBmaster.disconnect();
MBmaster.Dispose();
MBmaster = null;
lock (AIMapLock)
{
if (AIValueMap.ContainsKey(ioIp))
{
AIValueMap.Remove(ioIp);
}
}
}
mastMap.Remove(ioIp);
}
try
{
// Create new modbus master and add event functions
MBmaster = new AITcpClient(ioIp, port);
MBmaster.OnResponseData += new AITcpClient.ResponseData(MBmaster_OnResponseData);
MBmaster.OnException += new AITcpClient.ExceptionData(MBmaster_OnException);
MBmaster.autoConnectOfBreak = false;
mastMap.Add(ioIp, MBmaster);
Thread.Sleep(10);
WriteAIScope(ioIp, 1);
Thread.Sleep(10);
ReadAll(ioIp);
LogUtil.info(LOGGER, "连接AI模块[" + ioIp + "]");
}
catch (Exception error)
{
LogUtil.error(LOGGER, "连接AI模块[" + ioIp + "]出错:" + error.ToString());
}
}
private static void ReadAll(string ioIp)
{
//读取所有的DO
ReadMultipleAI(ioIp, DefualtSlaveID, AIStartAddress, DefaultAILength);
}
/// <summary>
/// 判断Io模块是否连接
/// </summary>
public static bool IsConnection(string ip)
{
try
{
List<string> list = new List<string>(mastMap.Keys);
foreach (string io in list)
{
if (io.Equals(ip))
{
//判断是否连接,如果没有连接自动重连
AITcpClient clinet = mastMap[io];
if (clinet.ISConnection())
{
return true;
}
}
}
}
catch (Exception ex)
{
LogUtil.error(LOGGER, "出错啦:" + ex.ToString());
}
return false;
}
private static DateTime PreCheckTime = DateTime.Now;
private static bool isProcess = false;
private static void timer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
{
if (isProcess)
{
return;
}
try
{
isProcess = true;
TimeSpan span = DateTime.Now - PreCheckTime;
List<string> list = new List<string>(mastMap.Keys);
foreach (string io in list)
{
//判断是否连接,如果没有连接自动重连
AITcpClient clinet = mastMap[io];
if (span.TotalSeconds > 3)
{
if (clinet.ISConnection())
{
if (IsNeedReadAI)
{
ReadAll(clinet.IP);
}
}
else
{
ConnectionIP(io);
LogUtil.error(LOGGER, "AI模块" + io + "当前没有连上,重连" + io);
}
PreCheckTime = DateTime.Now;
}
else
{
if (clinet.ISConnection())
{
if (IsNeedReadAI)
{
ReadAll(clinet.IP);
}
}
}
}
PreCheckTime = DateTime.Now;
}
catch (Exception ex)
{
LogUtil.error(LOGGER, "出错啦:" + ex.ToString());
}
Thread.Sleep(1);
isProcess = false;
}
private static void WriteAIScope(string ioIp,int value)
{
// 0 表示 0 - 10V, 1 表示 0 - 5V
WriteAIScope(ioIp, DefualtSlaveID, "03EA", value);
}
private static void WriteAIScope(string ioIp, byte slaveId, string Adress, int value)
{
// 写 AI 模块采样范围,可以往寄存器里面写入 0 或 1。 0 表示 0 - 10V, 1 表示 0 - 5V。默
//认 0,写 AI 模块采样范围为 0 - 5V
ushort ID = 1;
AITcpClient MBmaster = null;
if (mastMap.ContainsKey(ioIp))
{
MBmaster = mastMap[ioIp];
MBmaster.WriteAIScope(ID, slaveId, Adress, value);
}
else
{
LogUtil.error(LOGGER, "WriteAIScope出错没有连接AI模块:" + ioIp);
}
}
private static void ReadMultipleAI(string ioIp, byte slaveId, string StartAddress, int length)
{
ushort ID = 1;
AITcpClient MBmaster = null;
if (mastMap.ContainsKey(ioIp))
{
MBmaster = mastMap[ioIp];
MBmaster.ReadAllAI(ID, StartAddress, length * 2, slaveId);
}
else
{
LogUtil.error(LOGGER, "ReadMultipleAI出错没有连接AI模块:" + ioIp);
}
}
public static void CloseAllConnection()
{
List<AITcpClient> list = new List<AITcpClient>();
foreach (AITcpClient tcp in list)
{
tcp.disconnect();
}
mastMap.Clear();
}
public static double GetAIValue(string ioiP, int index)
{
double aiValue = GetAIValue(ioiP, DefualtSlaveID, index);
return aiValue;
}
public static double GetAIValue(string ioIP, byte slaveId, int index)
{
double value = 0;
try
{
lock (AIMapLock)
{
if (AIValueMap.ContainsKey(ioIP))
{
List<KNDAI> allIo = new List<KNDAI>(AIValueMap[ioIP]);
List<KNDAI> list = (from m in allIo where m.SlaveId.Equals(slaveId) && m.AIIndex.Equals(index) select m).ToList<KNDAI>();
if (list.Count > 0)
{
value = list[0].AIValue;
}
}
}
}
catch (Exception ex)
{
LogUtil.error("GetAIValue 出错了 :ioIP[" + ioIP + "]index[" + index + "]:" + ex);
}
return value;
}
private static void SaveAIData(string ioIp, ushort ID, byte[] values)
{
try
{
if (values.Length.Equals(DefaultAILength * 4))
{
List<KNDAI> kndList = new List<KNDAI>();
string strFromat = "{0:X2}";
for (int index = 0; index < DefaultAILength; index++)
{
string str1 = String.Format(strFromat, values[index * 4 + 2]) + String.Format(strFromat, values[index * 4 + 3])
+ String.Format(strFromat, values[index * 4 + 1]) + String.Format(strFromat, values[index * 4]);
double value = BitToFloat(str1);
KNDAI io = new KNDAI(ioIp, (byte)DefualtSlaveID, index, value);
if (value > 0)
{
Console.WriteLine(str1 + " float convert = {0}", value);
}
kndList.Add(io);
}
lock (AIMapLock)
{
if (AIValueMap.ContainsKey(ioIp))
{
AIValueMap.Remove(ioIp);
}
AIValueMap.Add(ioIp, kndList);
}
}
}
catch (Exception ex)
{
LogUtil.error(LOGGER, "SaveAIData出错:" + ex.ToString());
}
}
private static float BitToFloat(string hexString)
{
uint num = uint.Parse(hexString, System.Globalization.NumberStyles.AllowHexSpecifier);
byte[] floatVals = BitConverter.GetBytes(num);
float f = BitConverter.ToSingle(floatVals, 0);
return f;
}
private static void MBmaster_OnResponseData(string ioIp, ushort ID, byte function, byte[] values, byte[] reviceData)
{
try
{
if (ioIp.IndexOf(":") > 0)
{
ioIp = ioIp.Substring(0, ioIp.IndexOf(":"));
}
string strFromat = "{0:X2}";
string reviceMsg = "";
foreach (byte data in reviceData)
{
reviceMsg = reviceMsg + " " + String.Format(strFromat, data);
if (reviceMsg.Length > 200)
{
break;
}
}
LOGGER.Info("Read data:【" + reviceMsg + "】 ");
if (ID == 0xFF)
{
return;
}
// ------------------------------------------------------------------------
// Identify requested data
ushort Func = ID;
if (Func == 0 && reviceData.Length > 8)
{
Func = reviceData[7];
}
byte SlaveId = 0xFF;
if (reviceData.Length >= 7)
{
SlaveId = reviceData[6];
}
switch (function)
{
case 1:
//LOGGER.Info("Read coils end:【" + reviceMsg + "】 ");
break;
case 2:
//LOGGER.Info("Read discrete inputs end:【" + reviceMsg + "】 ");
//SaveAIData(ioIp, SlaveId, values);
break;
case 3:
SaveAIData(ioIp, ID, values);
break;
case 4:
//LOGGER.Info("读入(多个)寄存器完成 end:【" + reviceMsg + "】 ");
break;
case 5:
//LOGGER.Info("Write single coil:【" + reviceMsg + "】 ");
break;
}
}
catch (Exception ex)
{
LogUtil.error(LOGGER, "处理接受数据出错:" + ex.ToString());
}
}
private static void MBmaster_OnException(string ioIp, ushort id, byte function, byte exception, byte[] reviceData)
{
string exc = "Modbus says error: ";
switch (exception)
{
case AITcpClient.excIllegalFunction: exc += "Illegal function!"; break;
case AITcpClient.excIllegalDataAdr: exc += "Illegal data adress!"; break;
case AITcpClient.excIllegalDataVal: exc += "Illegal data value!"; break;
case AITcpClient.excSlaveDeviceFailure: exc += "Slave device failure!"; break;
case AITcpClient.excAck: exc += "Acknoledge!"; break;
case AITcpClient.excSlaveIsBusy: exc += "Slave is busy!"; break;
case AITcpClient.excGatePathUnavailable: exc += "Gateway path unavailbale!"; break;
case AITcpClient.excExceptionTimeout: exc += "Slave timed out!"; break;
case AITcpClient.excExceptionConnectionLost: exc += "Connection is lost!"; break;
case AITcpClient.excExceptionNotConnected: exc += "Not connected!"; break;
default:
break;
}
LOGGER.Error("接收数据出错:" + exc);
}
}
public class KNDAI
{
public KNDAI(string ioIp, byte ID, int index, double value)
{
this.IoIP = ioIp;
this.SlaveId = ID;
this.AIIndex = index;
this.AIValue = value;
UpdateTime = DateTime.Now;
}
/// <summary>
/// AI模块IP
/// </summary>
public string IoIP { get; set; }
/// <summary>
/// 地址
/// </summary>
public byte SlaveId { get; set; }
/// <summary>
/// 第几个AI
/// </summary>
public int AIIndex { get; set; }
/// <summary>
/// 值
/// </summary>
public double AIValue { get; set; }
/// <summary>
/// 更新时间
/// </summary>
public DateTime UpdateTime { get; set; }
}
}
......@@ -145,11 +145,7 @@ namespace OnlineStore.DeviceLibrary
//端口号暂时使用固定的502;
ushort port = 502;
foreach (string ip in DIONameList)
{
//if (ip.Equals("192.168.10.10"))
//{
// continue;
//}
{
ConnectionIP(ip, port);
}
}
......
......@@ -34,9 +34,10 @@ DO,相机照明开,CameraLight_Power,110,192.168.200.10,0,相机照明开,Y11,DO-11,0,
AXIS,(轴一)旋转轴,Middle_Axis,1,COM3,0,,,,,
AXIS,(轴二)升降轴轴,UpDown_Axis,1,COM4,0,,,,,
AXIS,(轴三)进出轴,InOut_Axis,1,COM5,0,,,,,
PRO,温湿度传感器地址,Temperate_ServerAddress,192.168.200.14,,,,,,,
PRO,扫码枪IP,Scanner_Ip,192.168.200.13,,,,,,,
PRO,扫码枪端口号,Scanner_Port,51236,,,,,,,
PRO,模拟量IO模块的IP地址,AIDevice_IP,192.168.200.11,,,,,,,
,温湿度传感器地址,Temperate_ServerAddress,192.168.200.14,,,,,,,
,扫码枪IP,Scanner_Ip,192.168.200.13,,,,,,,
,扫码枪端口号,Scanner_Port,51236,,,,,,,
PRO,升降轴 进料口取料点 P1,UpDownAxis_DoorOPosition_P1,423300,,,,,,,
PRO,升降轴 进料口出料前点 P2,UpDownAxis_DoorIPosition_P2,450000,,,,,,,
PRO,升降轴 进料口取料缓冲点 P7,UpDownAxis_DoorOBPosition_P7,450000,,,,,,,
......@@ -45,11 +46,11 @@ PRO,旋转轴(轴1)P1 待机原位点,MiddleAxis_P1_Position,-200400,,,,,,,
PRO,进出轴(轴3)P1待机原位点,InOutAxis_P1_Position,500,,,,,,,
PRO,押金轴(轴4)P1待机原位点,CompressAxis_P1_Position,0,,,,,,,
PRO,是否使用定位气缸,IsHasLocationCylinder,0,,,,,,,
PRO,是否有左右侧门,IsHasDoorLimit,0,,,,,,,
PRO,是否有左右侧门,IsHasDoorLimit,1,,,,,,,
PRO,是否使用压紧轴(1=使用),IsHasCompress_Axis,1,,,,, ,,
PRO,设备是否处于调试状态(1=调试,0=正常),IsInDebug,0,,,,,,,
PRO,气压检测IO关闭需要持续的时间,AirCheckSeconds,3,,,,,,,
PRO,温湿度传感器地址,TemperateServer_Port,9001,,,,,,,
,温湿度传感器地址,TemperateServer_Port,9001,,,,,,,
PRO,预警温度,WarnTemperate,80,,,,,,,
PRO,预警湿度,WarnHumidity,80,,,,,,,
PRO,(轴一)旋转轴目标速度,MiddleAxis_TargetSpeed,40,,,,,,,
......
......@@ -89,7 +89,7 @@ namespace OnlineStore.DeviceLibrary
//初始化 //连接设备
KNDManager.ConnectionKND(Config.DIODeviceNameList);
KNDAIManager.ConnectionIP(Config.AIDevice_IP);
//scanSocket.OnScanRevice += onCodeReceived;
timersTimer.Enabled = false;
......
......@@ -60,12 +60,12 @@ namespace OnlineStore.LoadCSVLibrary
/// <summary>
/// PRO 扫码枪IP Scanner_Ip 192.168.200.13
/// </summary>
[ConfigProAttribute("Scanner_Ip")]
[ConfigProAttribute("Scanner_Ip",false)]
public string Scanner_Ip { get; set; }
/// <summary>
/// PRO 扫码枪端口号 Scanner_Port 51236
/// </summary>
[ConfigProAttribute("Scanner_Port")]
[ConfigProAttribute("Scanner_Port",false)]
public int Scanner_Port { get; set; }
/// <summary>
/// PRO (轴一)旋转轴原点目标速度 MiddleAxis_TargetSpeed 30000
......@@ -475,13 +475,20 @@ namespace OnlineStore.LoadCSVLibrary
[ConfigProAttribute("BlowAir_Interval", false)]
public int BlowAir_Interval { get; set; }
public int InoutAxis_PositionMax { get; set; }
/// <summary>
/// PRO,温湿度端口号,Humiture_Port,COM1,,,,,,,
/// </summary>
[ConfigProAttribute("Humiture_Port", true )]
public string Humiture_Port { get; set; }
public int InoutAxis_PositionMax { get; set; }
/// <summary>
/// PRO 模拟量IO模块的IP地址 AIDevice_IP 192.168.200.11
/// </summary>
[ConfigProAttribute("AIDevice_IP", true)]
public string AIDevice_IP { get; set; }
//private List<string> TempAddrList = null;
//public static char TempAddrSpilt = '#';
///// <summary>
......
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!