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.
353 lines
12 KiB
353 lines
12 KiB
5 months ago
|
using System;
|
||
|
using System.Collections.Generic;
|
||
|
using System.Text;
|
||
|
using System.Data;
|
||
|
using System.Threading;
|
||
|
using Microsoft.VisualBasic;
|
||
|
using DBFactory;
|
||
|
using ICommLayer;
|
||
|
|
||
|
namespace SimensSerialPort
|
||
|
{
|
||
|
/// <summary>
|
||
|
/// ͨ�����������ߵ�̨�����ɿڷ�ʽ��ͨѶ�ӿ�������
|
||
|
/// �����豸������
|
||
|
/// �����ߣ�Richard.Liu
|
||
|
/// </summary>
|
||
|
public class CSendDeviceOrder: ISendDeviceOrder
|
||
|
{
|
||
|
string _commLayerError;
|
||
|
|
||
|
public string CommLayerError
|
||
|
{
|
||
|
get { return _commLayerError; }
|
||
|
set { _commLayerError = value; }
|
||
|
}
|
||
|
DBOperator dbo = CommonClassLib.AppSettings.dbo;//20130510
|
||
|
public CSendDeviceOrder()
|
||
|
{
|
||
|
dbo.Open();
|
||
|
}
|
||
|
//~CSendDeviceOrder()
|
||
|
//{
|
||
|
// dbo.Close();
|
||
|
//}
|
||
|
/// <summary>
|
||
|
/// ���ͶѶ�������
|
||
|
/// </summary>
|
||
|
/// <param name="MessageIndex">��Ϣ����</param>
|
||
|
/// <param name="TaskIndex">��������</param>
|
||
|
/// <param name="Order">�Ѷ���������</param>
|
||
|
///���浥���죺
|
||
|
///1-��λ
|
||
|
///2-��ȡ
|
||
|
///3-����
|
||
|
///4-ȡ��
|
||
|
///5-��
|
||
|
///6-ȡ�Ż�
|
||
|
///˫�浥���죺
|
||
|
///1-��λ
|
||
|
///2-��ȡ
|
||
|
///3-����
|
||
|
///4-����ȡ��
|
||
|
///5-������
|
||
|
///6-����ȡ�Ż�
|
||
|
///14-�Ҳ�ȡ��
|
||
|
///15-�Ҳ��Ż�
|
||
|
///16-�Ҳ�ȡ�Ż�
|
||
|
///24-˫��ȡ��
|
||
|
///25-˫���Ż�
|
||
|
///26-˫��ȡ�Ż�
|
||
|
///����˫���죺
|
||
|
///1-��λ
|
||
|
///2-��ȡ
|
||
|
///3-����
|
||
|
///4-��λȡ��
|
||
|
///5-��λ�Ż�
|
||
|
///6-��λȡ�Ż�
|
||
|
///14-Զλȡ��
|
||
|
///15-Զλ�Ż�
|
||
|
///16-Զλȡ�Ż�
|
||
|
/// <param name="DeviceIndex">�豸����</param>
|
||
|
/// <param name="StartX">��ʼx���꣬��-�ع�������</param>
|
||
|
/// <param name="StartY">��ʼy���꣬��-�߶ȷ���</param>
|
||
|
/// <param name="StartZ">��ʼz���꣬��-�����Ѷ����������壬1-���࣬2-�Ҳ�</param>
|
||
|
/// <param name="EndX">Ŀ��x���꣬��-�ع�������</param>
|
||
|
/// <param name="EndY">Ŀ��y���꣬��-�߶ȷ���</param>
|
||
|
/// <param name="EndZ">Ŀ��z���꣬��-�����Ѷ����������壬1-���࣬2-�Ҳ�</param>
|
||
|
/// <returns>���ͶѶ��������Ƿ��ɹ�</returns>
|
||
|
public bool SendDeviceOrder(int MessageIndex, int TaskIndex, int Order, int DeviceIndex, int StartX, int StartY, int StartZ, int EndX, int EndY, int EndZ)
|
||
|
{
|
||
|
//return false;
|
||
|
Model.MDevice devinfo = Model.CGetInfo.GetDeviceInfo(DeviceIndex);
|
||
|
CSimensSerialPort ssp;
|
||
|
byte[] _Sdata = new byte[16];
|
||
|
try
|
||
|
{
|
||
|
|
||
|
byte WXor = 0;
|
||
|
_Sdata[0] = 16;
|
||
|
_Sdata[1] = Convert.ToByte(MessageIndex);
|
||
|
_Sdata[2] = Convert.ToByte(TaskIndex >> 8);//�߰�λ
|
||
|
_Sdata[3] = Convert.ToByte(TaskIndex & 255);//�Ͱ�λ
|
||
|
_Sdata[4] = Convert.ToByte(Order);
|
||
|
_Sdata[5] = Convert.ToByte(DeviceIndex);
|
||
|
_Sdata[6] = Convert.ToByte(StartX);
|
||
|
_Sdata[7] = Convert.ToByte(StartY);
|
||
|
_Sdata[8] = Convert.ToByte(StartZ);
|
||
|
_Sdata[9] = Convert.ToByte(EndX);
|
||
|
_Sdata[10] = Convert.ToByte(EndY);
|
||
|
_Sdata[11] = Convert.ToByte(EndZ);
|
||
|
_Sdata[12] = 0;
|
||
|
_Sdata[13] = 0;
|
||
|
_Sdata[14] = 0;
|
||
|
WXor = _Sdata[0];
|
||
|
for (int i = 1; i <= 14; i++)
|
||
|
{
|
||
|
WXor = Convert.ToByte(Convert.ToInt16(WXor) ^ Convert.ToInt16(_Sdata[i]));
|
||
|
}
|
||
|
_Sdata[15] = WXor;
|
||
|
//����DeviceIndex,�õ����ںźͳ�ʼ����
|
||
|
|
||
|
|
||
|
|
||
|
if (devinfo!=null)
|
||
|
{
|
||
|
|
||
|
ssp = new CSimensSerialPort((short)devinfo.SerialPort, devinfo.CommSettings);
|
||
|
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
return false;
|
||
|
}
|
||
|
|
||
|
if (ssp.InitCom() == true)
|
||
|
{
|
||
|
//CommonClassLib.CCarryConvert.WriteDarkCasket(this.ToString(), "WriteCom", _Sdata);
|
||
|
if (ssp.WriteCom(_Sdata) == true)
|
||
|
{
|
||
|
ssp.CloseCom();
|
||
|
return true;
|
||
|
|
||
|
//Thread.Sleep(300);
|
||
|
//byte[] _GetData = ssp.ReadCom(16);
|
||
|
////CommonClassLib.CCarryConvert.WriteDarkCasket(this.ToString(), "ReadCom", _GetData);
|
||
|
//if (_GetData != null)
|
||
|
//{
|
||
|
// if ((_GetData[0] == 8) && (_GetData[1] == 240) && (_GetData[2] == MessageIndex) &&
|
||
|
// ((_GetData[3] * Math.Pow(2, 8) + _GetData[4]) == TaskIndex) &&
|
||
|
// (_GetData[5] == DeviceIndex) && (_GetData[6] == 170))
|
||
|
// {
|
||
|
// byte GXor = 0;
|
||
|
// GXor = _GetData[0];
|
||
|
// for (int i = 1; i <= 6; i++)
|
||
|
// {
|
||
|
// GXor = Convert.ToByte(Convert.ToInt16(GXor) ^ Convert.ToInt16(_GetData[i]));
|
||
|
// }
|
||
|
// if (GXor == _GetData[7])
|
||
|
// {
|
||
|
// ssp.CloseCom();
|
||
|
// return true;
|
||
|
// }
|
||
|
// else
|
||
|
// {
|
||
|
// ssp.CloseCom();
|
||
|
// return false;
|
||
|
// }
|
||
|
// }
|
||
|
// else
|
||
|
// {
|
||
|
// ssp.CloseCom();
|
||
|
// return false;
|
||
|
// }
|
||
|
//}
|
||
|
//else
|
||
|
//{
|
||
|
// ssp.CloseCom();
|
||
|
// _commLayerError = this.ToString() + ":SendDeviceOrder---" + ssp.ComError;
|
||
|
// return false;
|
||
|
//}
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
ssp.CloseCom();
|
||
|
_commLayerError = this.ToString() + ":SendDeviceOrder---" + ssp.ComError;
|
||
|
return false;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
else
|
||
|
{
|
||
|
ssp.CloseCom();
|
||
|
_commLayerError = this.ToString() + ":SendDeviceOrder---" + ssp.ComError;
|
||
|
return false;
|
||
|
}
|
||
|
}
|
||
|
catch (Exception ex)
|
||
|
{
|
||
|
_commLayerError = this.ToString() + ":SendDeviceOrder---" + ex.Message;
|
||
|
return false;
|
||
|
}
|
||
|
finally
|
||
|
{
|
||
|
ssp = null;
|
||
|
|
||
|
_Sdata = null;
|
||
|
devinfo = null;
|
||
|
}
|
||
|
}
|
||
|
/// <summary>
|
||
|
/// ���ͶѶ��������������豸����
|
||
|
/// </summary>
|
||
|
/// <param name="MessageIndex">��Ϣ����</param>
|
||
|
/// <param name="TaskIndex">��������</param>
|
||
|
/// <param name="Order">������</param>
|
||
|
/// �����������֣�
|
||
|
///1-��λ
|
||
|
///2-���ӻ�
|
||
|
///3-���ͻ�
|
||
|
///4-�ҽӻ�
|
||
|
///5-���ͻ�
|
||
|
///6-ֹͣ
|
||
|
///7-�˶���1#λ��
|
||
|
///8-�˶���2#λ��
|
||
|
/// ��
|
||
|
///���ͻ���̨�������֣�
|
||
|
///1-���⣨�����⣩
|
||
|
/// 2-���⣨�����⣩
|
||
|
/// 3-�ͻ�
|
||
|
/// 4-ֹͣ
|
||
|
/// <param name="DeviceIndex">�豸����</param>
|
||
|
/// <returns>���������豸�����Ƿ��ɹ�</returns>
|
||
|
public bool SendDeviceOrder(int MessageIndex, int TaskIndex, int Order, int DeviceIndex, int ArrowDeviceIndex)
|
||
|
{
|
||
|
Model.MDevice devinfo = Model.CGetInfo.GetDeviceInfo(DeviceIndex);
|
||
|
byte[] _Sdata = new byte[16]; CSimensSerialPort ssp;
|
||
|
try
|
||
|
{
|
||
|
byte WXor = 0;
|
||
|
_Sdata[0] = 16;
|
||
|
_Sdata[1] = Convert.ToByte(MessageIndex);
|
||
|
_Sdata[2] = Convert.ToByte(TaskIndex >> 8);//�߰�λ
|
||
|
_Sdata[3] = Convert.ToByte(TaskIndex & 255);//�Ͱ�λ
|
||
|
_Sdata[4] = Convert.ToByte(Order);
|
||
|
_Sdata[5] = Convert.ToByte(DeviceIndex);
|
||
|
_Sdata[6] = 0;
|
||
|
_Sdata[7] = 0;
|
||
|
_Sdata[8] = 0;
|
||
|
_Sdata[9] = 0;
|
||
|
_Sdata[10] = 0;
|
||
|
_Sdata[11] = 0;
|
||
|
_Sdata[12] = 0;
|
||
|
_Sdata[13] = 0;
|
||
|
_Sdata[14] = 0;
|
||
|
WXor = _Sdata[0];
|
||
|
for (int i = 1; i <= 14; i++)
|
||
|
{
|
||
|
WXor = Convert.ToByte(Convert.ToInt16(WXor) ^ Convert.ToInt16(_Sdata[i]));
|
||
|
}
|
||
|
_Sdata[15] = WXor;
|
||
|
//����DeviceIndex,�õ����ںźͳ�ʼ����
|
||
|
|
||
|
if (devinfo!=null)
|
||
|
{
|
||
|
|
||
|
ssp = new CSimensSerialPort((short)devinfo.SerialPort, devinfo.CommSettings);
|
||
|
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
return false;
|
||
|
}
|
||
|
|
||
|
if (ssp.InitCom() == true)
|
||
|
{
|
||
|
//CommonClassLib.CCarryConvert.WriteDarkCasket(this.ToString(), "WriteCom", _Sdata);
|
||
|
if (ssp.WriteCom(_Sdata) == true)
|
||
|
{
|
||
|
ssp.CloseCom();
|
||
|
return true;
|
||
|
|
||
|
//Thread.Sleep(300);
|
||
|
//byte[] _GetData = ssp.ReadCom(16);
|
||
|
////CommonClassLib.CCarryConvert.WriteDarkCasket(this.ToString(), "ReadCom", _GetData);
|
||
|
//if (_GetData != null)
|
||
|
//{
|
||
|
// if ((_GetData[0] == 8) && (_GetData[1] == 240) && (_GetData[2] == MessageIndex) &&
|
||
|
// ((_GetData[3] * Math.Pow(2, 8) + _GetData[4]) == TaskIndex) &&
|
||
|
// (_GetData[5] == DeviceIndex) && (_GetData[6] == 170))
|
||
|
// {
|
||
|
// byte GXor = 0;
|
||
|
// GXor = _GetData[0];
|
||
|
// for (int i = 1; i <= 6; i++)
|
||
|
// {
|
||
|
// GXor = Convert.ToByte(Convert.ToInt16(GXor) ^ Convert.ToInt16(_GetData[i]));
|
||
|
// }
|
||
|
// if (GXor == _GetData[7])
|
||
|
// {
|
||
|
// ssp.CloseCom();
|
||
|
// return true;
|
||
|
// }
|
||
|
// else
|
||
|
// {
|
||
|
// ssp.CloseCom();
|
||
|
// return false;
|
||
|
// }
|
||
|
// }
|
||
|
// else
|
||
|
// {
|
||
|
// ssp.CloseCom();
|
||
|
// return false;
|
||
|
// }
|
||
|
//}
|
||
|
//else
|
||
|
//{
|
||
|
// ssp.CloseCom();
|
||
|
// return false;
|
||
|
//}
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
ssp.CloseCom();
|
||
|
return false;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
else
|
||
|
{
|
||
|
ssp.CloseCom();
|
||
|
return false;
|
||
|
}
|
||
|
}
|
||
|
catch (Exception ex)
|
||
|
{
|
||
|
_commLayerError = this.ToString() + ":SendDeviceOrder---" + ex.Message;
|
||
|
return false;
|
||
|
}
|
||
|
finally
|
||
|
{
|
||
|
ssp = null;
|
||
|
|
||
|
_Sdata = null;
|
||
|
devinfo = null;
|
||
|
}
|
||
|
|
||
|
|
||
|
}
|
||
|
|
||
|
public bool SendDeviceOrder(int DeviceIndex, string TobaccoCode, bool HaveFirstProjectCode, bool IfSmallTobacco, int Count)
|
||
|
{
|
||
|
return true;
|
||
|
}
|
||
|
public bool WriteDBData(StringBuilder[] ItemNames, StringBuilder[] ItemValues)
|
||
|
{
|
||
|
return true;
|
||
|
}
|
||
|
public bool WriteDBData(StringBuilder[] ItemNames, StringBuilder[] ItemValues, string PLCconnectionID)
|
||
|
{
|
||
|
return true;
|
||
|
}
|
||
|
}
|
||
|
}
|