You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
761 lines
40 KiB
761 lines
40 KiB
5 months ago
|
using System;
|
||
|
using System.Collections.Generic;
|
||
|
using System.Text;
|
||
|
using DBFactory;
|
||
|
using ICommLayer;
|
||
|
using System.Data;
|
||
|
using Microsoft.VisualBasic;
|
||
|
namespace OPCClient
|
||
|
{
|
||
|
public class CGetDeviceState:IGetDeviceState
|
||
|
{
|
||
|
string _commLayerError;
|
||
|
|
||
|
public string CommLayerError
|
||
|
{
|
||
|
get { return _commLayerError; }
|
||
|
set { _commLayerError = value; }
|
||
|
}
|
||
|
DBOperator dbo = CCommonOPCClient.dbo;
|
||
|
public CGetDeviceState()
|
||
|
{
|
||
|
dbo.Open();
|
||
|
}
|
||
|
/// <summary>
|
||
|
///1����λ������λ�������豸��������״̬��Ϣ
|
||
|
///����أ� 0-��1-�л�
|
||
|
///ȷ�ϰ�ť��
|
||
|
///��1�ֽڣ�
|
||
|
///һ���仯��ֵ��ÿȷ��һ�Σ���ֵ�仯һ�Σ��Ա�־һ��
|
||
|
///�µ�ȷ����Ϣ������������0��1�����仯��Ҳ�����ǵ�
|
||
|
///���仯��
|
||
|
///��2�ֽڣ�
|
||
|
///1-��ȷ��
|
||
|
///2-�л�ȷ��
|
||
|
///�����豸��
|
||
|
///��1�� �ڣ��豸״̬
|
||
|
///�Ѷ�����0-����
|
||
|
///1-��������
|
||
|
///2-��������
|
||
|
///3-Ҫ�������ط�����
|
||
|
///4-֪ͨ����ȡ����ǰ����
|
||
|
///����ֵ��ʾ����
|
||
|
/// ����
|
||
|
/// 0-����
|
||
|
/// 1-��������
|
||
|
/// 2-����
|
||
|
/// 3-Ҫ�������ط�����
|
||
|
/// 4-֪ͨ����ȡ����ǰ����
|
||
|
/// ����ֵ��ʾ����
|
||
|
/// ���ͻ���
|
||
|
/// 0-����
|
||
|
/// 1-��������
|
||
|
/// 2-���ɣ�ֻ��PC�·���Ŀ���豸�������㱨���ɣ�
|
||
|
/// ���ϻ�����Ҫ��������״̬
|
||
|
/// ����ֵ��ʾ����
|
||
|
/// ��2��3�ֽڣ� �����ţ�����λ���´�����ʱ��������
|
||
|
/// ��4��5��6��7�ֽ�
|
||
|
/// �Ѷ���������
|
||
|
/// �յ�X���꣨�ع���������
|
||
|
/// ����8�ֽ��Ժ�ֻ�ԶѶ��������壩
|
||
|
/// ��8��9��10��11�ֽ�
|
||
|
/// �յ�Y���꣨�ظ߶ȷ�����
|
||
|
///
|
||
|
/// 2.��λ������λ������������Ϣ
|
||
|
/// �������룺
|
||
|
/// ��1-10�ֽڣ������������δ��������ϵ�10λ��������Ϣ
|
||
|
/// ����һ�Ź����룺
|
||
|
/// ��1-9�ֽڣ� �����������δ��������ϵĺ�9λһ�Ź�������Ϣ
|
||
|
/// һ�Ź�������32λ����ͬƷ��������һ�Ź�������ǰ23λ��ͬ��
|
||
|
/// ����ֻ���ź�9λ���롣ÿ������λ���̿�����������һ�Ź�������������
|
||
|
/// ��18���ֽڣ���λ��һ�ν���������һ�Ź���������Ϣͬʱ��ȡ��
|
||
|
/// ��λ���ɹ���ȡ18���ֽں���18���ֽ�ȫ��д���㣬
|
||
|
/// ��λ��ֻ�м��18���ֽ�ȫ������ʱ�ſ���д���µ�һ�Ź�������Ϣ��
|
||
|
///
|
||
|
/// 3.��λ������λ�������ֳ����ƴ����������ź�
|
||
|
/// ��1�ֽ� ����ָ��
|
||
|
/// 1- �ط���ǰ�豸ָ��
|
||
|
/// 2- �����ĵ�ǰ�豸��ִ��������Ŀ��λ��
|
||
|
/// ��2��3�ֽ� �豸��������ǰ�����豸��������
|
||
|
/// ��4��5�ֽ� �����ţ���Ҫ��Ŀ��λ�õ������ţ�
|
||
|
/// ��6��15�ֽ� �������루��ǰ�����豸�ϵ����̵����룩
|
||
|
/// ��λ���������������������������������䶪ʧ��
|
||
|
/// ��ʱ�����豸��ͣ�����̵���������������������������
|
||
|
/// ��λ���յ������������·��͵�ǰ�豸��ָ�
|
||
|
/// ���豸��������ʱ����λ������������������Ŀ��λ�á�
|
||
|
/// ��λ���յ��������������������ҵ��µ�·�������Ĵ������ŵ�Ŀ��λ�á�
|
||
|
/// ������ָ��Ϊ1ʱ�������ſ���������ֵ��������ָ��Ϊ2ʱ��������������������ֵ��
|
||
|
/// </summary>
|
||
|
/// <param name="DeviceIndex">�豸����</param>
|
||
|
/// <returns>����������Ϣ�ɹ�����Ӧ����Ϣ��22���ֵ�״̬</returns>
|
||
|
public int[] GetDeviceState(int DeviceIndex, int TaskIndex)
|
||
|
{//20091107
|
||
|
//string[] itemnames;
|
||
|
int[] _Rword = new int[20];
|
||
|
//string[] www;
|
||
|
//string[] wi;
|
||
|
//int add = 0;
|
||
|
//int Bit = 0;
|
||
|
//string ivalue;
|
||
|
//List< string> itemvalue = new List<string>();
|
||
|
Model.MDevice devinfo = Model.CGetInfo.GetDeviceInfo(DeviceIndex);
|
||
|
//Model.MDevice askdev;
|
||
|
//string sql = "";
|
||
|
try
|
||
|
{
|
||
|
|
||
|
|
||
|
////DataView dv = dbo.ExceSQL("SELECT F_DBW2Address,F_DBWGetLength,F_DeviceIndex,F_DeviceKindIndex,F_OPCProgID, F_RemoteIP FROM T_Base_Device where F_DeviceIndex=" + DeviceIndex).Tables[0].DefaultView;
|
||
|
//if (devinfo.DeviceIndex == 0)
|
||
|
//{
|
||
|
// _commLayerError = "OPCClient.CGetDeviceState.GetDeviceState�������������豸����û�ҵ��豸������";
|
||
|
|
||
|
// return null;
|
||
|
//}
|
||
|
//else
|
||
|
//{
|
||
|
// CCommonOPCClient.Hostname = CommonClassLib.AppSettings.GetValue("HostName");//20090922 devinfo.RemoteIP;
|
||
|
// CCommonOPCClient.ProgID = CommonClassLib.AppSettings.GetValue("OPCProgID");
|
||
|
// switch (devinfo.DeviceKind.ToString())
|
||
|
// {
|
||
|
// #region ���翪���ܵIJɼ�
|
||
|
// case "28":
|
||
|
// int[] _RRword = new int[(int)devinfo.Dbw2Getlength];
|
||
|
// byte[] br = CCommonOPCClient.SyncReadAllItems(devinfo.S7Connection);//20110216
|
||
|
// if (br == null)
|
||
|
// {
|
||
|
// _commLayerError = "OPCClient.CGetDeviceState.GetDeviceState��" + CCommonOPCClient.OpcError;
|
||
|
// return null;
|
||
|
// }
|
||
|
// Array.Copy(br, _RRword, (int)devinfo.Dbw2Getlength);
|
||
|
// return _RRword;
|
||
|
|
||
|
// #endregion
|
||
|
|
||
|
|
||
|
// #region ���翪�ؼ�����
|
||
|
// //case "18":
|
||
|
// // Bit = Convert.ToInt16(devinfo.Dbw2Getlength * 8) - 1;//ת����bit0--bit7
|
||
|
// // if (Bit > 7)
|
||
|
// // {
|
||
|
// // add = 1;
|
||
|
// // Bit = Bit - 8;
|
||
|
// // }
|
||
|
// // else
|
||
|
// // {
|
||
|
// // add = 0;
|
||
|
// // }
|
||
|
// // ivalue = CCommonOPCClient.SyncReadItemValue("DB2,X" + Convert.ToString(devinfo.Dbw2Address + add) + "." + Bit.ToString());
|
||
|
// // if ((ivalue == null) || (ivalue == ""))
|
||
|
// // {
|
||
|
// // _commLayerError = "OPCClient.CGetDeviceState.GetDeviceState��" + CCommonOPCClient.OpcError;
|
||
|
// // return null;
|
||
|
// // }
|
||
|
// // if (ivalue.ToLower() == "true")
|
||
|
// // {
|
||
|
// // _Rword[0] = 1;
|
||
|
// // }
|
||
|
// // else
|
||
|
// // {
|
||
|
// // _Rword[0] = 0;
|
||
|
// // }
|
||
|
|
||
|
// // _Rword[1] = 3;//3-�����״̬
|
||
|
// // _Rword[2] = TaskIndex;//������
|
||
|
// // _Rword[3] = 0;
|
||
|
// // _Rword[4] = 0;
|
||
|
// // _Rword[5] = DeviceIndex;//�豸������
|
||
|
|
||
|
// // break;
|
||
|
// //#endregion
|
||
|
// //#region ��ť
|
||
|
// //case "14":
|
||
|
// // Bit = Convert.ToInt16(devinfo.Dbw2Getlength * 8) - 1;//ת����bit0--bit7
|
||
|
// // if (Bit > 7)
|
||
|
// // {
|
||
|
// // add = 1;
|
||
|
// // Bit = Bit - 8;
|
||
|
// // }
|
||
|
// // else
|
||
|
// // {
|
||
|
// // add = 0;
|
||
|
// // }
|
||
|
// // ivalue = CCommonOPCClient.SyncReadItemValue("DB2,X" + Convert.ToString(devinfo.Dbw2Address + add) + "." + Bit.ToString());
|
||
|
// // if ((ivalue == null) || (ivalue == ""))
|
||
|
// // {
|
||
|
// // _commLayerError = "OPCClient.CGetDeviceState.GetDeviceState��" + CCommonOPCClient.OpcError;
|
||
|
// // return null;
|
||
|
// // }
|
||
|
|
||
|
// // _Rword[0] = Convert.ToInt32(ivalue);
|
||
|
// // _Rword[1] = 3;//3-�����״̬
|
||
|
// // _Rword[2] = TaskIndex;//������
|
||
|
// // _Rword[3] = 0;
|
||
|
// // _Rword[4] = 0;
|
||
|
// // _Rword[5] = DeviceIndex;//�豸������
|
||
|
|
||
|
// // break;
|
||
|
// //#endregion
|
||
|
|
||
|
|
||
|
// //#region �ֳ����ƴ�����������Ϣ��16���ֽڣ�
|
||
|
// //case "22":
|
||
|
// // itemnames = new string[14];
|
||
|
// // itemnames[0] = "DB2,byte" + Convert.ToString((devinfo.Dbw2Address + 0));
|
||
|
// // itemnames[1] = "DB2,byte" + Convert.ToString((devinfo.Dbw2Address + 1));
|
||
|
// // itemnames[2] = "DB2,int" + Convert.ToString((devinfo.Dbw2Address + 2));
|
||
|
// // itemnames[3] = "DB2,int" + Convert.ToString((devinfo.Dbw2Address + 4));
|
||
|
// // for (int i = 6; i < 16; i++)
|
||
|
// // {
|
||
|
// // itemnames[i - 2] = "DB2,byte" + Convert.ToString((devinfo.Dbw2Address + i));
|
||
|
// // }
|
||
|
// // object[] obj = CCommonOPCClient.SyncReadItemValues(itemnames);
|
||
|
|
||
|
// // if ((obj == null))
|
||
|
// // {
|
||
|
// // _commLayerError = "OPCClient.CGetDeviceState.GetDeviceState��" + CCommonOPCClient.OpcError;
|
||
|
// // return null;
|
||
|
// // }
|
||
|
// // if (obj[0].ToString() != "1") return null;
|
||
|
// // _Rword[0] = TaskIndex;
|
||
|
// // _Rword[1] = DeviceIndex;
|
||
|
// // _Rword[2] = Convert.ToInt32(obj[1]);
|
||
|
// // _Rword[3] = Convert.ToInt32(obj[2]);
|
||
|
// // _Rword[4] = Convert.ToInt32(obj[3]);
|
||
|
// // askdev = Model.CGetInfo.GetDeviceInfo(_Rword[3]);
|
||
|
// // //_Rword[2];//������
|
||
|
// // //_Rword[3];//�豸��������ǰ�����豸��������
|
||
|
// // //_Rword[4];//�����ţ���Ҫ��Ŀ��λ�õ������ţ�
|
||
|
// // int bcz = 0;
|
||
|
// // www = new string[1];
|
||
|
// // wi = new string[1] { itemnames[0] };
|
||
|
// // string barcode = string.Empty;
|
||
|
// // for (int j = 6; j < 16; j++)
|
||
|
// // {
|
||
|
// // bcz = bcz + Convert.ToInt32(obj[j - 2]);
|
||
|
// // barcode += Convert.ToChar(obj[j - 2]).ToString().ToUpper();
|
||
|
// // _Rword[j - 1] = Convert.ToInt32(obj[j - 2]);
|
||
|
// // }
|
||
|
// // #region �����ط���ǰ�豸ָ��(1)
|
||
|
|
||
|
// // if (_Rword[2] == 1)//������
|
||
|
// // {
|
||
|
// // if (_Rword[4] == 0)//��������
|
||
|
// // {
|
||
|
// // if (bcz == 0)//��������
|
||
|
// // {
|
||
|
// // //32�����������ź������붼������
|
||
|
// // www[0] = "32";
|
||
|
// // CCommonOPCClient.SyncWriteAllItemValue(wi, www);
|
||
|
// // 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 = "SELECT F_MonitorIndex,F_DeviceIndex,F_DeviceCommandIndex,F_NumParam1,F_NumParam2," +
|
||
|
// // "F_NumParam3,F_NumParam4,F_NumParam5,F_NumParam6 FROM T_Monitor_Task WHERE F_TxtParam = '" +
|
||
|
// // barcode + "' order by F_MonitorIndex asc";
|
||
|
// // }
|
||
|
// // else
|
||
|
// // {
|
||
|
// // sql = "SELECT F_MonitorIndex,F_DeviceIndex,F_DeviceCommandIndex,F_NumParam1,F_NumParam2," +
|
||
|
// // "F_NumParam3,F_NumParam4,F_NumParam5,F_NumParam6 FROM T_Monitor_Task WHERE F_TxtParam = '" +
|
||
|
// // barcode + "' and F_DeviceIndex=" + _Rword[3] + " order by F_MonitorIndex asc";
|
||
|
// // }
|
||
|
// // DataView dvbc = dbo.ExceSQL(sql).Tables[0].DefaultView;
|
||
|
// // if (dvbc.Count > 0)
|
||
|
// // {
|
||
|
// // if (askdev.UseCommonDB == "1")
|
||
|
// // {
|
||
|
// // dbo.ExceSQL("update T_Monitor_Task set F_AheadDetect='',F_DeviceIndex=" + _Rword[3] + " where F_MonitorIndex=" + dvbc[0]["F_MonitorIndex"] + "");
|
||
|
// // }
|
||
|
|
||
|
// // www[0] = "4";
|
||
|
// // CCommonOPCClient.SyncWriteAllItemValue(wi, www);
|
||
|
// // return _Rword;
|
||
|
// // }
|
||
|
// // else
|
||
|
// // {
|
||
|
// // //35�������豸�ź������벻ƥ��
|
||
|
// // www[0] = "35";
|
||
|
// // CCommonOPCClient.SyncWriteAllItemValue(wi, www);
|
||
|
// // 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 (_Rword[4] == dv[i]["F_TaskIndex"].ToString())
|
||
|
// // // {
|
||
|
// // // return null;
|
||
|
// // // }
|
||
|
// // // else
|
||
|
// // // {
|
||
|
// // if (askdev.UseCommonDB == "1")
|
||
|
// // {
|
||
|
// // sql = "SELECT F_MonitorIndex,F_DeviceIndex,F_DeviceCommandIndex,F_NumParam1,F_NumParam2," +
|
||
|
// // "F_NumParam3,F_NumParam4,F_NumParam5,F_NumParam6 FROM T_Monitor_Task WHERE F_MonitorIndex = '" +
|
||
|
// // _Rword[4] + "' order by F_MonitorIndex asc";
|
||
|
// // }
|
||
|
// // else
|
||
|
// // {
|
||
|
// // sql = "SELECT F_MonitorIndex,F_DeviceIndex,F_DeviceCommandIndex,F_NumParam1,F_NumParam2," +
|
||
|
// // "F_NumParam3,F_NumParam4,F_NumParam5,F_NumParam6 FROM T_Monitor_Task WHERE F_MonitorIndex = '" +
|
||
|
// // _Rword[4] + "' and F_DeviceIndex=" + _Rword[3] + " order by F_MonitorIndex asc";
|
||
|
// // }
|
||
|
// // DataView dvbc = dbo.ExceSQL(sql).Tables[0].DefaultView;
|
||
|
// // if (dvbc.Count > 0)
|
||
|
// // {
|
||
|
// // if (askdev.UseCommonDB == "1")
|
||
|
// // {
|
||
|
// // dbo.ExceSQL("update T_Monitor_Task set F_AheadDetect='',F_DeviceIndex=" + _Rword[3] + " where F_MonitorIndex=" + dvbc[0]["F_MonitorIndex"] + "");
|
||
|
// // }
|
||
|
// // //RestoreDevice(Convert.ToInt32(dvbc[0]["F_MonitorIndex"]));
|
||
|
// // www[0] = "4";
|
||
|
// // CCommonOPCClient.SyncWriteAllItemValue(wi, www);
|
||
|
// // ////��¼������
|
||
|
// // //dbo.ExceSQL("update T_Base_PLC_Ask set F_TaskIndex='" + _Rword[4]
|
||
|
// // // + "' where F_DeviceIndex=" + DeviceIndex);
|
||
|
// // return _Rword;
|
||
|
// // }
|
||
|
// // else
|
||
|
// // {
|
||
|
// // //36�������豸�ź������Ų�ƥ��
|
||
|
// // www[0] = "36";
|
||
|
// // CCommonOPCClient.SyncWriteAllItemValue(wi, www);
|
||
|
// // return null;
|
||
|
// // }
|
||
|
// // // }
|
||
|
// // //}
|
||
|
// // #endregion
|
||
|
// // }
|
||
|
|
||
|
// // }
|
||
|
|
||
|
// // #endregion
|
||
|
|
||
|
// // #region �����ĵ�ǰ�豸��ִ������Ŀ��λ��(2)
|
||
|
|
||
|
// // else if (_Rword[2] == 2)//������
|
||
|
// // {
|
||
|
// // //�����ĵ�ǰ�豸��ִ������Ŀ��λ�õ�F_TaskIndex�ظ�ʱ��������Ӧ����
|
||
|
|
||
|
// // }
|
||
|
|
||
|
// // #endregion
|
||
|
|
||
|
// // #region �ϱ�����(3)
|
||
|
// // else if (_Rword[2] == 3)//������
|
||
|
// // {
|
||
|
// // if (_Rword[4] == 0)//��������
|
||
|
// // {
|
||
|
// // if (bcz == 0)//��������
|
||
|
// // {
|
||
|
// // //32�����������ź������붼������
|
||
|
// // www[0] = "32";
|
||
|
// // CCommonOPCClient.SyncWriteAllItemValue(wi, www);
|
||
|
// // return null;
|
||
|
// // }
|
||
|
// // else//��������
|
||
|
// // {
|
||
|
// // #region ��������
|
||
|
// // sql = "SELECT F_MonitorIndex,F_DeviceIndex,F_DeviceCommandIndex,F_NumParam1,F_NumParam2," +
|
||
|
// // "F_NumParam3,F_NumParam4,F_NumParam5,F_NumParam6 FROM T_Monitor_Task WHERE F_TxtParam = '" +
|
||
|
// // barcode + "' order by F_MonitorIndex asc";
|
||
|
// // DataView dvbc = dbo.ExceSQL(sql).Tables[0].DefaultView;
|
||
|
|
||
|
// // if (dvbc.Count > 0)
|
||
|
// // {
|
||
|
// // www[0] = "2";
|
||
|
// // CCommonOPCClient.SyncWriteAllItemValue(wi, www);
|
||
|
|
||
|
// // return _Rword;
|
||
|
// // }
|
||
|
// // else
|
||
|
// // {
|
||
|
// // //30�����������벻����
|
||
|
// // www[0] = "30";
|
||
|
// // CCommonOPCClient.SyncWriteAllItemValue(wi, www);
|
||
|
// // return null;
|
||
|
// // }
|
||
|
// // #endregion
|
||
|
// // }
|
||
|
// // }
|
||
|
// // else
|
||
|
// // {
|
||
|
|
||
|
// // #region ��������
|
||
|
|
||
|
// // sql = "SELECT F_MonitorIndex,F_DeviceIndex,F_DeviceCommandIndex,F_NumParam1,F_NumParam2," +
|
||
|
// // "F_NumParam3,F_NumParam4,F_NumParam5,F_NumParam6 FROM T_Monitor_Task WHERE F_MonitorIndex = '" +
|
||
|
// // _Rword[4] + "' order by F_MonitorIndex asc";
|
||
|
|
||
|
// // DataView dvbc = dbo.ExceSQL(sql).Tables[0].DefaultView;
|
||
|
|
||
|
// // if (dvbc.Count > 0)
|
||
|
// // {
|
||
|
// // www[0] = "2";
|
||
|
// // CCommonOPCClient.SyncWriteAllItemValue(wi, www);
|
||
|
|
||
|
// // return _Rword;
|
||
|
// // }
|
||
|
// // else
|
||
|
// // {
|
||
|
// // //31����������������
|
||
|
// // www[0] = "31";
|
||
|
// // CCommonOPCClient.SyncWriteAllItemValue(wi, www);
|
||
|
// // return null;
|
||
|
// // }
|
||
|
// // // }
|
||
|
// // //}
|
||
|
// // #endregion
|
||
|
// // }
|
||
|
// // }
|
||
|
// // #endregion
|
||
|
|
||
|
// // #region ɾ����ǰ�豸��ִ�е�����(4)���������ߣ�
|
||
|
// // else if (_Rword[2] == 4)//������
|
||
|
// // {
|
||
|
// // if (_Rword[4] == 0)//��������
|
||
|
// // {
|
||
|
// // if (bcz == 0)//��������
|
||
|
// // {
|
||
|
// // //32�����������ź������붼������
|
||
|
// // www[0] = "32";
|
||
|
// // CCommonOPCClient.SyncWriteAllItemValue(wi, www);
|
||
|
// // return null;
|
||
|
// // }
|
||
|
// // else//��������
|
||
|
// // {
|
||
|
// // #region ��������
|
||
|
// // sql = "SELECT F_MonitorIndex,F_DeviceIndex,F_DeviceCommandIndex,F_NumParam1,F_NumParam2," +
|
||
|
// // "F_NumParam3,F_NumParam4,F_NumParam5,F_NumParam6 FROM T_Monitor_Task WHERE F_TxtParam = '" +
|
||
|
// // barcode + "' order by F_MonitorIndex asc";
|
||
|
// // DataView dvbc = dbo.ExceSQL(sql).Tables[0].DefaultView;
|
||
|
|
||
|
// // if (dvbc.Count > 0)
|
||
|
// // {
|
||
|
// // www[0] = "2";
|
||
|
// // CCommonOPCClient.SyncWriteAllItemValue(wi, www);
|
||
|
|
||
|
// // return _Rword;
|
||
|
// // }
|
||
|
// // else
|
||
|
// // {
|
||
|
// // //30�����������벻����
|
||
|
// // www[0] = "30";
|
||
|
// // CCommonOPCClient.SyncWriteAllItemValue(wi, www);
|
||
|
// // return null;
|
||
|
// // }
|
||
|
// // #endregion
|
||
|
// // }
|
||
|
// // }
|
||
|
// // else
|
||
|
// // {
|
||
|
|
||
|
// // #region ��������
|
||
|
|
||
|
// // sql = "SELECT F_MonitorIndex,F_DeviceIndex,F_DeviceCommandIndex,F_NumParam1,F_NumParam2," +
|
||
|
// // "F_NumParam3,F_NumParam4,F_NumParam5,F_NumParam6 FROM T_Monitor_Task WHERE F_MonitorIndex = '" +
|
||
|
// // _Rword[4] + "' order by F_MonitorIndex asc";
|
||
|
|
||
|
// // DataView dvbc = dbo.ExceSQL(sql).Tables[0].DefaultView;
|
||
|
// // if (dvbc.Count > 0)
|
||
|
// // {
|
||
|
// // www[0] = "3";
|
||
|
// // CCommonOPCClient.SyncWriteAllItemValue(wi, www);
|
||
|
|
||
|
// // return _Rword;
|
||
|
// // }
|
||
|
// // else
|
||
|
// // {
|
||
|
// // //31����������������
|
||
|
// // www[0] = "31";
|
||
|
// // CCommonOPCClient.SyncWriteAllItemValue(wi, www);
|
||
|
// // return null;
|
||
|
// // }
|
||
|
// // #endregion
|
||
|
// // }
|
||
|
// // }
|
||
|
// // #endregion
|
||
|
// // break;
|
||
|
// //#endregion
|
||
|
|
||
|
|
||
|
// //#region ������������Ϣ
|
||
|
// //case "24":
|
||
|
// // itemnames = new string[3];
|
||
|
// // itemnames[0] = "DB2,byte" + Convert.ToString((devinfo.Dbw2Address + 0));
|
||
|
// // itemnames[1] = "DB2,byte" + Convert.ToString((devinfo.Dbw2Address + 1));
|
||
|
// // itemnames[2] = "DB2,byte" + Convert.ToString((devinfo.Dbw2Address + 2));
|
||
|
// // obj = CCommonOPCClient.SyncReadItemValues(itemnames);
|
||
|
|
||
|
// // if ((obj == null))
|
||
|
// // {
|
||
|
// // _commLayerError = "OPCClient.CGetDeviceState.GetDeviceState��" + CCommonOPCClient.OpcError;
|
||
|
// // return null;
|
||
|
// // }
|
||
|
// // if (obj[0].ToString() != "1") return null;
|
||
|
// // _Rword[0] = TaskIndex;
|
||
|
// // _Rword[1] = DeviceIndex;
|
||
|
// // _Rword[2] = Convert.ToInt32(obj[1]);//�����˶���:1-ȡ������;2-�Ż�����;3-������������
|
||
|
// // _Rword[3] = Convert.ToInt32(obj[2]);//������������
|
||
|
// // www = new string[1];
|
||
|
// // wi = new string[1] { itemnames[0] };
|
||
|
// // www[0] = "2";
|
||
|
// // CCommonOPCClient.SyncWriteAllItemValue(wi, www);
|
||
|
|
||
|
// // break;
|
||
|
// //#endregion
|
||
|
|
||
|
// //#region �����豸
|
||
|
// //case "1"://�Ѷ���
|
||
|
// // itemnames = new string[5];
|
||
|
// // itemnames[0] = "DB2,byte" + Convert.ToString((devinfo.Dbw2Address + 0));
|
||
|
// // itemnames[1] = "DB2,byte" + Convert.ToString((devinfo.Dbw2Address + 1));
|
||
|
// // itemnames[2] = "DB2,int" + Convert.ToString((devinfo.Dbw2Address + 2));
|
||
|
// // itemnames[3] = "DB2,DWORD" + Convert.ToString((devinfo.Dbw2Address + 4));
|
||
|
// // itemnames[4] = "DB2,DWORD" + Convert.ToString((devinfo.Dbw2Address + 8));
|
||
|
// // itemvalue = CCommonOPCClient.SyncReadAllItems(itemnames);
|
||
|
// // if (itemvalue.Count == 0)
|
||
|
// // {
|
||
|
// // _commLayerError = "OPCClient.CGetDeviceState.GetDeviceState��" + CCommonOPCClient.OpcError;
|
||
|
// // return null;
|
||
|
// // }
|
||
|
// // _Rword[0] = Convert.ToInt32(itemvalue[0]);//��д��־
|
||
|
// // _Rword[1] = Convert.ToInt32(itemvalue[1]);//״̬
|
||
|
// // _Rword[2] = Convert.ToInt32(itemvalue[2]);//������
|
||
|
// // _Rword[3] = Convert.ToInt32(itemvalue[3]);//X����
|
||
|
// // _Rword[4] = Convert.ToInt32(itemvalue[4]);//Y����
|
||
|
// // _Rword[5] = DeviceIndex;//�豸������
|
||
|
// // break;
|
||
|
// //case "2"://���ͻ�
|
||
|
// // itemnames = new string[3];
|
||
|
// // itemnames[0] = "DB2,byte" + Convert.ToString((devinfo.Dbw2Address + 0));
|
||
|
// // itemnames[1] = "DB2,byte" + Convert.ToString((devinfo.Dbw2Address + 1));
|
||
|
// // itemnames[2] = "DB2,int" + Convert.ToString((devinfo.Dbw2Address + 2));
|
||
|
|
||
|
// // itemvalue = CCommonOPCClient.SyncReadAllItems(itemnames);
|
||
|
// // if ((itemvalue == null) || (itemvalue.Count == 0))
|
||
|
// // {
|
||
|
// // _commLayerError = "OPCClient.CGetDeviceState.GetDeviceState��" + CCommonOPCClient.OpcError;
|
||
|
// // return null;
|
||
|
// // }
|
||
|
// // _Rword[0] = Convert.ToInt32(itemvalue[0]);//��д��־
|
||
|
// // _Rword[1] = Convert.ToInt32(itemvalue[1]);//״̬
|
||
|
// // _Rword[2] = Convert.ToInt32(itemvalue[2]);//������
|
||
|
// // _Rword[3] = 0;
|
||
|
// // _Rword[4] = 0;
|
||
|
// // _Rword[5] = DeviceIndex;//�豸������
|
||
|
// // break;
|
||
|
// //case "4"://RGV
|
||
|
// // itemnames = new string[4];
|
||
|
// // itemnames[0] = "DB2,byte" + Convert.ToString((devinfo.Dbw2Address + 0));
|
||
|
// // itemnames[1] = "DB2,byte" + Convert.ToString((devinfo.Dbw2Address + 1));
|
||
|
// // itemnames[2] = "DB2,int" + Convert.ToString((devinfo.Dbw2Address + 2));
|
||
|
// // itemnames[3] = "DB2,DWORD" + Convert.ToString((devinfo.Dbw2Address + 4));
|
||
|
|
||
|
// // itemvalue = CCommonOPCClient.SyncReadAllItems(itemnames);
|
||
|
// // if ((itemvalue == null) || (itemvalue.Count == 0))
|
||
|
// // {
|
||
|
// // _commLayerError = "OPCClient.CGetDeviceState.GetDeviceState��" + CCommonOPCClient.OpcError;
|
||
|
// // return null;
|
||
|
// // }
|
||
|
// // _Rword[0] = Convert.ToInt32(itemvalue[0]);//��д��־
|
||
|
// // _Rword[1] = Convert.ToInt32(itemvalue[1]);//״̬
|
||
|
// // _Rword[2] = Convert.ToInt32(itemvalue[2]);//������
|
||
|
// // _Rword[3] = Convert.ToInt32(itemvalue[3]);//X����
|
||
|
// // _Rword[4] = 0;
|
||
|
// // _Rword[5] = DeviceIndex;//�豸������
|
||
|
// // break;
|
||
|
// //case "13"://������������������
|
||
|
// // itemnames = new string[4];
|
||
|
// // itemnames[0] = "DB2,byte" + Convert.ToString((devinfo.Dbw2Address + 0));
|
||
|
// // itemnames[1] = "DB2,byte" + Convert.ToString((devinfo.Dbw2Address + 1));
|
||
|
// // itemnames[2] = "DB2,byte" + Convert.ToString((devinfo.Dbw2Address + 2));
|
||
|
// // itemnames[3] = "DB2,byte" + Convert.ToString((devinfo.Dbw2Address + 3));
|
||
|
|
||
|
// // itemvalue = CCommonOPCClient.SyncReadAllItems(itemnames);
|
||
|
// // if ((itemvalue == null) || (itemvalue.Count == 0))
|
||
|
// // {
|
||
|
// // _commLayerError = "OPCClient.CGetDeviceState.GetDeviceState��" + CCommonOPCClient.OpcError;
|
||
|
// // return null;
|
||
|
// // }
|
||
|
// // if (itemvalue[0] != "1") return null;
|
||
|
// // _Rword[0] = Convert.ToInt32(itemvalue[1]);//��������λ
|
||
|
// // _Rword[1] = Convert.ToInt32(itemvalue[2]);//��������λ
|
||
|
// // _Rword[2] = Convert.ToInt32(itemvalue[3]);//��������λ
|
||
|
// // _Rword[3] = 0;
|
||
|
// // _Rword[4] = 0;
|
||
|
// // _Rword[5] = DeviceIndex;//�豸������
|
||
|
// // break;
|
||
|
// #endregion
|
||
|
// default:
|
||
|
// break;
|
||
|
// }
|
||
|
//}
|
||
|
return _Rword;
|
||
|
}
|
||
|
catch (Exception ex)
|
||
|
{
|
||
|
_commLayerError = "OPCClient.CGetDeviceState.GetDeviceState����������" + ex.Message;
|
||
|
return null;
|
||
|
}
|
||
|
finally
|
||
|
{
|
||
|
//itemnames=null;
|
||
|
_Rword = null;
|
||
|
//www=null;
|
||
|
//wi=null;
|
||
|
//ivalue=null;
|
||
|
//itemvalue =null;
|
||
|
devinfo = null;
|
||
|
//askdev=null;
|
||
|
//sql = null;
|
||
|
}
|
||
|
|
||
|
}
|
||
|
public string GetStringData(int DeviceIndex, int TaskIndex)
|
||
|
{//20091107
|
||
|
//string headstr = "";
|
||
|
//string[] itemnames;
|
||
|
//string retdata = "";
|
||
|
//string[] witemnames;
|
||
|
//byte[] itemvalue;
|
||
|
//object[] obj;
|
||
|
Model.MDevice devinfo = Model.CGetInfo.GetDeviceInfo(DeviceIndex);
|
||
|
try
|
||
|
{
|
||
|
|
||
|
//if (devinfo.DeviceIndex == 0)
|
||
|
//{
|
||
|
// _commLayerError = "OPCClient.CGetDeviceState.GetStringData�������������豸����û�ҵ��豸������";
|
||
|
|
||
|
// return null;
|
||
|
//}
|
||
|
//else
|
||
|
//{
|
||
|
// CCommonOPCClient.Hostname = CommonClassLib.AppSettings.GetValue("HostName");//20090922 devinfo.RemoteIP;
|
||
|
// CCommonOPCClient.ProgID = CommonClassLib.AppSettings.GetValue("OPCProgID");
|
||
|
// CCommonOPCClient.PlcConnectionID = devinfo.S7Connection;//20110216
|
||
|
// witemnames = new string[1] { Model.CGeneralFunction.DBGet+",byte" + Convert.ToString((devinfo.Dbw2Address + 0)) };
|
||
|
// switch (devinfo.DeviceKind.ToString())
|
||
|
// {
|
||
|
|
||
|
// #region ����������Ϣ(10���ֽ�)
|
||
|
// case "7":
|
||
|
// itemnames = new string[11];
|
||
|
// itemnames[0] = Model.CGeneralFunction.DBGet+",byte" + Convert.ToString((devinfo.Dbw2Address + 0));
|
||
|
// for (int i = 1; i < 11; i++)
|
||
|
// {
|
||
|
// itemnames[i] = Model.CGeneralFunction.DBGet+",byte" + Convert.ToString((devinfo.Dbw2Address + i));
|
||
|
// }
|
||
|
// obj = CCommonOPCClient.SyncReadItemValues(itemnames);
|
||
|
// if ((obj == null))
|
||
|
// {
|
||
|
// _commLayerError = "OPCClient.CGetDeviceState.GetDeviceState��" + CCommonOPCClient.OpcError;
|
||
|
// return null;
|
||
|
// }
|
||
|
// if (obj[0].ToString() != "1") return null;
|
||
|
// itemvalue = new byte[obj.Length];
|
||
|
// Array.Copy(obj, itemvalue, obj.Length);
|
||
|
|
||
|
// headstr = itemvalue[0].ToString();
|
||
|
// for (int i = 1; i <= 10; i++)
|
||
|
// {
|
||
|
// retdata += Convert.ToChar(itemvalue[i]);
|
||
|
|
||
|
// }
|
||
|
|
||
|
|
||
|
// break;
|
||
|
// #endregion
|
||
|
|
||
|
// #region ����һ�Ź����루���鹲32���ֽ�+һ����־ͷ��
|
||
|
// case "21":
|
||
|
// itemnames = new string[33];
|
||
|
// itemnames[0] = Model.CGeneralFunction.DBGet+",byte" + Convert.ToString((devinfo.Dbw2Address + 0));
|
||
|
// for (int i = 1; i < 33; i++)
|
||
|
// {
|
||
|
// itemnames[i] = Model.CGeneralFunction.DBGet+",byte" + Convert.ToString((devinfo.Dbw2Address + i));
|
||
|
// }
|
||
|
// obj = CCommonOPCClient.SyncReadItemValues(itemnames);
|
||
|
// if ((obj == null))
|
||
|
// {
|
||
|
// _commLayerError = "OPCClient.CGetDeviceState.GetDeviceState��" + CCommonOPCClient.OpcError;
|
||
|
// return null;
|
||
|
// }
|
||
|
// if (obj[0].ToString() != "1") return null;
|
||
|
// itemvalue = new byte[obj.Length];
|
||
|
// Array.Copy(obj, itemvalue, obj.Length);
|
||
|
|
||
|
// headstr = itemvalue[0].ToString();
|
||
|
// for (int i = 1; i <= 32; i++)
|
||
|
// {
|
||
|
// retdata += Convert.ToChar(itemvalue[i]);
|
||
|
|
||
|
// }
|
||
|
// break;
|
||
|
// #endregion
|
||
|
|
||
|
// default:
|
||
|
// break;
|
||
|
// }
|
||
|
//}
|
||
|
//if (headstr == "1")
|
||
|
//{
|
||
|
// string[] wv = new string[1] { "2" };
|
||
|
// if (CCommonOPCClient.SyncWriteAllItemValue(witemnames, wv) == false)
|
||
|
// {
|
||
|
// _commLayerError = "OPCClient.CGetDeviceState.GetDeviceState��" + CCommonOPCClient.OpcError;
|
||
|
// return null;
|
||
|
// }
|
||
|
// else
|
||
|
// {
|
||
|
// return retdata;
|
||
|
// }
|
||
|
//}
|
||
|
//else
|
||
|
//{
|
||
|
// return null;
|
||
|
//}
|
||
|
return null;
|
||
|
}
|
||
|
catch (Exception ex)
|
||
|
{
|
||
|
_commLayerError = "OPCClient.CGetDeviceState.GetStringData����������" + ex.Message;
|
||
|
return null;
|
||
|
}
|
||
|
finally
|
||
|
{
|
||
|
//headstr = null;
|
||
|
//itemnames=null;
|
||
|
//retdata = null;
|
||
|
//witemnames=null;
|
||
|
//itemvalue=null;
|
||
|
//obj = null ;
|
||
|
devinfo = null;
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|