333 lines
12 KiB
C#
333 lines
12 KiB
C#
|
using System;
|
|||
|
using System.Collections.Generic;
|
|||
|
using System.ComponentModel;
|
|||
|
using System.Data;
|
|||
|
using System.Drawing;
|
|||
|
using System.Text;
|
|||
|
using System.Windows.Forms;
|
|||
|
using ICommLayer;
|
|||
|
using CommLayerFactory;
|
|||
|
namespace ControlSystem
|
|||
|
{
|
|||
|
/// <summary>
|
|||
|
/// Creator:Richard.liu and Jack.Ma
|
|||
|
/// <20>豸ʵʱ״̬<D7B4><CCAC>ʾ
|
|||
|
/// </summary>
|
|||
|
public partial class FrmDeviceStatus : Form
|
|||
|
{
|
|||
|
#region <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
Model.MDevice _device = null;
|
|||
|
int _deviceIndex;
|
|||
|
ISendDeviceOrder sdo;
|
|||
|
|
|||
|
CCommonFunction ccf = new CCommonFunction();
|
|||
|
DBFactory.DBOperator dbo = CStaticClass.dbo;
|
|||
|
/// <summary>
|
|||
|
/// <20><><EFBFBD><EFBFBD>Ҫ<EFBFBD><D2AA>ʾ<EFBFBD><CABE><EFBFBD>豸<EFBFBD><E8B1B8><EFBFBD><EFBFBD>
|
|||
|
/// </summary>
|
|||
|
public int DeviceIndex
|
|||
|
{
|
|||
|
set { _deviceIndex = value;}
|
|||
|
}
|
|||
|
#endregion
|
|||
|
|
|||
|
#region <EFBFBD><EFBFBD><EFBFBD>캯<EFBFBD><EFBFBD>/<EFBFBD><EFBFBD>ʼ<EFBFBD><EFBFBD>
|
|||
|
public FrmDeviceStatus()
|
|||
|
{
|
|||
|
InitializeComponent();
|
|||
|
}
|
|||
|
|
|||
|
private void FrmDeviceStatus_Load(object sender, EventArgs e)
|
|||
|
{
|
|||
|
btnRefresh_Click(null, EventArgs.Empty);
|
|||
|
}
|
|||
|
#endregion
|
|||
|
|
|||
|
#region <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>豸״̬
|
|||
|
private void btnRefresh_Click(object sender, EventArgs e)
|
|||
|
{
|
|||
|
|
|||
|
//timer1.Enabled = true;
|
|||
|
_device = Model.CGetInfo.GetDeviceInfo(_deviceIndex);
|
|||
|
//20100108
|
|||
|
if (_device == null)
|
|||
|
{
|
|||
|
MessageBox.Show("<22><>ѡ<EFBFBD><D1A1><EFBFBD><EFBFBD><EFBFBD>豸<EFBFBD><E8B1B8><EFBFBD><EFBFBD><EFBFBD>ݿ<EFBFBD>û<EFBFBD>м<EFBFBD>¼<EFBFBD><C2BC>", "<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʾ<EFBFBD><CABE>", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|||
|
return;
|
|||
|
|
|||
|
}
|
|||
|
//<2F>豸<EFBFBD><E8B1B8><EFBFBD><EFBFBD>
|
|||
|
this.lblDeviceIndex.Text = _device.DeviceIndex.ToString();
|
|||
|
//<2F>豸<EFBFBD><E8B1B8><EFBFBD><EFBFBD>
|
|||
|
this.lblDeviceName.Text = _device.DeviceName;
|
|||
|
//<2F>豸ָ<E8B1B8><D6B8><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
this.lblTaskIndex.Text = _device.TaskNo.ToString();
|
|||
|
//Ŀ<><C4BF>λ<EFBFBD><CEBB>
|
|||
|
this.lblArrowLocation.Text = _device.ArrowLocation;
|
|||
|
//<2F>豸״̬
|
|||
|
switch (_device.RunState)
|
|||
|
{
|
|||
|
case 0:
|
|||
|
lblDeviceStatus.Text = "<22><><EFBFBD><EFBFBD>";
|
|||
|
break;
|
|||
|
case 1:
|
|||
|
lblDeviceStatus.Text = "<22><><EFBFBD><EFBFBD>";
|
|||
|
break;
|
|||
|
case 2:
|
|||
|
lblDeviceStatus.Text = "<22><><EFBFBD><EFBFBD>";
|
|||
|
break;
|
|||
|
case 3:
|
|||
|
lblDeviceStatus.Text = "<22><><EFBFBD><EFBFBD>";
|
|||
|
break;
|
|||
|
case 4:
|
|||
|
lblDeviceStatus.Text = "ͣ<><CDA3>";
|
|||
|
break;
|
|||
|
case 5://20090920
|
|||
|
lblDeviceStatus.Text = "<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>";
|
|||
|
break;
|
|||
|
}
|
|||
|
//<2F>л<EFBFBD>/<2F><EFBFBD>
|
|||
|
this.lblHaveGoods.Text = _device.HaveGoods == true ? "<22>л<EFBFBD>" : "<22><EFBFBD>";
|
|||
|
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
if(_device.DeviceKind==7)//20110418
|
|||
|
{
|
|||
|
// this.lblBarcode.Text= dbo.GetSingle("Select F_BarCode from T_Base_PLC_Ask where F_DeviceIndex="+ _device.DeviceIndex +"" ).ToString();
|
|||
|
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
this.lblBarcode.Text = _device.Barcode;
|
|||
|
}
|
|||
|
if (_device.ErrorCode >= 30)
|
|||
|
{
|
|||
|
|
|||
|
Model.MError err = Model.CGetInfo.GetErrorInfo(Convert.ToInt32(_device.DeviceKind.ToString() + _device.ErrorCode.ToString()));
|
|||
|
string errmessage = "";//20110401
|
|||
|
if (err == null)
|
|||
|
{
|
|||
|
errmessage = "<22><><EFBFBD>ϴ<EFBFBD><CFB4><EFBFBD>δ<EFBFBD><CEB4><EFBFBD><EFBFBD>!";
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
errmessage = err.ErrorName;
|
|||
|
}
|
|||
|
this.lblErrorName.Text = string.Format("{0}:{1}",_device.ErrorCode,errmessage);
|
|||
|
|
|||
|
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
this.lblErrorName.Text = "";
|
|||
|
}
|
|||
|
if ((_device.DeviceKind == 1) || (_device.DeviceKind == 4))
|
|||
|
{
|
|||
|
this.lblNowX.Text = _device.XCoor.ToString();
|
|||
|
this.lblNowY.Text = _device.YCoor.ToString();
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
this.lblNowX.Text ="";
|
|||
|
this.lblNowY.Text = "";
|
|||
|
}
|
|||
|
//<2F>Ƿ<EFBFBD><C7B7><EFBFBD><DFBC><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
DataView dv = dbo.ExceSQL("select F_DeviceIndex from T_Base_Device where F_HaveGoods = 1 and F_DeviceIndex =" + this._deviceIndex).Tables[0].DefaultView;
|
|||
|
if (dv.Count > 0)
|
|||
|
{
|
|||
|
lblGoods.Text = "<22><EFBFBD><DFBC><EFBFBD><EFBFBD><EFBFBD>";
|
|||
|
//if((_device.DeviceKind ==9)||(_device.DeviceKind ==2&&_device.IfCorrelDoubleFork == "1"))
|
|||
|
//{
|
|||
|
bthave.Visible=false;
|
|||
|
bthaveno.Visible=true;
|
|||
|
//}
|
|||
|
//else
|
|||
|
//{
|
|||
|
// bthave.Visible = false;
|
|||
|
// bthaveno.Visible = false;
|
|||
|
//}
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
lblGoods.Text = "<22><EFBFBD><DFBC><EFBFBD><EFBFBD><EFBFBD>";
|
|||
|
//if((_device.DeviceKind ==9)||(_device.DeviceKind ==2&&_device.IfCorrelDoubleFork == "1"))
|
|||
|
// {
|
|||
|
bthave.Visible=true;
|
|||
|
bthaveno.Visible=false;
|
|||
|
// }
|
|||
|
//else
|
|||
|
//{
|
|||
|
// bthave.Visible = false;
|
|||
|
// bthaveno.Visible = false;
|
|||
|
//}
|
|||
|
|
|||
|
}
|
|||
|
//<2F>´<EFBFBD><C2B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ť
|
|||
|
|
|||
|
//Ӧ<><D3A6><EFBFBD><EFBFBD>ť<EFBFBD><C5A5>ʾ
|
|||
|
if (_device.Dbw1Address != -1&&_device.DeviceKind!=5)
|
|||
|
{
|
|||
|
btAnswer.Visible = true;
|
|||
|
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
btAnswer.Visible = false;
|
|||
|
}
|
|||
|
//<2F><EFBFBD><DFBC><EFBFBD><EFBFBD>ﰴť<EFB0B4><C5A5>ʾ
|
|||
|
|
|||
|
if (_device.DeviceKind == 2 && _deviceIndex > 14000 && _deviceIndex < 15000)
|
|||
|
{
|
|||
|
|
|||
|
}
|
|||
|
|
|||
|
}
|
|||
|
#endregion
|
|||
|
|
|||
|
#region <EFBFBD>رմ<EFBFBD><EFBFBD><EFBFBD>
|
|||
|
private void btnClose_Click(object sender, EventArgs e)
|
|||
|
{
|
|||
|
this.Close();
|
|||
|
}
|
|||
|
#endregion
|
|||
|
|
|||
|
private void timer1_Tick(object sender, EventArgs e)
|
|||
|
{
|
|||
|
btnRefresh_Click(sender, e);
|
|||
|
}
|
|||
|
|
|||
|
private void button2_Click(object sender, EventArgs e)
|
|||
|
{
|
|||
|
if (MessageBox.Show("<22><>ȷ<EFBFBD><C8B7>Ҫ<EFBFBD><D2AA><EFBFBD>豸<EFBFBD><E8B1B8>" + this._deviceIndex + "<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><DFBC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>", "<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʾ<EFBFBD><CABE>", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) != DialogResult.OK)
|
|||
|
{
|
|||
|
return;
|
|||
|
}
|
|||
|
dbo.ExceSQL("UPDATE T_Base_Device SET F_HaveGoods = 0 where F_DeviceIndex =" + this._deviceIndex);
|
|||
|
btnRefresh_Click(sender, e);
|
|||
|
}
|
|||
|
|
|||
|
private void button1_Click(object sender, EventArgs e)
|
|||
|
{
|
|||
|
|
|||
|
if (MessageBox.Show("<22><>ȷ<EFBFBD><C8B7>Ҫ<EFBFBD><D2AA><EFBFBD>豸<EFBFBD><E8B1B8>" + this._deviceIndex + "<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><DFBC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>", "<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʾ<EFBFBD><CABE>", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) != DialogResult.OK)
|
|||
|
{
|
|||
|
return;
|
|||
|
}
|
|||
|
dbo.ExceSQL("UPDATE T_Base_Device SET F_HaveGoods = 1 where F_DeviceIndex =" + this._deviceIndex);
|
|||
|
btnRefresh_Click(sender, e);
|
|||
|
}
|
|||
|
|
|||
|
private void button3_Click(object sender, EventArgs e)
|
|||
|
{
|
|||
|
if (MessageBox.Show("<22><>ȷ<EFBFBD><C8B7>Ҫ<EFBFBD><D2AA><EFBFBD>豸<EFBFBD><E8B1B8>" + this._deviceIndex + "<22><><EFBFBD><EFBFBD>Ӧ<EFBFBD><D3A6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>", "<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʾ<EFBFBD><CABE>", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) != DialogResult.OK)
|
|||
|
{
|
|||
|
return;
|
|||
|
}
|
|||
|
int deviceKind = ccf.GetDeviceKindIdx(this._deviceIndex);
|
|||
|
sdo = CommModeCreate.CreateSendDeviceOrder(this._deviceIndex);
|
|||
|
if ((deviceKind == 1) || (deviceKind == 6))
|
|||
|
{
|
|||
|
sdo.SendDeviceOrder(2, 0, 0, this._deviceIndex, 0, 0, 0, 0, 0, 0);
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
if (deviceKind == 2 && _deviceIndex > 14000)
|
|||
|
{
|
|||
|
StringBuilder[] wv = { new StringBuilder("2") };
|
|||
|
StringBuilder[] witemnames = { new StringBuilder("") };
|
|||
|
witemnames[0].Remove(0, witemnames[0].Length);
|
|||
|
witemnames[0].Append(Model.CGeneralFunction.DBGet).Append(",byte").Append(Convert.ToString(_device.Dbw2Address + 0));
|
|||
|
sdo.WriteDBData(witemnames, wv, _deviceIndex);
|
|||
|
CommonClassLib.CCarryConvert.WriteDarkCasket("OPCClient", "<22>ֶ<EFBFBD>Ӧ<EFBFBD><D3A6>"+_device.DeviceName, "", "");
|
|||
|
return;
|
|||
|
}
|
|||
|
if(_device.Dbw1Address!=-1)
|
|||
|
{
|
|||
|
sdo.SendDeviceOrder(2, 0, 0, this._deviceIndex, 0);
|
|||
|
}
|
|||
|
|
|||
|
}
|
|||
|
CommonClassLib.CCarryConvert.WriteDarkCasket("OPCClient", "<22>ֶ<EFBFBD>Ӧ<EFBFBD><D3A6>" + _device.DeviceName, "", "");
|
|||
|
|
|||
|
}
|
|||
|
|
|||
|
private void btQuitPallet_Click(object sender, EventArgs e)
|
|||
|
{
|
|||
|
int enddev = 0;
|
|||
|
//<2F><><EFBFBD>ɳ<EFBFBD><C9B3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
if ((_device.DeviceIndex == 12074) || (_device.DeviceIndex == 12080) || (_device.DeviceIndex == 12086))
|
|||
|
{
|
|||
|
enddev=_device.DeviceIndex;
|
|||
|
}
|
|||
|
else
|
|||
|
if(_device.DeviceIndex==22054)
|
|||
|
{
|
|||
|
enddev=22052;
|
|||
|
}
|
|||
|
else
|
|||
|
if(_device.DeviceIndex==32074)
|
|||
|
{
|
|||
|
enddev=32072;
|
|||
|
}
|
|||
|
else
|
|||
|
if (_device.DeviceIndex == 32063)
|
|||
|
{
|
|||
|
enddev = 32082;
|
|||
|
}
|
|||
|
else
|
|||
|
if (_device.DeviceIndex == 12100)
|
|||
|
{
|
|||
|
enddev = 12103;
|
|||
|
}
|
|||
|
else
|
|||
|
if (_device.DeviceIndex == 12043)
|
|||
|
{
|
|||
|
enddev = 12100;
|
|||
|
}
|
|||
|
DataView dvbc = dbo.ExceSQL("SELECT FID FROM T_Manage_Task WHERE (FSTARTDEVICE=" + _device.DeviceIndex + ") And (FENDDEVICE=" + enddev+ ")").Tables[0].DefaultView;
|
|||
|
if (dvbc.Count > 0)
|
|||
|
{
|
|||
|
MessageBox.Show("<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ѵ<EFBFBD><D1B4><EFBFBD>,<2C>봦<EFBFBD><EBB4A6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>´", "<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʾ<EFBFBD><CABE>", MessageBoxButtons.OK, MessageBoxIcon.Warning);
|
|||
|
return;
|
|||
|
}
|
|||
|
if (MessageBox.Show("<22><>ȷ<EFBFBD><C8B7>Ҫ<EFBFBD>´<EFBFBD><C2B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>", "<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʾ<EFBFBD><CABE>", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK)
|
|||
|
{
|
|||
|
string dtime = DateTime.Now.ToString("u");
|
|||
|
dtime = dtime.Substring(0, dtime.Length - 1);
|
|||
|
|
|||
|
int fid = ccf.GetTempManageIdx();
|
|||
|
string sql = "INSERT INTO T_Manage_Task" +
|
|||
|
"(FID, F_ManageTaskKindIndex,FPALLETBARCODE,FMANAGETASKTYPE,FCONTROLTASKTYPE, FTASKLEVEL, FISRETURN," +
|
|||
|
"FSTARTWAREHOUSE, FSTARTCELL, FSTARTDEVICE, FENDDEVICE, FENDCELL, " +
|
|||
|
"FSTATUS, FBEGTIME, FENDTIME,FIntoStepOK,FREMARK,FLANEWAY,FSTACK,FENDWAREHOUSE,FUseAwayFork)" +
|
|||
|
"VALUES (" + fid + ",2,'000000000000000','0','3','1','1','','-','"
|
|||
|
+ _device.DeviceIndex + "','" + enddev + "','-','0','"+dtime+"','-','0','',0,0,'','-')";
|
|||
|
dbo.ExceSQL(sql);
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
}
|
|||
|
|
|||
|
private void button1_Click_1(object sender, EventArgs e)
|
|||
|
{
|
|||
|
if (MessageBox.Show("<22><>ȷ<EFBFBD><C8B7>Ҫ<EFBFBD><D2AA><EFBFBD>豸<EFBFBD><E8B1B8>" + this._deviceIndex + "<22><><EFBFBD>й<EFBFBD><D0B9><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>", "<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʾ<EFBFBD><CABE>", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) != DialogResult.OK)
|
|||
|
{
|
|||
|
return;
|
|||
|
}
|
|||
|
int deviceKind = ccf.GetDeviceKindIdx(this._deviceIndex);
|
|||
|
sdo = CommModeCreate.CreateSendDeviceOrder(this._deviceIndex);
|
|||
|
if ((deviceKind == 1) || (deviceKind == 6))
|
|||
|
{
|
|||
|
sdo.SendDeviceOrder(4, 0, 0, this._deviceIndex, 0, 0, 0, 0, 0, 0);
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
if (_device.Dbw1Address != -1)
|
|||
|
{
|
|||
|
sdo.SendDeviceOrder(4, 0, 0, this._deviceIndex, 0);
|
|||
|
}
|
|||
|
}
|
|||
|
CommonClassLib.CCarryConvert.WriteDarkCasket("OPCClient", "<22><><EFBFBD>й<EFBFBD><D0B9><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>" + _device.DeviceName, "", "");
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
}
|
|||
|
}
|