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.
199 lines
8.3 KiB
199 lines
8.3 KiB
3 months ago
|
using System;
|
||
|
using System.Collections.Generic;
|
||
|
using System.Text;
|
||
|
using System.Data;
|
||
|
using ICommLayer;
|
||
|
using DBFactory;
|
||
|
namespace SimensSerialPort
|
||
|
{
|
||
|
/// <summary>
|
||
|
/// ͨ�����������ߵ�̨�����ɿڷ�ʽ��ͨѶ�ӿ�������
|
||
|
/// �����豸״̬��
|
||
|
/// �����ߣ�Richard.Liu
|
||
|
/// </summary>
|
||
|
public class CGetDeviceState:IGetDeviceState
|
||
|
{
|
||
|
string _commLayerError;
|
||
|
|
||
|
public string CommLayerError
|
||
|
{
|
||
|
get { return _commLayerError; }
|
||
|
set { _commLayerError = value; }
|
||
|
}
|
||
|
DBOperator dbo = CommonClassLib.AppSettings.dbo;//20130510
|
||
|
public CGetDeviceState()
|
||
|
{
|
||
|
dbo.Open();
|
||
|
}
|
||
|
//~CGetDeviceState()
|
||
|
//{
|
||
|
// dbo.Close();
|
||
|
//}
|
||
|
/// <summary>
|
||
|
/// �������ؿ�ֵ����û�гɹ�����������Ϣ(��λ��->��λ��)
|
||
|
/// ��1�ֽڣ� ���кţ�����λ����������0��ʼ��ÿ����һ����Ϣ���кż�1��
|
||
|
/// ������С��240(0XF0)��ѭ��ʹ�á�
|
||
|
/// ��2��3�ֽڣ������ţ�����λ���´�����ʱ�������ţ���λ�������ϱ�����ʱ���̶�
|
||
|
/// ��255(0XFF)��255(0XFF)��
|
||
|
/// ��4�ֽڣ� ��Ϣ�� 1-��������
|
||
|
/// 2-�������꣨���ڶѶ�����
|
||
|
/// 3-�����״̬���������ͻ��ȣ�
|
||
|
/// ����ֵ-����
|
||
|
/// ��5�ֽڣ� �豸�ţ�������Ŀ�������¹滮��
|
||
|
/// ��6�ֽڣ�
|
||
|
/// �Ѷ�����
|
||
|
/// x���꣬��-�ع���������
|
||
|
/// ����أ�
|
||
|
/// 0-��
|
||
|
/// 1-�л�
|
||
|
/// ��7�ֽڣ�y���꣬��-�߶ȷ�����
|
||
|
/// 6�ֽ������ͻ��ȱ��������״̬ʱ��ʵ��ֵ��6��7�ֽ��ڶѶ��������������ɺͱ�������ʱ��ʵ��ֵ������������Ϣ���ǿ���������ֵ��
|
||
|
/// ��8-14�ֽڣ����ã�����������ֵ��
|
||
|
/// </summary>
|
||
|
/// <param name="DeviceIndex">�豸����</param>
|
||
|
/// <returns>����������Ϣ�ɹ�����Ӧ����Ϣ��14���ֽ���״̬</returns>
|
||
|
public int[] GetDeviceState(int DeviceIndex, int TaskIndex)
|
||
|
{
|
||
|
Model.MDevice devinfo = Model.CGetInfo.GetDeviceInfo(DeviceIndex);
|
||
|
try
|
||
|
{
|
||
|
//����DeviceIndex,�õ����ںźͳ�ʼ����
|
||
|
|
||
|
CSimensSerialPort ssp;
|
||
|
if (devinfo != null)
|
||
|
{
|
||
|
|
||
|
ssp = new CSimensSerialPort((short)devinfo.SerialPort, devinfo.CommSettings);
|
||
|
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
return null;
|
||
|
}
|
||
|
//ds.Dispose();
|
||
|
|
||
|
|
||
|
if (ssp.InitCom() == true)
|
||
|
{
|
||
|
byte[] _Senddata = new byte[8];
|
||
|
int[] _IntData = new int[6];
|
||
|
byte[] _GetData = ssp.ReadCom(16);
|
||
|
//CommonClassLib.CCarryConvert.WriteDarkCasket(this.ToString(), "ReadCom", _GetData);
|
||
|
if (_GetData != null)
|
||
|
{
|
||
|
|
||
|
if ((_GetData[5] == DeviceIndex) && ((_GetData[2] * Math.Pow(2, 8) + _GetData[3]) == TaskIndex)
|
||
|
|| ((_GetData[2] == 255) && (_GetData[3] == 255)))
|
||
|
{
|
||
|
byte GXor = _GetData[0];
|
||
|
for (int i = 1; i <= 14; i++)
|
||
|
{
|
||
|
GXor = Convert.ToByte(Convert.ToInt16(GXor) ^ Convert.ToInt16(_GetData[i]));
|
||
|
}
|
||
|
if (GXor == _GetData[15])
|
||
|
{
|
||
|
//������Ϣ����
|
||
|
_Senddata[0] = 8;
|
||
|
_Senddata[1] = 240;
|
||
|
_Senddata[2] = _GetData[1];
|
||
|
_Senddata[3] = Convert.ToByte(TaskIndex >> 8);
|
||
|
_Senddata[4] = Convert.ToByte(TaskIndex & 255);
|
||
|
_Senddata[5] = Convert.ToByte(DeviceIndex);
|
||
|
_Senddata[6] = 170;
|
||
|
byte SXor = _Senddata[0];
|
||
|
for (int k = 1; k <= 6; k++)
|
||
|
{
|
||
|
SXor = Convert.ToByte(Convert.ToInt16(SXor) ^ Convert.ToInt16(_Senddata[k]));
|
||
|
}
|
||
|
_Senddata[7] = SXor;
|
||
|
//CommonClassLib.CCarryConvert.WriteDarkCasket(this.ToString(), "WriteCom", _Senddata);
|
||
|
if (ssp.WriteCom(_Senddata) == true)
|
||
|
{
|
||
|
//for (int j = 0; j <= 15; j++)
|
||
|
//{
|
||
|
// _IntData[j] = Convert.ToInt16(_GetData[j]);
|
||
|
//}
|
||
|
if ((devinfo.DeviceKind == 14) ||
|
||
|
(devinfo.DeviceKind == 18))//ȷ�ϰ�ť,�����
|
||
|
{
|
||
|
_IntData[0] = Convert.ToInt16(_GetData[6]);//ʵ��ֵ
|
||
|
_IntData[1] = Convert.ToInt16(_GetData[4]);//��Ϣ��3-���������״̬���������ͻ��ȣ�����ֵ���ϴ���
|
||
|
_IntData[2] = TaskIndex;//������
|
||
|
_IntData[3] = 0;//�Ѷ���x����
|
||
|
_IntData[4] = 0;//�Ѷ���y����
|
||
|
_IntData[5] = DeviceIndex;// �豸��
|
||
|
|
||
|
}
|
||
|
else if (devinfo.DeviceKind == 1)//�Ѷ���
|
||
|
{
|
||
|
_IntData[0] = 0;
|
||
|
_IntData[1] = Convert.ToInt16(_GetData[4]);//��Ϣ��1-�������� 2-�������꣨���ڶѶ���������ֵ���ϴ���
|
||
|
_IntData[2] = TaskIndex;//������
|
||
|
_IntData[3] = Convert.ToInt16(_GetData[6]);//�Ѷ���x����
|
||
|
_IntData[4] = Convert.ToInt16(_GetData[7]);//�Ѷ���y����
|
||
|
_IntData[5] = DeviceIndex;// �豸��
|
||
|
}
|
||
|
else//�����豸
|
||
|
{
|
||
|
_IntData[0] = Convert.ToInt16(_GetData[6]);//ʵ��ֵ
|
||
|
_IntData[1] = Convert.ToInt16(_GetData[4]);//��Ϣ��1-�������� 2-�������꣨���ڶѶ����� 3-�����״̬ ����ֵ���ϴ���
|
||
|
_IntData[2] = TaskIndex;//������
|
||
|
_IntData[3] = Convert.ToInt16(_GetData[6]);//�Ѷ���x����
|
||
|
_IntData[4] = Convert.ToInt16(_GetData[7]);//�Ѷ���y����
|
||
|
_IntData[5] = DeviceIndex;// �豸��
|
||
|
}
|
||
|
ssp.CloseCom();
|
||
|
return _IntData;
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
ssp.CloseCom();
|
||
|
_commLayerError = this.ToString() + ":GetDeviceState---" + ssp.ComError;
|
||
|
return null;
|
||
|
}
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
ssp.CloseCom();
|
||
|
return null;
|
||
|
}
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
ssp.CloseCom();
|
||
|
return null;
|
||
|
}
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
ssp.CloseCom();
|
||
|
_commLayerError = this.ToString() + ":GetDeviceState---" + ssp.ComError;
|
||
|
return null;
|
||
|
}
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
ssp.CloseCom();
|
||
|
return null;
|
||
|
}
|
||
|
|
||
|
}
|
||
|
catch (Exception ex)
|
||
|
{
|
||
|
_commLayerError = this.ToString() + ":GetDeviceState---" + ex.Message;
|
||
|
return null;
|
||
|
}
|
||
|
finally
|
||
|
{
|
||
|
devinfo = null;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
public string GetStringData(int DeviceIndex, int TaskIndex)
|
||
|
{
|
||
|
return "";
|
||
|
}
|
||
|
|
||
|
}
|
||
|
}
|