using System ;
using System.Collections.Generic ;
using System.Text ;
using System.Data ;
using ICommLayer ;
using CommLayerFactory ;
using DBFactory ;
using CommonLib ;
namespace WcfControlMonitorLib
{
/// <summary>
/// Creator:Richard.liu
///
/// ����ص�ȫ�ֱ����Ķ���
/// </summary>
public static class CStaticClass
{
public static event CDataSourceChangeEventHandler DataChange ;
public static void OnDataChange ( object sender , CDataChangeEventArgs e )
{
if ( DataChange ! = null )
{
DataChange ( sender , e ) ;
}
}
public static event RefreshMonitorEventHandler RefreshMonitor ;
public static void OnRefreshMonitor ( RefreshMonitorEventArgs e )
{
if ( RefreshMonitor ! = null )
{
RefreshMonitor ( e ) ;
}
}
static StringBuilder sss = new StringBuilder ( ) ;
static StringBuilder [ ] wv = { new StringBuilder ( "2" ) } ;
static StringBuilder [ ] witemnames = { new StringBuilder ( "" ) } ;
static char [ ] dd = new char [ 1 ] { '.' } ; //20101124
static string [ ] sp ; //20101124
static string _ userID ;
/// <summary>
/// �û�����
/// </summary>
public static string UserID
{
get { return CStaticClass . _ userID ; }
set { CStaticClass . _ userID = value ; }
}
static bool _ testSendOrder = false ; //���Խ�����ָ��
/// <summary>
/// ���Խ���������Ϊָ��
/// </summary>
public static bool TestSendOrder
{
get { return _ testSendOrder ; }
set { CStaticClass . _ testSendOrder = value ; }
}
public static bool StopTestLane = true ;
public static bool TestOutEnd = false ;
public static bool TestInEnd = false ;
public static bool ContainAGV = false ; //�Ƿ�Я��AGV����
public static int TestKind = 1 ; //����������2�����
private static Dictionary < int , bool > _ stoptest = new Dictionary < int , bool > ( ) ; //�Ƿ�ֹͣ����
public static Dictionary < int , bool > StopTest
{
get { return _ stoptest ; }
set { _ stoptest = value ; }
}
private static Dictionary < int , bool > _ stopout = new Dictionary < int , bool > ( ) ; //�Ƿ�ֹͣ��������
public static Dictionary < int , bool > StopOut
{
get { return _ stopout ; }
set { _ stopout = value ; }
}
private static Dictionary < int , bool > _ stopin = new Dictionary < int , bool > ( ) ; //�Ƿ�ֹͣ��������
public static Dictionary < int , bool > StopIn
{
get { return _ stopin ; }
set { _ stopin = value ; }
}
private static Dictionary < int , string > _ testcell = new Dictionary < int , string > ( ) ; //���²��洢�ϴβ��ԵĻ�λ
public static Dictionary < int , string > TestCell
{
get { return _ testcell ; }
set { _ testcell = value ; }
}
private static Dictionary < int , string > _ testenddevice = new Dictionary < int , string > ( ) ; //�洢�յ��豸����
public static Dictionary < int , string > TestEndDevice
{
get { return _ testenddevice ; }
set { _ testenddevice = value ; }
}
static int _ MessageIndex ;
static bool _ Order ; //
static bool _ ObtainManageTask ; //
static bool _ autoOrder ;
static bool _ handOrder ;
static bool _ tempOrder ;
static ISendDeviceOrder sdo ;
//20091102
public static int gcCount = 0 ;
//20091107
static string _ ManageServiceAddress = "http://localhost:525/lcs/thirdParty/taskStatusReport" ; //WCS ����ִ�й��̣�������ִ�е�״̬�ش��� LCS ϵͳ��
static string _ ManageServiceAddress2 = "http://localhost:5252/lcs/thirdParty/inboundApply" ; //����������ҵ��Ҫ�����ⲿɨ���豸����������λ��У���Ƿ�������ʱ��WCS ͨ���� �ӿ��� LCS ���롣
static string _ ManageServiceAddress3 = "http://localhost:5252/lcs/thirdParty/wcsTaskInfo" ; //WCS ֪ͨ LCS ���� AGV ȡ��
static string _ ManageServiceAddress4 = "http://localhost:5252/api/lcs/thirdParty/requestRescore" ; //WCS ͨ���ýӿ����� LCS ��Ŀ����λ�������·��䡣
static string _ ManageServiceAddress5 = "http://localhost:5252/api/lcs/thirdParty/autoMoveOut" ; //WCS ���� WMS �ж������Ƿ���Ҫ�Զ��ƿ�
public static string ManageServiceAddress
{
get { return CStaticClass . _ ManageServiceAddress ; }
set
{
if ( value ! = "" )
{
CStaticClass . _ ManageServiceAddress = value ;
}
}
}
public static string ManageServiceAddressTwo
{
get { return CStaticClass . _ ManageServiceAddress2 ; }
set
{
if ( value ! = "" )
{
CStaticClass . _ ManageServiceAddress2 = value ;
}
}
}
public static string ManageServiceAddressThree
{
get { return CStaticClass . _ ManageServiceAddress3 ; }
set
{
if ( value ! = "" )
{
CStaticClass . _ ManageServiceAddress3 = value ;
}
}
}
public static string ManageServiceAddressFour
{
get { return CStaticClass . _ ManageServiceAddress4 ; }
set
{
if ( value ! = "" )
{
CStaticClass . _ ManageServiceAddress4 = value ;
}
}
}
public static string ManageServiceAddressFive
{
get { return CStaticClass . _ ManageServiceAddress5 ; }
set
{
if ( value ! = "" )
{
CStaticClass . _ ManageServiceAddress5 = value ;
}
}
}
static string _ movedDeviceAheadTrigger = "1" ;
/// <summary>
/// �ƶ��豸�Ƿ�����ǰ������ȡ
/// </summary>
public static string MovedDeviceAheadTrigger
{
get { return CStaticClass . _ movedDeviceAheadTrigger ; }
set
{
if ( ( value = = "0" ) | | ( value = = "1" ) )
{
CStaticClass . _ movedDeviceAheadTrigger = value ;
}
else
{
CStaticClass . _ movedDeviceAheadTrigger = "1" ;
}
}
}
static string _ outDetectArrowIdleGoods = "1" ;
/// <summary>
/// �Ѷ��������Ƿ�����Ŀ�����ͻ����к�����
/// </summary>
public static string OutDetectArrowIdleGoods
{
get { return CStaticClass . _ outDetectArrowIdleGoods ; }
set
{
if ( ( value = = "0" ) | | ( value = = "1" ) )
{
CStaticClass . _ outDetectArrowIdleGoods = value ;
}
else
{
CStaticClass . _ outDetectArrowIdleGoods = "1" ;
}
}
}
static string _d eviceErrorAutoModifyRoutePath = "0" ;
/// <summary>
/// �豸���������Զ�����·��
/// </summary>
public static string DeviceErrorAutoModifyRoutePath
{
get { return CStaticClass . _d eviceErrorAutoModifyRoutePath ; }
set
{
if ( ( value = = "0" ) | | ( value = = "1" ) )
{
CStaticClass . _d eviceErrorAutoModifyRoutePath = value ;
}
else
{
CStaticClass . _d eviceErrorAutoModifyRoutePath = "0" ;
}
}
}
static string _d oubleForkWaitTime = "120" ;
/// <summary>
/// ���������������������ȴ���ʱ�䵥λ���룩��Ĭ��120��
/// </summary>
public static string DoubleForkWaitTime
{
get { return CStaticClass . _d oubleForkWaitTime ; }
set
{ int aa ;
if ( int . TryParse ( _d oubleForkWaitTime , out aa ) = = true )
{
CStaticClass . _d oubleForkWaitTime = value ;
}
else
{
CStaticClass . _d oubleForkWaitTime = "120" ;
}
}
}
static string _ transportTimeout = "5" ;
/// <summary>
/// ���ͳ�ʱ��������ʱ�䵥λ���֣���Ĭ��5����//20110608
/// </summary>
public static string TransportTimeout
{
get { return CStaticClass . _ transportTimeout ; }
set
{
int aa ;
if ( int . TryParse ( _ transportTimeout , out aa ) = = true )
{
CStaticClass . _ transportTimeout = value ;
}
else
{
CStaticClass . _ transportTimeout = "5" ;
}
}
}
static string _ agvAllowSingleFork = "1" ;
/// <summary>
/// AGV�Ƿ��������涯������Ĭ���������涯�� 1
/// </summary>
public static string AGVAllowSingleFork
{
get { return CStaticClass . _ agvAllowSingleFork ; }
set
{
if ( ( value = = "0" ) | | ( value = = "1" ) )
{
CStaticClass . _ agvAllowSingleFork = value ;
}
else
{
CStaticClass . _ agvAllowSingleFork = "0" ;
}
}
}
static string _ stockCodeCheck = "^[B|D|G|P][A-Z][0-9]{4}$" ;
/// <summary>
/// ������ʽ����
/// </summary>
public static string StockCodeCheck
{
get { return CStaticClass . _ stockCodeCheck ; }
set
{
int aa ;
if ( int . TryParse ( _ stockCodeCheck , out aa ) = = true )
{
CStaticClass . _ stockCodeCheck = value ;
}
else
{
CStaticClass . _ stockCodeCheck = "^[B|D|G|P][A-Z][0-9]{4}$" ;
}
}
}
static string _ HCA12068 = "6" ;
public static string HCA12068
{
get { return CStaticClass . _ HCA12068 ; }
set
{
int aa ;
if ( int . TryParse ( value , out aa ) = = true )
{
CStaticClass . _ HCA12068 = value ;
}
}
}
static string _ HCB12019 = "4" ;
public static string HCB12019
{
get { return CStaticClass . _ HCB12019 ; }
set
{
int aa ;
if ( int . TryParse ( value , out aa ) = = true )
{
CStaticClass . _ HCB12019 = value ;
}
}
}
static string _ HCB12034 = "3" ;
public static string HCB12034
{
get { return CStaticClass . _ HCB12034 ; }
set
{
int aa ;
if ( int . TryParse ( value , out aa ) = = true )
{
CStaticClass . _ HCB12034 = value ;
}
}
}
static string _ HCBLanewayOutDB = "2" ;
public static string HCBLanewayOutDB
{
get { return CStaticClass . _ HCBLanewayOutDB ; }
set
{
int aa ;
if ( int . TryParse ( value , out aa ) = = true )
{
CStaticClass . _ HCBLanewayOutDB = value ;
}
}
}
static string _ savedays = "60" ;
/// <summary>
/// ����������ʷ��¼��ʱ��
/// </summary>
public static string SaveDays
{
get { return CStaticClass . _ savedays ; }
set
{
int aa ;
if ( int . TryParse ( _ savedays , out aa ) = = true )
{
CStaticClass . _ savedays = value ;
}
else
{
CStaticClass . _ savedays = "60" ;
}
}
}
static string _ outtaskcounts = "4" ;
/// <summary>
/// �յ���ͬ�ij���������ִ�е���������,ͨ��
/// </summary>
public static string OutTaskCounts
{
get { return CStaticClass . _ outtaskcounts ; }
set
{
int aa ;
if ( int . TryParse ( _ outtaskcounts , out aa ) = = true )
{
CStaticClass . _ outtaskcounts = value ;
}
else
{
CStaticClass . _ outtaskcounts = "4" ;
}
}
}
static string _ outtaskcounts1 = "4" ;
/// <summary>
/// �յ���ͬ�ij���������ִ�е���������
/// </summary>
public static string OutTaskCounts1
{
get { return CStaticClass . _ outtaskcounts1 ; }
set
{
int aa ;
if ( int . TryParse ( _ outtaskcounts1 , out aa ) = = true )
{
CStaticClass . _ outtaskcounts1 = value ;
}
else
{
CStaticClass . _ outtaskcounts1 = "4" ;
}
}
}
static string _ outtaskcounts2 = "4" ;
/// <summary>
/// �յ���ͬ�ij���������ִ�е���������
/// </summary>
public static string OutTaskCounts2
{
get { return CStaticClass . _ outtaskcounts2 ; }
set
{
int aa ;
if ( int . TryParse ( _ outtaskcounts2 , out aa ) = = true )
{
CStaticClass . _ outtaskcounts2 = value ;
}
else
{
CStaticClass . _ outtaskcounts2 = "4" ;
}
}
}
static string _ outtaskcounts3 = "3" ;
/// <summary>
/// �յ���ͬ�ij���������ִ�е���������
/// </summary>
public static string OutTaskCounts3
{
get { return CStaticClass . _ outtaskcounts3 ; }
set
{
int aa ;
if ( int . TryParse ( _ outtaskcounts3 , out aa ) = = true )
{
CStaticClass . _ outtaskcounts3 = value ;
}
else
{
CStaticClass . _ outtaskcounts3 = "4" ;
}
}
}
//20100108
/// <summary>
/// ����ͷ������IP
/// </summary>
public static string CameraIP = "1" ;
/// <summary>
/// ��½����ͷ���������û���ʶ
/// </summary>
public static string CameraUsername = "1" ;
/// <summary>
/// ��½����ͷ������������
/// </summary>
public static string CameraPassword = "1" ;
public static bool IfRemind = false ;
public static DateTime routetime = DateTime . Now . AddSeconds ( - 1 0 ) ;
public static DBOperator dbo = CommonClassLib . AppSettings . dbo ; //20130510
public static DBOperator dbo1 = CommonClassLib . AppSettings . dbo1 ; //20130510
public static DBOperator dboM = CommonClassLib . AppSettings . dboM ; //20130510
public static DBOperator dboM1 = CommonClassLib . AppSettings . dboM1 ; //20130510
static bool _d eviceInit ;
static string _ routeSearchMode = "0" ;
static bool _ realRefresh = true ;
public static Model . MDevice devinfo28 ;
//20100609
public static Dictionary < int , System . IO . Ports . SerialPort > serialports = new Dictionary < int , System . IO . Ports . SerialPort > ( ) ;
static Model . MDevice devinfo ;
static string _ manstatus = " F_Status<>-1 " ; //Ĭ�ϣ���ʾ��������ȫ������
static string _ monstatus = " F_Status<>-1 " ; //Ĭ�ϣ���ʾ�豸ָ��ȫ������
static StringBuilder manZWhere = new StringBuilder ( ) ;
/// <summary>
/// ��ȡ���������ţ�Z����between����OR��ϵ
/// </summary>
public static StringBuilder ManZWhere
{
get { return CStaticClass . manZWhere ; }
set {
CStaticClass . manZWhere = value ;
}
}
//20100607�������ݿ������ʼ��
static string _ manDBFactory = dboM . GetValue ( "ManDBFactory" ) ;
/// <summary>
/// ����ϵͳ�����ݿ����SQLServerDBFactory��OracleDBFactory��OleDBFactory
/// </summary>
public static string ManDBFactory
{
get { return CStaticClass . _ manDBFactory ; }
set
{
if ( ( value = = "SQLServerDBFactory" ) | | ( value = = "OracleDBFactory" ) | | ( value = = "OleDBFactory" ) )
{
CStaticClass . _ manDBFactory = value ;
}
else
{
CStaticClass . _ manDBFactory = "SQLServerDBFactory" ;
}
}
}
static string _D BFactory = dbo . GetValue ( "DBFactory" ) ; //20151120����ϵͳ���ݿ��
/// <summary>
/// ����ϵͳ���ݿ����SQLServerDBFactory��OracleDBFactory��OleDBFactory
/// </summary>
public static string DBFactory
{ //20151120����ϵͳ���ݿ��
get { return CStaticClass . _D BFactory ; }
set
{
if ( ( value = = "SQLServerDBFactory" ) | | ( value = = "OracleDBFactory" ) | | ( value = = "OleDBFactory" ) )
{
CStaticClass . _D BFactory = value ;
}
else
{
CStaticClass . _D BFactory = "SQLServerDBFactory" ;
}
}
}
/// <summary>
/// ��ʾ��������ȫ������" F_Status<>-1 ";�ȴ�����" F_Status=0 "�����ж���" F_Status=1 "��
/// </summary>
public static string Manstatus
{
get { return CStaticClass . _ manstatus ; }
set { CStaticClass . _ manstatus = value ; }
}
/// <summary>
/// ��ʾ�豸ָ��ȫ������" F_Status<>-1 ";�ȴ�����" F_Status=0 "�����ж���" F_Status=1 "��
/// </summary>
public static string Monstatus
{
get { return CStaticClass . _ monstatus ; }
set { CStaticClass . _ monstatus = value ; }
}
/// <summary>
/// �Ƿ�ʵʱˢ�¼��غ͵��������б�
/// </summary>
public static bool RealRefresh
{
get { return CStaticClass . _ realRefresh ; }
set { CStaticClass . _ realRefresh = value ; }
}
/// <summary>
/// ·��������ʽ:0����������·��ѡ���̶�·�ߣ�1��ÿ�����ڹ����Ľڵ���Ϊ��ʼ�㣬��ĩ�˽ڵ�����������һ������·���Ľڵ�
/// </summary>
public static string RouteSearchMode
{
get { return CStaticClass . _ routeSearchMode ; }
set {
if ( ( value = = "0" ) | | ( value = = "1" ) )
{
CStaticClass . _ routeSearchMode = value ;
}
else
{
CStaticClass . _ routeSearchMode = "0" ;
}
}
}
/// <summary>
/// ִ���Զ������
/// </summary>
public static bool AutoOrder
{
get { return CStaticClass . _ autoOrder ; }
set { CStaticClass . _ autoOrder = value ; }
}
/// <summary>
/// ִ���ֹ������
/// </summary>
public static bool HandOrder
{
get { return CStaticClass . _ handOrder ; }
set { CStaticClass . _ handOrder = value ; }
}
/// <summary>
/// ִ����ʱ���������
/// </summary>
public static bool TempOrder
{
get { return CStaticClass . _ tempOrder ; }
set { CStaticClass . _ tempOrder = value ; }
}
/// <summary>
/// ���ط�����Ϣ����
/// </summary>
public static int MessageIndex
{
get { return CStaticClass . _ MessageIndex ; }
set
{
if ( value > 2 4 0 )
{
value = 1 ;
}
CStaticClass . _ MessageIndex = value ;
}
}
/// <summary>
/// ������Ƿ�����
/// </summary>
public static bool Order
{
get { return CStaticClass . _ Order ; }
set { CStaticClass . _ Order = value ; }
}
/// <summary>
/// �Ƿ���ȡ��������
/// </summary>
public static bool ObtainManageTask
{
get { return _ ObtainManageTask ; }
set { _ ObtainManageTask = value ; }
}
/// <summary>
/// �Ƿ�ִ���豸��ʼ������
/// </summary>
public static bool DeviceInit
{
get { return CStaticClass . _d eviceInit ; }
set { CStaticClass . _d eviceInit = value ; }
}
public static void ReConnect ( )
{
//20100127
//SimensProdave6.CSimensProdave6_S7.InitCount = 0;
SocketsTCPIP . CClientTCPIP . TcpIPInitCount = new Dictionary < string , int > ( ) ;
OPCClient . CCommonOPCClient . ConnectCount = new Dictionary < string , int > ( ) ;
}
static StringBuilder sql = new StringBuilder ( ) ;
public static int [ ] DeviceStateAllReturns ;
public static string GetDeviceReadSubscription ( int deviceindex )
{ //20110216
//object lockthis = new object();
//lock (lockthis)
{
DataView dv = dbo . ExceSQL ( string . Format ( "SELECT F_ReadSubscription FROM T_Base_Device WHERE (F_DeviceIndex = {0})" , deviceindex ) ) . Tables [ 0 ] . DefaultView ;
if ( dv . Count > 0 )
{
return dv [ 0 ] [ "F_ReadSubscription" ] . ToString ( ) ;
}
else
{
return null ;
}
}
}
/// <summary>
/// 20110216֧�ֶ���S7Connnection��̬OPC
/// </summary>
public static Dictionary < string , int [ ] > MutiReadSubscriptionDeviceStateReturns = new Dictionary < string , int [ ] > ( ) ;
public static Dictionary < string , int [ ] > MutiReadSubscriptionDeviceSplitReturns = new Dictionary < string , int [ ] > ( ) ;
/// <summary>
/// ȡ�����й��翪�ص��ź�
/// </summary>
//public static void GetAllReturns()
//{//20110216
// try
// {
// DataView dv = dbo.ExceSQL("SELECT F_DeviceIndex,F_S7Connection FROM T_Base_Device WHERE (F_DeviceKindIndex = 28)").Tables[0].DefaultView;
// if (dv.Count > 0)
// {
// for (int i = 0; i < dv.Count; i++)
// {
// gds = CommModeCreate.CreateGetDeviceState(Convert.ToInt32(dv[i]["F_DeviceIndex"]));
// MutiS7ConnReturns[dv[i]["F_S7Connection"].ToString()] = gds.GetDeviceState(Convert.ToInt32(dv[i]["F_DeviceIndex"]), 0);
// if (gds.CommLayerError != null)
// {
// RefreshMonitorEventArgs rea = new RefreshMonitorEventArgs("tsStatus", "ȡ�����й��翪�ص��ź�ʱ��" + gds.CommLayerError);
// OnRefreshMonitor(rea);
// }
// }
// }
// else
// {
// MutiS7ConnReturns = null;
// }
// }
// catch (Exception ex)
// {
// RefreshMonitorEventArgs rea = new RefreshMonitorEventArgs("tsStatus", "ȡ�����й��翪�ص��ź�ʱ��" + ex.Message);
// OnRefreshMonitor(rea);
// return;
// }
//}
/// <summary>
/// 20101118�����豸�ź�bitλ��ȡ��F_SplitByte���Ĺ���bitֵ��0,1
/// </summary>
/// <param name="deviceIdx"></param>
/// <param name="bit"></param>
/// <returns></returns>
public static int GetDevicePhotoelectric ( int deviceIdx , int abit )
{
try
{
devinfo = Model . CGetInfo . GetDeviceInfo ( deviceIdx ) ;
if ( devinfo ! = null )
{
switch ( abit )
{
case 0 :
return devinfo . SplitByte_0 ;
case 1 :
return devinfo . SplitByte_1 ;
case 2 :
return devinfo . SplitByte_2 ;
case 3 :
return devinfo . SplitByte_3 ;
case 4 :
return devinfo . SplitByte_4 ;
case 5 :
return devinfo . SplitByte_5 ;
case 6 :
return devinfo . SplitByte_6 ;
case 7 :
return devinfo . SplitByte_7 ;
}
return - 9 9 9 9 ;
}
else
{
return - 9 9 9 9 ;
}
#region �ɰ�����
////20110216
//DeviceStateAllReturns = CStaticClass.MutiReadSubscriptionDeviceSplitReturns[GetDeviceReadSubscription(deviceIdx)];
//if (DeviceStateAllReturns != null)
//{
// #region ��ȡ��������ֵ
// devinfo = Model.CGetInfo.GetDeviceInfo(deviceIdx);
// int glen = 0;
// int IfVis = 0;
// if (devinfo.SplitByte != -1)
// {
// //20110216
// devinfo28 = Model.CGeneralFunction.GetDeviceReadSubscriptionDB2Data(new StringBuilder(devinfo.ReadSubscription));
// int temp = devinfo.SplitByte - devinfo28.SplitByte;
// if (abit > 7)
// {
// glen = abit - 8;
// temp = temp + 1;
// }
// else
// {
// glen = abit;
// }
// if (temp >= 0)
// {
// IfVis = CommonClassLib.CCarryConvert.GetBitFromInteger(DeviceStateAllReturns[temp], glen);
// return IfVis;
// }
// else
// {
// return -1;
// }
// }
// else
// {
// return -1;
// }
// #endregion
//}
//else
//{
// return -1;
//}
#endregion
}
catch ( Exception ex )
{
RefreshMonitorEventArgs rea = new RefreshMonitorEventArgs ( "tsStatus" , string . Format ( "ȡ�ù��翪�ص��ź�ʱ��{0}" , ex . StackTrace + ex . Message ) ) ;
OnRefreshMonitor ( rea ) ;
return - 1 ;
}
}
/// <summary>
/// //20101124���ݡ��豸��.bitλ�����ַ�����ȡ��F_SplitByte���Ĺ���bitֵ��0,1
/// </summary>
/// <param name="deviceIdx"></param>
/// <param name="bit"></param>
/// <returns></returns>
public static int GetDevicePhotoelectric ( string devicebit )
{
sp = devicebit . Split ( dd ) ; //20101124
if ( sp . GetLength ( 0 ) < = 1 ) return - 1 ;
int deviceIdx , abit ;
int . TryParse ( sp [ 0 ] , out deviceIdx ) ;
int . TryParse ( sp [ 1 ] , out abit ) ;
try
{
devinfo = Model . CGetInfo . GetDeviceInfo ( deviceIdx ) ;
if ( devinfo ! = null )
{
switch ( abit )
{
case 0 :
return devinfo . SplitByte_0 ;
case 1 :
return devinfo . SplitByte_1 ;
case 2 :
return devinfo . SplitByte_2 ;
case 3 :
return devinfo . SplitByte_3 ;
case 4 :
return devinfo . SplitByte_4 ;
case 5 :
return devinfo . SplitByte_5 ;
case 6 :
return devinfo . SplitByte_6 ;
case 7 :
return devinfo . SplitByte_7 ;
}
return - 9 9 9 9 ;
}
else
{
return - 9 9 9 9 ;
}
#region �ɰ�����
////20110216
//DeviceStateAllReturns = CStaticClass.MutiReadSubscriptionDeviceSplitReturns[GetDeviceReadSubscription(deviceIdx)];
//if (DeviceStateAllReturns != null)
//{
// #region ��ȡ��������ֵ
// devinfo = Model.CGetInfo.GetDeviceInfo(deviceIdx);
// int glen = 0;
// int IfVis = 0;
// if (devinfo.SplitByte != -1)
// {
// devinfo28 = Model.CGeneralFunction.GetDeviceReadSubscriptionDB2Data(new StringBuilder(devinfo.ReadSubscription));
// int temp = devinfo.SplitByte - devinfo28.SplitByte;
// if (abit > 7)
// {
// glen = abit - 8;
// temp = temp + 1;
// }
// else
// {
// glen = abit;
// }
// if (temp >= 0)
// {
// IfVis = CommonClassLib.CCarryConvert.GetBitFromInteger(DeviceStateAllReturns[temp], glen);
// return IfVis;
// }
// else
// {
// return -1;
// }
// }
// else
// {
// return -1;
// }
// #endregion
//}
//else
//{
// return -1;
//}
#endregion
}
catch ( Exception ex )
{
RefreshMonitorEventArgs rea = new RefreshMonitorEventArgs ( "tsStatus" , string . Format ( "ȡ�ù��翪�ص��ź�ʱ��{0}" , ex . StackTrace + ex . Message ) ) ;
OnRefreshMonitor ( rea ) ;
return - 9 9 9 9 ;
}
}
/// <summary>
/// ״̬:0���У�1���У�2���ϣ�3���ߣ�4��ͣ�ã�5��������
/// ȡ��ָ���豸�������豸״̬:[0]��д��־;[1]״̬;[2]�����ţ�[3]X����;[4]Y����;[5]�豸����
///
/// </summary>
/// <param name="deviceIdx">�豸����</param>
/// <returns></returns>
public static int [ ] GetDeviceState ( int deviceIdx )
{
int [ ] states = new int [ 6 ] { 1 , 0 , 0 , 0 , 0 , deviceIdx } ;
devinfo = Model . CGetInfo . GetDeviceInfo ( deviceIdx ) ;
if ( devinfo ! = null )
{
states [ 1 ] = devinfo . RunState ;
return states ;
}
else
{
return null ;
}
#region �ɰ���������
//Model.MDevice askdev;
//DataView dvbc;
//string s = DateTime.Now.Millisecond.ToString();
//try
//{
// //20110216
// DeviceStateAllReturns = CStaticClass.MutiReadSubscriptionDeviceStateReturns[GetDeviceReadSubscription(deviceIdx)];
// string s1 = DateTime.Now.Millisecond.ToString();
// if (DeviceStateAllReturns != null)
// {
// #region ��ȡ�豸״̬
// devinfo = Model.CGetInfo.GetDeviceInfo(deviceIdx);
// if (devinfo.Dbw2Address != -1)
// {
// //20100108
// //DataView dv;
// //DataView dvM;
// //Model.MDevice askdev;
// //20110216
// devinfo28 = Model.CGeneralFunction.GetDeviceReadSubscriptionDB2Data(new StringBuilder(devinfo.ReadSubscription));
// int temp = devinfo.Dbw2Address - devinfo28.Dbw2Address;
// decimal glen = devinfo.Dbw2Getlength;
// //20100108
// states = new int[6];
// wv[0].Remove(0, wv[0].Length);
// wv[0].Append("2");
// witemnames[0].Remove(0, witemnames[0].Length);
// witemnames[0].Append(Model.CGeneralFunction.DBGet).Append(",byte").Append(Convert.ToString(devinfo.Dbw2Address + 0));
// sdo = CommModeCreate.CreateSendDeviceOrder(deviceIdx);
// switch (devinfo.DeviceKind.ToString())
// {
// #region �ֳ����ƴ�����������Ϣ��16���ֽڣ�
// case "22":
// if (DeviceStateAllReturns[temp] != 1) return null;
// states = new int[16];
// states[0] = 0;
// states[1] = deviceIdx;
// states[2] = DeviceStateAllReturns[temp + 1];//������
// states[3] = (DeviceStateAllReturns[temp + 2] << 8) + DeviceStateAllReturns[temp + 3];//�豸����
// states[4] = (DeviceStateAllReturns[temp + 4] << 8) + DeviceStateAllReturns[temp + 5];//������
// askdev = Model.CGetInfo.GetDeviceInfo(states[3]);
// //states[2];//������
// //states[3];//�豸��������ǰ�����豸��������
// //states[4];//�����ţ���Ҫ��Ŀ��λ�õ������ţ�
// //20091102
// if (askdev == null)
// {
// wv[0].Remove(0, wv[0].Length);
// wv[0].Append("37");
// sdo.WriteDBData(witemnames, wv);//20091013
// CommonClassLib.CCarryConvert.WriteDarkCasket("OPCClient", "�����ֳ����ƴ����������ķ�����Ϣ", deviceIdx.ToString(), "37�������豸�Ų�����");
// return null;
// }
// int bcz = 0;
// StringBuilder barcode = new StringBuilder();
// for (int j = 6; j < 16; j++)
// {
// bcz = bcz + DeviceStateAllReturns[temp + j];
// barcode.Append(Convert.ToChar(DeviceStateAllReturns[temp + j]).ToString().ToUpper());
// states[j - 1] = DeviceStateAllReturns[temp + j];
// }
// //20090902������arraylength
// if (IsEquals(devinfo.ReturnMessage, states, 5) == false)
// {
// devinfo.ReturnMessage = states;
// Model.CGetInfo.SetDeviceMessage(devinfo);
// sss.Remove(0, sss.Length);
// sss.Append("**�������豸����" + states[1]).Append("**������" + states[2])
// .Append("**�������豸����" + states[3]).Append("**������������" + states[4]).Append("**����������" + barcode);
// CommonClassLib.CCarryConvert.WriteDarkCasket("OPCClient", "�յ��ֳ����ƴ�����������Ϣ", deviceIdx.ToString(), sss.ToString());
// }
// #region �����ط���ǰ�豸ָ��(1)
// if (states[2] == 1)//������
// {
// if (states[4] == 0)//��������
// {
// if (bcz == 0)//��������
// {
// //32�����������ź������붼������
// wv[0].Remove(0, wv[0].Length);
// wv[0].Append("32");
// sdo.WriteDBData(witemnames, wv);//20091013
// CommonClassLib.CCarryConvert.WriteDarkCasket("OPCClient", "�����ֳ����ƴ����������ķ�����Ϣ", deviceIdx.ToString(), "32�����������ź������붼������");
// return null;
// }
// else//��������
// {
// #region ��������
// //DataView dv = dbo.ExceSQL("SELECT F_BarCode, F_Askkind, F_DeviceIndex FROM T_Base_PLC_Ask where F_DeviceIndex=" + DeviceIndex).Tables[0].DefaultView;
// //if (dv.Count > 0)
// //{
// // if (barcode == dv[i]["F_BarCode"].ToString())
// // {
// // return null;
// // }
// // else
// // {
// if (askdev.UseCommonDB == "1")
// {
// sql.Remove(0, sql.Length);
// sql.Append("SELECT F_MonitorIndex,F_DeviceCommandIndex,F_NumParam1,F_NumParam2,").Append(
// "F_NumParam3,F_NumParam4,F_NumParam5,F_NumParam6 FROM T_Monitor_Task WHERE F_TxtParam = '").Append(
// barcode).Append("' order by F_MonitorIndex asc");
// }
// else
// {//20090928 and F_DeviceIndex=" + states[3] + "
// sql.Remove(0, sql.Length);
// sql.Append("SELECT F_MonitorIndex,F_DeviceCommandIndex,F_NumParam1,F_NumParam2,").Append(
// "F_NumParam3,F_NumParam4,F_NumParam5,F_NumParam6 FROM T_Monitor_Task WHERE F_TxtParam = '").Append(
// barcode).Append("' order by F_MonitorIndex asc");
// }
// //20100108
// dvbc = dbo.ExceSQL(sql.ToString()).Tables[0].DefaultView;
// if (dvbc.Count > 0)
// {
// if (askdev.UseCommonDB == "1")
// {
// //20090915
// sql.Remove(0, sql.Length);
// sql.Append("update T_Monitor_Task set F_AheadDetect='',F_DeviceIndex=").Append(states[3]).Append(" where F_MonitorIndex=").Append(dvbc[0]["F_MonitorIndex"]).Append("");
// dbo.ExceSQL(sql.ToString());
// }
// //wv[0] = "4";
// //sdo.WriteDBData(witemnames, wv);
// return states;
// }
// else
// {
// //35�������豸�ź������벻ƥ��
// wv[0].Remove(0, wv[0].Length);
// wv[0].Append("35");
// sdo.WriteDBData(witemnames, wv);//20091013
// CommonClassLib.CCarryConvert.WriteDarkCasket("OPCClient", "�����ֳ����ƴ����������ķ�����Ϣ", deviceIdx.ToString(), "35�������豸�ź������벻ƥ��");
// return null;
// }
// // }
// //}
// #endregion
// }
// }
// else//��������
// {
// #region ��������
// //DataView dv = dbo.ExceSQL("SELECT F_TaskIndex, F_Askkind, F_DeviceIndex FROM T_Base_PLC_Ask where F_DeviceIndex=" + DeviceIndex).Tables[0].DefaultView;
// //if (dv.Count > 0)
// //{
// // if (states[4] == dv[i]["F_TaskIndex"].ToString())
// // {
// // return null;
// // }
// // else
// // {
// if (askdev.UseCommonDB == "1")
// {
// sql.Remove(0, sql.Length);
// sql.Append("SELECT F_MonitorIndex,F_DeviceCommandIndex,F_NumParam1,F_NumParam2,").Append(
// "F_NumParam3,F_NumParam4,F_NumParam5,F_NumParam6 FROM T_Monitor_Task WHERE F_MonitorIndex = '").Append(
// states[4]).Append("' order by F_MonitorIndex asc");
// }
// else
// {//20090928 and F_DeviceIndex=" + states[3] + "
// sql.Remove(0, sql.Length);
// sql.Append("SELECT F_MonitorIndex,F_DeviceCommandIndex,F_NumParam1,F_NumParam2,").Append(
// "F_NumParam3,F_NumParam4,F_NumParam5,F_NumParam6 FROM T_Monitor_Task WHERE F_MonitorIndex = '").Append(
// states[4]).Append("' order by F_MonitorIndex asc");
// }
// //20101008
// dvbc = dbo.ExceSQL(sql.ToString()).Tables[0].DefaultView;
// if (dvbc.Count > 0)
// {
// if (askdev.UseCommonDB == "1")
// {
// //20090915
// sql.Remove(0, sql.Length);
// sql.Append("update T_Monitor_Task set F_AheadDetect='',F_DeviceIndex=").Append(states[3]).Append(" where F_MonitorIndex=").Append(dvbc[0]["F_MonitorIndex"]);
// dbo.ExceSQL(sql.ToString());
// }
// //RestoreDevice(Convert.ToInt32(dvbc[0]["F_MonitorIndex"]));
// //wv[0] = "4";
// //sdo.WriteDBData(witemnames, wv);
// ////��¼������
// //dbo.ExceSQL("update T_Base_PLC_Ask set F_TaskIndex='" + states[4]
// // + "' where F_DeviceIndex=" + DeviceIndex);
// return states;
// }
// else
// {
// //36�������豸�ź������Ų�ƥ��
// wv[0].Remove(0, wv[0].Length);
// wv[0].Append("36");
// sdo.WriteDBData(witemnames, wv);//20091013
// CommonClassLib.CCarryConvert.WriteDarkCasket("OPCClient", "�����ֳ����ƴ����������ķ�����Ϣ", deviceIdx.ToString(), "36�������豸�ź������Ų�ƥ��");
// return null;
// }
// // }
// //}
// #endregion
// }
// }
// #endregion
// #region �����ĵ�ǰ�豸��ִ������Ŀ��λ��(2)
// else if (states[2] == 2)//������
// {
// //�����ĵ�ǰ�豸��ִ������Ŀ��λ�õ�F_TaskIndex�ظ�ʱ��������Ӧ����
// return states;
// }
// #endregion
// #region �ϱ�����(3)
// else if (states[2] == 3)//������
// {
// if (states[4] == 0)//��������
// {
// if (bcz == 0)//��������
// {
// //32�����������ź������붼������
// wv[0].Remove(0, wv[0].Length);
// wv[0].Append("32");
// sdo.WriteDBData(witemnames, wv);//20091013
// CommonClassLib.CCarryConvert.WriteDarkCasket("OPCClient", "�����ֳ����ƴ����������ķ�����Ϣ", deviceIdx.ToString(), "32�����������ź������붼������");
// return null;
// }
// else//��������
// {
// #region ��������
// //20100108
// sql.Remove(0, sql.Length);
// sql.Append("SELECT F_MonitorIndex,F_DeviceCommandIndex,F_NumParam1,F_NumParam2,").Append(
// "F_NumParam3,F_NumParam4,F_NumParam5,F_NumParam6 FROM T_Monitor_Task WHERE F_TxtParam = '").Append(
// barcode).Append("' order by F_MonitorIndex asc");
// dvbc = dbo.ExceSQL(sql.ToString()).Tables[0].DefaultView;
// if (dvbc.Count > 0)
// {
// return states;
// }
// else
// {
// //30����������������
// wv[0].Remove(0, wv[0].Length);
// wv[0].Append("30");
// sdo.WriteDBData(witemnames, wv);//20091013
// CommonClassLib.CCarryConvert.WriteDarkCasket("OPCClient", "�����ֳ����ƴ����������ķ�����Ϣ", deviceIdx.ToString(), "30�����������Ų�����");
// return null;
// }
// #endregion
// }
// }
// else
// {
// #region ��������
// //DataView dv = dbo.ExceSQL("SELECT F_TaskIndex, F_Askkind, F_DeviceIndex FROM T_Base_PLC_Ask where F_DeviceIndex=" + DeviceIndex).Tables[0].DefaultView;
// //if (dv.Count > 0)
// //{
// // if (states[4] == dv[i]["F_TaskIndex"].ToString())
// // {
// // return null;
// // }
// // else
// // {
// //and F_DeviceIndex=" + states[3] + "
// //20100108
// sql.Remove(0, sql.Length);
// sql.Append("SELECT F_MonitorIndex,F_DeviceCommandIndex,F_NumParam1,F_NumParam2,").Append(
// "F_NumParam3,F_NumParam4,F_NumParam5,F_NumParam6 FROM T_Monitor_Task WHERE F_MonitorIndex = '").Append(
// states[4]).Append("' order by F_MonitorIndex asc");
// dvbc = dbo.ExceSQL(sql.ToString()).Tables[0].DefaultView;
// if (dvbc.Count > 0)
// {
// //wv[0] = "2";
// //sdo.WriteDBData(witemnames, wv);
// ////��¼������
// //dbo.ExceSQL("update T_Base_PLC_Ask set F_TaskIndex='" + states[4]
// // + "' where F_DeviceIndex=" + DeviceIndex);
// return states;
// }
// else
// {
// //31����������������
// wv[0].Remove(0, wv[0].Length);
// wv[0].Append("31");
// sdo.WriteDBData(witemnames, wv);//20091013
// CommonClassLib.CCarryConvert.WriteDarkCasket("OPCClient", "�����ֳ����ƴ����������ķ�����Ϣ", deviceIdx.ToString(), "31�����������Ų�����");
// return null;
// }
// // }
// //}
// #endregion
// }
// }
// #endregion
// #region ɾ����ǰ�豸��ִ�е�����(4)���������ߣ�
// else if (states[2] == 4)//������
// {
// //20090915
// if (states[4] == 0)//��������
// {
// if (bcz == 0)//��������
// {
// //32�����������ź������붼������
// wv[0].Remove(0, wv[0].Length);
// wv[0].Append("32");
// sdo.WriteDBData(witemnames, wv);//20091013
// CommonClassLib.CCarryConvert.WriteDarkCasket("OPCClient", "�����ֳ����ƴ����������ķ�����Ϣ", deviceIdx.ToString(), "32�����������ź������붼������");
// return null;
// }
// else//��������
// {
// #region ��������
// //20100108
// sql.Remove(0, sql.Length);
// sql.Append("SELECT F_MonitorIndex,F_DeviceCommandIndex,F_NumParam1,F_NumParam2,").Append(
// "F_NumParam3,F_NumParam4,F_NumParam5,F_NumParam6 FROM T_Monitor_Task WHERE F_TxtParam = '").Append(
// barcode).Append("' order by F_MonitorIndex asc");
// dvbc = dbo.ExceSQL(sql.ToString()).Tables[0].DefaultView;
// if (dvbc.Count > 0)
// {
// return states;
// }
// else
// {
// //30����������������
// wv[0].Remove(0, wv[0].Length);
// wv[0].Append("30");
// sdo.WriteDBData(witemnames, wv);//20091013
// CommonClassLib.CCarryConvert.WriteDarkCasket("OPCClient", "�����ֳ����ƴ����������ķ�����Ϣ", deviceIdx.ToString(), "30�����������Ų�����");
// return null;
// }
// #endregion
// }
// }
// else
// {//20090915
// #region ��������
// //20100108
// sql.Remove(0, sql.Length);
// sql.Append("SELECT F_MonitorIndex,F_DeviceCommandIndex,F_NumParam1,F_NumParam2,").Append(
// "F_NumParam3,F_NumParam4,F_NumParam5,F_NumParam6 FROM T_Monitor_Task WHERE F_MonitorIndex = '").Append(
// states[4]).Append("' order by F_MonitorIndex asc");
// dvbc = dbo.ExceSQL(sql.ToString()).Tables[0].DefaultView;
// if (dvbc.Count > 0)
// {
// return states;
// }
// else
// {
// //31����������������
// wv[0].Remove(0, wv[0].Length);
// wv[0].Append("31");
// sdo.WriteDBData(witemnames, wv);//20091013
// CommonClassLib.CCarryConvert.WriteDarkCasket("OPCClient", "�����ֳ����ƴ����������ķ�����Ϣ", deviceIdx.ToString(), "31�����������Ų�����");
// return null;
// }
// #endregion
// }
// }
// #endregion
// break;
// #endregion
// #region ������������Ϣ
// case "24":
// if (DeviceStateAllReturns[temp] != 1) return null;
// states[0] = 0;
// states[1] = deviceIdx;
// states[2] = DeviceStateAllReturns[temp + 1];//�����˶���:1-ȡ������;2-�Ż�����;3-������������
// states[3] = DeviceStateAllReturns[temp + 2];//������������
// //sdo.WriteDBData(witemnames, wv);
// devinfo.ReturnMessage = states;
// Model.CGetInfo.SetDeviceMessage(devinfo);
// //string ssss = "";
// //for (int j = 0; j <= 3; j++)
// //{
// // ssss += "**" + states[j].ToString();
// //}
// //CommonClassLib.CCarryConvert.WriteDarkCasket("OPCClient", "CGetDeviceState", deviceIdx.ToString(), ssss);
// break;
// #endregion
// #region �����豸
// case "1"://�Ѷ���
// states[0] = DeviceStateAllReturns[temp];//��д��־
// states[1] = DeviceStateAllReturns[temp + 1];//״̬
// states[2] = (DeviceStateAllReturns[temp + 2] << 8) + DeviceStateAllReturns[temp + 3];//������
// states[3] = DeviceStateAllReturns[temp + 7] + (DeviceStateAllReturns[temp + 6] << 8) + (DeviceStateAllReturns[temp + 5] << 16) + (DeviceStateAllReturns[temp + 4] << 32);//X����
// states[4] = DeviceStateAllReturns[temp + 11] + (DeviceStateAllReturns[temp + 10] << 8) + (DeviceStateAllReturns[temp + 9] << 16) + (DeviceStateAllReturns[temp + 8] << 32);//Y����
// states[5] = deviceIdx;//�豸������
// if (IsEquals(devinfo.ReturnMessage, states, 3) == false)
// {
// devinfo.ReturnMessage = states;
// Model.CGetInfo.SetDeviceMessage(devinfo);
// sss.Remove(0, sss.Length);
// sss.Append("**����־" + states[0]).Append("**״̬" + states[1]).Append("**������" + states[2])
// .Append("**������" + states[3]).Append("**������" + states[4]);
// CommonClassLib.CCarryConvert.WriteDarkCasket("OPCClient", "�յ��Ѷ���״̬", deviceIdx.ToString(), sss.ToString());
// }
// break;
// case "2"://���ͻ�
// states[0] = DeviceStateAllReturns[temp];//��д��־
// states[1] = DeviceStateAllReturns[temp + 1];//״̬
// states[2] = (DeviceStateAllReturns[temp + 2] << 8) + DeviceStateAllReturns[temp + 3];//������
// states[3] = 0;
// states[4] = 0;
// states[5] = deviceIdx;//�豸������
// if (IsEquals(devinfo.ReturnMessage, states, 3) == false)
// {
// devinfo.ReturnMessage = states;
// Model.CGetInfo.SetDeviceMessage(devinfo);
// sss.Remove(0, sss.Length);
// sss.Append("**����־" + states[0]).Append("**״̬" + states[1]).Append("**������" + states[2]);
// CommonClassLib.CCarryConvert.WriteDarkCasket("OPCClient", "�յ����ͻ�״̬", deviceIdx.ToString(), sss.ToString());
// }
// break;
// case "4"://RGV
// states[0] = DeviceStateAllReturns[temp];//��д��־
// states[1] = DeviceStateAllReturns[temp + 1];//״̬
// states[2] = (DeviceStateAllReturns[temp + 2] << 8) + DeviceStateAllReturns[temp + 3];//������
// states[3] = DeviceStateAllReturns[temp + 7] + (DeviceStateAllReturns[temp + 6] << 8) + (DeviceStateAllReturns[temp + 5] << 16) + (DeviceStateAllReturns[temp + 4] << 32);//X����
// states[4] = 0;
// states[5] = deviceIdx;//�豸������
// if (IsEquals(devinfo.ReturnMessage, states, 3) == false)
// {
// devinfo.ReturnMessage = states;
// Model.CGetInfo.SetDeviceMessage(devinfo);
// sss.Remove(0, sss.Length);
// sss.Append("**����־" + states[0]).Append("**״̬" + states[1]).Append("**������" + states[2]).Append("**X����" + states[3]);
// CommonClassLib.CCarryConvert.WriteDarkCasket("OPCClient", "CGetDeviceState", deviceIdx.ToString(), sss.ToString());
// }
// break;
// #endregion
// #region �߶˼������豸
// case "31"://��λ���ͻ�
// states[0] = DeviceStateAllReturns[temp];//��д��־
// states[1] = DeviceStateAllReturns[temp + 1];//״̬
// StringBuilder barcode1 = new StringBuilder();
// for (int i = 2; i <= 7; i++)
// {
// barcode1.Append(Convert.ToChar(DeviceStateAllReturns[temp + i]));
// }
// states[2] = GetMonitorTaskIndexFromBarCode(barcode1);
// states[3] = 0;
// states[4] = 0;
// states[5] = deviceIdx;//�豸������
// if (IsEquals(devinfo.ReturnMessage, states, 3) == false)
// {
// devinfo.ReturnMessage = states;
// Model.CGetInfo.SetDeviceMessage(devinfo);
// sss.Remove(0, sss.Length);
// sss.Append("**����־" + states[0]).Append("**״̬" + states[1]).Append("**������" + barcode1 + "**������" + states[2]);
// CommonClassLib.CCarryConvert.WriteDarkCasket("OPCClient", "�յ���λ���ͻ�״̬", deviceIdx.ToString(), sss.ToString());
// }
// break;
// case "32"://�������
// if (DeviceStateAllReturns[temp] != 1) return null;
// states = new int[16];
// states[0] = 0;
// states[1] = deviceIdx;
// states[2] = DeviceStateAllReturns[temp + 1];//������
// states[3] = (DeviceStateAllReturns[temp + 2] << 8) + DeviceStateAllReturns[temp + 3];//�豸����
// int bcz11 = 0;
// StringBuilder barcode11 = new StringBuilder();
// for (int j = 6; j <= 11; j++)
// {
// bcz11 = bcz11 + DeviceStateAllReturns[temp + j];
// barcode11.Append(Convert.ToChar(DeviceStateAllReturns[temp + j]).ToString().ToUpper());
// states[j - 1] = DeviceStateAllReturns[temp + j];
// }
// states[4] = GetMonitorTaskIndexFromBarCode(barcode11);//������
// askdev = Model.CGetInfo.GetDeviceInfo(states[3]);
// //states[2];//������
// //states[3];//�豸��������ǰ�����豸��������
// //states[4];//�����ţ���Ҫ��Ŀ��λ�õ������ţ�
// //20091102
// if (askdev == null)
// {
// wv[0].Remove(0, wv[0].Length);
// wv[0].Append("34");
// sdo.WriteDBData(witemnames, wv);//20091013
// CommonClassLib.CCarryConvert.WriteDarkCasket("OPCClient", "�����ֳ����ƴ����������ķ�����Ϣ", deviceIdx.ToString(), "34�������豸�Ų�����");
// return null;
// }
// //20090902������arraylength
// if (IsEquals(devinfo.ReturnMessage, states, 5) == false)
// {
// devinfo.ReturnMessage = states;
// Model.CGetInfo.SetDeviceMessage(devinfo);
// sss.Remove(0, sss.Length);
// sss.Append("**�������豸����" + states[1]).Append("**������" + states[2])
// .Append("**�������豸����" + states[3]).Append("**������������" + states[4]).Append("**����������" + barcode11);
// CommonClassLib.CCarryConvert.WriteDarkCasket("OPCClient", "�յ��ֳ����ƴ�����������Ϣ", deviceIdx.ToString(), sss.ToString());
// }
// if (bcz11 == 0)//��������
// {
// //30�����벻����
// wv[0].Remove(0, wv[0].Length);
// wv[0].Append("30");
// sdo.WriteDBData(witemnames, wv);//20091013
// CommonClassLib.CCarryConvert.WriteDarkCasket("OPCClient", "�����ֳ����ƴ����������ķ�����Ϣ", deviceIdx.ToString(), "30�����벻����");
// return null;
// }
// else//��������
// {
// #region ��������
// sql.Remove(0, sql.Length);
// sql.Append("SELECT F_MonitorIndex,F_DeviceCommandIndex,F_NumParam1,F_NumParam2,").Append(
// "F_NumParam3,F_NumParam4,F_NumParam5,F_NumParam6 FROM T_Monitor_Task WHERE F_TxtParam = '").Append(
// barcode11).Append("' order by F_MonitorIndex asc");
// dvbc = dbo.ExceSQL(sql.ToString()).Tables[0].DefaultView;
// if (dvbc.Count > 0)
// {
// return states;
// }
// else
// {
// //35�������豸�ź������벻ƥ��
// wv[0].Remove(0, wv[0].Length);
// wv[0].Append("33");
// sdo.WriteDBData(witemnames, wv);//20091013
// CommonClassLib.CCarryConvert.WriteDarkCasket("OPCClient", "�����ֳ����ƴ����������ķ�����Ϣ", deviceIdx.ToString(), "33�������豸�ź������벻ƥ��");
// return null;
// }
// #endregion
// }
// #endregion
// }
// return states;
// }
// else
// {
// return null;
// }
// #endregion
// }
// else
// {
// return null;
// }
//}
//catch (Exception ex)
//{
// string s1 = DateTime.Now.Millisecond.ToString();
// RefreshMonitorEventArgs rea = new RefreshMonitorEventArgs("tsStatus", "�����豸״̬ʱ��" + ex.Message);
// OnRefreshMonitor(rea);
// return null;
//}
//finally
//{//20100108
// //dv=null;
// //dvM = null;
// askdev = null;
// states = null;
// dvbc = null;
//}
#endregion
}
public static string GetStringData ( int deviceIdx )
{
try
{
//20110216
DeviceStateAllReturns = CStaticClass . MutiReadSubscriptionDeviceStateReturns [ GetDeviceReadSubscription ( deviceIdx ) ] ;
if ( DeviceStateAllReturns ! = null )
{
#region ��ȡ�豸״̬
devinfo = Model . CGetInfo . GetDeviceInfo ( deviceIdx ) ;
if ( devinfo . Dbw2Address ! = - 1 )
{
//20110216
devinfo28 = Model . CGeneralFunction . GetDeviceReadSubscriptionDB2Data ( new StringBuilder ( devinfo . S7Connection ) ) ;
int temp = devinfo . Dbw2Address - devinfo28 . Dbw2Address ;
decimal glen = devinfo . Dbw2Getlength ;
string headstr = DeviceStateAllReturns [ temp ] . ToString ( ) ;
if ( headstr ! = "1" ) return null ;
wv [ 0 ] . Remove ( 0 , wv [ 0 ] . Length ) ;
wv [ 0 ] . Append ( "2" ) ;
witemnames [ 0 ] . Append ( Model . CGeneralFunction . DBGet ) . Append ( "." ) . Append ( Convert . ToString ( devinfo . Dbw2Address + 0 ) ) . Append ( ",b" ) ; //20130510
sdo = CommModeCreate . CreateSendDeviceOrder ( deviceIdx ) ;
switch ( devinfo . DeviceKind . ToString ( ) )
{
#region �ַ�����Ϣ
case "7" : //������
sss . Remove ( 0 , sss . Length ) ;
for ( int i = 1 ; i < = 1 0 ; i + + )
{
sss . Append ( Convert . ToChar ( DeviceStateAllReturns [ temp + i ] ) ) ;
}
//sdo.WriteDBData(witemnames, wv);
CommonClassLib . CCarryConvert . WriteDarkCasket ( "OPCClient" , "��PLC����" , deviceIdx . ToString ( ) , "����־1**���룺" + sss . ToString ( ) . ToUpper ( ) ) ;
break ;
case "21" : //һ�Ź�����
sss . Remove ( 0 , sss . Length ) ;
for ( int i = 1 ; i < = 3 2 ; i + + )
{
sss . Append ( Convert . ToChar ( DeviceStateAllReturns [ temp + i ] ) ) ;
}
//sdo.WriteDBData(witemnames, wv);
//CommonClassLib.CCarryConvert.WriteDarkCasket("OPCClient", "CGetDeviceState", deviceIdx.ToString(), strdata);
break ;
#endregion
}
return sss . ToString ( ) . ToUpper ( ) ;
}
else
{
return null ;
}
#endregion
}
else
{
return null ;
}
}
catch ( Exception ex )
{
RefreshMonitorEventArgs rea = new RefreshMonitorEventArgs ( "tsStatus" , string . Format ( "CStaticClassȡ���豸�ַ�����Ϣʱ��{0}" , ex . StackTrace + ex . Message ) ) ;
OnRefreshMonitor ( rea ) ;
return null ;
}
}
/// <summary>
/// �Ƚ�����ֵ��һά���������Ƿ�ֵ����
/// </summary>
/// <param name="array1">ֵ��һά����1</param>
/// <param name="array2">ֵ��һά����2</param>
/// <returns>�ȽϽ�����������true������false</returns>
public static bool IsEquals ( Array array1 , Array array2 , int arraylength )
{ //20090902������arraylength
//�Ƚ������Ƿ�һ��
if ( ( array1 = = null ) | | ( array2 = = null ) ) return false ;
if ( ! Object . ReferenceEquals ( array1 . GetType ( ) , array2 . GetType ( ) ) )
{
return false ;
}
//�Ƚϳ����Ƿ�һ��
if ( array1 . GetLength ( 0 ) ! = array2 . GetLength ( 0 ) )
{
return false ;
}
//�Ƚϳ�Ա�Ƿ���Ӧ����
ValueType v1 , v2 ;
for ( int i = 0 ; i < arraylength ; i + + )
{
v1 = ( ValueType ) array1 . GetValue ( i ) ;
v2 = ( ValueType ) array2 . GetValue ( i ) ;
if ( ! v1 . Equals ( v2 ) )
{
return false ;
}
}
return true ;
}
static int GetMonitorTaskIndexFromBarCode ( StringBuilder BarCode )
{ //20110216
DataView dv = dbo . ExceSQL ( string . Format ( "SELECT F_MonitorIndex FROM T_Monitor_Task WHERE (F_TxtParam = '{0}') order by F_MonitorIndex asc" , BarCode . ToString ( ) ) ) . Tables [ 0 ] . DefaultView ;
if ( dv . Count > 0 )
{
return Convert . ToInt32 ( dv [ 0 ] [ "F_MonitorIndex" ] ) ;
}
else
{
return - 1 ;
}
}
public static string SelectGoodsCell ( int lane , int enddevice )
{
string strCellCode = string . Empty ;
string sqlstr = string . Empty ;
string sqlshort = "1=1" ;
DataView dv ;
if ( enddevice > = 1 2 0 0 1 & & enddevice < = 1 2 0 1 3 ) //��ǰ����
{
sqlstr = string . Format ( "SELECT top 1 * FROM ST_CELL WHERE (FCELLSTATUS = 1) AND(FRunStatus = 0) And(F_X>10)And(F_Y =1)and (FLaneWay={0}) ORDER BY F_Z,F_X , F_Y desc" , lane ) ;
}
else
if ( enddevice = = 1 2 1 1 4 | | enddevice = = 2 2 1 1 6 | | enddevice = = 2 2 1 3 4 ) //LT1����
{
//if (lane == 15801)
//{
// sqlshort = "((F_Z=5 or F_Z=6) And F_X>=3 And F_X<=50 And F_X%3=0 ) ";
//}
//else//15802
//{
// sqlshort = "((F_Z=7 And F_X>=2 And F_X<=49 And F_X%3=2 )or (F_Z=8 And F_X>=34 And F_X<=51 And F_X%3=1 )) ";
//}
sqlstr = string . Format ( "SELECT top 1 * FROM ST_CELL WHERE (FCELLSTATUS = 1) AND(FRunStatus = 0)And(F_X >10) And(F_Y =1)and (FLaneWay={0}) and {1} ORDER BY F_Z, F_X , F_Y desc" , lane , sqlshort ) ;
}
dv = dbo . ExceSQL ( sqlstr ) . Tables [ 0 ] . DefaultView ;
if ( dv . Count > 0 )
{
strCellCode = dv [ 0 ] [ "fcellcode" ] . ToString ( ) . Trim ( ) ;
dbo . ExceSQL ( "update ST_CELL set FRunStatus = 1 where FLaneWay= " + lane + " and fcellcode = '" + strCellCode + "'" ) ;
return strCellCode ;
}
else
{
return "-" ;
}
}
public static string SelectEmptyPalletCell ( string lanes , int enddevice )
{
string strCellCode = string . Empty ;
string sqlstr = string . Empty ;
string sqlshort = "1=1" ;
DataView dv ;
if ( enddevice = = 2 2 0 5 2 | | enddevice = = 2 2 0 6 6 ) //�����������⣬��һ��
{
sqlstr = string . Format ( "SELECT top 1 * FROM ST_CELL WHERE (FCELLSTATUS = 1) AND(FRunStatus = 0) And(F_X >19) And(F_X <=30) And(F_Y =1)and (FLaneWay in ({0})) and {1} ORDER BY F_Z, F_X desc" , lanes , sqlshort ) ;
}
else
//if (enddevice >= 12001 && enddevice <= 12013)//
{
sqlstr = string . Format ( "SELECT top 1 * FROM ST_CELL WHERE (FCELLSTATUS = 1) AND(FRunStatus = 0) And(F_X>10)And(F_Y =1)and (FLaneWay in ({0})) ORDER BY F_Z,F_X , F_Y desc" , lanes ) ;
}
dv = dbo . ExceSQL ( sqlstr ) . Tables [ 0 ] . DefaultView ;
if ( dv . Count > 0 )
{
strCellCode = dv [ 0 ] [ "fcellcode" ] . ToString ( ) . Trim ( ) ;
dbo . ExceSQL ( "update ST_CELL set FRunStatus = 1 where fcellcode = '" + strCellCode + "'" ) ;
return strCellCode ;
}
else
{
return "-" ;
}
}
public static string SelectEmptyCell ( int lane )
{
string strCellCode = string . Empty ;
DataView dv ;
dv = dbo . ExceSQL ( "SELECT top 1 * FROM ST_CELL WHERE (FCELLSTATUS = 0) AND(FRunStatus = 0)AND(F_X > 50)AND(F_X != 57)and (FLaneWay=" + lane + ") ORDER BY F_Z, F_Y, F_X" ) . Tables [ 0 ] . DefaultView ;
if ( dv . Count > 0 )
{
strCellCode = dv [ 0 ] [ "fcellcode" ] . ToString ( ) . Trim ( ) ;
dbo . ExceSQL ( "update ST_CELL set FRunStatus = 1 where FLaneWay= " + lane + " and fcellcode = '" + strCellCode + "'" ) ;
return strCellCode ;
}
else
{
return "-" ;
}
}
public static string GetCellBarCode ( string cell , int lane )
{
string barcode = string . Empty ;
DataView dv = dbo . ExceSQL ( "SELECT FPALLETBARCODE FROM ST_CELL WHERE FLaneWay= " + lane + " and fcellcode = '" + cell + "'" ) . Tables [ 0 ] . DefaultView ;
if ( dv . Count > 0 )
{
barcode = dv [ 0 ] [ "FPALLETBARCODE" ] . ToString ( ) . Trim ( ) ;
return barcode ;
}
else
{
return "-" ;
}
}
public static int GetStackIndexFromLaneInfo ( int LaneIndex )
{
//20101124
StringBuilder sql = new StringBuilder ( ) ;
sql . Append ( "SELECT F_StackIndex FROM T_Base_LaneInfo WHERE (F_LaneDeviceIndex = " ) . Append ( LaneIndex ) . Append ( ")" ) ;
DataView dv = dbo . ExceSQL ( sql . ToString ( ) ) . Tables [ 0 ] . DefaultView ;
if ( dv . Count > 0 )
{
return Convert . ToInt32 ( dv [ 0 ] [ 0 ] ) ;
}
else
{
return - 1 ;
}
}
public static string SelectEmptyCell ( int lane , string cell , int kind )
{
char [ ] cc = new char [ 1 ] { '-' } ;
string [ ] sp = cell . Split ( cc ) ;
DataView dv ;
string strCellCode = string . Empty ;
if ( sp . Length > 2 ) //
{
if ( kind = = 1 )
{
if ( Convert . ToInt32 ( sp [ 1 ] ) < = 5 ) //�ж���ֵ,���ش���ֵ
{
dv = dbo . ExceSQL ( "SELECT top 1 * FROM ST_CELL WHERE (FCELLSTATUS = 0) AND(FRunStatus = 0)AND(F_X > 50)AND(F_X != 57)and (FLaneWay=" + lane + ") ORDER BY F_Z, F_Y, F_X desc" ) . Tables [ 0 ] . DefaultView ;
if ( dv . Count > 0 )
{
strCellCode = dv [ 0 ] [ "fcellcode" ] . ToString ( ) . Trim ( ) ;
dbo . ExceSQL ( "update ST_CELL set FRunStatus = 1 where FLaneWay= " + lane + " and fcellcode = '" + strCellCode + "'" ) ;
return strCellCode ;
}
else
{
return "-" ;
}
}
else //�ж���ֵ,����С��ֵ
{
dv = dbo . ExceSQL ( "SELECT top 1 * FROM ST_CELL WHERE (FCELLSTATUS = 0) AND(FRunStatus = 0)AND(F_X > 3)AND(F_X != 57)and (FLaneWay=" + lane + ") ORDER BY F_Z, F_Y, F_X " ) . Tables [ 0 ] . DefaultView ;
if ( dv . Count > 0 )
{
strCellCode = dv [ 0 ] [ "fcellcode" ] . ToString ( ) . Trim ( ) ;
dbo . ExceSQL ( "update ST_CELL set FRunStatus = 1 where FLaneWay= " + lane + " and fcellcode = '" + strCellCode + "'" ) ;
return strCellCode ;
}
else
{
return "-" ;
}
}
}
return "-" ;
if ( kind = = 2 )
{
dv = dbo . ExceSQL ( "SELECT * FROM ST_CELL WHERE (FLaneWay=" + lane + " and F_Z=" +
sp [ 0 ] + " and F_X=" + sp [ 1 ] + " and F_Y=" + sp [ 2 ] + ")" ) . Tables [ 0 ] . DefaultView ;
if ( dv . Count > 0 )
{
DataView dv0 = dbo . ExceSQL ( "SELECT * FROM ST_CELL WHERE FLaneWay=" + lane + " and FID>" + dv [ 0 ] [ "FID" ] + " order by fid asc" ) . Tables [ 0 ] . DefaultView ;
if ( dv0 . Count > 0 )
{
if ( lane = = 2 8 0 1 )
{
if ( ( dv0 [ 0 ] [ "FCELLCODE" ] . ToString ( ) = = "2-1-8" ) | | ( dv0 [ 0 ] [ "FCELLCODE" ] . ToString ( ) = = "2-2-8" ) )
{
return "2-3-1" ;
}
}
return dv0 [ 0 ] [ "FCELLCODE" ] . ToString ( ) ;
}
else
{
return "1-1-1" ;
}
}
}
}
else
{
return "-" ;
}
}
public static int GetDeviceKindIdx ( int devIdx )
{
try
{
string strSql = "SELECT F_DeviceIndex, F_DeviceKindIndex FROM T_Base_Device WHERE F_DeviceIndex=" + devIdx ;
DataSet ds = dbo . ExceSQL ( strSql ) ;
DataView dv = ds . Tables [ 0 ] . DefaultView ;
if ( dv . Count > 0 )
{
return Convert . ToInt32 ( dv [ 0 ] [ "F_DeviceKindIndex" ] ) ;
}
else
return - 1 ;
}
catch ( Exception ex )
{
throw ex ;
}
}
}
}