|
|
|
|
using Mesnac.Log;
|
|
|
|
|
using SocketProcess;
|
|
|
|
|
using SqlDb;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.ComponentModel;
|
|
|
|
|
using System.Data;
|
|
|
|
|
using System.Diagnostics;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.ServiceProcess;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using Mesnac.Log;
|
|
|
|
|
|
|
|
|
|
namespace Mesnac.Ngstation
|
|
|
|
|
{
|
|
|
|
|
public partial class Service1 : ServiceBase
|
|
|
|
|
{
|
|
|
|
|
public Service1()
|
|
|
|
|
{
|
|
|
|
|
InitializeComponent();
|
|
|
|
|
}
|
|
|
|
|
SocketProcess.SocketServer socket;
|
|
|
|
|
protected override void OnStart(string[] args)
|
|
|
|
|
{
|
|
|
|
|
LogService.Instance.Debug("开始启动服务");
|
|
|
|
|
socket= new SocketProcess.SocketServer();
|
|
|
|
|
socket.ReciveEvent += ReciveData;
|
|
|
|
|
socket.StartService(8000);
|
|
|
|
|
}
|
|
|
|
|
public void ReciveData(string o, object e)
|
|
|
|
|
{
|
|
|
|
|
StateObject state = e as StateObject;
|
|
|
|
|
string bacode = DataAnalysis(o);
|
|
|
|
|
if (!string.IsNullOrEmpty(bacode))
|
|
|
|
|
{
|
|
|
|
|
LogService.Instance.Debug("收到数据:" + bacode);
|
|
|
|
|
DbHandler db = new DbHandler();
|
|
|
|
|
string NgStation = db.GetNGStation(bacode);
|
|
|
|
|
//SocketProcess.SocketServer socket = new SocketProcess.SocketServer();
|
|
|
|
|
LogService.Instance.Debug("发送数据数据:" + NgStation);
|
|
|
|
|
socket.Send(state.workSocket, NgStation.Trim());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private string DataAnalysis(string message)
|
|
|
|
|
{
|
|
|
|
|
if (message.ToUpper().StartsWith("A5"))
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
string strLen = message.Substring(2, 2);
|
|
|
|
|
int len = Convert.ToInt32(strLen);
|
|
|
|
|
if (len != message.Length - 4)
|
|
|
|
|
{
|
|
|
|
|
LogService.Instance.Debug("数据格式错误");
|
|
|
|
|
//Console.WriteLine("数据格式错误");
|
|
|
|
|
return "";
|
|
|
|
|
}
|
|
|
|
|
string barcode = message.Substring(4, message.Length - 4);
|
|
|
|
|
return barcode;
|
|
|
|
|
}
|
|
|
|
|
catch
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
//Console.WriteLine("信息格式错误");
|
|
|
|
|
LogService.Instance.Debug("信息格式错误");
|
|
|
|
|
}
|
|
|
|
|
return "";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void OnStop()
|
|
|
|
|
{
|
|
|
|
|
socket.StopService();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|