Commit e617e614 刘韬

添加项目文件。

1 个父辈 a8405a1d
正在显示 137 个修改的文件 包含 4889 行增加0 行删除
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{43CDD09E-FCF3-4960-A01D-3BBFE9933122}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>OnlineStore.Common</RootNamespace>
<AssemblyName>MyCommon</AssemblyName>
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<TargetFrameworkProfile />
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<ItemGroup>
<Reference Include="log4net, Version=2.0.8.0, Culture=neutral, PublicKeyToken=669e0ddf0bb1aa2a, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\增广夹爪\Rmaxis\bin\Debug\log4net.dll</HintPath>
</Reference>
<Reference Include="Newtonsoft.Json, Version=13.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>..\packages\Newtonsoft.Json.13.0.1\lib\net45\Newtonsoft.Json.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Configuration" />
<Reference Include="System.Core" />
<Reference Include="System.Drawing" />
<Reference Include="System.Windows.Forms" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="bean\Bean.cs" />
<Compile Include="CodeResourceControl.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Setting_Init.cs" />
<Compile Include="util\ConfigAppSettings.cs" />
<Compile Include="util\FormUtil.cs" />
<Compile Include="util\JsonHelper.cs" />
<Compile Include="util\LogUtil.cs" />
<Compile Include="util\MyWebClient.cs">
<SubType>Component</SubType>
</Compile>
<Compile Include="util\NetTCPServer.cs">
<SubType>Code</SubType>
</Compile>
<Compile Include="util\CTcpClient.cs" />
<Compile Include="util\TcpServer.cs" />
<Compile Include="util\UdpServer.cs" />
</ItemGroup>
<ItemGroup>
<WCFMetadata Include="Service References\" />
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>
\ No newline at end of file
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// 有关程序集的常规信息通过以下
// 特性集控制。更改这些特性值可修改
// 与程序集关联的信息。
[assembly: AssemblyTitle("Common")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("Common")]
[assembly: AssemblyCopyright("Copyright © 2016")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// 将 ComVisible 设置为 false 使此程序集中的类型
// 对 COM 组件不可见。如果需要从 COM 访问此程序集中的类型,
// 则将该类型上的 ComVisible 特性设置为 true。
[assembly: ComVisible(false)]
// 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID
[assembly: Guid("f8eab140-5f98-4df7-842c-0d866e759c9a")]
// 程序集的版本信息由下面四个值组成:
//
// 主版本
// 次版本
// 生成号
// 修订号
//
// 可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值,
// 方法是按如下所示使用“*”:
[assembly: AssemblyVersion("1.0.*")]
//[assembly: AssemblyVersion("1.0.0.0")]
//[assembly: AssemblyFileVersion("1.0.0.0")]
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace OnlineStore.Common
{
/// <summary>
/// 记录配置的key
/// </summary>
public class Setting_Init
{ /// <summary>
/// 系统启动时自动启动料仓,=1时自动启动,并隐藏窗口,=0时不需要
/// </summary>
public static string App_AutoRun = "App_AutoRun";
/// <summary>
/// 系统主界面标题
/// </summary>
public static string App_Title = "App_Title";
/// <summary>
/// 摄像机名称
/// </summary>
public static string CameraName = "CameraName";
public static string Config_Pwd = "Config_Pwd";
public static string UseBuzzer = "UseBuzzer";
/// <summary>
/// 检测到料串自动入料
/// </summary>
public static string AutoInput = "AutoInput";
/// <summary>
/// 进出轴待机点位,进出轴在此位置时,升降和旋转才可以走
/// </summary>
public static string InoutDefaultPosition = "InoutDefaultPosition";
public static string LabelName = "LabelName";
public static string PrinterName = "PrinterName";
public static string NeedPrintLabel = "NeedPrintLabel";
public static string StickingPosJudgment = "StickingPosJudgment";
public static string GratingSignal = " GratingSignal";
/// <summary>
/// 启用贴标功能
/// </summary>
public static string UseLabel = "UseLabel";
public static string CodeType = "CodeType";
public static string CodeParamPath = "CodeParamPath";
public static string QRCodeCount = "QRCodeCount";
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace OnlineStore.Common
{
public class LineGetPosOp
{
public LineGetPosOp(string cids,string code)
{
this.cids = cids;
this.code = code;
}
public string cids = "";
public string code = "";
}
public class LineOperation
{
// //{"result":"0","msg":"","pos":"11#AC1_18_4_28","barcode":"R506072019102200414","cid":"line-ac-11"}
// 返回: {"code": 0, "msg":"ok", data:7}
/// <summary>
/// 0=成功
/// </summary>
public int result;
public string cid;
public string msg = "";
public string pos = "";
public string barcode = "";
}
/// <summary>
/// 与服务器通信用对象
/// </summary>
public class Operation
{
/// <summary>
/// 料仓唯一标识,分号分割
/// </summary>
private string _cid = "";
public string cid
{
get { return _cid; }
set { _cid = value; }
}
/// <summary>
/// 请求序列号
/// </summary>
public int seq { get; set; }
/// <summary>
/// 操作码(0无操作(发送料仓状态给服务器),
/// 1扫码入库(扫码成功后发送给服务器),
/// 2 出库(服务器发送),3表示错误信息 )
/// 4,发送给服务表示二维码扫码入库,收到开始扫码
/// </summary>
public int op { get; set; }
/// <summary>
/// 操作相关数据,
/// op=1时,客户端发送 code 二维码给服务器,服务器返回时有:posId库位编号,plateW:料盘宽度,plateH:料盘高度
/// 如果需要更新温湿度的报警值,服务器会发送alarmTemperature,alarmHumidity给客户端,客户端缓存,如果没有发送,不处理
/// op=3时,data发送BoxID和AlarmCode
/// =4时扫码入库
/// =5时服务器发送预警温度
/// </summary>
private Dictionary<string, string> _data = new Dictionary<string, string>();
public Dictionary<string, string> data
{
get { return _data; }
set { _data = value; }
}
/// <summary>
/// 整体料仓状态
/// 1=正常运行中
/// 2=急停中
/// 3=故障(气压检测不到等,用msg发送详细故障说明)
/// 4=警告(用msg发送提醒,如出库到达工位但是没有工人操作)
/// </summary>
public int status { get; set; }
/// <summary>
/// 提示消息
/// 出入库错误: BOX正在调试中,不能出入库
/// 出入库错误: 急停了不能出入库
/// 入库错误:料盘过大,放不到指定的位置中去
/// 故障:气压信号检测不到
/// 警告:出库盘到达工位但是没有工人操作
/// </summary>
public string msg { get; set; }
/// <summary>
/// 包含的多个 BOX 的状态信息
/// </summary>
public Dictionary<int, BoxStatus> boxStatus = new Dictionary<int, BoxStatus>();
/// <summary>
/// 报警集合
/// </summary>
public List<AlarmInfo> alarmList = new List<AlarmInfo>();
}
/// <summary>
/// 单台料仓状态(包含流水线)
/// </summary>
public class BoxStatus
{
/// <summary>
/// Box编号,从1开始
/// </summary>
public int boxId { get; set; }
/// <summary>
/// 单台BOX状态
/// 急停,故障,调试中,就绪状态(正常待机)
/// 入库执行中,入库完成,入库失败
/// 出库执行中,出库完成,出库失败
/// </summary>
public int status { get; set; }
/// <summary>
/// 单台BOX的消息
/// 正在调试中,不能出入库
/// 入库失败原因:
/// 出库失败原因:
/// </summary>
public string msg { get; set; }
/// <summary>
/// 温度
/// </summary>
public string temperature { get; set; }
/// <summary>
/// 湿度
/// </summary>
public string humidity { get; set; }
/// <summary>
/// 操作相关数据,
/// 出库完成后发送posId库位编号给服务器
/// </summary>
private Dictionary<string, string> _data = new Dictionary<string, string>();
public Dictionary<string, string> data
{
get { return _data; }
set { _data = value; }
}
}
public class AlarmInfo
{
public AlarmInfo(int StoreID, int aType, string alarmDetial, string WarnMsg, int inoutStatus)
{
// TODO: Complete member initialization
this.boxId = StoreID;
this.alarmType = aType;
this.alarmDetail = alarmDetial;
this.alarmMsg = WarnMsg;
this.inOutStatus = inoutStatus;
}
public AlarmInfo()
{
// TODO: Complete member initialization
}
/// <summary>
/// 料仓ID,0表示流水线
/// </summary>
public int boxId { get; set; }
/// <summary>
/// 报警类型,
/// </summary>
public int alarmType { get; set; }
/// <summary>
/// 报警详情
///AlarmType= 0 消息 "1=原点返回
//AlarmType= 0 消息 2=复位"
//AlarmType=1 总体错误 "1=急停
//AlarmType=1 总体错误 2=没有气压信号
//AlarmType=1 总体错误,3=盘错乱"
//AlarmType=2 运动轴错误 1=第一轴(旋转)
//AlarmType=2 运动轴错误 2=第二轴(上下轴)
//AlarmType=2 运动轴错误 3=第三轴(前进轴)
//AlarmType=2 运动轴错误 4=第四轴(压紧轴)"
//AlarmType=2 电钢报警 5=上下电钢
//AlarmType=3 IO报警,信号超时 io电器定义(电器定义)
/// </summary>
public string alarmDetail { get; set; }
/// <summary>
/// 报警消息
/// </summary>
public string alarmMsg { get; set; }
/// <summary>
/// 0,1=入库,2=出库
/// </summary>
public int inOutStatus { get; set; }
}
public class ParamDefine
{
/// <summary>
/// 库位 ID
/// </summary>
public static string posId = "posId";
/// <summary>
/// 料盘宽
/// </summary>
public static string plateW = "plateW";
/// <summary>
/// 料盘高
/// </summary>
public static string plateH = "plateH";
/// <summary>
/// 料仓ID
/// </summary>
public static string storeId = "storeId";
/// <summary>
/// 报警码
/// </summary>
public static string alarmCode = "alarmCode";
/// <summary>
/// 报警详情或参数
/// </summary>
public static string alarmDetial = "alarmDetial";
/// <summary>
/// 湿度报警值
/// </summary>
public static string maxHumidity = "humi";
/// <summary>
/// 温度报警值
/// </summary>
public static string maxTemperature = "temp";
/// <summary>
/// urgentReel: true 表示紧急料,需要出到料串上
/// </summary>
public static string urgentReel = "urgentReel";
/// <summary>
/// cutReel: true 表示分盘料,需要出到料串上
/// </summary>
public static string cutReel = "cutReel";
/// <summary>
/// smallReel: true 小料(7x8),放置到小料串上
/// </summary>
public static string smallReel = "smallReel";
/// <summary>
/// rfid: 分配的料串RFID
/// </summary>
public static string rfid = "rfid";
/// <summary>
/// rfidLoc: 料串的架位,值为 - 1时,可以自由分配皮带线, 小料时,架位为1 - 46优先走1 / 2号皮带线,47 - 92优先走3 / 4号皮带线,
/// 70,71,72时只能分配到3 / 4号皮带线; 大料时,架位1 - 6优先走1 / 2号皮带线, 7 - 12优先走3 / 4号皮带线
/// </summary>
public static string rfidLoc = "rfidLoc";
public static string barcode = "barcode";
}
}
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Newtonsoft.Json" version="13.0.1" targetFramework="net461" />
</packages>
\ No newline at end of file
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net;
using System.Net.Sockets;
using System.Reflection;
using System.Threading;
namespace OnlineStore.Common
{
public class CTcpClient
{
// public static readonly ILog LOGGER = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
public delegate void HandleMessage(string message);
private Socket m_clientSocket = null;
private byte[] m_receiveBuffer = new byte[1024];
private HandleMessage onReceived;
public int TimeOutTime = 0;
/// <summary>
/// 当前连接状态
/// </summary>
public bool IsConnected()
{
if (m_clientSocket == null)
{
return false;
}
if (m_clientSocket.Connected)
{
return true;
}
#region remarks
/********************************************************************************************
* 当Socket.Conneted为false时, 如果您需要确定连接的当前状态,请进行非阻塞、零字节的 Send 调用。
* 如果该调用成功返回或引发 WAEWOULDBLOCK 错误代码 (10035),则该套接字仍然处于连接状态;
* 否则,该套接字不再处于连接状态。
* Depending on http://msdn.microsoft.com/zh-cn/library/system.net.sockets.socket.connected.aspx?cs-save-lang=1&cs-lang=csharp#code-snippet-2
********************************************************************************************/
#endregion
try
{
#region 过程
// This is how you can determine whether a socket is still connected.
bool connectState = true;
bool blockingState = m_clientSocket.Blocking;
try
{
byte[] tmp = new byte[1];
m_clientSocket.Blocking = false;
m_clientSocket.Send(tmp, 0, 0);
//Console.WriteLine("Connected!");
connectState = true; //若Send错误会跳去执行catch体,而不会执行其try体里其之后的代码
}
catch (SocketException e)
{
// 10035 == WSAEWOULDBLOCK
if (e.NativeErrorCode.Equals(10035))
{
connectState = true;
}
else
{
connectState = false;
}
}
finally
{
if (m_clientSocket != null && m_clientSocket.Connected)
{
m_clientSocket.Blocking = blockingState;
}
}
//Console.WriteLine("Connected: {0}", client.Connected);
return connectState;
#endregion
}
catch (Exception ex)
{
LogUtil.error( "出错啦" + ex.ToString());
return false;
}
}
/// <summary>
/// 连接服务器
/// </summary>
public bool connect(string serverIP, int serverPort, HandleMessage HandleMessage)
{
m_clientSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
if (TimeOutTime <= 0)
{
IPEndPoint remoteEndPoint = new IPEndPoint(IPAddress.Parse(serverIP), serverPort);
m_clientSocket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, true);
try
{
if (!m_clientSocket.Connected)
{
m_clientSocket.Connect(remoteEndPoint);
}
if (m_clientSocket.Connected)
{
m_clientSocket.BeginReceive(m_receiveBuffer, 0, m_receiveBuffer.Length, 0, new AsyncCallback(ReceiveCallBack), null);
onReceived = HandleMessage;
LogUtil.info( "Connect to " + serverIP + ":" + serverPort + " success!");
return true;
}
else
{
LogUtil.info( "Connect to " + serverIP + ":" + serverPort + " fail!");
}
}
catch (Exception ex)
{
LogUtil.error( "Connect to " + serverIP + ":" + serverPort + " fail!" + ex.ToString(), 103);
//m_clientSocket = null;
}
}
else
{
m_clientSocket.ReceiveTimeout = TimeOutTime;
m_clientSocket.SendTimeout = TimeOutTime;
IAsyncResult connResult = m_clientSocket.BeginConnect(serverIP, serverPort, null, null);
connResult.AsyncWaitHandle.WaitOne(this.TimeOutTime, true); //等待2秒
if (!connResult.IsCompleted || (!m_clientSocket.Connected))
{
LogUtil.info( "Connect to " + serverIP + ":" + serverPort + " fail!");
m_clientSocket.Close();
//处理连接不成功的动作
return false;
}
else
{
//处理连接成功的动作
m_clientSocket.BeginReceive(m_receiveBuffer, 0, m_receiveBuffer.Length, 0, new AsyncCallback(ReceiveCallBack), null);
onReceived = HandleMessage;
LogUtil.info( "Connect to " + serverIP + ":" + serverPort + " success!");
return true;
}
}
return false;
}
/// <summary>
/// 断开连接
/// </summary>
public void close()
{
try
{
if (m_clientSocket != null && m_clientSocket.Connected)
{
m_clientSocket.Shutdown(SocketShutdown.Both);
//Thread.Sleep(300);
//m_clientSocket.Disconnect(true);
//Thread.Sleep(300);
m_clientSocket.Close();
//m_clientSocket = null;
LogUtil.info( "Socket closed!");
}
else
{
LogUtil.error( "No socket is running!");
}
}
catch (Exception ex)
{
LogUtil.error( "close error :" + ex.ToString());
}
}
/// <summary>
/// 发送信息
/// </summary>
public void send(string strSendData)
{
byte[] sendBuffer = new byte[1024];
sendBuffer = Encoding.UTF8.GetBytes(strSendData);
if (m_clientSocket != null && m_clientSocket.Connected)
{
m_clientSocket.Send(sendBuffer);
LogUtil.debug( "Send >> " + strSendData);
}
}
/// <summary>
/// 发送信息
/// </summary>
public void sendLine(string strSendData)
{
if (strSendData.StartsWith("save"))
{
LogUtil.debug( "发送数据:" + strSendData);
}
else
{
LogUtil.info( "发送数据:" + strSendData);
}
strSendData = strSendData + "\r\n";
byte[] sendBuffer = new byte[1024];
sendBuffer = Encoding.UTF8.GetBytes(strSendData);
if (m_clientSocket != null && m_clientSocket.Connected)
{
m_clientSocket.Send(sendBuffer);
LogUtil.debug( "Send >> " + strSendData);
}
}
private void ReceiveCallBack(IAsyncResult ar)
{
try
{
if (m_clientSocket != null && m_clientSocket.Connected)
{
int REnd = m_clientSocket.EndReceive(ar);
string strReceiveData = Encoding.Default.GetString(m_receiveBuffer, 0, REnd);
onReceived(strReceiveData);
Thread.Sleep(100);
//LOGGER.Debug("m_clientSocket:" + m_clientSocket + "\n m_receiveBuffer" + m_receiveBuffer);
m_clientSocket.BeginReceive(m_receiveBuffer, 0, m_receiveBuffer.Length, 0, new AsyncCallback(ReceiveCallBack), null);
}
}
catch (Exception ex)
{
LogUtil.error( "socket received error:" + ex.ToString(), 104);
}
}
}
}
using System;
using System.Configuration;
using System.Threading;
using System.Xml;
using System.Windows.Forms;
namespace OnlineStore.Common
{
public class ConfigAppSettings
{
//public static readonly ILog LOGGER = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
private static int seq = 1;
public static int nextSeq()
{
if (seq.Equals(Int32.MaxValue))
{
LogUtil.info("seq当前值:" + seq + ",重置seq=0");
seq = 0;
}
Interlocked.Increment(ref seq);
return seq;
}
public static string GetValue(string keyStr, string storeStr)
{
string key = keyStr + storeStr;
System.Configuration.Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
if (config.AppSettings.Settings[key] == null)
{
return GetValue(keyStr);
}
else
{
return config.AppSettings.Settings[key].Value;
}
}
public static decimal GetNumValue(string keyStr, string storeStr)
{
string key = keyStr + storeStr;
decimal a = 0;
System.Configuration.Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
if (config.AppSettings.Settings[key] == null)
{
return GetNumValue(keyStr);
}
else
{
{
Decimal.TryParse(config.AppSettings.Settings[key].Value, out a);
}
}
return a;
}
public static int GetIntValue(string keyStr, string storeStr)
{
string key = keyStr + storeStr;
int a = 0;
System.Configuration.Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
if (config.AppSettings.Settings[key] == null)
{
return GetIntValue(keyStr);
}
else
{
{
Int32.TryParse(config.AppSettings.Settings[key].Value, out a);
}
} return a;
}
public static string GetValue(string key)
{
System.Configuration.Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
if (config.AppSettings.Settings[key] == null)
{
LogUtil.error("未找到配置:" + key + ",请检查配置是否完整!");
return "";
}
else
{
return config.AppSettings.Settings[key].Value;
}
}
public static decimal GetNumValue(string key)
{
decimal a = 0;
System.Configuration.Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
if (config.AppSettings.Settings[key] == null)
{
LogUtil.error("未找到配置:" + key + ",请检查配置是否完整!");
return a;
}
else
{
{
Decimal.TryParse(config.AppSettings.Settings[key].Value, out a);
}
}
return a;
}
public static int GetIntValue(string key)
{
int a = 0;
System.Configuration.Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
if (config.AppSettings.Settings[key] == null)
{
LogUtil.error("未找到配置:" + key + ",请检查配置是否完整!");
return a;
}
else
{
{
Int32.TryParse(config.AppSettings.Settings[key].Value, out a);
}
} return a;
}
public static void SaveValue(string key, int value)
{
SaveValue(key, value.ToString());
}
public static void SaveValue(string key, string value)
{
try
{
if (key.Equals("") || value.Equals(""))
{
return;
}
//增加的内容写在appSettings段下 <add key="RegCode" value="0"/>
System.Configuration.Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
if (config.AppSettings.Settings[key] == null)
{
SetValue(key, value);
}
else
{
UpdateConfig(key, value);
}
}
catch (Exception ex)
{
LogUtil.error( "SaveValue保存配置出错:AppKey=" + key + ",AppValue=" + value + ",",ex);
}
}
public static string GetValue(object debugDeviceId)
{
throw new NotImplementedException();
}
/// <summary>
/// 更新配置文件信息
/// </summary>
/// <param name="name">配置文件字段名称</param>
/// <param name="Xvalue">值</param>
private static void UpdateConfig(string name, string Xvalue)
{
try
{
XmlDocument doc = new XmlDocument();
doc.Load(Application.ExecutablePath + ".config");
XmlNode node = doc.SelectSingleNode(@"//add[@key='" + name + "']");
XmlElement ele = (XmlElement)node;
ele.SetAttribute("value", Xvalue);
doc.Save(Application.ExecutablePath + ".config");
}
catch (Exception ex)
{
LogUtil.error( "UpdateConfig保存配置出错:name=" + name + ",Xvalue=" + Xvalue + ",",ex);
}
}
///<summary>
///向.config文件的appKey结写入信息AppValue 保存设置
///</summary>
///<param name="AppKey">节点名</param>
///<param name="AppValue">值</param>
private static void SetValue(String AppKey, String AppValue)
{
try
{
XmlDocument xDoc = new XmlDocument();
xDoc.Load(System.Windows.Forms.Application.ExecutablePath + ".config");
XmlNode xNode;
XmlElement xElem1;
XmlElement xElem2;
xNode = xDoc.SelectSingleNode("//appSettings");
xElem1 = (XmlElement)xNode.SelectSingleNode("//add[@key='" + AppKey + "']");
if (xElem1 != null)
xElem1.SetAttribute("value", AppValue);
else
{
xElem2 = xDoc.CreateElement("add");
xElem2.SetAttribute("key", AppKey);
xElem2.SetAttribute("value", AppValue);
xNode.AppendChild(xElem2);
}
xDoc.Save(System.Windows.Forms.Application.ExecutablePath + ".config");
}
catch (Exception ex)
{
LogUtil.error( "SetValue保存配置出错:AppKey=" + AppKey + ",AppValue=" + AppValue + ",",ex);
}
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace OnlineStore.Common
{
public class FormUtil
{
public static string GetValue(TextBox txt)
{
string value = txt.Text;
return value;
}
public static int GetIntValue(TextBox txt)
{
int value = 0;
try
{
value = int.Parse(txt.Text);
}
catch (Exception ex)
{
value = 0;
}
return value;
}
public static short GetShortValue(TextBox txt)
{
short value = 0;
try
{
value = short.Parse(txt.Text);
}
catch (Exception ex)
{
value = 0;
}
return value;
}
public static double getDoubleValue(TextBox txt)
{
double value = 0;
try
{
value = double.Parse(txt.Text);
}
catch (Exception ex)
{
value = 0;
}
return value;
}
public static short get16ShortValue(TextBox txt)
{
short value = 0;
try
{
value = System.Convert.ToInt16(txt.Text,16);
}
catch
{
value = 0;
}
return value;
}
//public static string GetShowStr(double value)
//{
// string wStr = "";
// if (value == (int)value)
// {
// wStr = string.Format("{0:d}", (int)value);
// }
// else
// {
// wStr = string.Format("{0:f}", value);
// }
// return wStr;
//}
public static string GetSpanStr(TimeSpan span)
{
//return Convert.ToDateTime(span.ToString()).ToString("HH:mm:ss");
string seconds = Math.Round(span.TotalSeconds % 60, 1).ToString();
if (seconds.IndexOf(".") >= 0)
{
seconds = seconds.ToString().PadLeft(4, '0');
}
else
{
seconds = seconds.ToString().PadLeft(2, '0');
}
return span.Hours.ToString().PadLeft(2, '0') + ":" + span.Minutes.ToString().PadLeft(2, '0') + ":" + seconds;
}
}
}
using System;
using System.IO;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
using System.Collections;
using System.Net;
using System.Net.Security;
using System.Security;
using System.Security.Cryptography;
using System.Security.Cryptography.X509Certificates;
using System.Reflection;
using log4net;
namespace OnlineStore.Common
{
public class HttpHelper
{
public static readonly ILog LOGGER = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
public static string Post(string url, string paramData)
{
return Post(url, paramData, Encoding.UTF8);
}
private static int isLog = ConfigAppSettings.GetIntValue(Setting_Init.Server_Log_Open);
public static string Post(string url, string paramData, Encoding encoding)
{
if (isLog == 1)
{
LOGGER.Info("给服务器发送数据【" + paramData + "】 ");
}
if (paramData != "null" && paramData != null)
{
// LogUtil.debug(LOGGER, "HTTP POST to " + url + " \n\t >> " + paramData);
}
string result = "";
if (url.ToLower().IndexOf("https", System.StringComparison.Ordinal) > -1)
{
ServicePointManager.ServerCertificateValidationCallback =
new RemoteCertificateValidationCallback((sender, certificate, chain, errors) => { return true; });
}
try
{
var wc = new MyWebClient(5000);
if (string.IsNullOrEmpty(wc.Headers["Content-Type"]))
wc.Headers.Add("Content-Type", "application/json;charset=UTF-8");
wc.Encoding = encoding;
result = wc.UploadString(url, "POST", paramData);
//LogUtil.info(result);
}
catch (Exception e)
{
LogUtil.error( "POST ERROR:" + e.StackTrace, 1001);
}
if (!result.Contains("null") && result.Length != 0)
{
//LogUtil.debug(LOGGER,"receive << " + result);
}
if (isLog == 1)
{
LOGGER.Info("收到服务器数据【" + result + "】");
}
return result;
}
public static string Get(string url)
{
return Get(url, Encoding.UTF8);
}
public static string Get(string url, Encoding encoding)
{
try
{
LogUtil.info(LOGGER, "HTTP GET FROM: " + url);
var wc = new WebClient { Encoding = encoding };
var readStream = wc.OpenRead(url);
using (var sr = new StreamReader(readStream, encoding))
{
var result = sr.ReadToEnd();
LogUtil.info(LOGGER, "receive << " + result);
return result;
}
}
catch (Exception e)
{
LogUtil.error( "HTTP GET ERROR:" + e.Message, 1002);
}
return "";
}
}
}
\ No newline at end of file
using log4net;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Reflection;
using System.Text;
namespace OnlineStore.Common
{
/// <summary>
/// 奥松温湿度服务器
/// </summary>
public class HumitureServer
{
private static readonly ILog LOGGER = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
/// <summary>
/// 最后一次接受到的温度信息,key=温湿度传感器IP地址
/// </summary>
public static Dictionary<string, ASTemperateParam> TemperateParamMap = new Dictionary<string, ASTemperateParam>();
/// <summary>
/// 根据IP 地址获得最后一次取到的温湿度
/// </summary>
public static ASTemperateParam GetTemperateParam(string ipAddr)
{
ASTemperateParam temperate = null;
TemperateParamMap.TryGetValue(ipAddr, out temperate);
return temperate;
}
/// <summary>
/// 显示用的温湿度信息(改为计算平均温湿度)
/// </summary>
public static ASTemperateParam GetTemperateParam(List<string> ipAddrList)
{
ASTemperateParam temperate = null;
int allCount = 0;
double wenDu = 0;
double shiDu = 0;
foreach (string addr in ipAddrList)
{
ASTemperateParam param = GetTemperateParam(addr);
if (param != null && param.IsValid())
{
allCount++;
wenDu = wenDu + param.Temperate;
shiDu = shiDu + param.Humidity;
}
}
if (allCount > 0)
{
double avgWendu = Math.Round(wenDu / allCount, 1);
double avgShidu = Math.Round(shiDu / allCount, 1);
temperate = new ASTemperateParam(avgWendu, avgShidu);
}
return temperate;
}
public static double GetMaxHumidity(List<string> ipAddrList)
{
double maxValue = 0;
foreach (string addr in ipAddrList)
{
ASTemperateParam param = GetTemperateParam(addr);
if (param != null && param.IsValid())
{
if (param.Humidity > maxValue)
{
maxValue = param.Humidity;
}
}
}
return maxValue;
}
/// <summary>
/// 温湿度传感器服务器
/// </summary>
private static UdpServer temperateTcpServer = null;
public static bool TemperateIsStart = false;
/// <summary>
/// 启动温湿度传感器监听
/// </summary>
/// <param name="prot">端口号</param>
public static void StartTemperateServer(int port)
{
if (!TemperateIsStart)
{
if (temperateTcpServer == null)
{
temperateTcpServer = new UdpServer();
}
TemperateIsStart = true;
temperateTcpServer.Start(port);
LogUtil.info(LOGGER, "温湿度已开始在端口[" + port + "]监听!");
temperateTcpServer.ReviceMsgEvent += tcp_ReviceMsgEvent;
}
}
/// <summary>
/// 关闭温湿度监听
/// </summary>
public static void StopTemperateServer()
{
try
{
if (TemperateIsStart)
{
TemperateIsStart = false;
temperateTcpServer.Stop();
}
}
catch (Exception ex)
{
LogUtil.error(LOGGER, "关闭温湿度监听出错:" + ex.ToString());
}
}
/// <summary>
/// 温湿度传感器 服务器回调函数
/// </summary>
private static void tcp_ReviceMsgEvent(EndPoint remote, string Msg)
{
IPEndPoint clientipe = (IPEndPoint)remote;
string add = clientipe.Address.ToString();
try
{
string[] strList = Msg.Split('+');
if (strList.Length == 12)
{
double wendu = double.Parse(strList[2]) / 10;
double shidu = double.Parse(strList[3]) / 10;
string deviceId = strList[10];
string pwd = strList[11];
LogUtil.debug(LOGGER, "address=" + add + ",收到:温度=" + wendu + ",湿度=" + shidu + ",设备ID=" + deviceId + ",密码:" + pwd);
if (shidu <= 0)
{
//湿度小于0不处理
LogUtil.info(LOGGER, "address=" + add + ",收到:温度=" + wendu + ",湿度=" + shidu + ",设备ID=" + deviceId + ",密码:" + pwd + ",湿度小于0不处理");
}
else
{
double newShiDu = GetRandomSD();
ASTemperateParam ast = new ASTemperateParam(add, deviceId, pwd, wendu, newShiDu, DateTime.Now);
if (TemperateParamMap.ContainsKey(add))
{
TemperateParamMap.Remove(add);
}
TemperateParamMap.Add(add, ast);
}
}
}
catch (Exception ex)
{
LogUtil.error(LOGGER, ex.ToString());
}
}
private static double PreShiDu = 7;
private static double PreWenDu = 25;
public static void RandomData(List<string> ipAddrList)
{
try
{
foreach (string IP in ipAddrList)
{
double newShiDu = GetRandomSD();
double newWenDu = GetRandomWD();
ASTemperateParam ast = new ASTemperateParam(IP, "", "", newWenDu, newShiDu, DateTime.Now);
if (TemperateParamMap.ContainsKey(IP))
{
TemperateParamMap.Remove(IP);
}
TemperateParamMap.Add(IP, ast);
//LogUtil.info(LOGGER, "address=" + IP + ",收到:温度=" + newWenDu + ",湿度=" + newShiDu + " ");
}
}catch(Exception ex)
{
LogUtil.error("温湿度数据保存出错:"+ex.ToString());
}
}
public static double GetRandomWD()
{
Random rd = new Random((int)DateTime.Now.Ticks + 99);
int num = rd.Next(-20, 20);
double newWendu = Math.Round(PreWenDu + (double)num / 1000F, 3);
if (newWendu > 25.5 || newWendu < 24.5)
{
newWendu = PreWenDu;
}
else
{
PreWenDu = newWendu;
}
return newWendu;
}
public static double GetRandomSD()
{
Random rd = new Random((int)DateTime.Now.Ticks);
int num = rd.Next(-100, 100);
double newShiDu = Math.Round(PreShiDu + (double)num / 1000F, 3);
if (newShiDu > 9.8 || newShiDu < 5.6)
{
newShiDu = PreShiDu;
}
else
{
PreShiDu = newShiDu;
}
return newShiDu;
}
}
/// <summary>
/// 奥松温湿度上传参数
/// </summary>
public class ASTemperateParam
{
public ASTemperateParam(string clientipe, string add, string pwd, double wendu, double shidu, DateTime updateTime)
{
this.IpAddress = clientipe;
this.DeviceAddress = add;
this.Password = pwd;
this.Temperate = wendu;
this.Humidity = shidu;
this.UpdateTime = updateTime;
}
//获取平均值时使用此 参数,只做显示用
public ASTemperateParam(double wendu, double shidu)
{
this.IpAddress = "";
this.DeviceAddress = "";
this.Password = "";
this.Temperate = wendu;
this.Humidity = shidu;
this.UpdateTime = DateTime.Now;
}
/// <summary>
/// 判断值是否在有效期内。默认有效期是一分钟
/// </summary>
/// <returns></returns>
public bool IsValid()
{
TimeSpan span = DateTime.Now - UpdateTime;
if (span.TotalMinutes > 3)
{
return false;
}
return true;
}
/// <summary>
/// 更新时间
/// </summary>
public DateTime UpdateTime { get; set; }
/// <summary>
/// IP地址
/// </summary>
public string IpAddress { get; set; }
/// <summary>
/// 设备地址
/// </summary>
public string DeviceAddress { get; set; }
/// <summary>
/// 访问密码
/// </summary>
public string Password { get; set; }
/// <summary>
/// 温度
/// </summary>
public double Temperate { get; set; }
/// <summary>
/// 湿度
/// </summary>
public double Humidity { get; set; }
}
}
using System.Collections.Generic;
using System.IO;
using Newtonsoft.Json;
namespace OnlineStore.Common
{
/// <summary>
/// Json帮助类
/// </summary>
public class JsonHelper
{
/// <summary>
/// 将对象序列化为JSON格式
/// </summary>
/// <param name="o">对象</param>
/// <returns>json字符串</returns>
public static string SerializeObject(object o)
{
string json = JsonConvert.SerializeObject(o);
return json;
}
/// <summary>
/// 解析JSON字符串生成对象实体
/// </summary>
/// <typeparam name="T">对象类型</typeparam>
/// <param name="json">json字符串(eg.{"ID":"112","Name":"石子儿"})</param>
/// <returns>对象实体</returns>
public static T DeserializeJsonToObject<T>(string json) where T : class
{
JsonSerializer serializer = new JsonSerializer();
StringReader sr = new StringReader(json);
object o = serializer.Deserialize(new JsonTextReader(sr), typeof(T));
T t = o as T;
return t;
}
/// <summary>
/// 解析JSON数组生成对象实体集合
/// </summary>
/// <typeparam name="T">对象类型</typeparam>
/// <param name="json">json数组字符串(eg.[{"ID":"112","Name":"石子儿"}])</param>
/// <returns>对象实体集合</returns>
public static List<T> DeserializeJsonToList<T>(string json) where T : class
{
JsonSerializer serializer = new JsonSerializer();
StringReader sr = new StringReader(json);
object o = serializer.Deserialize(new JsonTextReader(sr), typeof(List<T>));
List<T> list = o as List<T>;
return list;
}
/// <summary>
/// 反序列化JSON到给定的匿名对象.
/// </summary>
/// <typeparam name="T">匿名对象类型</typeparam>
/// <param name="json">json字符串</param>
/// <param name="anonymousTypeObject">匿名对象</param>
/// <returns>匿名对象</returns>
public static T DeserializeAnonymousType<T>(string json, T anonymousTypeObject)
{
T t = JsonConvert.DeserializeAnonymousType(json, anonymousTypeObject);
return t;
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using log4net;
using System.Reflection;
using System.Drawing;
using System.Runtime.ExceptionServices;
using System.Collections.Concurrent;
using System.Threading;
namespace OnlineStore.Common
{
public class LogUtil
{
public delegate void ShowLogDelegate(string msg, Color color);
public static event ShowLogDelegate ShowLog;
public static readonly ILog LOGGER = LogManager.GetLogger("RollingLogFileAppender");
public static ConcurrentDictionary<int, DateTime> lastErrorLogTime = new ConcurrentDictionary<int, DateTime>();
public static bool debug_opened = false;
public static void info(ILog log, string msg)
{
if (log == null)
{
return;
}
log.Info(msg);
AddToBox(msg, Color.Black);
}
public static void info(ILog log, string msg, Color color)
{
log.Info(msg);
AddToBox(msg, color);
}
public static void debug(ILog log, string msg, Color color)
{
log.Debug(msg);
if (debug_opened)
{
AddToBox(msg, color);
}
}
public static void debug(ILog log, string msg)
{
log.Debug(msg);
if (debug_opened)
{
AddToBox(msg, Color.Gray);
}
}
public static void error(string errorMsg, int type, int seconds = 10)
{
try
{
if (lastErrorLogTime.ContainsKey(type))
{
TimeSpan span = DateTime.Now - lastErrorLogTime[type];
if (span.TotalSeconds > seconds)
{
lastErrorLogTime[type] = DateTime.Now;
error(LOGGER, errorMsg);
}
}
else
{
lastErrorLogTime.TryAdd(type, DateTime.Now);
error(LOGGER, errorMsg);
}
}
catch (Exception ex)
{
LOGGER.Error(" 打印日志【" + type + "-" + errorMsg + "】出错:" + ex.ToString());
}
}
public static void error(ILog log, string errorMsg, Exception ex = null)
{
if (errorMsg.Trim().Equals("") && (ex == null))
{
return;
}
if (ex == null)
{
log.Error(errorMsg);
}
else
{
log.Error(errorMsg, ex);
}
AddToBox(errorMsg, Color.Red);
}
private static object lockObj = "";
private static void AddToBox(string msg, Color color)
{
if (Monitor.TryEnter(lockObj, 10))
{
try
{
ShowLog?.Invoke(msg, color);
}
catch (Exception ex)
{
LOGGER.Error("出错:", ex);
}
finally
{
Monitor.Exit(lockObj);
}
}
else
{
LOGGER.Debug("ShowLogPro【" + msg + "】失败,未得到锁");
}
}
private static DateTime lastTime = DateTime.Now;
public static void debug(string msg)
{
debug(LOGGER, msg);
}
public static void error(string errorMsg, Exception ex = null)
{
error(LOGGER, errorMsg, ex);
}
public static string lastlog = "";
public static void info(string msg)
{
if (lastlog != msg)
{
info(LOGGER, msg);
lastlog = msg;
}
}
}
}
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Net.NetworkInformation;
using System.Net.Security;
using System.Reflection;
using System.Text;
namespace OnlineStore.Common
{
public class MyWebClient : WebClient
{
private int _timeout;
/// <summary>
/// 超时时间(毫秒)
/// </summary>
public int Timeout
{
get
{
return _timeout;
}
set
{
_timeout = value;
}
}
public MyWebClient()
{
this._timeout = 60000;
}
public MyWebClient(int timeout)
{
this._timeout = timeout;
}
protected override WebRequest GetWebRequest(Uri address)
{
HttpWebRequest result = (HttpWebRequest)base.GetWebRequest(address);
result.Timeout = this._timeout;
return result;
}
}
public class HttpHelper
{
public static bool PingURLIP(string url, int ms = 100)
{
string[] urlArray = url.Split('/');
if (urlArray.Length > 3)
{
string ip = urlArray[2];
Ping pingSender = new Ping();
PingReply reply = pingSender.Send(ip, ms);//第一个参数为ip地址,第二个参数为ping的时间
if (reply.Status == IPStatus.Success)
{
//通
return true;
}
else
{
LogUtil.error("Ping IP " + ip + " : false");
//不通
return false;
}
}
return true;
}
public static string Post(string url, string paramData, int timeOut = 10000)
{
return Post(url, paramData, Encoding.UTF8, timeOut);
}
public static string Post(string url, string paramData, Encoding encoding, int timeOut = 10000)
{
string result = "";
if (url.ToLower().IndexOf("https", System.StringComparison.Ordinal) > -1)
{
ServicePointManager.ServerCertificateValidationCallback =
new RemoteCertificateValidationCallback((sender, certificate, chain, errors) => { return true; });
}
try
{
using (var wc = new MyWebClient(10000))
{
if (string.IsNullOrEmpty(wc.Headers["Content-Type"]))
{
wc.Headers.Add("Content-Type", "application/json;charset=UTF-8");
}
wc.Headers.Add("User-Agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1;SV1)");
wc.Encoding = encoding;
result = wc.UploadString(url, "POST", paramData);
}
//LogUtil.info(result);
}
catch (Exception e)
{
LogUtil.error("POST ERROR:" + e.ToString(), 101);
}
return result;
}
public static Operation Post(string url, Operation operation, bool simulate)
{
try
{
if (simulate)
{//模拟服务器返回
operation.status = 200;
operation.data.Clear();
operation.data.Add("posId", "A001");
string pos = "D100-111#D102-222#D104-333";
operation.data.Add("pos", pos);
if (operation.op == 1 || operation.op == 2)
{//入库或出库
string json = JsonHelper.SerializeObject(operation);
LogUtil.error( "模拟HTTP服务器返回出库入库信息:" + json);
return operation;
}
}
else
{
string json = JsonHelper.SerializeObject(operation);
string result = Post(url, json);
Operation op = JsonHelper.DeserializeJsonToObject<Operation>(result);
if (operation.op > 0 || (op != null && op.op > 0))
{
LogUtil.info("Send [" + json + "] Revice [" + result + "]");
}
return op;
}
}
catch (Exception ex)
{
LogUtil.error("Post 出错【operation.op=" + operation.op + "】:" + ex);
}
return null;
}
public static string Get(string url)
{
return Get(url, Encoding.UTF8);
}
public static string Get(string url, Encoding encoding, int timeOut = 10000)
{
try
{
LogUtil.debug("HTTP GET FROM: " + url);
using (var wc = new MyWebClient { Encoding = encoding })
{
var readStream = wc.OpenRead(url);
using (var sr = new StreamReader(readStream, encoding))
{
var result = sr.ReadToEnd();
LogUtil.debug("receive << " + result);
return result;
}
}
}
catch (Exception e)
{
LogUtil.error("HTTP GET ERROR:" + e.Message, 102);
}
return "";
}
}
}
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Net.Sockets;
using System.Net;
using System.IO;
using log4net;
using System.Text;
using OnlineStore.Common;
namespace OnlineStore
{
public class NetTCPServer
{
// public static readonly ILog LOGGER = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
/// <summary>
/// TCP服务端监听
/// </summary>
TcpListener tcpsever = null;
/// <summary>
/// 监听状态
/// </summary>
bool isListen = false;
public BindingList<NewClient> lstClient = new BindingList<NewClient>();
public IPAddress[] getLoacalIPAddress()
{
IPHostEntry ipHostEntry = Dns.GetHostEntry(Dns.GetHostName());
return ipHostEntry.AddressList;
}
public delegate void ReviceData(NewClient client, string ip, byte[] data);
public event ReviceData ReviceDataEvent;
/// <summary>
/// 开启TCP监听
/// </summary>
/// <returns></returns>
public void StartTCPServer(int port)
{
try
{
tcpsever = new TcpListener(IPAddress.Any, port);
tcpsever.Start();
tcpsever.BeginAcceptTcpClient(new AsyncCallback(Acceptor), tcpsever);
isListen = true;
}
catch (Exception ex)
{
}
}
/// <summary>
/// 停止TCP监听
/// </summary>
/// <returns></returns>
public void StopTCPServer()
{
tcpsever.Stop();
isListen = false;
}
/// <summary>
/// 客户端连接初始化
/// </summary>
/// <param name="o"></param>
private void Acceptor(IAsyncResult o)
{
TcpListener server = o.AsyncState as TcpListener;
try
{
//初始化连接的客户端
NewClient newClient = new NewClient();
newClient.tcpClient = server.EndAcceptTcpClient(o);
lstClient.Add(newClient);
newClient.tcpClient.GetStream().BeginRead(newClient.Buffer, 0, newClient.Buffer.Length, new AsyncCallback(TCPCallBack), newClient);
server.BeginAcceptTcpClient(new AsyncCallback(Acceptor), server);//继续监听客户端连接
}
catch (ObjectDisposedException ex)
{ //监听被关闭
}
catch (Exception ex)
{
}
}
/// <summary>
/// 对当前选中的客户端发送数据
/// </summary>
/// <param name="sender"></param>
/// <param name="data"></param>
public bool SendData(NewClient selClient, byte[] data)
{
try
{
selClient.tcpClient.GetStream().Write(data, 0, data.Length);
}
catch (Exception ex)
{
return false;
}
return true;
}
/// <summary>
/// 客户端通讯回调函数
/// </summary>
/// <param name="ar"></param>
private void TCPCallBack(IAsyncResult ar)
{
NewClient client = (NewClient)ar.AsyncState;
if (client.tcpClient.Connected)
{
NetworkStream ns = client.tcpClient.GetStream();
StreamReader sr = new StreamReader(ns);
string str = sr.ReadLine();
LogUtil.info("读取到数据:"+str);
byte[] recdata = new byte[ns.EndRead(ar)];
if (recdata.Length > 0)
{
//Array.Copy(client.Buffer, recdata, recdata.Length);
LogUtil.info("读取到数据1111:" + Encoding.ASCII.GetString(recdata));
//ns.BeginRead(client.Buffer, 0, client.Buffer.Length, new AsyncCallback(TCPCallBack), client);
}
else
{
client.tcpClient.Close();
lstClient.Remove(client);
}
}
}
/// <summary>
/// 清理
/// </summary>
public void ClearSelf()
{
foreach (NewClient client in lstClient)
{
client.tcpClient.Close();
}
lstClient.Clear();
if (tcpsever != null)
{
tcpsever.Stop();
}
}
}
public class NewClient
{
public TcpClient tcpClient { get; set; }
public byte[] Buffer = new byte[1024];
}
}
using log4net;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
namespace OnlineStore.Common
{
/// <summary>
/// 扫码枪连接类
/// </summary>
public class ScanSocket
{
private readonly ILog LOGGER = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
public event ScanRevice OnScanRevice;
public delegate void ScanRevice(string message);
/// <summary>
/// 扫码枪链接
/// </summary>
private TcpClient scannerSocket;
/// <summary>
/// 扫描枪 是否开始运行
/// </summary>
public bool isScannerRun = false;
/// <summary>
/// 连接扫码枪
/// </summary>
/// <param name="serverIp">扫码枪Ip</param>
/// <param name="port">扫码枪端口号</param>
/// <returns>是否连接成功</returns>
public bool ConnectScanner(string serverIp, int port)
{
return StartScanner(serverIp, port, false);
}
/// <summary>
/// 停止扫码枪
/// </summary>
public void StopScanner()
{
try
{
scannerSocket.close();
isScannerRun = false;
}
catch (Exception ex)
{
LogUtil.error(LOGGER, "出错:" + ex);
}
}
/// <summary>
/// 发送扫码命令开始扫码
/// </summary>
public void BeginScannering()
{
string str = ConfigAppSettings.GetValue(Setting_Init.scanner_start_command);
if (str.Equals(""))
{
str = "S";
}
scannerSocket.send(str);
//onCodeReceived("AAAA");
}
/// <summary>
/// 开启扫码枪
/// </summary>
private bool StartScanner(string serverIp, int port, bool isMustCon)
{
bool result = true;
try
{
if (!isScannerRun || isMustCon)
{
if (scannerSocket == null)
{
scannerSocket = new TcpClient();
}
result = scannerSocket.connect(serverIp, port, new TcpClient.HandleMessage(onCodeReceived));
if (result)
{
isScannerRun = true;
}
}
}
catch (Exception ex)
{
LogUtil.error(LOGGER, "出错:" + ex);
}
return result;
}
/// <summary>
/// 扫码枪数据接收
/// </summary>
/// <param name="message"></param>
private void onCodeReceived(string message)
{
try
{
message = ScanCodeManager.ReplaceCode(message);
if (OnScanRevice != null)
{
OnScanRevice.Invoke(message);
}
}
catch (Exception ex)
{
LogUtil.error(LOGGER, "出错:" + ex.ToString());
}
}
}
}
using System;
using System.Text;
using System.Windows.Forms;
using System.Net;
using System.Net.Sockets;
using System.Threading;
using System.Collections.Concurrent;
namespace OnlineStore.Common
{
public class TcpServer
{
// public static readonly ILog LOGGER = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
/// <summary>
/// 接受消息时的间隔
/// </summary>
public static int ReviceMsgMS = 10;
private Thread m_serverThread;
private Socket m_serverSocket;
public delegate void ReviceMsg(TcpClientBean client, string Msg);
public event ReviceMsg ReviceMsgEvent;
private delegate void ReceiveMessageDelegate(TcpClientBean client);
public event AcceptClientDelegate AcceptClientEvent;
public delegate void AcceptClientDelegate(TcpClientBean client);
ReceiveMessageDelegate receiveMessageDelegate;
private bool isRun = true;
private int serverPort = 0;
private void logLocalIp()
{
string[] addresses = GetLocalAddresses();
string iplist = "本机IP:[";
if (addresses.Length > 0)
{
for (int i = 0; i < addresses.Length; i++)
{
if (addresses.Length != 0)
{
iplist = iplist + " " + addresses[i];
}
}
}
LogUtil.info( iplist + "]");
}
/// <summary>
/// 开始服务
/// </summary>
public void Start(int m_serverPort)
{
try
{
isRun = true;
m_serverSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
IPEndPoint localEndPoint = new IPEndPoint(IPAddress.Any, m_serverPort);
this.serverPort = m_serverPort;
m_serverSocket.Bind(localEndPoint);
m_serverSocket.Listen(10);
m_serverThread = new Thread(new ThreadStart(ReceiveAccept));
m_serverThread.Start();
LogUtil.info( " Server start listen : " + m_serverPort);
logLocalIp();
//this.AddRunningInfo(">> " + DateTime.Now.ToString() + " Server started.");
}
catch (SocketException se)
{
throw new Exception(se.Message);
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
}
/// <summary>
/// 停止服务
/// </summary>
public void Stop()
{
try
{
isRun = false;
m_serverThread.Interrupt(); // 线程终止
m_serverSocket.Close(); // Socket Close
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
}
private void ReceiveAccept()
{
while (isRun)
{
TcpClientBean client = new TcpClientBean();
try
{
client.ClientSocket = m_serverSocket.Accept();
IPEndPoint clientipe = (IPEndPoint)client.ClientSocket.RemoteEndPoint;
client.AddStr = clientipe.Address.ToString()+":"+clientipe.Port.ToString();
LogUtil.info( "["+serverPort+"]有新的客户端链接上:[" + client.AddStr+"]");
AcceptClientEvent?.Invoke(client);
receiveMessageDelegate = new ReceiveMessageDelegate(ReceiveMessages);
receiveMessageDelegate.BeginInvoke(client, ReceiveMessagesCallback, "");
}
catch (Exception ex)
{
LogUtil.error( "ReceiveAccept方法,客户端【"+client.AddStr+"】:" + ex.Message);
//throw new Exception(ex.Message);
}
}
}
// private StringBuilder sb = new StringBuilder(); //这个是用来保存:接收到了的,但是还没有结束的消息
private int receiveBufferSize = 1024;
private string terminateString = "\r";
public void ReceiveMessages(TcpClientBean client) //这个函数会被以线程方式运行
{
try
{
StringBuilder sb = new StringBuilder();
Socket socket = (Socket)client.ClientSocket;
while (true)
{
byte[] buffer = new byte[receiveBufferSize]; //buffer大小,此处为1024
int receivedSize = socket.Receive(buffer);
if (receivedSize > 0)
{
string rawMsg = Encoding.ASCII.GetString(buffer, 0, receivedSize);
int rnFixLength = terminateString.Length; //这个是指消息结束符的长度,此处为\r\n
for (int i = 0; i < rawMsg.Length;) //遍历接收到的整个buffer文本
{
if (i <= rawMsg.Length - rnFixLength)
{
if (rawMsg.Substring(i, rnFixLength) != terminateString)//非消息结束符,则加入sb
{
sb.Append(rawMsg[i]);
i++;
}
else
{
this.ReviceMsgEvent.Invoke(client, sb.ToString());//找到了消息结束符,触发消息接收完成事件
sb = new StringBuilder();
i += rnFixLength;
}
}
else
{
sb.Append(rawMsg[i]);
i++;
}
}
}
Thread.Sleep(ReviceMsgMS);
}
}
catch (SocketException e)
{
LogUtil.error("客户端{" + client.AddStr + "]:" + e.ToString(), 106);
}
catch (Exception ex)
{
LogUtil.error("客户端{" + client.AddStr + "]:" + ex.ToString(), 105);
}
}
//private void ReceiveMessages(Client client)
//{
// try
// {
// while (true)
// {
// byte[] receiveBuffer = new byte[1024];
// //int size = ;
// int size = client.ClientSocket.Receive(receiveBuffer);
// string strReceiveData = Encoding.ASCII.GetString(receiveBuffer, 0, size);
// if (!string.IsNullOrEmpty(strReceiveData))
// {
// LogUtil.info(LOGGER, "收到数据:" + strReceiveData);
// // this.AddRunningInfo(">> Receive data from [" + client.ClientSocket.RemoteEndPoint.ToString()+ "]:" + strReceiveData);
// string strSendData = "OK. The content is:" + strReceiveData;
// //LogUtil.info(LOGGER, "OK. The content is:" + strReceiveData);
// int sendBufferSize = Encoding.Unicode.GetByteCount(strSendData);
// byte[] sendBuffer = new byte[sendBufferSize];
// sendBuffer = Encoding.Unicode.GetBytes(strSendData);
// client.ClientSocket.Send(sendBuffer);
// }
// }
// }
// catch (SocketException e)
// {
// LogUtil.error(LOGGER, e.ToString());
// }
// catch (Exception ex)
// {
// LOGGER.Error(ex.ToString());
// }
//}
private void ReceiveMessagesCallback(IAsyncResult AR)
{
try
{
receiveMessageDelegate.EndInvoke(AR);
}
catch (Exception ex)
{
LogUtil.error(ex.ToString());
}
}
/// <summary>
/// 获取本机地址列表
/// </summary>
public string[] GetLocalAddresses()
{
// 获取主机名
string strHostName = Dns.GetHostName();
// 根据主机名进行查找
IPHostEntry iphostentry = Dns.GetHostEntry(strHostName);
string[] retval = new string[iphostentry.AddressList.Length];
int i = 0;
foreach (IPAddress ipaddress in iphostentry.AddressList)
{
if (ipaddress.AddressFamily != AddressFamily.InterNetworkV6)
{
retval[i] = ipaddress.ToString();
i++;
}
}
return retval;
}
}
/// <summary>
/// 客户端会话信息类
/// </summary>
public class TcpClientBean
{
Socket m_clientSocket;
public TcpClientBean() { }
public string AddStr = "";
public Socket ClientSocket
{
get { return m_clientSocket; }
set { this.m_clientSocket = value; }
}
}
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Sockets;
using System.Text;
using System.Threading;
namespace OnlineStore.Common
{
public class UdpServer
{
// public static readonly ILog LOGGER = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
private Thread m_serverThread;
private Socket udpServer;
public delegate void ReviceMsg(EndPoint address, string Msg);
/// <summary>
/// 接受到数据事件
/// </summary>
public event ReviceMsg ReviceMsgEvent;
private bool isRun = true;
private void logLocalIp()
{
string[] addresses = GetLocalAddresses();
string iplist = "本机IP:[";
if (addresses.Length > 0)
{
for (int i = 0; i < addresses.Length; i++)
{
if (addresses.Length != 0)
{
iplist = iplist + " " + addresses[i];
}
}
}
LogUtil.info( iplist + "]");
}
/// <summary>
/// 开始服务
/// </summary>
public void Start(int m_serverPort)
{
try
{
IPEndPoint ipep = new IPEndPoint(IPAddress.Any, m_serverPort);//定义一网络端点
udpServer = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);//定义一个Socket
udpServer.Bind(ipep);//Socket与本地的一个终结点相关联
m_serverThread = new Thread(new ThreadStart(ReceiveData));
m_serverThread.Start();
logLocalIp();
isRun = true;
}
catch (Exception ex)
{
LogUtil.error("启动udpserver出错:" + ex.ToString());
}
}
/// <summary>
/// 停止服务
/// </summary>
public void Stop()
{
try
{
isRun = false;
m_serverThread.Interrupt(); // 线程终止
udpServer.Close(); // Socket Close
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
}
private StringBuilder sb = new StringBuilder(); //这个是用来保存:接收到了的,但是还没有结束的消息
private int receiveBufferSize = 1024;
private string terminateString = "\r";
private void ReceiveData()
{
try
{
IPEndPoint sender = new IPEndPoint(IPAddress.Any, 0);//定义要发送的计算机的地址
EndPoint Remote = (EndPoint)(sender);//
while (true)
{
byte[] buffer = new byte[receiveBufferSize];
int receivedSize = udpServer.ReceiveFrom(buffer, ref Remote);
if (receivedSize > 0)
{
string rawMsg = Encoding.ASCII.GetString(buffer, 0, receivedSize);
int rnFixLength = terminateString.Length; //这个是指消息结束符的长度,此处为\r\n
for (int i = 0; i < rawMsg.Length; ) //遍历接收到的整个buffer文本
{
if (i <= rawMsg.Length - rnFixLength)
{
if (rawMsg.Substring(i, rnFixLength) != terminateString)//非消息结束符,则加入sb
{
sb.Append(rawMsg[i]);
i++;
}
else
{
this.ReviceMsgEvent.Invoke(Remote, sb.ToString());//找到了消息结束符,触发消息接收完成事件
sb = new StringBuilder();
i += rnFixLength;
}
}
else
{
sb.Append(rawMsg[i]);
i++;
}
}
}
Thread.Sleep(500);
}
}
catch (Exception ex)
{
LogUtil.error("启动udpserver出错:" + ex.ToString());
}
}
/// <summary>
/// 获取本机地址列表
/// </summary>
public string[] GetLocalAddresses()
{
// 获取主机名
string strHostName = Dns.GetHostName();
// 根据主机名进行查找
IPHostEntry iphostentry = Dns.GetHostEntry(strHostName);
string[] retval = new string[iphostentry.AddressList.Length];
int i = 0;
foreach (IPAddress ipaddress in iphostentry.AddressList)
{
if (ipaddress.AddressFamily != AddressFamily.InterNetworkV6)
{
retval[i] = ipaddress.ToString();
i++;
}
}
return retval;
}
}
}
类型,分类编号,说明,名称,属性值,设备名称,电器定义,目标速度,加速时间,减速时间,原点低速度,原点高速,原点加速度,脉冲最小误差,脉冲最大误差,脉冲最小限位,脉冲最大限位
AXIS,,0-行走机构,XAxis,0,HC,,40000,200000,200000,2000,20000,80000,10,300,0,0
AXIS,,1-升降轴,YAxis,1,HC,,40000,200000,200000,2000,20000,80000,10,300,0,0
AXIS,,2-伸缩轴,ZAxis,2,HC,,40000,200000,200000,1000,4000,15000,10,300,0,0
AXIS,,3-入料线体顶升电机,InLift_Moto,3,HC,,40000,200000,200000,1000,4000,15000,10,300,0,0
AXIS,,4-出料线体顶升电机,OutLift_Moto,4,HC,,40000,200000,200000,1000,4000,15000,10,300,0,0
,,,,,,,,,,,,,,,,
PRO,50,IO信号超时时间(秒),IOSingle_TimerOut,15,,,,,,,,,,,,
PRO,50,气压检测超时,AirCheckSeconds,5,,,,,,,,,,,,
PRO,50,扫码相机,CameraName,asdasdasd,,,,,,,,,,,,
PRO,40,入料线体顶升电机速度,InLift_Moto_Speed,10,,,,,,,,,,,,
PRO,40,出料线体顶升电机速度,OutLift_Moto_Speed,10,,,,,,,,,,,,
PRO,40,称重传感器端口,WeightSensorPort,COM1,,,,,,,,,,,,
PRO,40,称重传感器皮重,WeightSensorBase,22,,,,,,,,,,,,
PRO,40,库位最大承重,StoreWeightLimited,30,,,,,,,,,,,,
,,,,,,,,,,,,,,,,
,,,,,,,,,,,,,,,,
PRO,10,行走机构待机点P1,Xaxis_P1,1,,,22,,,,,,,,,
PRO,10,行走机构取料点A侧P2,Xaxis_P2,1,,,22,,,,,,,,,
PRO,10,行走机构取料点B侧P3,Xaxis_P3,1,,,22,,,,,,,,,
,,,,,,,,,,,,,,,,
PRO,11,升降轴待机点P1,Yaxis_P1,2,,,22,,,,,,,,,
PRO,11,升降取料低点A侧P2/入库速度,Yaxis_P2,2,,,22,,,,,,,,,
PRO,11,升降取料低点B侧P3,Yaxis_P3,2,,,22,,,,,,,,,
PRO,11,升降取料高点A侧P4/出库速度,Yaxis_P4,2,,,22,,,,,,,,,
PRO,11,升降取料高点B侧P5,Yaxis_P5,2,,,22,,,,,,,,,
,,,,,,,,,,,,,,,,
PRO,12,伸缩轴待机点P1,Zaxis_P1,3,,,22,,,,,,,,,
PRO,12,伸缩轴A面取料点P2,Zaxis_P2,3,,,22,,,,,,,,,
PRO,12,伸缩轴B面取料点P3,Zaxis_P3,3,,,22,,,,,,,,,
,,,,,,,,,,,,,,,,
DI,0,急停,SuddenStop_BTN,0,HC,X00,,,,,,,,,,
DI,0,复位,Reset_BTN,1,HC,X01,,,,,,,,,,
DI,0,气压检测,Airpressure_Check,2,HC,X02,,,,,,,,,,
DI,0,前门门禁信号,FrontDoor_Check,3,HC,X03,,,,,,,,,,
DI,0,后门门禁信号,BackDoor_Check,4,HC,X04,,,,,,,,,,
DI,0,进线入口安全光栅,InEntry_SafetyGrating,5,HC,X05,,,,,,,,,,
DI,0,进线侧方安全光栅,InSide_SafetyGrating,6,HC,X06,,,,,,,,,,
DI,0,出线出口安全光栅,OutExit_SafetyGrating,7,HC,X07,,,,,,,,,,
DI,0,出线侧方安全光栅,OutSide_SafetyGrating,8,HC,X08,,,,,,,,,,
DI,0,伸缩叉物料检测,ForkMaterial_Check,9,HC,X09,,,,,,,,,,
DI,0,A侧伸缩叉物料检测,SideA_ForkMaterial_Check,10,HC,X10,,,,,,,,,,
DI,0,B侧伸缩叉物料检测,SideB_ForkMaterial_Check,11,HC,X11,,,,,,,,,,
DI,0,提升机构第一层检测,Lift_1Level_Check,12,HC,X12,,,,,,,,,,
DI,0,提升机构第二层检测,Lift_2Level_Check,13,HC,X13,,,,,,,,,,
DI,0,提升机构第三层检测,Lift_3Level_Check,14,HC,X14,,,,,,,,,,
DI,0,提升机构第四层检测,Lift_4Level_Check,15,HC,X15,,,,,,,,,,
DI,0,提升机构第五层检测,Lift_5Level_Check,16,HC,X16,,,,,,,,,,
DI,0,提升机构第六层检测,Lift_6Level_Check,17,HC,X17,,,,,,,,,,
DI,0,进线物料超高检测,InOverHead_Check,18,HC,X18,,,,,,,,,,
DI,0,进线启动,InStart_BTN,19,HC,X19,,,,,,,,,,
DI,0,进线前端推车检测,InFrontCar_Check,20,HC,X20,,,,,,,,,,
DI,0,进线前端物料检测,InFrontMaterial_Check,21,HC,X21,,,,,,,,,,
DI,0,进线阻挡物料检测,InStopMaterial_Check,22,HC,X22,,,,,,,,,,
DI,0,进线阻挡上升端,InStop_Up,23,HC,X23,,,,,,,,,,
DI,0,进线阻挡下降端,InStop_Down,24,HC,X24,,,,,,,,,,
DI,0,进线末端上方物料检测,InEndMaterialTop_Check,25,HC,X25,,,,,,,,,,
DI,0,进线末端下方物料检测,InEndMaterialBottom_Check,26,HC,X26,,,,,,,,,,
DI,0,进线定位前进端,InMaterialLocation_Fwd,27,HC,X27,,,,,,,,,,
DI,0,进线定位后退端,InMaterialLocation_Bck,28,HC,X28,,,,,,,,,,
DI,0,进线顶升机构上升端,InLift_Up,29,HC,X29,,,,,,,,,,
DI,0,进线顶升机构下降端,InLift_Down,30,HC,X30,,,,,,,,,,
DI,0,出线物料放行,OutLeave_BTN,31,HC,X31,,,,,,,,,,
DI,0,出线出口推车检测,OutExitCar_Check,32,HC,X32,,,,,,,,,,
DI,0,出线出口物料检测,OutExitMaterial_Check,33,HC,X33,,,,,,,,,,
DI,0,出线出口阻挡上升端,OutExitStop_Up,34,HC,X34,,,,,,,,,,
DI,0,出线出口阻挡下降端,OutExitStop_Down,35,HC,X35,,,,,,,,,,
DI,0,出线阻挡物料检测,OutStopMaterial_Check,36,HC,X36,,,,,,,,,,
DI,0,出线阻挡上升端,OutStop_Up,37,HC,X37,,,,,,,,,,
DI,0,出线阻挡下降端,OutStop_Down,38,HC,X38,,,,,,,,,,
DI,0,出线入口上方物料检测,OutEntryMaterialTop_Check,39,HC,X39,,,,,,,,,,
DI,0,出线入口下方物料检测,OutEntryMaterialBottom_Check,40,HC,X40,,,,,,,,,,
DI,0,出线顶升机构上升端,OutLift_Up,41,HC,X41,,,,,,,,,,
DI,0,出线顶升机构下降端,OutLift_Down,42,HC,X42,,,,,,,,,,
,,,,,,,,,,,,,,,,
DO,0,自动绿色指示灯,Run_Led,0,HC,Y00,,,,,,,,,,
DO,0,故障红色指示灯,Alarm_Led,1,HC,Y01,,,,,,,,,,
DO,0,待机黄色指示灯,Standby_Led,2,HC,Y02,,,,,,,,,,
DO,0,报警蜂鸣器,Alarm_Buzzer,3,HC,Y03,,,,,,,,,,
DO,0,物料NG指示灯,MaterialNG_Led,4,HC,Y04,,,,,,,,,,
DO,0,门禁屏蔽,DoorSafe_Disable,5,HC,Y05,,,,,,,,,,
DO,0,设备照明,Device_Led,6,HC,Y06,,,,,,,,,,
DO,0,相机照明,Camera_Led,7,HC,Y07,,,,,,,,,,
DO,0,进线顶升电机刹车解除,InLift_Break,8,HC,Y08,,,,,,,,,,
DO,0,进线电机启动,InMoto_Run,9,HC,Y09,,,,,,,,,,
DO,0,进线阻挡上升,InStop_Up,10,HC,Y10,,,,,,,,,,
DO,0,进线阻挡下降,InStop_Down,11,HC,Y11,,,,,,,,,,
DO,0,进线定位阻挡上升,InMaterialLocation_Fwd,12,HC,Y12,,,,,,,,,,
DO,0,进线定位阻挡下降,InMaterialLocation_Bck,13,HC,Y13,,,,,,,,,,
DO,0,出线顶升电机刹车解除,OutLift_Break,14,HC,Y14,,,,,,,,,,
DO,0,出线电机启动,OutMoto_Run,15,HC,Y15,,,,,,,,,,
DO,0,出线出口阻挡上升,OutExitStop_Up,16,HC,Y16,,,,,,,,,,
DO,0,出线出口阻挡下降,OutExitStop_Down,17,HC,Y17,,,,,,,,,,
DO,0,出线阻挡上升,OutStop_Up,18,HC,Y18,,,,,,,,,,
DO,0,出线阻挡下降,OutStop_Down,19,HC,Y19,,,,,,,,,,
<?xml version="1.0" encoding="UTF-8"?>
<config ver="10">
<item key="App_Title" ver="10" value="SMD-BOX-XLC" />
<item key="EnableBuzzer" ver="10" value="False" />
</config>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{BB23296C-AA1D-45C6-9FA6-5A37B2ABFE9B}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>DeviceLibrary</RootNamespace>
<AssemblyName>DeviceLibrary</AssemblyName>
<TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<Deterministic>true</Deterministic>
<TargetFrameworkProfile />
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="Asa.PrintLabel">
<HintPath>..\..\PrintLabel\PrintLabel\bin\Debug\Asa.PrintLabel.dll</HintPath>
</Reference>
<Reference Include="CodeLibrary">
<HintPath>..\..\GeneralClassLibrary\CodeLibraryProject\CodeLibrary\bin\Debug\CodeLibrary.dll</HintPath>
</Reference>
<Reference Include="ConfigHelper">
<HintPath>..\..\ConfigHelper\ConfigHelper\bin\Debug\ConfigHelper.dll</HintPath>
</Reference>
<Reference Include="halcondotnet">
<HintPath>..\..\RC1271-DUOStore\dll\halcondotnet.dll</HintPath>
</Reference>
<Reference Include="HuichuanLibrary">
<HintPath>..\..\HuichuanLibrary\HuichuanLibrary\bin\Debug\HuichuanLibrary.dll</HintPath>
</Reference>
<Reference Include="log4net">
<HintPath>..\..\增广夹爪\Rmaxis\bin\Debug\log4net.dll</HintPath>
</Reference>
<Reference Include="Neotel.Rmaxis">
<HintPath>..\..\增广夹爪\Rmaxis\bin\Debug\Neotel.Rmaxis.dll</HintPath>
</Reference>
<Reference Include="SdkApi.Core">
<HintPath>..\..\LinkOS-PC-Samples-ZSDK_DevDemos_.NET\Source\Sdk\SdkApi.Core.dll</HintPath>
</Reference>
<Reference Include="SdkApi.Desktop">
<HintPath>..\..\LinkOS-PC-Samples-ZSDK_DevDemos_.NET\Source\Sdk\SdkApi.Desktop.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Drawing" />
<Reference Include="System.Windows.Forms" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="DeviceLibrary\AcSerialBean.cs" />
<Compile Include="DeviceLibrary\IOMonitor.cs" />
<Compile Include="DeviceLibrary\LiftMonitor.cs" />
<Compile Include="DeviceLibrary\LineRunMonitor.cs" />
<Compile Include="DeviceLibrary\C8WeightSensor.cs" />
<Compile Include="DeviceLibrary\OKLEController.cs" />
<Compile Include="DeviceLibrary\ServerCommunication.cs" />
<Compile Include="theMachine\AxisBean.cs" />
<Compile Include="theMachine\BoxTransport.cs" />
<Compile Include="theMachine\Common.cs" />
<Compile Include="theMachine\JobList.cs" />
<Compile Include="theMachine\LabelParam.cs" />
<Compile Include="theMachine\MainMachine _BtnProcess.cs" />
<Compile Include="theMachine\MainMachine _Common.cs" />
<Compile Include="theMachine\MainMachine _Out.cs" />
<Compile Include="theMachine\MainMachine _Store.cs" />
<Compile Include="theMachine\MainMachine _IN.cs" />
<Compile Include="theMachine\MainMachine _IOMonitor.cs" />
<Compile Include="theMachine\MainMachine _LedProcess.cs" />
<Compile Include="theMachine\MainMachine.cs" />
<Compile Include="theMachine\MoveInfo.cs" />
<Compile Include="theMachine\MoveStep.cs" />
<Compile Include="DeviceLibrary\AlarmBuzzer.cs" />
<Compile Include="DeviceLibrary\CodeManager.cs" />
<Compile Include="theMachine\RobotManage.cs" />
<Compile Include="theMachine\IRobot.cs" />
<Compile Include="DeviceLibrary\IAxisManager.cs" />
<Compile Include="DeviceLibrary\AxisManager.cs" />
<Compile Include="DeviceLibrary\HC\HCAxisManager.cs" />
<Compile Include="DeviceLibrary\HC\HCIOManager.cs" />
<Compile Include="DeviceLibrary\I_IOManager.cs" />
<Compile Include="DeviceLibrary\IOManager.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="userControl\AxisMoveControl.cs">
<SubType>UserControl</SubType>
</Compile>
<Compile Include="userControl\AxisMoveControl.Designer.cs">
<DependentUpon>AxisMoveControl.cs</DependentUpon>
</Compile>
<Compile Include="userControl\AxisTipControl.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="userControl\AxisTipControl.Designer.cs">
<DependentUpon>AxisTipControl.cs</DependentUpon>
</Compile>
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="userControl\AxisMoveControl.resx">
<DependentUpon>AxisMoveControl.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="userControl\AxisTipControl.resx">
<DependentUpon>AxisTipControl.cs</DependentUpon>
</EmbeddedResource>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Common\Common.csproj">
<Project>{43cdd09e-fcf3-4960-a01d-3bbfe9933122}</Project>
<Name>Common</Name>
</ProjectReference>
<ProjectReference Include="..\LoadCVSLibrary\LoadCSVLibrary.csproj">
<Project>{064bebf5-8faa-4ea2-a5f3-a06e6e7d9251}</Project>
<Name>LoadCSVLibrary</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<Content Include="Config\Config.csv">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
</ItemGroup>
<ItemGroup>
<None Include="Config\general.config">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="packages.config" />
<None Include="StoreConfig\linePositions.csv">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
\ No newline at end of file
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DeviceLibrary
{
public class AlarmBuzzer
{
delegate void on();
static on ondelegate;
static on offdelegate;
static bool enable = false;
public static bool Enable
{
get => enable; set
{
enable = value;
if (!value)
{
OFF();
}
}
}
static AlarmBuzzerState State = AlarmBuzzerState.OFF;
public static event EventHandler<bool> BuzzerStateChange;
public static void SetOnOffAction(Action ona, Action offa)
{
ondelegate = new on(ona);
offdelegate = new on(offa);
}
public static void ON(bool force = false)
{
if (!Enable)
return;
if (force || (State != AlarmBuzzerState.ON && State != AlarmBuzzerState.MuteOnce))
{
State = AlarmBuzzerState.ON;
ondelegate?.Invoke();
BuzzerStateChange?.Invoke(null, true);
}
}
public static void OFF()
{
if (State == AlarmBuzzerState.OFF)
return;
State = AlarmBuzzerState.OFF;
offdelegate?.Invoke();
BuzzerStateChange?.Invoke(null, false);
}
public static void MuteOnce()
{
if (State == AlarmBuzzerState.ON)
{
State = AlarmBuzzerState.MuteOnce;
offdelegate?.Invoke();
BuzzerStateChange?.Invoke(null, false);
}
}
}
enum AlarmBuzzerState
{
ON,
OFF,
MuteOnce
}
}
using OnlineStore.Common;
using OnlineStore.LoadCSVLibrary;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DeviceLibrary
{
public class AxisManager
{
public bool IsShowMsg = false;
static IAxisManager instance;
public static bool UseHCBoard = true;
static AxisManager() {
instance = new HCAxisManager();
}
public static bool IsServeoOn(string portName, short slvAddr) {
return instance.IsServeoOn(portName, slvAddr);
}
public static bool OpenCard() {
return instance.OpenCard();
}
public bool CloseCard() {
return instance.CloseCard();
}
public static bool IsHomeMoveEnd(string portName, short slvAddr) {
return instance.IsHomeMoveEnd(portName, slvAddr);
}
public static bool AbsMoveIsEnd(string portName, short axisNo, int targetPosition, int canErrorCount, out bool countError)
{
return instance.AbsMoveIsEnd(portName, axisNo, targetPosition, canErrorCount, out countError);
}
public static void ServoOn(string portName, short slvAddr)
{
instance.ServoOn(portName, slvAddr);
}
public static void ServoOff(string portName, short slvAddr)
{
instance.ServoOff(portName, slvAddr);
}
public static void RelMove(string portName, short slvAddr, int position, int targetSpeed , int ptpAcc , int ptpDec )
{
instance.RelMove(portName, slvAddr, position, targetSpeed, ptpAcc, ptpDec);
}
public static void HomeMove(string portName, short slvAddr, int highVel, int lowVel, int acc)
{
instance.HomeMove(portName, slvAddr, highVel, lowVel, acc);
}
public static void SpeedMove(string portName, short slvAddr, int speed,int acc,int dec)
{
instance.SpeedMove(portName, slvAddr, speed,acc,dec);
}
public static void SuddenStop(string portName, short slvAddr)
{
instance.SuddenStop(portName, slvAddr);
}
public static bool isInPosition(string portName, short slvAddr, int PPosition, int canErrorCount, bool isLog = false)
{
return instance.isInPosition(portName, slvAddr, PPosition, canErrorCount, isLog);
}
public static void AbsMove(string portName, short slvAddr, int targetPosition, int targetSpeed , int ptpAcc , int ptpDec )
{
instance.AbsMove(portName, slvAddr, targetPosition, targetSpeed, ptpAcc, ptpDec);
}
public static void AlarmClear(string portName, short slvAddr)
{
instance.AlarmClear(portName, slvAddr);
}
public static int GetTargetPosition(string portName, short slvAddr)
{
return instance.GetTargetPosition(portName, slvAddr);
}
public static int GetActualtPosition(string portName, short slvAddr)
{
return instance.GetActualtPosition(portName, slvAddr);
}
public static int AxisStsINP(string portName, short slvAddr)
{
return instance.AxisStsINP(portName, slvAddr);
}
public static int GetAlarmStatus(string portName, short slvAddr)
{
return instance.GetAlarmStatus(portName, slvAddr);
}
public static int GetBusyStatus(string portName, short slvAddr)
{
return instance.GetBusyStatus(portName, slvAddr);
}
public static int GetHomeEndStatus(string portName, short slvAddr)
{
return instance.GetHomeEndStatus(portName, slvAddr);
}
public static int GetHomeSingle(string portName, short slvAddr)
{
return instance.GetHomeSingle(portName, slvAddr);
}
/// <summary>
/// 负极限
/// </summary>
public static int GetLimitNegativeSingle(string portName, short slvAddr)
{
return instance.GetLimitNegativeSingle(portName, slvAddr);
}
/// <summary>
/// 正极限
/// </summary>
public static int GetLimitPositiveSingle(string portName, short slvAddr)
{
return instance.GetLimitPositiveSingle(portName, slvAddr);
}
public static short GetErrorCode(string portName, short slvAddr)
{
return instance.GetErrorCode(portName, slvAddr);
}
public static void SuddenStop(ConfigMoveAxis configMoveAxis)
{
SuddenStop(configMoveAxis.DeviceName, configMoveAxis.GetAxisValue());
}
public static int GetActualtPosition(ConfigMoveAxis configMoveAxis) {
return GetActualtPosition(configMoveAxis.DeviceName, configMoveAxis.GetAxisValue());
}
public static bool ServerOnStatus(string portName, short slvAddr) {
return IsServeoOn(portName, slvAddr);
}
public static bool isInPosition(ConfigMoveAxis configMoveAxis, int PPosition, bool isLog = false) {
return isInPosition(configMoveAxis.DeviceName, configMoveAxis.GetAxisValue(), PPosition, configMoveAxis.CanErrorCountMax, isLog);
}
}
}
using OnlineStore.Common;
using System;
using System.Collections.Generic;
using System.IO.Ports;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
public class C8WeightSensor
{
private static int bautRate = 9600;//波特率
private static Parity parity = Parity.None;//校验位
private static int dataBits = 8;//数据位
private static StopBits stopBits = StopBits.One; //停止位
private static Dictionary<string, AcSerialBean> SerialMap = new Dictionary<string, AcSerialBean>();
private static string LogName = "";
private static AcSerialBean GetSerialBean(string port)
{
if (SerialMap.ContainsKey(port))
{
return SerialMap[port];
}
return null;
}
public static bool Init(string port)
{
if (SerialMap.ContainsKey(port))
{
return true;
}
LogName = "[OKLE_" + port + "]";
AcSerialBean sb = new AcSerialBean(port, bautRate, parity, dataBits, stopBits);
try
{
if (sb.openPort())
{
if (SerialMap.ContainsKey(port))
{
SerialMap.Remove(port);
}
SerialMap.Add(port, sb);
return true;
}
else
{
LogUtil.error(LogName + "串口打开失败!");
return false;
}
}
catch (Exception ex)
{
LogUtil.error(LogName + "打开出错:" + ex.ToString());
}
return true;
}
public static bool IsRun(string port)
{
if (GetSerialBean(port) != null)
{
return true;
}
return false;
}
/// <summary>
/// 释放资源
/// </summary>
public static void Release(params string[] ports)
{
if (ports.Length <= 0)
{
ports = (new List<string>(SerialMap.Keys)).ToArray();
}
foreach (string port in ports)
{
try
{
AcSerialBean sb = GetSerialBean(port);
if (sb != null)
{
sb.closePort();
}
//IsRun = false;
SerialMap.Remove(port);
}
catch (Exception ex)
{
LogUtil.error("Release OKLE port [" + port + "] error :" + ex.ToString());
}
}
}
public static double queryData(string port)
{
double weight = 0d;
AcSerialBean sb = GetSerialBean(port);
if (sb == null)
{
return weight;
}
LogName = "[OKLE_" + port + "]";
//12..1.2读取力值(毛重)指令,指令格式:02 41 42 30 33 03
byte[] sendData = new byte[6];
sendData[0] = 0x02;
sendData[1] = 0x41;
sendData[2] = 0x42;
sendData[3] = 0x30;
sendData[4] = 0x44;
sendData[5] = 0x03;
//sendData = buildCheckData(sendData, sendData.Length - 2);
string str = AcSerialBean.byteToHexStr(sendData, " ");
byte[] reviceData = new byte[14];
bool isOk = false;
sb.SendCommand(sendData, ref reviceData, 100, out isOk);
LogUtil.debug(LogName + "发送数据:" + str + ",收到数据 :" + AcSerialBean.byteToHexStr(reviceData, " "));
return getReviceData(reviceData);
}
public static double CalWeight(double value, double dValue = 0, double xishu = 1)
{
double v = (double)(value - dValue) * xishu;
LogUtil.debug("重量计算 (" + value + "-" + dValue + ")*" + xishu + "=" + v);
return v;
}
private static double getReviceData(byte[] dataArray)
{
double value = 0d;
try
{
if (dataArray.Length >= 14)
{
//以栈号01仪表为例子
//01仪表发送的毛重消息为02 41 62 2B 30 30 31 2E 30 30 30 32 37 03。
//2B 30 30 31 2E 30 30 30位具体的毛重数据,转换为ASCII码为 + 001.000;
//32H为校验码高位,37H为校验码低位,03H为结束符;
var datatxt = Encoding.ASCII.GetString(dataArray);
datatxt = datatxt.Substring(3, 8);
double.TryParse(datatxt, out value);
}
}
catch (Exception ex)
{
LogUtil.info(LogName + "转换出错:" + ex.ToString());
}
return value;
}
private static byte[] buildCheckData(byte[] sendData, int length)
{
ushort pChecksum = 0;
AcSerialBean.CalculateCRC(sendData, length, out pChecksum);
string checkStr = Convert.ToString(pChecksum, 16);
byte[] checkByte = AcSerialBean.StringToByte(checkStr);
if (checkByte.Length == 1)
{
sendData[length] = checkByte[0];
sendData[length + 1] = 0x00;
}
else
{
sendData[length + 1] = checkByte[0];
sendData[length] = checkByte[1];
}
return sendData;
}
}
using HuichuanLibrary;
using OnlineStore.LoadCSVLibrary;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DeviceLibrary
{
public class HCAxisManager : IAxisManager
{
public bool OpenCard()
{
return HCBoardManager.OpenCard();
}
public bool CloseCard()
{
return HCBoardManager.CloseCard();
}
public void AbsMove(string portName, short slvAddr, int targetPosition, int targetSpeed,int ptpAcc,int ptpDec)
{
HCBoardManager.AbsMove((short)slvAddr, targetPosition, targetSpeed, ptpAcc, ptpDec);
}
public void AlarmClear(string portName, short slvAddr)
{
HCBoardManager.ClearAxisSts((short)slvAddr);
}
public int GetActualtPosition(string portName, short slvAddr)
{
return (int)HCBoardManager.GetAxisCurrPos(slvAddr);
}
public int GetAlarmStatus(string portName, short slvAddr)
{
AxisSts axisS= HCBoardManager.GetAxisSts(slvAddr);
return axisS.ALM;
}
public int GetBusyStatus(string portName, short slvAddr)
{
AxisSts axisS = HCBoardManager.GetAxisSts(slvAddr);
//HCLogUtil.info(axisS.ToStr());
return axisS.BUSY;
}
public int GetHomeEndStatus(string portName, short slvAddr)
{
return (int) HCBoardManager.GetHomeStatus(slvAddr);
}
public int GetHomeSingle(string portName, short slvAddr)
{
AxisSts axisS = HCBoardManager.GetAxisSts(slvAddr);
return axisS.ALM;
}
public int GetLimitNegativeSingle(string portName, short slvAddr)
{
AxisSts axisS = HCBoardManager.GetAxisSts(slvAddr);
return axisS.NEL;
}
public int GetLimitPositiveSingle(string portName, short slvAddr)
{
AxisSts axisS = HCBoardManager.GetAxisSts(slvAddr);
return axisS.PEL;
}
public int GetTargetPosition(string portName, short slvAddr)
{
return (int)HCBoardManager.GetAxisPrfPos(slvAddr);
}
public void HomeMove(string portName, short slvAddr, int highVel, int lowVel, int acc)
{
HCBoardManager.StartHomeMove(slvAddr,(uint) highVel, (uint)lowVel, (uint)acc);
}
public bool IsHomeMoveEnd(string portName, short slvAddr)
{
return HCBoardManager.HomeingIsEnd(slvAddr);
}
public bool isInPosition(string portName, short slvAddr, int PPosition, int canErrorCount, bool isLog = false)
{
return HCBoardManager.IsInPosition(slvAddr, PPosition,canErrorCount );
}
public void RelMove(string portName, short slvAddr, int position, int targetSpeed, int ptpAcc , int ptpDec )
{
HCBoardManager.RelMove(slvAddr, position, targetSpeed, ptpAcc, ptpDec);
}
public bool IsServeoOn(string portName, short slvAddr)
{
AxisSts axisS = HCBoardManager.GetAxisSts(slvAddr);
return axisS.ServoOn.Equals(1);
}
public int AxisStsINP(string portName, short slvAddr)
{
return HCBoardManager.GetAxisSts(slvAddr).INP;
}
public void ServoOff(string portName, short slvAddr)
{
HCBoardManager.ServoOff(slvAddr);
}
public void ServoOn(string portName, short slvAddr)
{
HCBoardManager.ServoOn(slvAddr);
}
public void SpeedMove(string portName, short slvAddr, int speed,int acc=0, int dec=0)
{
HCBoardManager.SpeedMove(slvAddr, speed, acc, dec);
}
public void SuddenStop(string portName, short slvAddr)
{
HCBoardManager.AxisStop(slvAddr);
}
public bool AbsMoveIsEnd(string portName, short axisNo, int targetPosition, int canErrorCount, out bool countError)
{
countError = false;
bool isOk = HCBoardManager.MoveIsEnd(axisNo);
if (isOk)
{
if (HCBoardManager.IsInPosition(axisNo, targetPosition, canErrorCount))
{
return true;
}
else
{
countError = true;
}
}
return false;
}
public short GetErrorCode(string portName, short slvAddr)
{
return HCBoardManager.GetAxErrCode(slvAddr);
}
}
}
using DeviceLibrary;
using HuichuanLibrary;
using OnlineStore.Common;
using OnlineStore.LoadCSVLibrary;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
namespace OnlineStore.DeviceLibrary.IO
{
public class HCIOManager : I_IOManager
{
public void CloseAllConnection()
{
HCBoardManager.CloseCard();
}
public void CloseAllDO()
{
HCBoardManager.CloseAllDO();
}
public bool ConnectionIOList(List<string> dIODeviceNameList)
{
if (!HCBoardManager.CardInitOk())
{
HCBoardManager.InitConfig("", "", "HCBOARD");
if (!HCBoardManager.OpenCard())
{
LogUtil.info("板卡第一次打开失败,关闭后重新打开");
HCBoardManager.CloseCard();
Thread.Sleep(2000);
return HCBoardManager.OpenCard();
}
}
return true;
}
public IO_VALUE GetDIValue(string deviceName, byte slaveID, ushort index)
{
short v = HCBoardManager.GetBitDI((short)index);
return (IO_VALUE)v;
}
public IO_VALUE GetDOValue(string deviceName, byte slaveID, ushort index)
{
short v = HCBoardManager.GetBitDO((short)index);
return (IO_VALUE)v;
}
public IO_VALUE GetIOValue(ConfigIO configIO)
{
short index =(short) configIO.GetIOAddr();
short v;
if (configIO.ProType=="DO")
v= HCBoardManager.GetBitDO(index);
else
v = HCBoardManager.GetBitDI(index);
return (IO_VALUE)v;
}
public void ReadAllDI(string deviceName, byte slaveId)
{
}
public void ReadAllDO(string deviceName, byte slaveId)
{
}
public void WriteSingleDO(string deviceName, byte slaveId, ushort index, IO_VALUE value, int time)
{
try
{
short v = (short)value;
HCBoardManager.SetBitDO((short)index, v);
short targetV = 0;
if (v.Equals((short)0))
{
targetV = 1;
}
//写入之后,等待指定间隔后回写
System.Timers.Timer mytimer = new System.Timers.Timer(time);
mytimer.Elapsed += (o1, e1) =>
{
try
{
HCBoardManager.SetBitDO((short)index, targetV);
}
catch (Exception ex)
{
LogUtil.error("**********定时回写入 出错:" + ex.StackTrace);
}
};
mytimer.AutoReset = false;
mytimer.Enabled = true;
}
catch (Exception ex)
{
LogUtil.error("AIO WriteSingleDO [" + index + "] 出错:" + ex.ToString());
}
}
public void WriteSingleDO(string deviceName, byte slaveId, ushort index, IO_VALUE value)
{
short v = (short)value;
HCBoardManager.SetBitDO((short)index, v);
}
}
}
using HuichuanLibrary;
using OnlineStore.Common;
using OnlineStore.LoadCSVLibrary;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DeviceLibrary
{
public interface IAxisManager
{
bool IsServeoOn(string portName, short slvAddr);
bool OpenCard();
bool CloseCard();
bool IsHomeMoveEnd(string portName, short slvAddr);
bool AbsMoveIsEnd(string portName, short axisNo, int targetPosition, int canErrorCount, out bool countError);
void ServoOn(string portName, short slvAddr);
void ServoOff(string portName, short slvAddr);
void RelMove(string portName, short slvAddr, int position, int targetSpeed , int ptpAcc , int ptpDec );
void HomeMove(string portName, short slvAddr, int highVel, int lowVel, int acc);
void SpeedMove(string portName, short slvAddr, int speed,int acc,int dec);
void SuddenStop(string portName, short slvAddr);
bool isInPosition(string portName, short slvAddr, int PPosition, int canErrorCount, bool isLog = false);
void AbsMove(string portName, short slvAddr, int targetPosition, int targetSpeed , int ptpAcc , int ptpDec );
void AlarmClear(string portName, short slvAddr);
int GetTargetPosition(string portName, short slvAddr);
int GetActualtPosition(string portName, short slvAddr);
int GetAlarmStatus(string portName, short slvAddr);
int GetBusyStatus(string portName, short slvAddr);
int GetHomeEndStatus(string portName, short slvAddr);
int GetHomeSingle(string portName, short slvAddr);
/// <summary>
/// 负极限
/// </summary>
int GetLimitNegativeSingle(string portName, short slvAddr);
/// <summary>
/// 正极限
/// </summary>
int GetLimitPositiveSingle(string portName, short slvAddr);
int AxisStsINP(string portName, short slvAddr);
short GetErrorCode(string portName, short slvAddr);
}
}
using DeviceLibrary;
using OnlineStore.Common;
using OnlineStore.DeviceLibrary.IO;
using OnlineStore.LoadCSVLibrary;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
namespace DeviceLibrary
{
using StoreManager = RobotManage;
public class IOManager
{
static I_IOManager instance = null;
static IOManager()
{
instance = new HCIOManager();
}
public static void IOMove(string ioType, IO_VALUE ioValue)
{
if (StoreManager.Config.DOList.ContainsKey(ioType))
{
ConfigIO configIo = StoreManager.Config.DOList[ioType];
instance.WriteSingleDO(configIo.DeviceName, configIo.SlaveID, configIo.GetIOAddr(), ioValue);
//Thread.Sleep(60);
}
else
{
LogUtil.error("没有DO=" + ioType);
}
}
public static IO_VALUE IOValue(string ioType, object o = null)
{
IO_VALUE ioValue = IO_VALUE.LOW;
if (StoreManager.Config.DIList.ContainsKey(ioType))
{
ConfigIO configIo = StoreManager.Config.DIList[ioType];
ioValue = instance.GetDIValue(configIo.DeviceName, configIo.SlaveID, configIo.GetIOAddr());
//UpdateDoValue(ioType, ioValue);
}
else if (StoreManager.Config.DOList.ContainsKey(ioType))
{
ConfigIO configIo = StoreManager.Config.DOList[ioType];
ioValue = instance.GetDOValue(configIo.DeviceName, configIo.SlaveID, configIo.GetIOAddr());
}
else
{
LogUtil.error("没有DO=" + ioType);
}
return ioValue;
}
public static IO_VALUE DOValue(string ioType)
{
IO_VALUE ioValue = IO_VALUE.LOW;
if (StoreManager.Config.DOList.ContainsKey(ioType))
{
ConfigIO configIo = StoreManager.Config.DOList[ioType];
ioValue = instance.GetDOValue(configIo.DeviceName, configIo.SlaveID, configIo.GetIOAddr());
}
else
{
LogUtil.error("没有DO=" + ioType);
}
return ioValue;
}
public static bool ConnectionIOList(List<string> dIODeviceNameList)
{
return instance.ConnectionIOList(dIODeviceNameList);
}
static void ReadAllDI(string deviceName, byte slaveId)
{
instance.ReadAllDI(deviceName, slaveId);
}
static void ReadAllDO(string deviceName, byte slaveId)
{
instance.ReadAllDO(deviceName, slaveId);
}
public static void WriteSingleDO(string deviceName, byte slaveId, ushort index, IO_VALUE value, int time)
{
instance.WriteSingleDO(deviceName, slaveId, index, value, time);
}
public static void WriteSingleDO(string deviceName, byte slaveId, ushort index, IO_VALUE value)
{
instance.WriteSingleDO(deviceName, slaveId, index, value);
}
public static IO_VALUE GetDIValue(string deviceName, byte slaveID, ushort v)
{
return instance.GetDIValue(deviceName, slaveID, v);
}
public static IO_VALUE GetDOValue(string deviceName, byte slaveID, ushort v)
{
return instance.GetDOValue(deviceName, slaveID, v);
}
public static IO_VALUE GetIOValue(ConfigIO configIO)
{
return instance.GetIOValue(configIO);
}
public static void CloseAllDO()
{
instance.CloseAllDO();
}
public static void CloseAllConnection()
{
instance.CloseAllConnection();
}
}
}
using OnlineStore.Common;
using OnlineStore.LoadCSVLibrary;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Timers;
namespace DeviceLibrary
{
public class IOMonitor
{
static List<IOMonitorStrut> iOMonitorStruts = new List<IOMonitorStrut>();
readonly static System.Timers.Timer T1 = new System.Timers.Timer();
static IOMonitor() {
Thread.Sleep(5000);
T1.Interval = 30;
T1.Elapsed += T1_Elapsed;
T1.AutoReset = true;
T1.Start();
}
~IOMonitor()
{
T1.Stop();
}
private static void T1_Elapsed(object sender, ElapsedEventArgs e)
{
foreach (var iOMonitorStrut in iOMonitorStruts)
{
var current_iovalue = IOManager.IOValue(iOMonitorStrut.ioType, iOMonitorStrut.Config);
var timediff = new TimeSpan(DateTime.Now.Ticks - iOMonitorStrut.lastFireTime);
if (iOMonitorStrut.last_iO_VALUE == IO_VALUE.None) {
iOMonitorStrut.last_iO_VALUE = current_iovalue;
continue;
}
//LogUtil.OutputDebugString($"IOMonitor: {timediff.TotalMilliseconds},{iOMonitorStrut.Interval},last_iO_VALUE:{iOMonitorStrut.last_iO_VALUE},IOVALUE:{current_iovalue},Need:{iOMonitorStrut.iO_VALUE}");
if (timediff.TotalMilliseconds > iOMonitorStrut.Interval && iOMonitorStrut.last_iO_VALUE != current_iovalue && current_iovalue== iOMonitorStrut.iO_VALUE)
{
iOMonitorStrut.deboundCount += 30;
if (iOMonitorStrut.deboundCount > iOMonitorStrut.debound)
{
iOMonitorStrut.last_iO_VALUE = current_iovalue;
iOMonitorStrut.lastFireTime = DateTime.Now.Ticks;
iOMonitorStrut.deboundCount = 0;
LogUtil.info($"IOMonitor Fire:{iOMonitorStrut.ioType} , value:{iOMonitorStrut.iO_VALUE}");
iOMonitorStrut.a();
}
}
else if (iOMonitorStrut.last_iO_VALUE == current_iovalue)
{
iOMonitorStrut.deboundCount = 0;
}
}
}
public static void RegisterIO(string ioType, DeviceConfig Config, IO_VALUE iO_VALUE, Action a, int Interval=5000,int debound=500) {
IOMonitorStrut iOMonitorStrut = new IOMonitorStrut()
{
ioType = ioType,
Config = Config,
iO_VALUE= iO_VALUE,
a=a,
Interval= Interval,
debound= debound
};
iOMonitorStruts.Add(iOMonitorStrut);
}
static Dictionary<string, long> IODebounddict = new Dictionary<string, long>();
public static bool IODebound(string ioType, DeviceConfig Config, IO_VALUE iO_VALUE, int debound = 1000)
{
long LastStateTick;
if (IODebounddict.ContainsKey(ioType))
LastStateTick = IODebounddict[ioType];
else {
LastStateTick = DateTime.Now.Ticks;
IODebounddict.Add(ioType, LastStateTick);
}
var current_iovalue = IOManager.IOValue(ioType, Config);
if (current_iovalue != iO_VALUE)
{
LastStateTick = DateTime.Now.Ticks;
return false;
}
var timediff = new TimeSpan(DateTime.Now.Ticks - LastStateTick).TotalMilliseconds;
if (timediff > debound) {
return true;
}
return false;
}
class IOMonitorStrut {
public string ioType;
public DeviceConfig Config;
public IO_VALUE iO_VALUE;
public IO_VALUE last_iO_VALUE= IO_VALUE.None;
public Action a;
public int Interval;
public long lastFireTime=DateTime.Now.Ticks;
public int debound;
public int deboundCount=0;
public long LastStateTick = 0;
}
}
}
using DeviceLibrary;
using OnlineStore.Common;
using OnlineStore.DeviceLibrary.IO;
using OnlineStore.LoadCSVLibrary;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
namespace DeviceLibrary
{
public interface I_IOManager
{
bool ConnectionIOList(List<string> dIODeviceNameList);
void ReadAllDI(string deviceName, byte slaveId);
void ReadAllDO(string deviceName, byte slaveId);
void WriteSingleDO(string deviceName, byte slaveId, ushort index, IO_VALUE value, int time);
void WriteSingleDO(string deviceName, byte slaveId, ushort index, IO_VALUE value);
IO_VALUE GetDIValue(string deviceName, byte slaveID, ushort v);
IO_VALUE GetDOValue(string deviceName, byte slaveID, ushort v);
IO_VALUE GetIOValue(ConfigIO configIO);
void CloseAllDO();
void CloseAllConnection();
}
}
using OnlineStore.Common;
using OnlineStore.LoadCSVLibrary;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DeviceLibrary
{
class LiftMonitor
{
string up;
string down;
string axisbreak;
AxisBean axisBean;
int speed;
public LiftMonitor(string _up, string _down,string _break, AxisBean _axisBean,int _speed) {
up = _up;
down = _down;
axisBean = _axisBean;
speed = _speed;
axisbreak = _break;
}
public bool isAtTOP {
get {
return IOManager.IOValue(up.ToString()).Equals(IO_VALUE.HIGH);
}
}
public bool isAtBOTTOM
{
get
{
return IOManager.IOValue(down.ToString()).Equals(IO_VALUE.HIGH);
}
}
public void LiftUp(MoveInfo moveInfo) {
if (IOManager.IOValue(up.ToString()).Equals(IO_VALUE.HIGH)) {
moveInfo.log($"{axisBean.AxisName},已在位置,无需上升");
return;
}
IOManager.IOMove(axisbreak,IO_VALUE.HIGH);
axisBean.SpeedMove(speed);
DateTime d = DateTime.Now;
moveInfo.log($"{axisBean.AxisName},LiftUp");
if(moveInfo!=null)
moveInfo.WaitList.Add(WaitResultInfo.WaitAction(new Func<WaitResultInfo, bool>(WaitUp), "等待顶升机构上升"));
Task.Run(()=> {
while (!IOManager.IOValue(up.ToString()).Equals(IO_VALUE.HIGH)) {
Task.Delay(30);
}
axisBean.SuddenStop();
IOManager.IOMove(axisbreak, IO_VALUE.LOW);
var t = (DateTime.Now - d).TotalSeconds;
moveInfo.log($"{axisBean.AxisName},上升到位,s:{t}");
});
}
bool WaitUp(WaitResultInfo w)
{
if (IOManager.IOValue(up.ToString()).Equals(IO_VALUE.HIGH))
{
axisBean.SuddenStop();
return true;
}
if (!axisBean.IsBusy) {
axisBean.SpeedMove(speed);
}
return false;
}
public void LiftDown(MoveInfo moveInfo)
{
if (IOManager.IOValue(down.ToString()).Equals(IO_VALUE.HIGH))
{
moveInfo.log($"{axisBean.AxisName},已在位置,无需下降");
return;
}
IOManager.IOMove(axisbreak, IO_VALUE.HIGH);
axisBean.SpeedMove(-speed);
DateTime d = DateTime.Now;
moveInfo.log($"{axisBean.AxisName},LiftDown");
if (moveInfo != null)
moveInfo.WaitList.Add(WaitResultInfo.WaitAction(new Func<WaitResultInfo, bool>(WaitDown), "等待顶升机构下降"));
Task.Run(() => {
while (!IOManager.IOValue(down.ToString()).Equals(IO_VALUE.HIGH))
{
Task.Delay(30);
}
axisBean.SuddenStop();
IOManager.IOMove(axisbreak, IO_VALUE.LOW);
var t = (DateTime.Now - d).TotalSeconds;
moveInfo.log($"{axisBean.AxisName},下降到位,s:{t}");
});
}
bool WaitDown(WaitResultInfo w)
{
if (IOManager.IOValue(down.ToString()).Equals(IO_VALUE.HIGH))
{
axisBean.SuddenStop();
return true;
}
if (!axisBean.IsBusy)
{
axisBean.SpeedMove(-speed);
}
return false;
}
}
}
using OnlineStore.Common;
using OnlineStore.LoadCSVLibrary;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Timers;
namespace DeviceLibrary
{
public class LineRunMonitor
{
Timer lineTimer = null;
Dictionary<string, DateTime> linrunlist = new Dictionary<string, DateTime>();
string Name;
ushort LineIO;
public LineRunMonitor(string name, ushort io) {
Name = name;
LineIO = io;
LineInit();
}
void LineInit()
{
if (lineTimer == null)
{
lineTimer = new Timer(100);
lineTimer.Elapsed += LineTimer_Elapsed;
lineTimer.Start();
GC.KeepAlive(lineTimer);
}
}
private void LineTimer_Elapsed(object sender, ElapsedEventArgs e)
{
lock (linrunlist)
{
if (canStopLine(out _) && DOValue(LineIO).Equals(IO_VALUE.HIGH))
{
DOMove(LineIO, IO_VALUE.LOW);
LogUtil.info(Name + $" 线体管理器 停止线体.");
}
}
}
private void DOMove(ushort LineIO, IO_VALUE iovalue)
{
IOManager.WriteSingleDO("", 0x00, LineIO, iovalue);
}
private object DOValue(ushort LineIO)
{
return IOManager.GetDOValue("", 0x00, LineIO);
}
/// <summary>
/// 控制线体运转
/// </summary>
/// <param name="id">需求方标识</param>
/// <param name="seconds">秒数</param>
public void LineRun(string id, int seconds, string parentname = "")
{
LineInit();
DOMove(LineIO, IO_VALUE.HIGH);
lock (linrunlist)
{
DOMove(LineIO, IO_VALUE.HIGH);
if (!string.IsNullOrEmpty(id) && seconds > 0)
{
if (linrunlist.ContainsKey(id))
linrunlist[id] = DateTime.Now.AddSeconds(seconds);
else
{
linrunlist.Add(id, DateTime.Now.AddSeconds(seconds));
}
LogUtil.info(Name + $" 线体管理器 {id},{parentname} 请求链条运行 {seconds}秒.");
}
}
}
public void LineStop(string id, string parentname = "")
{
lock (linrunlist)
{
if (!string.IsNullOrEmpty(id))
{
if (linrunlist.ContainsKey(id))
linrunlist.Remove(id);
LogUtil.info(Name + $" 线体管理器 {id},{parentname} 请求立刻停止线体.");
}
}
if (!canStopLine(out string msg))
LogUtil.info(Name + $" {Name}");
// IOMove(IO_Type.Line_Run, IO_VALUE.LOW);
}
bool canStopLine(out string msg)
{
msg = "";
bool canStop = true;
lock (linrunlist)
{
foreach (var x in linrunlist.ToList())
{
if (x.Value > DateTime.Now)
{
canStop = false;
msg = Name + $" 线体管理器 {x.Key} 不允许停止线体 需求停止时间 {x.Value.ToString()}.";
//LogUtil.info(Name + $" {x.Key} 不允许停止线体 需求停止时间 {x.Value.ToString()}.");
}
else
{
LogUtil.info(Name + $" 线体管理器 {x.Key} 请求时间已过期,删除.");
linrunlist.Remove(x.Key);
}
}
}
return canStop;
}
}
}
using OnlineStore.Common;
using System;
using System.Collections.Generic;
using System.IO.Ports;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
public class OKLEController
{
private static int bautRate = 9600;//波特率
private static Parity parity = Parity.None;//校验位
private static int dataBits = 8;//数据位
private static StopBits stopBits = StopBits.One; //停止位
private static Dictionary<string, AcSerialBean> SerialMap = new Dictionary<string, AcSerialBean>();
private static string LogName = "";
private static AcSerialBean GetSerialBean(string port)
{
if (SerialMap.ContainsKey(port))
{
return SerialMap[port];
}
return null;
}
public static void OpenAll(string[] ports)
{
foreach (string port in ports)
{
Init(port);
}
}
public static bool Init(string port)
{
if (SerialMap.ContainsKey(port))
{
return true;
}
LogName = "[OKLE_" + port + "]";
AcSerialBean sb = new AcSerialBean(port, bautRate, parity, dataBits, stopBits);
try
{
if (sb.openPort())
{
if (SerialMap.ContainsKey(port))
{
SerialMap.Remove(port);
}
SerialMap.Add(port, sb);
return true;
}
else
{
LogUtil.error(LogName + "串口打开失败!");
return false;
}
}
catch (Exception ex)
{
LogUtil.error(LogName + "打开出错:" + ex.ToString());
}
return true;
}
public static bool IsRun(string port)
{
if (GetSerialBean(port) != null)
{
return true;
}
return false;
}
/// <summary>
/// 释放资源
/// </summary>
public static void Release(params string[] ports)
{
if (ports.Length <= 0)
{
ports = (new List<string>(SerialMap.Keys)).ToArray();
}
foreach (string port in ports)
{
try
{
AcSerialBean sb = GetSerialBean(port);
if (sb != null)
{
sb.closePort();
}
//IsRun = false;
SerialMap.Remove(port);
}
catch (Exception ex)
{
LogUtil.error("Release OKLE port [" + port + "] error :" + ex.ToString());
}
}
}
public static bool Reset(string port)
{
AcSerialBean sb = GetSerialBean(port);
if (sb == null)
{
return false;
}
LogName = "[OKLE_" + port + "]";
//12.1.4执行手动置零
//指令格式:01 10 00 5E 00 01 02 00 01 6A EE
byte[] sendData = new byte[11];
sendData[0] = 0x01;
sendData[1] = 0x10;
sendData[2] = 0x00;
sendData[3] = 0x5E;
sendData[4] = 0x00;
sendData[5] = 0x01;
sendData[6] = 0x02;
sendData[7] = 0x00;
sendData[8] = 0x01;
sendData[9] = 0x00;
sendData[10] = 0x00;
sendData = buildCheckData(sendData, sendData.Length - 2);
string str = AcSerialBean.byteToHexStr(sendData);
LogUtil.debug(LogName + "发送数据:" + str);
byte[] reviceData = new byte[9];
bool isOk = false;
sb.SendCommand(sendData, ref reviceData, 100, out isOk);
return isOk;
}
public static double queryData(string port)
{
double weight = 0d;
AcSerialBean sb = GetSerialBean(port);
if (sb == null)
{
return weight;
}
LogName = "[OKLE_" + port + "]";
//12..1.2读取力值(毛重)指令,指令格式:01 03 00 50 00 02 C4 1A
//01 03 00 00 00 02 C4 0B
byte[] sendData = new byte[8];
sendData[0] = 0x01;
sendData[1] = 0x03;
sendData[2] = 0x00;
sendData[3] = 0x00;
sendData[4] = 0x00;
sendData[5] = 0x02;
sendData[6] = 0xC4;
sendData[7] = 0x0B;
//sendData = buildCheckData(sendData, sendData.Length - 2);
string str = AcSerialBean.byteToHexStr(sendData, " ");
byte[] reviceData = new byte[9];
bool isOk = false;
sb.SendCommand(sendData, ref reviceData, 100, out isOk);
LogUtil.debug(LogName + "发送数据:" + str + ",收到数据 :" + AcSerialBean.byteToHexStr(reviceData, " "));
return getReviceData(reviceData);
}
public static double CalWeight(double value, double dValue = 0, double xishu = 1)
{
double v = (double)(value - dValue) / xishu;
LogUtil.debug("重量计算 (" + value + "-" + dValue + ")/" + xishu + "=" + v);
return v;
}
private static double getReviceData(byte[] dataArray)
{
double value = 0d;
try
{
if (dataArray.Length >= 9)
{
//返回格式:01 03 04 FF FF C1 F0 AB C3(数据根据实际情况变化)
//地址 功能码 字节数 第一组寄存器数据 第二组寄存器数据 CRC16校验
//01 03 04 FF FF C1 F0 AB C3
string highV = String.Format("{0:X2}", dataArray[3]) + String.Format("{0:X2}", dataArray[4]);
string lowV = String.Format("{0:X2}", dataArray[5]) + String.Format("{0:X2}", dataArray[6]);
value = (double)Convert.ToInt32(highV + lowV, 16);
}
}
catch (Exception ex)
{
LogUtil.info(LogName + "转换出错:" + ex.ToString());
}
return value;
}
private static byte[] buildCheckData(byte[] sendData, int length)
{
ushort pChecksum = 0;
AcSerialBean.CalculateCRC(sendData, length, out pChecksum);
string checkStr = Convert.ToString(pChecksum, 16);
byte[] checkByte = AcSerialBean.StringToByte(checkStr);
if (checkByte.Length == 1)
{
sendData[length] = checkByte[0];
sendData[length + 1] = 0x00;
}
else
{
sendData[length + 1] = checkByte[0];
sendData[length] = checkByte[1];
}
return sendData;
}
}
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// 有关程序集的一般信息由以下
// 控制。更改这些特性值可修改
// 与程序集关联的信息。
[assembly: AssemblyTitle("DeviceLibrary")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("DeviceLibrary")]
[assembly: AssemblyCopyright("Copyright © 2021")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// 将 ComVisible 设置为 false 会使此程序集中的类型
//对 COM 组件不可见。如果需要从 COM 访问此程序集中的类型
//请将此类型的 ComVisible 特性设置为 true。
[assembly: ComVisible(false)]
// 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID
[assembly: Guid("bb23296c-aa1d-45c6-9fa6-5a37b2abfe9b")]
// 程序集的版本信息由下列四个值组成:
//
// 主版本
// 次版本
// 生成号
// 修订号
//
//可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值
//通过使用 "*",如下所示:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
位置,优先级,高度,宽度,料仓ID,行走机构位置P2,升降轴库位入料高点P3,升降轴库位入料低点P4,进出轴库位点取料点P3
1#AC1_0_0_1,1,8,7,1,139000,85635,76635,216000
1#AC1_0_0_2,2,8,7,1,139000,114988,105988,216000
1#AC1_1_0_1,3,8,7,1,139000,145635,136635,216000
1#AC1_1_0_2,4,8,7,1,139000,176235,167235,216000
1#AC1_1_0_3,5,8,7,1,139000,206882,197882,216000
1#AC1_1_0_4,6,8,7,1,139000,236867,227867,216000
1#AC1_1_0_5,7,8,7,1,139000,268094,259094,216000
1#AC1_1_0_6,8,8,7,1,139000,297486,288486,216000
1#AC1_2_0_1,9,8,7,1,139000,358117,349117,216000
1#AC1_2_0_2,10,8,7,1,139000,389346,380346,216000
1#AC1_2_0_3,11,8,7,1,139000,419989,410989,216000
1#AC1_2_0_4,12,8,7,1,139000,449990,440990,216000
1#AC1_2_0_5,13,8,7,1,139000,479971,470971,216000
1#AC1_2_0_6,14,8,7,1,139000,509965,500965,216000
1#AC1_3_0_1,15,8,7,1,139000,571209,562209,216000
1#AC1_3_0_2,16,8,7,1,139000,601848,592848,216000
1#AC1_3_0_3,17,8,7,1,139000,634980,625980,216000
1#AC1_3_0_4,18,8,7,1,139000,1250244,1241244,216000
1#AC1_3_0_5,19,8,7,1,139000,1281308,1272308,216000
1#AC1_3_0_6,20,8,7,1,139000,1311808,1302808,216000
1#AC1_4_0_1,21,8,7,1,139000,1372422,1363422,216000
1#AC1_4_0_2,22,8,7,1,139000,1403044,1394044,216000
1#AC1_4_0_3,23,8,7,1,139000,1433668,1424668,216000
1#AC1_4_0_4,24,8,7,1,139000,1464277,1455277,216000
1#AC1_4_0_5,25,8,7,1,139000,1494290,1485290,216000
1#AC1_4_0_6,26,8,7,1,139000,1524909,1515909,216000
1#AC1_5_0_1,27,8,7,1,139000,1586180,1577180,216000
1#AC1_5_0_2,28,8,7,1,139000,1614177,1607177,216000
1#AC1_5_0_3,29,8,7,1,139000,1644603,1637603,216000
1#AC1_5_0_4,30,8,7,1,139000,1675851,1668851,216000
1#AC1_5_0_5,31,8,7,1,139000,1705914,1698914,216000
1#AC1_5_0_6,32,8,7,1,139000,1735870,1728870,216000
1#AC1_6_0_1,33,8,7,1,139000,1797741,1790741,216000
1#AC1_6_0_2,34,8,7,1,139000,1827740,1820740,216000
1#AC1_6_0_3,35,8,7,1,139000,1857727,1850727,216000
1#AC1_6_0_4,36,8,7,1,139000,1888986,1881986,216000
1#AC1_6_0_5,37,8,7,1,139000,1919455,1912455,216000
1#AC1_6_0_6,38,8,7,1,139000,1949292,1942292,216000
1#AC1_7_0_1,39,8,7,1,139000,2009635,2002635,216000
1#AC1_7_0_2,40,8,7,1,139000,2040847,2033847,216000
1#AC1_7_0_3,41,8,7,1,139000,2070885,2063885,216000
1#AC1_7_0_4,42,8,7,1,139000,2101337,2094337,216000
1#AC1_7_0_5,43,8,7,1,139000,2131800,2124800,216000
1#AC1_7_0_6,44,8,7,1,139000,2162412,2155412,216000
1#AC1_8_0_1,45,8,7,1,139000,2223046,2216046,216000
1#AC1_8_0_2,46,8,7,1,139000,2253057,2246057,216000
1#AC1_8_0_3,47,8,7,1,164500,85635,76635,216000
1#AC1_8_0_4,48,8,7,1,164500,114988,105988,216000
1#AC1_8_0_5,49,8,7,1,164500,145635,136635,216000
1#AC1_8_0_6,50,8,7,1,164500,176235,167235,216000
1#AC1_9_0_1,51,8,7,1,164500,236867,227867,216000
1#AC1_9_0_2,52,8,7,1,164500,268094,259094,216000
1#AC1_9_0_3,53,8,7,1,164500,297486,288486,216000
1#AC1_9_0_4,54,8,7,1,164500,328116,319116,216000
1#AC1_9_0_5,55,8,7,1,164500,358117,349117,216000
1#AC1_9_0_6,56,8,7,1,164500,389346,380346,216000
1#AC1_10_0_1,57,8,7,1,164500,449990,440990,216000
1#AC1_10_0_2,58,8,7,1,164500,479971,470971,216000
1#AC1_10_0_3,59,8,7,1,164500,509965,500965,216000
1#AC1_10_0_4,60,8,7,1,164500,540585,531585,216000
1#AC1_10_0_5,61,8,7,1,164500,571209,562209,216000
1#AC1_10_0_6,62,8,7,1,164500,601848,592848,216000
1#AC1_11_0_1,63,8,7,1,164500,1250244,1241244,216000
1#AC1_11_0_2,64,8,7,1,164500,1281308,1272308,216000
1#AC1_11_0_3,65,8,7,1,164500,1311808,1302808,216000
1#AC1_11_0_4,66,8,7,1,164500,1342415,1333415,216000
1#AC1_11_0_5,67,8,7,1,164500,1372422,1363422,216000
1#AC1_11_0_6,68,8,7,1,164500,1403044,1394044,216000
1#AC1_12_0_1,69,8,7,1,164500,1464277,1455277,216000
1#AC1_12_0_2,70,8,7,1,164500,1494290,1485290,216000
1#AC1_12_0_3,71,8,7,1,164500,1524909,1515909,216000
1#AC1_12_0_4,72,8,7,1,164500,1554933,1545933,216000
1#AC1_12_0_5,73,8,7,1,164500,1586180,1577180,216000
1#AC1_12_0_6,74,8,7,1,164500,1614177,1607177,216000
1#AC1_13_0_1,75,8,7,1,164500,1675851,1668851,216000
1#AC1_13_0_2,76,8,7,1,164500,1705914,1698914,216000
1#AC1_13_0_3,77,8,7,1,164500,1735870,1728870,216000
1#AC1_13_0_4,78,8,7,1,164500,1766473,1759473,216000
1#AC1_13_0_5,79,8,7,1,164500,1797741,1790741,216000
1#AC1_13_0_6,80,8,7,1,164500,1827740,1820740,216000
1#AC1_14_0_1,81,8,7,1,164500,1888986,1881986,216000
1#AC1_14_0_2,82,8,7,1,164500,1919455,1912455,216000
1#AC1_14_0_3,83,8,7,1,164500,1949292,1942292,216000
1#AC1_14_0_4,84,8,7,1,164500,1979778,1972778,216000
1#AC1_14_0_5,85,8,7,1,164500,2009635,2002635,216000
1#AC1_14_0_6,86,8,7,1,164500,2040847,2033847,216000
1#AC1_15_0_1,87,8,7,1,164500,2040847,2033847,216000
1#AC1_15_0_2,88,8,7,1,164500,2040847,2033847,216000
1#AC1_15_0_3,89,8,7,1,164500,2040847,2033847,216000
1#AC1_15_0_4,90,8,7,1,164500,2040847,2033847,216000
1#AC1_15_0_5,91,8,7,1,164500,2040847,2033847,216000
1#AC1_15_0_6,92,8,7,1,164500,2040847,2033847,216000
1#AC1_16_0_1,93,8,7,1,164500,2040847,2033847,216000
1#AC1_16_0_2,94,8,7,1,164500,2040847,2033847,216000
1#AC1_16_0_3,95,8,7,1,164500,2040847,2033847,216000
1#AC1_16_0_4,96,8,7,1,164500,2040847,2033847,216000
1#AC1_16_0_5,97,8,7,1,164500,2040847,2033847,216000
1#AC1_16_0_6,98,8,7,1,164500,2040847,2033847,216000
1#AC1_17_0_1,99,8,7,1,164500,2040847,2033847,216000
1#AC1_17_0_2,100,8,7,1,164500,2040847,2033847,216000
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="System.ValueTuple" version="4.5.0" targetFramework="net461" requireReinstallation="true" />
</packages>
\ No newline at end of file
using OnlineStore.LoadCSVLibrary;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DeviceLibrary
{
public interface IRobot
{
//List<ConfigMoveAxis> moveAxisList { get; set; }
Robot_Config Config { get; set; }
string Name { get; set; }
bool canRunning { get; set; }
bool isBusy { get; set; }
bool isAlarm { get; set; }
RunStatus runStatus { get; set; }
void Run();
}
public enum RunStatus
{
Stop,
Running,
HomeReset
}
}
using OnlineStore.Common;
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DeviceLibrary
{
class OutStoreJobList
{
static ConcurrentQueue<JobInfo> jobInfos = new ConcurrentQueue<JobInfo>();
public static void Enqueue(JobInfo jobInfo) {
var l = jobInfos.ToList().Find((x) => { return x.PosId == jobInfo.PosId; });
if (l == null)
{
jobInfos.Enqueue(jobInfo);
LogUtil.info("出库任务加入队列:" + jobInfo.ToStr());
}else
LogUtil.info("出库任务已存在队列中:" + jobInfo.ToStr());
}
public static bool Dequeue(out JobInfo jobInfo)
{
return jobInfos.TryDequeue(out jobInfo);
}
public static int Count {
get => jobInfos.Count;
}
}
class InStoreJob : JobInfo
{
static ConcurrentQueue<JobInfo> jobInfos = new ConcurrentQueue<JobInfo>();
public static void Enqueue(JobInfo jobInfo)
{
var l = jobInfos.ToList().Find((x) => { return x.PosId == jobInfo.PosId; });
if (l == null)
{
jobInfos.Enqueue(jobInfo);
LogUtil.info("出库任务加入队列:" + jobInfo.ToStr());
}
else
LogUtil.info("出库任务已存在队列中:" + jobInfo.ToStr());
}
public static bool Enqueue(out JobInfo jobInfo)
{
return jobInfos.TryDequeue(out jobInfo);
}
}
public class JobInfo
{
public JobInfo()
{ }
public JobInfo(string wareNum, string posId)
{
this.WareNum = wareNum;
this.PosId = posId;
this.plateH = "";
this.plateW = "";
}
public JobInfo(string wareNum, string posId, string platew, string plateh)
{
this.WareNum = wareNum;
this.PosId = posId;
this.plateW = platew;
this.plateH = plateh;
}
/// <summary>
/// 夹具编码值(1-6)
/// </summary>
public int TrayCode { get; set; }
/// <summary>
/// 物品二维码
/// </summary>
public string WareNum { get; set; }
/// <summary>
/// 库位号编码
/// </summary>
public string PosId { get; set; }
/// <summary>
/// 料盘宽
/// </summary>
public string plateW { get; set; }
/// <summary>
/// 料盘高
/// </summary>
public string plateH { get; set; }
public string ToStr()
{
return "TrayCode【" + TrayCode + "】,WareNum=【" + WareNum + "】,PosId=【" + PosId + "】,plateW=【" + plateW + "】,plateH=【" + plateH + "】";
}
}
}
using CodeLibrary;
using OnlineStore.LoadCSVLibrary;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.Serialization.Formatters.Binary;
using System.Text;
using System.Threading.Tasks;
namespace DeviceLibrary
{
[Serializable]
public class BoxParam
{
/// <summary>
/// 创建新出入库信息
/// </summary>
/// <param name="wareNo">二维码内容</param>
/// <param name="platew">宽度</param>
/// <param name="plateh">高度</param>
/// <param name="IsNg">是否是入库NG料</param>
/// <param name="ngMsg">NG消息</param>
public BoxParam(string wareNo = "", int platew = 0, int plateh = 0, bool _IsNg = false, string ngMsg = "")
{
WareCode = wareNo;
PlateW = platew;
PlateH = plateh;
IsNg = _IsNg;
NgMsg = ngMsg;
}
/// <summary>
/// 物品二维码信息
/// </summary>
public string WareCode { get; set; }
/// <summary>
/// 库位号
/// </summary>
public string PosID { get; set; }
public string bitmapfilename = "";
public List<CodeInfo> codeInfos { get; set; }
/// <summary>
/// 料盘高度
/// </summary>
public int PlateH { get; set; }
/// <summary>
/// 料盘宽度
/// </summary>
public int PlateW { get; set; }
/// <summary>
/// 是否是入料NG料
/// </summary>
public bool IsNg = false;
/// <summary>
/// 入料NG消息
/// </summary>
public string NgMsg = "";
/// <summary>
/// 物料编码
/// </summary>
public string PN { get; set; }
/// <summary>
/// 数量
/// </summary>
public int QTY { get; set; } = 0;
/// <summary>
/// 厂家代码
/// </summary>
public string FC { get; set; }
/// <summary>
/// 唯一序列号
/// </summary>
public string RI { get; set; }
/// <summary>
/// 批次号
/// </summary>
public string Batch { get; set; }
public int HeightPos = 0;
public BoxParam clone()
{
BoxParam dstobject;
using (MemoryStream mStream = new MemoryStream())
{
BinaryFormatter bf = new BinaryFormatter();
bf.Serialize(mStream, this);
mStream.Seek(0, SeekOrigin.Begin);//指定当前流的位置为流的开头。
dstobject = (BoxParam)bf.Deserialize(mStream);
mStream.Close();
}
return dstobject;
}
public string ToStr()
{
if (IsNg)
{
return "[" + WareCode + "], [" + PlateW + "x" + PlateH + "]";
}
else
{
return "[" + WareCode + "], [" + PlateW + "x" + PlateH + "]";
}
}
}
class BoxStorePosition {
//行走机构取料点
public int Xaxis_P2;
//升降轴取料高点
public int Yaxis_PH;
//升降轴取料低点
public int Yaxis_PL;
//进出轴取料点
public int Zaxis_P2;
public string posid;
public BoxStorePosition(ACStorePosition aCStorePosition) {
Xaxis_P2 = aCStorePosition.XAxis_Position_P2;
Zaxis_P2 = aCStorePosition.InOutAxis_Position_P3;
Yaxis_PH = aCStorePosition.UpDownAxis_IHPosition_P3;
Yaxis_PL = aCStorePosition.UpDownAxis_ILPosition_P4;
posid = aCStorePosition.PositionNum;
}
public BoxStorePosition(Robot_Config Config, StoreSide storeSide)
{
if (storeSide == StoreSide.A)
{
Xaxis_P2 = Config.Xaxis_P2;
Zaxis_P2 = Config.Zaxis_P2;
Yaxis_PH = Config.Yaxis_P4;
Yaxis_PL = Config.Yaxis_P2;
posid = "入料口";
}
else {
Xaxis_P2 = Config.Xaxis_P3;
Zaxis_P2 = Config.Zaxis_P3;
Yaxis_PH = Config.Yaxis_P5;
Yaxis_PL = Config.Yaxis_P3;
posid = "出料口";
}
}
public BoxStorePosition clone()
{
BoxStorePosition dstobject;
using (MemoryStream mStream = new MemoryStream())
{
BinaryFormatter bf = new BinaryFormatter();
bf.Serialize(mStream, this);
mStream.Seek(0, SeekOrigin.Begin);//指定当前流的位置为流的开头。
dstobject = (BoxStorePosition)bf.Deserialize(mStream);
mStream.Close();
}
return dstobject;
}
}
public enum StoreSide
{
A, B
}
}
using CodeLibrary;
using OnlineStore.Common;
using OnlineStore.LoadCSVLibrary;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace DeviceLibrary
{
partial class MainMachine
{
void BtnProcess()
{
//右侧按钮按下,有料,出料
if (InMoveInfo.IsStep(MoveStep.Wait)
&& IOValue(IO_Type.InStart_BTN).Equals(IO_VALUE.HIGH))
{
}
}
}
}
using OnlineStore.Common;
using OnlineStore.LoadCSVLibrary;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
namespace DeviceLibrary
{
partial class MainMachine
{
public void StopMove(bool ServoOff=false)
{
runStatus = RunStatus.Stop;
MoveInfo.List.ForEach((m)=> { m.EndMove(); });
AxisBean.StopMultiAxis(AxisBean.List);
if (ServoOff)
{
AxisBean.CloseMultiAxis(AxisBean.List);
IOMove(IO_Type.InLift_Break, IO_VALUE.LOW);
IOMove(IO_Type.OutLift_Break, IO_VALUE.LOW);
}
}
public void OpenAllServo()
{
AxisBean.RunMultiAxis(true, out _, AxisBean.List);
IOMove(IO_Type.InLift_Break,IO_VALUE.HIGH);
IOMove(IO_Type.OutLift_Break,IO_VALUE.HIGH);
}
int logType = 1000;
string WarnMsg = "";
public bool CheckWait(MoveInfo MoveInfo)
{
//当等待超过一分钟时,需要打印提示
TimeSpan span = DateTime.Now - MoveInfo.LastSetpTime;
string NotOkMsg = "";
if (MoveInfo.WaitList.Count <= 0)
{
MoveInfo.EndStepWait();
return false;
}
bool isOk = true;
if (MoveInfo.OneWaitCanEndStep)
{
isOk = false;
}
foreach (WaitResultInfo wait in MoveInfo.WaitList)
{
if (wait.IsEnd)
{
if (!wait.WaitType.Equals(WaitEnum.W002_IOValue))
{
continue;
}
}
NotOkMsg = wait.ToStr();
if (wait.WaitType.Equals(WaitEnum.W001_AxisMove))
{
string msg = "";
if (wait.IsHomeMove)
{
wait.IsEnd = AxisBean.HomeMoveIsEnd(MoveInfo, wait.AxisInfo, out msg);
}
else
{
wait.IsEnd = AxisBean.ACAxisMoveIsEnd(MoveInfo, wait.AxisInfo, wait.TargetPosition, wait.TargetSpeed, out msg);
}
if (!msg.Equals(""))
{
isOk = false;
WarnMsg = msg;
Alarm(AlarmType.AxisMoveError, WarnMsg);
Msg.add(WarnMsg, MsgLevel.warning);
break;
}
}
else if (wait.WaitType.Equals(WaitEnum.W002_IOValue))
{
ConfigIO io = RobotManage.Config.getWaitIO(wait.IoType);
NotOkMsg = " 等待【" + io.DisplayStr + "】=【" + wait.IoValue + "】";
wait.IsEnd = IOManager.IOValue(wait.IoType).Equals(wait.IoValue);
if (!wait.IsEnd)
{
int timeOutMs = RobotManage.Config.IOSingle_TimerOut;
if (span.TotalMilliseconds > timeOutMs && NoAlarm())
{
WarnMsg = Name + "[" + MoveInfo.MoveStep + "] 等待(" + io.DisplayStr + "=" + wait.IoValue + ") 超时";
Msg.add(WarnMsg, MsgLevel.warning);
if (NoAlarm())
{
Alarm(AlarmType.IoSingleTimeOut, WarnMsg);
LogUtil.error(WarnMsg, logType + 14);
//MoveInfo.errlog(WarnMsg);
if (!MoveInfo.OneWaitCanEndStep)
{
isOk = false;
break;
}
}
}
}
}
else if (wait.WaitType.Equals(WaitEnum.W003_Time))
{
wait.IsEnd = (span.TotalMilliseconds >= wait.TimeMSeconds);
}
else if (wait.WaitType.Equals(WaitEnum.W013_Action))
{
wait.IsEnd = wait.Action.Invoke(wait);
LogUtil.info($"{Name} 自定义等待 IsEnd={wait.IsEnd},Type={wait.Action.GetType()}");
}
if (wait.IsEnd)
{
if (MoveInfo.OneWaitCanEndStep)
{
isOk = true;
break;
}
}
else
{
if (!MoveInfo.OneWaitCanEndStep)
{
isOk = false;
break;
}
}
}
if (isOk)
{
MoveInfo.EndStepWait();
return false;
}
else if (span.TotalSeconds > MoveInfo.TimeOutSeconds)
{
WarnMsg = Name + "[" + MoveInfo.MoveStep + "]等待" + NotOkMsg + "超时[" + Math.Round(span.TotalSeconds, 1) + "]秒";
int second = (int)(MoveInfo.TimeOutSeconds / span.TotalSeconds) * 10;
if (second > 120)
{
second = 120;
}
else if (second < 10)
{
second = 10;
}
LogUtil.error(WarnMsg, logType + 100, second);
//MoveInfo.errlog(WarnMsg);
Alarm(AlarmType.IoSingleTimeOut, WarnMsg);
Msg.add(WarnMsg, MsgLevel.warning);
}
return true;
}
/// <summary>
/// 是否再报警中
/// </summary>
AlarmType alarmType = AlarmType.None;
DateTime LastAlarmTime = DateTime.Now;
public void Alarm(AlarmType _alarmType, string alarmMsg = "")
{
if (_alarmType.Equals(AlarmType.None).Equals(false))
{
LastAlarmTime = DateTime.Now;
}
//SaveAlarmInfo(alarmType, alarmDetial, alarmMsg, storeMoveType);
if (this.alarmType.Equals(_alarmType))
{
return;
}
LogUtil.error(Name + " 报警,报警类型:" + _alarmType);
this.alarmType = _alarmType;
if (_alarmType.Equals(AlarmType.AxisAlarm) || _alarmType.Equals(AlarmType.AxisMoveError))
{
LogUtil.error(Name + "轴报警, 停止运动, 打开报警灯");
StopMove(true);
}
else if (_alarmType == AlarmType.SuddenStop)
{
//isInSuddenDown = true;
LogUtil.error(Name + "收到急停信号,停止运动, 打开报警灯 ");
StopMove(true);
//storeStatus = StoreStatus.SuddenStop;
}
else if (_alarmType.Equals(AlarmType.NoAirCheck))
{
//isNoAirCheck = true;
LogUtil.error(Name + " 未检测到气压信号 ,停止运动, 打开报警灯 ");
StopMove(true);
//storeStatus = StoreStatus.SuddenStop;
}
}
internal bool NoAlarm()
{
if (alarmType.Equals(AlarmType.None))
{
return true;
}
return false;
}
public void CylinderMove(MoveInfo moveInfo, string IoLowType, string IoHighType, IO_VALUE iO_VALUE = IO_VALUE.HIGH)
{
if (iO_VALUE == IO_VALUE.LOW)
{
var t = IoHighType;
IoHighType = IoLowType;
IoLowType = t;
}
IOMove(IoLowType, IO_VALUE.LOW);
IOMove(IoHighType, IO_VALUE.HIGH);
if (moveInfo != null)
{
moveInfo.WaitList.Add(WaitResultInfo.WaitIO(IoLowType, IO_VALUE.LOW));
moveInfo.WaitList.Add(WaitResultInfo.WaitIO(IoHighType, IO_VALUE.HIGH));
}
}
public IO_VALUE IOValue(string ioType) {
return IOManager.IOValue(ioType);
}
void IOMove(string IoType, IO_VALUE value, bool isCheck = false, int msTime = 0)
{
if (msTime <= 0)
{
if (isCheck && (IOValue(IoType).Equals(value)))
{
return;
}
IOManager.IOMove(IoType, value);
}
else
{
Task.Run(()=>
{
IOManager.IOMove(IoType, value);
Thread.Sleep(msTime);
IO_VALUE tValue = value.Equals(IO_VALUE.HIGH) ? IO_VALUE.LOW : IO_VALUE.HIGH;
LogUtil.info(Name + "定时回写IO: [" + IoType + "]=[" + value + "],msTime=" + msTime);
IOManager.IOMove(IoType, tValue);
});
}
}
}
}
using CodeLibrary;
using OnlineStore.Common;
using OnlineStore.LoadCSVLibrary;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace DeviceLibrary
{
partial class MainMachine
{
void ioMonitor()
{
//右侧料串已空
//if (RightMoveInfo.IsStep(MoveStep.Wait) && IOValue(IO_Type.RightEnd_Check).Equals(IO_VALUE.HIGH) && RightShelfNoTray)
{
Msg.add("右侧料串已空,等待取走料串", MsgLevel.warning);
}
//左侧料串已满
//if (LeftMoveInfo.IsStep(MoveStep.Wait) && IOValue(IO_Type.LeftEnd_Check).Equals(IO_VALUE.HIGH) && LeftShelfNoTray)
{
Msg.add("作侧料串已满,等待取走料串", MsgLevel.warning);
}
}
}
}
此文件的差异被折叠, 点击展开。
此文件的差异被折叠, 点击展开。
此文件的差异被折叠, 点击展开。
此文件的差异被折叠, 点击展开。
此文件的差异被折叠, 点击展开。
此文件的差异被折叠, 点击展开。
此文件的差异被折叠, 点击展开。
此文件的差异被折叠, 点击展开。
此文件的差异被折叠, 点击展开。
此文件的差异被折叠, 点击展开。
此文件类型无法预览
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!