287 lines
13 KiB
C#
287 lines
13 KiB
C#
|
using Microsoft.VisualBasic;
|
|||
|
using RGD.Common;
|
|||
|
using RGD.DataService;
|
|||
|
using RGD.DBUtility;
|
|||
|
using RGD.MdsAPI;
|
|||
|
using RGD.MdsAPI.WMS;
|
|||
|
using RGD.Model;
|
|||
|
using RGD.OPCClient;
|
|||
|
using System;
|
|||
|
using System.Data;
|
|||
|
|
|||
|
namespace RGD.WCS
|
|||
|
{
|
|||
|
/// <summary>
|
|||
|
/// Creator:RGD
|
|||
|
/// һ<><D2BB><EFBFBD><EFBFBD>λ<EFBFBD><CEBB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>λ<EFBFBD><CEBB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֳ<EFBFBD><D6B3><EFBFBD><EFBFBD>ƴ<EFBFBD><C6B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>źţ<C5BA>
|
|||
|
/// 1-<2D>ط<EFBFBD><D8B7><EFBFBD>ǰ<EFBFBD>豸ָ<E8B1B8><D6B8>
|
|||
|
/// 2-<2D><><EFBFBD><EFBFBD><EFBFBD>ĵ<DEB8>ǰ<EFBFBD>豸<EFBFBD><E8B1B8>ִ<EFBFBD><D6B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ŀ<EFBFBD><C4BF>λ<EFBFBD><CEBB>
|
|||
|
/// 3-<2D><><EFBFBD>浱ǰ<E6B5B1>豸<EFBFBD><E8B1B8>ִ<EFBFBD>е<EFBFBD><D0B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
/// 4-ɾ<><C9BE><EFBFBD><EFBFBD>ǰ<EFBFBD>豸<EFBFBD><E8B1B8>ִ<EFBFBD>е<EFBFBD><D0B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ߣ<EFBFBD>
|
|||
|
/// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>PLC<4C><43><EFBFBD><EFBFBD><EFBFBD>Զ<EFBFBD><D4B6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
/// </summary>
|
|||
|
public class CListenPLCAsk
|
|||
|
{
|
|||
|
private string _listenPLCAskError = "";
|
|||
|
|
|||
|
public string ListenPLCAskError
|
|||
|
{
|
|||
|
get { return _listenPLCAskError; }
|
|||
|
set { _listenPLCAskError = value; }
|
|||
|
}
|
|||
|
|
|||
|
private CCommonFunction ccf = new CCommonFunction();
|
|||
|
private CGetState cgs = new CGetState();
|
|||
|
private ISendDeviceOrder sdo;
|
|||
|
private Model.MDevice devinfo;
|
|||
|
|
|||
|
public CListenPLCAsk()
|
|||
|
{
|
|||
|
}
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// <20><><EFBFBD><EFBFBD>PLC<4C><43><EFBFBD><EFBFBD><EFBFBD>Զ<EFBFBD><D4B6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>:1:<3A><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>;2<><32><EFBFBD><EFBFBD><EFBFBD>̻<EFBFBD><CCBB>ϱ<EFBFBD><CFB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɣ<EFBFBD>
|
|||
|
/// 3<><33>PLC<4C><43><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɣ<EFBFBD>4<EFBFBD><34><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɨ<EFBFBD><C9A8><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>5<EFBFBD><35><EFBFBD><EFBFBD><EFBFBD>̻<EFBFBD><CCBB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>;6:<3A><>Ƶ<EFBFBD><C6B5>ͣ<EFBFBD>ź<EFBFBD>
|
|||
|
/// </summary>
|
|||
|
public void DealwithPLCAsk()
|
|||
|
{
|
|||
|
string sql = "";
|
|||
|
string[] wv = new string[1] { "2" };
|
|||
|
string[] witemnames = new string[1];
|
|||
|
DataView dv;
|
|||
|
DataView dv0;
|
|||
|
//<2F><>Ƶ<EFBFBD><C6B5>Ϣ
|
|||
|
DataView dvs;
|
|||
|
DataView dvt = DbHelperSQL.Query("select F_TASK_NO,F_TASK_TYPE,F_EQUIP_TYPE from T_WareHouse").Tables[0].DefaultView;
|
|||
|
string TASK_NO = dvt[0]["F_TASK_NO"].ToString();
|
|||
|
string TASK_TYPE = dvt[0]["F_TASK_TYPE"].ToString();
|
|||
|
try
|
|||
|
{
|
|||
|
dv = DbHelperSQL.Query("SELECT T_Base_PLC_Ask.F_DeviceIndex,T_Base_PLC_Ask.F_BindingDevice, F_Askkind,F_TaskIndex,F_BarCode,F_Remark" +
|
|||
|
",F_FirstProject,F_BoxBarcode,f_AskNo FROM T_Base_Device,T_Base_PLC_Ask" +
|
|||
|
" where T_Base_Device.F_DeviceIndex=T_Base_PLC_Ask.F_DeviceIndex " +
|
|||
|
" order by T_Base_Device.F_DeviceIndex desc").Tables[0].DefaultView;
|
|||
|
for (int i = 0; i < dv.Count; i++)
|
|||
|
{
|
|||
|
int deviceindex = Convert.ToInt32(dv[i]["F_DeviceIndex"]);
|
|||
|
int bindingdeviceindex = Convert.ToInt32(dv[i]["F_BindingDevice"]);
|
|||
|
devinfo = BaseDeviceService.GetDeviceInfo(deviceindex);
|
|||
|
witemnames[0] = "DB2,byte" + Convert.ToString((devinfo.Dbw2Address + 0));
|
|||
|
sdo = CommModeCreate.CreateSendDeviceOrder(deviceindex);
|
|||
|
|
|||
|
#region <EFBFBD><EFBFBD>Ƶ<EFBFBD><EFBFBD>ͣ6
|
|||
|
|
|||
|
if (dv[i]["F_Askkind"].ToString() == "6")
|
|||
|
{
|
|||
|
MDevice deviceInfo = BaseDeviceService.GetDeviceInfo(deviceindex);
|
|||
|
|
|||
|
sql = "select READ_FLAG,HAVE_GOODS,BEGIN_TIME from IO_RFID where STATION_CODE='" + deviceindex + "'";
|
|||
|
|
|||
|
dvs = DbHelperSQL.Query(sql).Tables[0].DefaultView;
|
|||
|
if (deviceInfo.SplitByte_6 == 1)//<2F>ж<EFBFBD><D0B6><EFBFBD>
|
|||
|
{
|
|||
|
if ((bool)dvs[0]["HAVE_GOODS"])
|
|||
|
{
|
|||
|
int time = 3;
|
|||
|
if (TASK_TYPE == "Inventory")
|
|||
|
{
|
|||
|
time = 5;
|
|||
|
}
|
|||
|
double s = (DateTime.Now - DateTime.Parse(dvs[0]["BEGIN_TIME"].ToString())).TotalSeconds;
|
|||
|
//LogUtil.WriteLog("", "line380<38><30>Ƶ<EFBFBD><C6B5>ʱֹͣ;READ_FLAG:" + dvs[0]["READ_FLAG"]+ ";s:"+s.ToString());
|
|||
|
if (dvs[0]["READ_FLAG"].ToString() == "1" && (DateTime.Now - DateTime.Parse(dvs[0]["BEGIN_TIME"].ToString())).TotalSeconds >= time)
|
|||
|
{
|
|||
|
sql = "update IO_RFID set READ_FLAG='0' where STATION_CODE='" + deviceindex + "'";
|
|||
|
DbHelperSQL.ExecuteSql(sql);
|
|||
|
}
|
|||
|
|
|||
|
continue;
|
|||
|
}
|
|||
|
sql = "update IO_RFID set READ_FLAG='1',HAVE_GOODS=1,BEGIN_TIME='" + DateTime.Now.ToString() + "' where STATION_CODE='" + deviceindex + "'";
|
|||
|
DbHelperSQL.ExecuteSql(sql);
|
|||
|
CCarryConvert.WriteDarkCasket("PLCAsk", "<22><>Ƶ<EFBFBD><C6B5><EFBFBD><EFBFBD>", deviceindex.ToString(), deviceInfo.SplitByte_6 + "**" + dvs[0]["BEGIN_TIME"]);
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
if ((bool)dvs[0]["HAVE_GOODS"])//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>״̬
|
|||
|
{
|
|||
|
sql = "update IO_RFID set HAVE_GOODS=0,read_flag='0' where STATION_CODE='" + deviceindex + "'";
|
|||
|
DbHelperSQL.ExecuteSql(sql);
|
|||
|
//LogUtil.WriteLog("", "line397<39><37>Ƶ<EFBFBD><C6B5>Ϊ<EFBFBD><CEAA><EFBFBD><EFBFBD>:" + sql);
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
#endregion <EFBFBD><EFBFBD>Ƶ<EFBFBD><EFBFBD>ͣ6
|
|||
|
#region <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>2
|
|||
|
if (dv[i]["F_Askkind"].ToString() == "2")
|
|||
|
{
|
|||
|
#region <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ϵͳ<EFBFBD>Ľ<EFBFBD><EFBFBD><EFBFBD>
|
|||
|
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>//20101220
|
|||
|
int sendouttype = CStaticClass.GetOverlapStatus(deviceindex);
|
|||
|
if (sendouttype > 0) // <20><>ȡ<EFBFBD><C8A1><EFBFBD>̻<EFBFBD><CCBB>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɣ<EFBFBD><C9A3><EFBFBD>0λ<30><CEBB>0,<2C><>1λ>2
|
|||
|
{
|
|||
|
|
|||
|
if (CStaticClass.GetDevicePhotoelectric(ccf.GetSendOutDetect(Convert.ToInt32(dv[i]["F_BindingDevice"]))) != 1)// <20><>ȡ<EFBFBD><C8A1><EFBFBD>̻<EFBFBD><CCBB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>豸<EFBFBD>Ŀ<EFBFBD><C4BF>ص<EFBFBD>ֵ (<28><><EFBFBD><EFBFBD>)
|
|||
|
{
|
|||
|
continue;
|
|||
|
}
|
|||
|
|
|||
|
int[] state;
|
|||
|
|
|||
|
state = CStaticClass.GetDeviceState(Convert.ToInt32(dv[i]["F_BindingDevice"])); //<2F><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD><EFBFBD>豸<EFBFBD><E8B1B8>״̬<D7B4><CCAC><EFBFBD><EFBFBD>
|
|||
|
// state[1] = 0; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>dzf
|
|||
|
if (state == null)
|
|||
|
{
|
|||
|
continue;
|
|||
|
}
|
|||
|
if ((state[1] >= 30) || (state[1] == 1) || (state[1] == 2))//<2F><><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD>ɼ<EFBFBD><C9BC><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
{
|
|||
|
//20091128
|
|||
|
state = null;
|
|||
|
continue;
|
|||
|
|
|||
|
}
|
|||
|
|
|||
|
#region <EFBFBD><EFBFBD><EFBFBD><EFBFBD>5s<EFBFBD><EFBFBD>ֻ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><EFBFBD>
|
|||
|
if (Information.IsDate(dv[i]["F_FirstProject"]))//20110513ʱ<33><CAB1>
|
|||
|
{
|
|||
|
if (Convert.ToDateTime(dv[i]["F_FirstProject"]).AddSeconds(5) > DateTime.Now)//<2F><><EFBFBD><EFBFBD>5s<35>ڣ<EFBFBD><DAA3><EFBFBD><EFBFBD><EFBFBD><EFBFBD>д<EFBFBD><D0B4><EFBFBD>
|
|||
|
{
|
|||
|
CCarryConvert.WriteDarkCasket("PLCAsk", "5<><35><EFBFBD><EFBFBD><EFBFBD>ϱ<EFBFBD><CFB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>", bindingdeviceindex.ToString(), "");
|
|||
|
|
|||
|
continue;
|
|||
|
}
|
|||
|
|
|||
|
}
|
|||
|
#endregion
|
|||
|
|
|||
|
#region <EFBFBD>Ѵ<EFBFBD><EFBFBD><EFBFBD>
|
|||
|
dv0 = DbHelperSQL.Query("SELECT FSTARTDEVICE, FENDDEVICE FROM T_Manage_Task WHERE (FSTARTDEVICE = " + Convert.ToInt32(dv[i]["F_BindingDevice"]) + ") and FSTATUS=0").Tables[0].DefaultView;
|
|||
|
if (dv0.Count > 0)
|
|||
|
{
|
|||
|
continue;
|
|||
|
}
|
|||
|
#endregion
|
|||
|
|
|||
|
#region û<EFBFBD>е<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
//if (TASK_NO == "")
|
|||
|
//{
|
|||
|
// continue;
|
|||
|
//}
|
|||
|
#endregion
|
|||
|
string dtime = DateTime.Now.ToString("u");//20101028
|
|||
|
dtime = dtime.Substring(0, dtime.Length - 1);//20101028
|
|||
|
|
|||
|
//20110331
|
|||
|
if (TASK_NO != "" && dv[i]["F_BarCode"].ToString() != "")
|
|||
|
{
|
|||
|
string stackcode = dv[i]["F_BarCode"].ToString().TrimEnd('|').Replace('|', ',');
|
|||
|
|
|||
|
string sResult = "";
|
|||
|
FrmControlMonitor.FormInstance.AddDebugMessage("getInStackLocation sending stackcode = " + stackcode);
|
|||
|
getInStackLocation gisl = new getInStackLocation();
|
|||
|
//bool bResult = true;
|
|||
|
bool bResult = gisl.Notify(dvt[0]["F_TASK_NO"].ToString(), stackcode, string.Empty, out sResult);//<2F><><EFBFBD>̽<EFBFBD><CCBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>봢λ
|
|||
|
FrmControlMonitor.FormInstance.AddDebugMessage(gisl.GetType().Name + " WCS->WMS\r\n" + gisl.XML_IN + sResult, sResult.IndexOf("<RESULT_FLAG>1</RESULT_FLAG>") > 0 ? 0 : 1);
|
|||
|
getInStackLocation.DATA outData = new Base().DeSerialize<getInStackLocation.DATA>(sResult);
|
|||
|
|
|||
|
if (bResult)
|
|||
|
{
|
|||
|
bResult = new ManageTaskService().CreateMove(TASK_NO, "1", bindingdeviceindex.ToString(), outData.LOC_NO, stackcode, out sResult);
|
|||
|
//bResult = new ManageTaskService().CreateMove(TASK_NO, "1", bindingdeviceindex.ToString(), "12004", stackcode, out sResult);
|
|||
|
}
|
|||
|
else
|
|||
|
{//<2F><>ȡʧ<C8A1>ܣ<EFBFBD><DCA3>쳣<EFBFBD>ͳ<EFBFBD>
|
|||
|
if (!sResult.Contains("RESULT_FLAG"))
|
|||
|
{
|
|||
|
continue;
|
|||
|
}
|
|||
|
bResult = new ManageTaskService().CreateMove(TASK_NO, 2, "3", bindingdeviceindex.ToString(), "12001", stackcode, out sResult);
|
|||
|
}
|
|||
|
|
|||
|
wv[0] = "0";
|
|||
|
sdo.WriteDBData(witemnames, wv);// <20><><EFBFBD><EFBFBD><EFBFBD>̻<EFBFBD>״̬<D7B4>ָ<EFBFBD>Ϊ<EFBFBD><CEAA><EFBFBD><EFBFBD>״̬
|
|||
|
CCarryConvert.WriteDarkCasket("PLCAsk", "<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>뿪", stackcode, "");
|
|||
|
DbHelperSQL.ExecuteSql("update T_Base_PLC_Ask set F_BarCode='',F_FirstProject='" + dtime + "',F_BOX_LABLE='' where (F_DeviceIndex=" + deviceindex + ")");
|
|||
|
}
|
|||
|
else if (dv[i]["F_BarCode"].ToString() != "")
|
|||
|
{
|
|||
|
string stackcode = dv[i]["F_BarCode"].ToString().TrimEnd('|').Replace('|', ',');
|
|||
|
|
|||
|
wv[0] = "0";
|
|||
|
sdo.WriteDBData(witemnames, wv);// <20><><EFBFBD><EFBFBD><EFBFBD>̻<EFBFBD>״̬<D7B4>ָ<EFBFBD>Ϊ<EFBFBD><CEAA><EFBFBD><EFBFBD>״̬
|
|||
|
CCarryConvert.WriteDarkCasket("PLCAsk", "<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>뿪", stackcode, "");
|
|||
|
DbHelperSQL.ExecuteSql("update T_Base_PLC_Ask set F_BarCode='',F_FirstProject='" + dtime + "',F_BOX_LABLE='' where (F_DeviceIndex=" + deviceindex + ")");
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
#endregion
|
|||
|
}
|
|||
|
#endregion
|
|||
|
}
|
|||
|
}
|
|||
|
catch (Exception ex)
|
|||
|
{
|
|||
|
_listenPLCAskError = "<22><><EFBFBD><EFBFBD>PLC<4C><43><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1>" + ex.Message;
|
|||
|
}
|
|||
|
finally
|
|||
|
{
|
|||
|
sql = null;
|
|||
|
wv = null;
|
|||
|
witemnames = null;
|
|||
|
dv = null;
|
|||
|
dv0 = null;
|
|||
|
dvs = null;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
private int GetAutoManageIdx()
|
|||
|
{
|
|||
|
DataSet ds;
|
|||
|
try
|
|||
|
{
|
|||
|
int maxIdx = 1;
|
|||
|
ds = DbHelperSQL.Query("SELECT F_ManageTaskIndex FROM T_Base_Manage_Task_Index_Auto_Task");
|
|||
|
if (ds.Tables[0].DefaultView.Count > 0)
|
|||
|
{
|
|||
|
if ((Convert.ToInt32(ds.Tables[0].DefaultView[0]["F_ManageTaskIndex"]) + 1) >= 9998)
|
|||
|
{
|
|||
|
maxIdx = 1;
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
maxIdx = (Convert.ToInt32(ds.Tables[0].DefaultView[0]["F_ManageTaskIndex"]) + 1);
|
|||
|
}
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
maxIdx = 1;
|
|||
|
}
|
|||
|
|
|||
|
DataView dv = DbHelperSQL.Query("select F_ManageTaskIndex from T_Base_Manage_Task_Index_Auto_Task").Tables[0].DefaultView;
|
|||
|
if (dv.Count > 0)
|
|||
|
{
|
|||
|
if (maxIdx > Convert.ToInt32(dv[0]["F_ManageTaskIndex"]))
|
|||
|
{
|
|||
|
DbHelperSQL.ExecuteSql("UPDATE T_Base_Manage_Task_Index_Auto_Task SET F_ManageTaskIndex =" + maxIdx);
|
|||
|
}
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
DbHelperSQL.ExecuteSql("INSERT INTO T_Base_Manage_Task_Index_Auto_Task (F_ManageTaskIndex)VALUES (" + maxIdx + ")");
|
|||
|
}
|
|||
|
|
|||
|
return maxIdx;
|
|||
|
}
|
|||
|
catch (Exception ex)
|
|||
|
{
|
|||
|
throw ex;
|
|||
|
}
|
|||
|
finally
|
|||
|
{
|
|||
|
ds = null;
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
}
|