Commit 79b9e98d 刘韬

1

1 个父辈 c4bb2802
正在显示 46 个修改的文件 包含 352 行增加20 行删除
......@@ -293,7 +293,16 @@ namespace BLL
get => config.Read<string>(LIGHT_SERIAL_PORT);
set => config.Write(LIGHT_SERIAL_PORT, value);
}
public string SmfServer
{
get => config.Read<string>(Smf_Server);
set => config.Write(Smf_Server, value);
}
public string CID
{
get => config.Read<string>(ClientID);
set => config.Write(ClientID, value);
}
public void Save()
{
config.Save();
......@@ -302,7 +311,10 @@ namespace BLL
public partial class Config
{
private const string LANGUAGE = "Language";
private const string Smf_Server = "SmfServer";
private const string ClientID = "CID";
private const string ENABLED_USER_LOGIN = "EnabledUserLogin";
private const string OPERATE_TIMEOUT = "OperateTimeout";
private const string CHECK_SHORTCUT = "CheckShortcut";
......
......@@ -189,6 +189,7 @@ namespace BLL
LogNet.log.Debug("Enter PrintLabel Method");
Dictionary<string, string> key = new();
for (int i = 0; i < extensions.Count; i++)
{
......@@ -201,11 +202,11 @@ namespace BLL
var keys =new List<string>(key.Keys);
foreach (var kk in keys)
{
if (string.IsNullOrEmpty(key[kk]))
key[kk] = "NA";
}
//foreach (var kk in keys)
//{
// if (string.IsNullOrEmpty(key[kk]))
// key[kk] = "NA";
//}
Printing?.Invoke(key);
}
......@@ -217,7 +218,6 @@ namespace BLL
if (string.IsNullOrWhiteSpace(url))
return false;
if (TryGetDictValue(keyv, "PART")=="" && TryGetDictValue(keyv, "MPN") == "")
{
var fm = new FaceMessageBox("MES MSG", "CPN,MPN均为空,无法继续", System.Windows.Forms.MessageBoxButtons.OK);
......
......@@ -66,3 +66,5 @@ D:\rick\vs\SmartScan\DAL\obj\Debug\DAL.csproj.CoreCompileInputs.cache
D:\rick\vs\SmartScan\DAL\obj\Debug\DAL.csproj.CopyComplete
D:\rick\vs\SmartScan\DAL\obj\Debug\DAL.dll
D:\rick\vs\SmartScan\DAL\obj\Debug\DAL.pdb
D:\rick\vs\SmartScan\DAL\bin\Debug\Newtonsoft.Json.dll
D:\rick\vs\SmartScan\DAL\bin\Debug\Newtonsoft.Json.xml
using RestSharp;
using Newtonsoft.Json;
using RestSharp;
using System;
using System.Collections.Generic;
......@@ -54,9 +55,10 @@ namespace Model
LogNet.log.Info("Return:" + s);
return FormatContent(s);
}
public static string PostJson<T>(string url,Dictionary<string,string> headers, T jsonobject)
public static string PostJson<T>(string url,Dictionary<string,string> headers, T jsonobject,int timeout = 10000)
{
RestClient client = new(url) { Timeout = 10000 };
RestClient client = new(url) { Timeout = timeout };
client.UseSerializer(new CustSerialize());
RestRequest request = new(Method.POST);
request.AddHeader("Content-Type", "application/json");
if (headers != null)
......@@ -90,4 +92,28 @@ namespace Model
}
}
public class CustSerialize : RestSharp.Serialization.IRestSerializer
{
public string ContentType { get; set; } = "application/json";
public string[] SupportedContentTypes { get; set; } = new string[] { "application/json" };
public DataFormat DataFormat { get; set; } = DataFormat.Json;
public T Deserialize<T>(IRestResponse response)
{
return JsonConvert.DeserializeObject<T>(response.Content);
}
public string Serialize(object obj)
{
return JsonConvert.SerializeObject(obj);
}
public string Serialize(Parameter parameter)
{
return JsonConvert.SerializeObject(parameter.Value);
}
}
}
......@@ -45,6 +45,9 @@
<Reference Include="log4net, Version=2.0.12.0, Culture=neutral, PublicKeyToken=669e0ddf0bb1aa2a, processorArchitecture=MSIL">
<HintPath>..\packages\log4net.2.0.12\lib\net45\log4net.dll</HintPath>
</Reference>
<Reference Include="Newtonsoft.Json, Version=13.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>..\packages\Newtonsoft.Json.13.0.1\lib\net45\Newtonsoft.Json.dll</HintPath>
</Reference>
<Reference Include="RestSharp, Version=106.11.7.0, Culture=neutral, PublicKeyToken=598062e77f915f75, processorArchitecture=MSIL">
<HintPath>..\packages\RestSharp.106.11.7\lib\net452\RestSharp.dll</HintPath>
</Reference>
......
624c5de82cba8586709a860569c97dce6c9a28b4
01b2d5ca38927b2b61ed6a650f31468a3ffe0e0d
......@@ -53,3 +53,5 @@ D:\rick\vs\SmartScan\Model\obj\Debug\Model.csproj.CopyComplete
D:\rick\vs\SmartScan\Model\obj\Debug\Model.dll
D:\rick\vs\SmartScan\Model\obj\Debug\Model.pdb
D:\rick\vs\SmartScan\Model\bin\Debug\Asa.Face.Control.dll
D:\rick\vs\SmartScan\Model\bin\Debug\Newtonsoft.Json.dll
D:\rick\vs\SmartScan\Model\bin\Debug\Newtonsoft.Json.xml
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="log4net" version="2.0.12" targetFramework="net461" />
<package id="Newtonsoft.Json" version="13.0.1" targetFramework="net461" />
<package id="RestSharp" version="106.11.7" targetFramework="net461" />
<package id="Tesseract" version="3.3.0" targetFramework="net461" />
</packages>
\ No newline at end of file
......@@ -15,6 +15,7 @@ namespace SmartScan
public static Asa.Camera.VisionLib cameraVision;
public static BLL.KND_IO ioModule;
public static LightSource lightSource;
public static ServerCommunication SCMM;
public static List<string> macroKey;
......
......@@ -134,13 +134,13 @@ namespace SmartScan
LogNet.log.Info("保存历史记录");
}
private void IoModule_DI_Changed_Event(Status[] sta)
private void IoModule_DI_Changed_Event(BLL.Status[] sta)
{
if (sta == null)
LogNet.log.Info("Work IO Status = null");
else if (sta.Length <= Common.config.IOTouch)
LogNet.log.Info($"Work Status.Length({sta.Length}) <= {Common.config.IOTouch}");
else if (sta[Common.config.IOTouch] == Status.Off)
else if (sta[Common.config.IOTouch] == BLL.Status.Off)
scanWork.TouchOff();
else
{
......@@ -157,7 +157,7 @@ namespace SmartScan
foreach (string key in content.Keys)
str += string.Format("({0}:{1})", key, content[key]);
LogNet.log.Info(str);
Common.SCMM.SendData(content);
Bitmap labelBmp = Common.labelEdit.PrintImage(Common.config.DefaultPrintLabel, content, out _);
Common.labelEdit.PrintLast(Common.config.DefaultPrintLabel, Common.config.PrinterName, Common.config.PrintLandscape, content, out string[] barcode);
LogNet.log.Info(string.Format("打印标签 Label[{0}] Printer[{1}]", Common.config.DefaultPrintLabel, Common.config.PrinterName));
......@@ -181,7 +181,7 @@ namespace SmartScan
Close();
return;
}
Common.SCMM = new();
if (!Common.config.Backgrounder)
{
monitor = new();
......@@ -189,7 +189,7 @@ namespace SmartScan
monitor.Timeout += Monitor_Timeout;
monitor.Start(Common.config.OperateTimeout);
}
scanWork = new();
LblVersion.Text = Common.config.SoftVersion;
LblUserName.Text = Common.config.UserName;
......@@ -357,6 +357,7 @@ namespace SmartScan
}
public void SetWaittingMsg(string msg)
{
if (this.InvokeRequired)
{
this.Invoke(delegate ()
......@@ -365,6 +366,7 @@ namespace SmartScan
});
return;
}
Common.SCMM.ShowMsg(msg, 3, msgType.INFO);
Common.frmWaitting.SetMessage(msg);
}
}
......
......@@ -74,7 +74,6 @@ namespace SmartScan
{
try
{
workCodeInfo = new();
workCodeKeyword = new();
originalCodeText = null;
......
using BLL;
using Model;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
namespace SmartScan
{
public class ServerCommunication
{
public Status status = Status.Online;
static string server = Common.config.SmfServer;
static string CID = Common.config.CID;
List<EquipMsg> msgList = new List<EquipMsg>();
int StoreID = 1;
string StoreName = "";
string WarnMsg = "";
private System.Timers.Timer serverConnectTimer = new System.Timers.Timer();
object serverclock = new object();
public ServerCommunication()
{
if (string.IsNullOrEmpty(server))
Common.config.SmfServer = "http://192.168.1.243/smf-core/";
if (string.IsNullOrEmpty(CID))
Common.config.CID = "NeoScan01";
readLazyData();
server = Common.config.SmfServer;
CID = Common.config.CID;
//Common.config.Save();
serverConnectTimer.Interval = 1000;
serverConnectTimer.AutoReset = true;
serverConnectTimer.Enabled = true;
serverConnectTimer.Elapsed += ServerConnectTimer_Elapsed;
GC.KeepAlive(serverConnectTimer);
}
~ServerCommunication()
{
while (Datalist.TryDequeue(out var msg))
{
backupdata(msg);
}
}
private void ServerConnectTimer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
{
if (!Monitor.TryEnter(serverConnectTimer))
return;
try
{
//ProcessMsg(Msg.msg);
SendStatus();
}
catch
{
}
finally
{
Monitor.Exit(serverConnectTimer);
}
}
public void StartConnectServer()
{
serverConnectTimer.Enabled = true;
}
public void StopConnectServer()
{
serverConnectTimer.Enabled = false;
}
/// <summary>
/// 获取整个料仓的状态
/// </summary>
Operation getStatus()
{
//构建发送给服务器的对象
Operation Operation = new Operation();
Operation.cid = CID;
Operation.seq = nextSeq();
Operation.status = status;
if (showMsglist.TryDequeue(out var msg))
{
Operation.msgList.Add(msg);
}
while (Datalist.TryDequeue(out var msg1))
{
Operation.msgList.Add(msg1);
}
return Operation;
}
private static string api_communication = "/service/equipment/communication"; //流水线状态通信接口
public static string GetPostApi()
{
var host = server;
if (!host.StartsWith("http://"))
{
host = "http://" + host;
}
if (!host.EndsWith("/"))
{
host = host + "/";
}
host= host.TrimEnd('/');
if (!Uri.TryCreate(host + api_communication, UriKind.Absolute, out Uri u)) {
throw new Exception("Smf服务器地址配置错误:"+ host);
}
return u.ToString();
}
public void SendStatus()
{
lock (serverclock)
{
DateTime time = DateTime.Now;
//构建发送给服务器的对象
Operation lineOperation = getStatus();
var returntxt = Http.PostJson(GetPostApi(), new Dictionary<string, string>(), lineOperation,900);
Operation resultOperation = JsonConvert.DeserializeObject<Operation>(returntxt);
if (resultOperation==null)
{
lineOperation.msgList.ForEach(m =>
{
if (m.type == msgType.DATA)
{
backupdata(m);
LogNet.log.Warn("Data发送到SMF失败:"+m.msg);
}
});
}
ResultProcess(resultOperation);
}
}
private static int seq = 1;
public static int nextSeq()
{
if (seq.Equals(Int32.MaxValue))
{
LogNet.log.Info("seq当前值:" + seq + ",重置seq=0");
seq = 0;
}
Interlocked.Increment(ref seq);
return seq;
}
public void ShowMsg(string msg,int keepsec=1, msgType _msgType = msgType.INFO)
{
while (showMsglist.TryDequeue(out _)) ;
var m = new EquipMsg();
m.module = "NEOSCAN";
m.type = _msgType;
m.msg = msg;
for (int i=0;i<keepsec;i++)
showMsglist.Enqueue(m);
}
public void SendData(object data) {
var m = new EquipMsg();
m.module = "NEOSCAN";
m.type = msgType.DATA;
m.msg = JsonConvert.SerializeObject(data);
Datalist.Enqueue(m);
}
const string lazyuploaddatafile = "Retrospect\\lazyuploaddata.txt";
void backupdata(EquipMsg msg) {
File.AppendAllText(lazyuploaddatafile, msg.msg+"\r\n");
}
void readLazyData() {
if (!File.Exists(lazyuploaddatafile))
return;
var list = File.ReadAllLines(lazyuploaddatafile).ToList();
list.ForEach(x => { SendData(x); });
File.Delete(lazyuploaddatafile);
}
ConcurrentQueue<EquipMsg> showMsglist = new ConcurrentQueue<EquipMsg>();
ConcurrentQueue<EquipMsg> Datalist = new ConcurrentQueue<EquipMsg>();
void ResultProcess(Operation resultOperation)
{
//发送状态信息到服务器
if (resultOperation == null)
{
//判断服务端是否返回出库操作
return;
}
}
}
public class ResultData
{
//{"code":0,"msg":"ok","data":"7"}
public int code { get; set; }
public string msg { get; set; }
public Dictionary<string, string> data { get; set; }
}
/// <summary>
///1=设备联机(正常就绪)(入库后,BOX恢复原始状态)(出库后,移载装置恢复原始状态),
///2=急停,3=故障,4=警告,5=调试
/// 6=入库执行中,7=入仓完成,8=入仓失败
/// 9=出库执行,10=出仓完成,11=出库失败
/// </summary>
public enum Status
{
/// <summary>
/// 1=设备联机(正常就绪)(入库后,BOX恢复原始状态)(出库后,移载装置恢复原始状态),
/// </summary>
Online = 1,
/// <summary>
///2=急停中
/// </summary>
SuddenStop = 2,
/// <summary>
/// 3=故障中
/// </summary>
InTrouble = 3,
/// <summary>
/// 4=警告
/// </summary>
Warning = 4,
}
public class LineOperation
{
// //{"result":"0","msg":"","pos":"11#AC1_18_4_28","barcode":"R506072019102200414","cid":"line-ac-11"}
// 返回: {"code": 0, "msg":"ok", data:7}
/// <summary>
/// 0=成功
/// </summary>
public int result;
public string cid;
public string msg = "";
public string pos = "";
public string barcode = "";
}
/// <summary>
/// 与服务器通信用对象
/// </summary>
public class Operation
{
public string cid;
public string type = "NEOSCAN"; //COUNTING
public Status status;
public int seq;
public int op;
public List<EquipMsg> msgList = new List<EquipMsg>();
}
public class EquipMsg {
public string module;
[JsonConverter(typeof(StringEnumConverter))]
public msgType type;
public string msgCode;
public string msg;
public List<string> msgParams = new List<string>();
}
public enum msgType
{
INFO,
WARING,
ERROR,
DATA
}
}
......@@ -54,6 +54,9 @@
<Reference Include="log4net, Version=2.0.12.0, Culture=neutral, PublicKeyToken=669e0ddf0bb1aa2a, processorArchitecture=MSIL">
<HintPath>..\packages\log4net.2.0.12\lib\net45\log4net.dll</HintPath>
</Reference>
<Reference Include="Newtonsoft.Json, Version=13.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>..\packages\Newtonsoft.Json.13.0.1\lib\net45\Newtonsoft.Json.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Configuration" />
<Reference Include="System.Core" />
......@@ -81,6 +84,7 @@
<DependentUpon>FrmWaitting.cs</DependentUpon>
</Compile>
<Compile Include="ScanWork.cs" />
<Compile Include="ServerCommunication.cs" />
<Compile Include="UserLoginWindow.cs" />
<Compile Include="Form\FrmAbout.cs">
<SubType>Form</SubType>
......
1435
\ No newline at end of file
1473
\ No newline at end of file
......@@ -6,7 +6,7 @@
<HistoryImage>Original</HistoryImage>
<SelectHttpPN>True</SelectHttpPN>
<LabelEmptyCheck>False</LabelEmptyCheck>
<PrintCompletedClear>True</PrintCompletedClear>
<PrintCompletedClear>False</PrintCompletedClear>
<OpenStartWork>True</OpenStartWork>
<OpenMaximize>True</OpenMaximize>
<DefaultPrintLabel>ALCOELECTRO 60x30mm</DefaultPrintLabel>
......@@ -34,4 +34,6 @@
<PromptAfterPrinting>False</PromptAfterPrinting>
<AutoPrint>True</AutoPrint>
<ReelIDKeyWord>Reelid</ReelIDKeyWord>
<SmfServer>http://192.168.11.243/smf-core/</SmfServer>
<CID>NeoScan01</CID>
</appSettings>
\ No newline at end of file
此文件的差异太大,无法显示。
此文件的差异太大,无法显示。
ec99df8ebbf296d4bcc52a6b9e7098bbe68f3a07
1f6f52a2c9a538c951873afd08ee8e13e86993e5
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="log4net" version="2.0.12" targetFramework="net461" />
<package id="Newtonsoft.Json" version="13.0.1" targetFramework="net461" />
</packages>
\ No newline at end of file
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!