115 lines
4.5 KiB
C#
115 lines
4.5 KiB
C#
|
using System;
|
|||
|
using System.Collections.Generic;
|
|||
|
using System.Text;
|
|||
|
using System.Data;
|
|||
|
using ICommLayer;
|
|||
|
using DBFactory;
|
|||
|
using System.Net;
|
|||
|
namespace SocketsUDP
|
|||
|
{
|
|||
|
/// <summary>
|
|||
|
/// ʹ<><CAB9>SocketsUDP<44>Ŀͻ<C4BF><CDBB>˽<EFBFBD><CBBD><EFBFBD>ͨѶ
|
|||
|
/// <20><><EFBFBD><EFBFBD><EFBFBD>豸״̬
|
|||
|
/// <20><><EFBFBD><EFBFBD><EFBFBD>ߣ<EFBFBD>Richard.Liu
|
|||
|
/// </summary>
|
|||
|
public class CGetDeviceState:IGetDeviceState
|
|||
|
{
|
|||
|
string _commLayerError;
|
|||
|
|
|||
|
public string CommLayerError
|
|||
|
{
|
|||
|
get { return _commLayerError; }
|
|||
|
set { _commLayerError = value; }
|
|||
|
}
|
|||
|
|
|||
|
//CClientUDP ccuR = new CClientUDP();
|
|||
|
DBOperator dbo = new DBOperator();
|
|||
|
public CGetDeviceState()
|
|||
|
{
|
|||
|
dbo.Open();
|
|||
|
|
|||
|
}
|
|||
|
|
|||
|
public int [] GetDeviceState(int DeviceIndex,int TaskIndex)
|
|||
|
{
|
|||
|
try
|
|||
|
{
|
|||
|
|
|||
|
//<2F><><EFBFBD><EFBFBD>DeviceIndex,<2C>õ<EFBFBD>SocketsͨѶ<CDA8>ij<EFBFBD>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD>
|
|||
|
DataSet ds = dbo.ExceSQL("SELECT F_DeviceIndex,F_DeviceKindIndex, F_LocalIP, F_LocalPort, F_RemoteIP, F_RemotePort FROM T_Base_Device where F_DeviceIndex=" + DeviceIndex);
|
|||
|
DataView dv = ds.Tables[0].DefaultView;
|
|||
|
if (ds.Tables[0].DefaultView.Count > 0)
|
|||
|
{
|
|||
|
CClientUDP.RemoteServer = (EndPoint)new IPEndPoint(IPAddress.Parse(dv[0]["F_RemoteIP"].ToString()), Convert.ToInt32(dv[0]["F_RemotePort"]));
|
|||
|
CClientUDP.LocalServer = (EndPoint)new IPEndPoint(IPAddress.Parse(dv[0]["F_LocalIP"].ToString()), Convert.ToInt32(dv[0]["F_LocalPort"]));
|
|||
|
|
|||
|
CClientUDP.ReceiveUdp(dv[0]["F_LocalIP"].ToString(), Convert.ToInt32(dv[0]["F_LocalPort"]));
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
return null;
|
|||
|
}
|
|||
|
int[] _IntData = new int[14];
|
|||
|
byte[] _GetData = new byte[16];
|
|||
|
int[] _sIntdata = new int[8];
|
|||
|
int wIntXor = 0;
|
|||
|
byte[] _temp = new byte[2];
|
|||
|
//<2F>Խ<EFBFBD><D4BD>յ<EFBFBD><D5B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݽ<EFBFBD><DDBD>м<EFBFBD><D0BC><EFBFBD><EFBFBD><EFBFBD>ʵ<EFBFBD><CAB5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѭ<EFBFBD><D1AD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
CClientUDP.ReceiveUdp();
|
|||
|
System.Threading.Thread.Sleep(300);
|
|||
|
_GetData = CClientUDP.ByteData;
|
|||
|
if (_GetData != null)
|
|||
|
{
|
|||
|
//<2F>Խ<EFBFBD><D4BD>յ<EFBFBD><D5B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݽ<EFBFBD><DDBD>м<EFBFBD><D0BC><EFBFBD><EFBFBD><EFBFBD>ʵ<EFBFBD><CAB5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѭ<EFBFBD><D1AD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֽ<EFBFBD>ת<EFBFBD><D7AA><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD><EFBFBD>
|
|||
|
for (int i = 0; i <= 6; i++)
|
|||
|
{
|
|||
|
_temp[0] = _GetData[(2 * i)];
|
|||
|
_temp[1] = _GetData[(2 * i + 1)];
|
|||
|
_sIntdata[i] = CommonClassLib.CCarryConvert.GetInt16FromBytes(_temp);
|
|||
|
}
|
|||
|
|
|||
|
//0<>ֵ<EFBFBD>5<EFBFBD>֣<EFBFBD>0--11<31>ֽڣ<D6BD><DAA3><EFBFBD><EFBFBD><EFBFBD>ֵ<EFBFBD><D6B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD>7<EFBFBD><37><EFBFBD>֣<EFBFBD>14<31><34>15<31>ֽڣ<D6BD>;<3B><><EFBFBD><EFBFBD><EFBFBD>֣<EFBFBD>12<31><32>13<31>ֽڣ<D6BD>Ĭ<EFBFBD><C4AC>ֵ0<D6B5><30><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
wIntXor = _sIntdata[0];
|
|||
|
for (int i = 1; i <= 5; i++)
|
|||
|
{
|
|||
|
wIntXor = wIntXor ^ _sIntdata[i];
|
|||
|
}
|
|||
|
_sIntdata[7] = wIntXor;
|
|||
|
|
|||
|
_temp[0] =_GetData[14] ;
|
|||
|
_temp[1]=_GetData[15] ;
|
|||
|
wIntXor=CommonClassLib.CCarryConvert.GetInt16FromBytes(_temp);
|
|||
|
if (wIntXor != _sIntdata[7])//<2F><><EFBFBD>鲻<EFBFBD>ԣ<EFBFBD><D4A3><EFBFBD><EFBFBD><EFBFBD>û<EFBFBD>յ<EFBFBD>
|
|||
|
{
|
|||
|
CClientUDP.CloseUDP();
|
|||
|
_commLayerError = this.ToString() + ":GetDeviceState---" + CClientUDP.UdpError;
|
|||
|
return null;
|
|||
|
|
|||
|
}
|
|||
|
_IntData[0] = Convert.ToInt16(_GetData[6]);//ʵ<><CAB5>ֵ
|
|||
|
_IntData[1] = Convert.ToInt16(_GetData[4]);//<2F><>Ϣ<EFBFBD><CFA2>1-<2D><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> 2-<2D><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>꣨<EFBFBD><EAA3A8><EFBFBD>ڶѶ<DAB6><D1B6><EFBFBD><EFBFBD><EFBFBD> 3-<2D><><EFBFBD><EFBFBD><E2BFAA>״̬ <20><><EFBFBD><EFBFBD>ֵ<EFBFBD><D6B5><EFBFBD>ϴ<EFBFBD><CFB4><EFBFBD>
|
|||
|
_IntData[2] = Convert.ToUInt16(_GetData[3] + (_GetData[2] * 256)); ;//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>TaskIndex
|
|||
|
_IntData[3] = Convert.ToInt16(_GetData[6]);//<2F>Ѷ<EFBFBD><D1B6><EFBFBD>x<EFBFBD><78><EFBFBD><EFBFBD>
|
|||
|
_IntData[4] = Convert.ToInt16(_GetData[7]);//<2F>Ѷ<EFBFBD><D1B6><EFBFBD>y<EFBFBD><79><EFBFBD><EFBFBD>
|
|||
|
_IntData[5] = DeviceIndex;// <20>豸<EFBFBD><E8B1B8>
|
|||
|
CClientUDP.CloseUDP();
|
|||
|
return _IntData;
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
CClientUDP.CloseUDP();
|
|||
|
_commLayerError = this.ToString() + ":GetDeviceState---" + CClientUDP.UdpError;
|
|||
|
return null;
|
|||
|
}
|
|||
|
}
|
|||
|
catch (Exception ex)
|
|||
|
{
|
|||
|
CClientUDP.CloseUDP();
|
|||
|
_commLayerError = this.ToString() + "<22><>GetDeviceState---" + ex.Message;
|
|||
|
return null;
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
}
|