- Added QRValidation vision control system - Includes CapCleaningControl UI components - WebSocket-based barcode validation system - Support for Crevis PLC integration - Test projects for PLC emulator, motion, IO panel, and Modbus 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
178 lines
6.5 KiB
C#
178 lines
6.5 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using Newtonsoft.Json.Linq;
|
|
using WatsonWebsocket;
|
|
|
|
namespace Project
|
|
{
|
|
public partial class fMain
|
|
{
|
|
|
|
public object listlock = new object();
|
|
public List<string> ClientList = new List<string>();
|
|
|
|
private void Ws_Disconnected(object sender, ClientDisconnectedEventArgs e)
|
|
{
|
|
var ws = sender as Class.WebSocket;
|
|
var ip = e.IpPort;
|
|
var logIdx = ws.Target == eTarget.Left ? 0 : 1;
|
|
PUB.Time_WS_Disconnected[ws.TargetIdx] = DateTime.Now;
|
|
PUB.log_[logIdx].AddAT("Host connection terminated");
|
|
lock (ClientList)
|
|
{
|
|
if (ClientList.Contains(ip))
|
|
ClientList.Remove(ip);
|
|
}
|
|
|
|
}
|
|
|
|
private void Ws_Connected(object sender, ClientConnectedEventArgs e)
|
|
{
|
|
var ws = sender as Class.WebSocket;
|
|
var logIdx = ws.Target == eTarget.Left ? 0 : 1;
|
|
PUB.Time_WS_Connected[ws.TargetIdx] = DateTime.Now;
|
|
PUB.log_[logIdx].AddAT("Host connection completed");
|
|
lock (ClientList)
|
|
{
|
|
if (ClientList.Contains(e.IpPort))
|
|
ClientList.Add(e.IpPort);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
void SendStatus(eTarget cam)
|
|
{
|
|
var camIdx = cam == eTarget.Left ? PUB.setting.CameraIndexL : PUB.setting.CameraIndexR;
|
|
var logIdx = cam == eTarget.Left ? 0 : 1;
|
|
var camTarget = PUB.GetTarget(camIdx);
|
|
if (camTarget == eTarget.None) return;
|
|
//데이터 생성
|
|
var msg = new
|
|
{
|
|
command = "status",
|
|
camera = PUB._isCrevisOpen[camIdx] ? "1" : "0",
|
|
live = PUB.IsLive[camIdx] ? "1" : "0",
|
|
stream = PUB.setting.DisableStreamData ? "0" : "1",
|
|
listen = PUB.wsock_[logIdx].IsListening ? "1" : "0",
|
|
trig = PUB.IsTrigger[camIdx] ? "1" : "0",
|
|
license = PUB.VisionLicense ? "1" : "0",
|
|
reel = PUB.DetectReel[camIdx] ? "1" : "0",
|
|
conv = "0",
|
|
};
|
|
var json = Newtonsoft.Json.JsonConvert.SerializeObject(msg);
|
|
try
|
|
{
|
|
//PUB.log_[logIdx].Add("상태전송:" + msg);
|
|
PUB.lastsendStatus[camIdx] = DateTime.Now;
|
|
PUB.Send_WSock(camTarget, json);
|
|
//PUB.ws[camIdx].ListClients().ToList().ForEach(t => PUB.ws[camIdx].SendAsync(t, json).Wait());
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
PUB.log_[logIdx].AddE($"(STATUS) send failed {ex.Message}");
|
|
}
|
|
}
|
|
|
|
|
|
|
|
private void Ws_DataArrival(object sender, MessageReceivedEventArgs e)
|
|
{
|
|
var ws = sender as Class.WebSocket;
|
|
var ip = e.IpPort;
|
|
var raw = Encoding.UTF8.GetString(e.Data);
|
|
var logIdx = ws.Target == eTarget.Left ? 0 : 1;
|
|
var camIdx = ws.TargetIdx;
|
|
var camTarget = PUB.GetTarget(camIdx);
|
|
|
|
PUB.log_[logIdx].Add($"Received:{raw}");
|
|
|
|
PUB.Time_WS_Recv[camIdx] = DateTime.Now;
|
|
|
|
var jvalue = JObject.Parse(raw);
|
|
|
|
//데이터 생성
|
|
var msg = new
|
|
{
|
|
guid = jvalue.Value<String>("guid"),
|
|
command = jvalue.Value<String>("command"),
|
|
data = jvalue.Value<String>("data")
|
|
};
|
|
|
|
if (msg.command == "ON" || msg.command == "BCDIN")
|
|
{
|
|
PUB.RequestNewRead = true;
|
|
PUB.triggerTime[ws.TargetIdx] = DateTime.Now;
|
|
PUB.lastguid[ws.TargetIdx] = msg.guid;
|
|
PUB.lastcmd[ws.TargetIdx] = msg.command;
|
|
PUB.lastdata[ws.TargetIdx] = msg.data;
|
|
PUB.lastip[ws.TargetIdx] = e.IpPort;
|
|
if (string.IsNullOrEmpty(PUB.lastlogbarcode)) PUB.lastlogbarcode = string.Empty;
|
|
PUB.IsTrigger[ws.TargetIdx] = true;
|
|
PUB.TriggerStart = DateTime.Now;
|
|
PUB.log_[logIdx].Add("Clearing existing data due to barcode GUID reception, value=" + PUB.lastlogbarcode);
|
|
PUB.lastlogbarcode = string.Empty; //211206
|
|
PUB.parsetime = DateTime.Now;
|
|
}
|
|
else if (msg.command == "TRIG")
|
|
{
|
|
PUB.RequestNewRead = true;
|
|
PUB.triggerTime[ws.TargetIdx] = DateTime.Now;
|
|
PUB.lastguid[ws.TargetIdx] = msg.guid;
|
|
PUB.lastcmd[ws.TargetIdx] = msg.command;
|
|
PUB.lastdata[ws.TargetIdx] = msg.data;
|
|
PUB.lastip[ws.TargetIdx] = e.IpPort;
|
|
if (string.IsNullOrEmpty(PUB.lastlogbarcode)) PUB.lastlogbarcode = string.Empty;
|
|
PUB.IsTrigger[ws.TargetIdx] = true;
|
|
PUB.TriggerStart = DateTime.Now;
|
|
PUB.log_[logIdx].Add("Clearing existing data due to barcode GUID reception, value=" + PUB.lastlogbarcode);
|
|
PUB.lastlogbarcode = string.Empty; //211206
|
|
PUB.parsetime = DateTime.Now;
|
|
PUB.IsLive[ws.TargetIdx] = true;
|
|
PUB.IsProcess[ws.TargetIdx] = true;
|
|
}
|
|
else if (msg.command == "LIVEON")
|
|
{
|
|
PUB.IsLive[ws.TargetIdx] = true;
|
|
PUB.log_[logIdx].Add("live on received");
|
|
}
|
|
else if (msg.command == "LIVEOFF")
|
|
{
|
|
PUB.IsLive[ws.TargetIdx] = false;
|
|
PUB.log_[logIdx].Add("live off received");
|
|
}
|
|
else if (msg.command == "STREAMOFF")
|
|
{
|
|
PUB.setting.DisableStreamData = true;
|
|
PUB.setting.Save();
|
|
}
|
|
else if (msg.command == "STREAMON")
|
|
{
|
|
PUB.setting.DisableStreamData = false;
|
|
PUB.setting.Save();
|
|
}
|
|
else if (msg.command == "OFF")
|
|
{
|
|
PUB.IsTrigger[ws.TargetIdx] = false;
|
|
PUB.log_[logIdx].Add("OFF 수신으로 트리거상태를 해제 합니다");
|
|
PUB.IsLive[ws.TargetIdx] = false;
|
|
PUB.IsProcess[ws.TargetIdx] = false;
|
|
}
|
|
else if (msg.command == "STATUS")
|
|
{
|
|
//나의 상태값을 전송 해야한다
|
|
SendStatus(camTarget);
|
|
|
|
}
|
|
else
|
|
{
|
|
PUB.log_[logIdx].AddAT($"Unknown command({msg.command})");
|
|
}
|
|
|
|
}
|
|
}
|
|
}
|