using DataEntity.Sockets.TakePhoto;
|
using HxModel.Sockets.HxHotel;
|
using HxSocket;
|
using Newtonsoft.Json;
|
using System;
|
using System.Collections.Generic;
|
using System.Data;
|
using System.Xml;
|
using XCommon.Log;
|
using XCoreBLL.Resource;
|
using XImagingXhandler.XDAL;
|
|
namespace XCore
|
{
|
public class TakePhotoBll
|
{
|
public HxSocketClient socketTcpListener = null;
|
public BacteriaBll bacteriaBll = new BacteriaBll();
|
private const string EQUIPMENT_ID = "ID2023";
|
|
string strCurrentCulture = "";
|
public TakePhotoBll()
|
{
|
strCurrentCulture = System.Threading.Thread.CurrentThread.CurrentCulture.Name;
|
}
|
|
#region 检查所有属性设置是否满足要求
|
/// <summary>
|
/// 检查所有属性设置是否满足要求
|
/// </summary>
|
/// <param name="methodTakePhoto">拍照属性对象</param>
|
/// <returns>检查所有属性设置是否满足要求</returns>
|
public MethodPropertyInfo CheckProperty(MethodTakePhoto methodTakePhoto)
|
{
|
MethodPropertyInfo methodPropertyInfo = new MethodPropertyInfo();
|
|
if (strCurrentCulture == "zh-CN")
|
{
|
methodPropertyInfo.property_tips_info = TakePhotoResourceCHS.tipsInfo.ToString();
|
|
if (methodTakePhoto.ismanualconfig == 1)
|
{
|
if (methodTakePhoto.bacteriaids == null || methodTakePhoto.bacteriaids == "")
|
{
|
methodPropertyInfo.property_name_info = TakePhotoResourceCHS.bacteriaids.ToString();
|
}
|
|
if (methodTakePhoto.gapValue == null || methodTakePhoto.gapValue == "")
|
{
|
methodPropertyInfo.property_name_info = TakePhotoResourceCHS.gapValue.ToString();
|
}
|
|
}
|
}
|
else if (strCurrentCulture == "en-US")
|
{
|
methodPropertyInfo.property_tips_info = TakePhotoResourceENU.tipsInfo.ToString();
|
|
if (methodTakePhoto.ismanualconfig == 1)
|
{
|
if (methodTakePhoto.bacteriaids == null || methodTakePhoto.bacteriaids == "")
|
{
|
methodPropertyInfo.property_name_info = TakePhotoResourceENU.bacteriaids.ToString();
|
}
|
|
if (methodTakePhoto.gapValue == null || methodTakePhoto.gapValue == "")
|
{
|
methodPropertyInfo.property_name_info = TakePhotoResourceENU.gapValue.ToString();
|
}
|
|
}
|
}
|
return methodPropertyInfo;
|
}
|
#endregion
|
|
#region 执行拍照,返回结果字符串
|
/// <summary>
|
/// 执行拍照,返回结果字符串
|
/// </summary>
|
/// <param name="xmlNode">拍照节点</param>
|
/// <param name="dtChoiceParams">拍照参数</param>
|
/// <param name="softwareDeviceNumber"></param>
|
/// <param name="bacteriaInfo"></param>
|
/// <param name="isSimulator"></param>
|
/// <returns>结果实体对象</returns>
|
public List<string> ExecuteTakePhoto(XmlNode xmlNode, DataTable dtChoiceParams, string softwareDeviceNumber,
|
Bacteria bacteriaInfo, bool isSimulator = false)
|
{
|
//调用Socket,下发拍照参数命令
|
List<string> strResult = new List<string>();
|
LoggerHelper.InfoLog("[TakePhotoBll][ExecuteTakePhoto] Start");
|
|
if (!isSimulator)
|
{
|
// 发送拍照请求
|
strResult = socketTcpListener.SendMessage(GenerateTakePhotoReq(xmlNode, dtChoiceParams, softwareDeviceNumber, bacteriaInfo), true);
|
}
|
else
|
{
|
strResult.Add("{ \"message_id\": \"02bb3628-0a29-48d7-8614-3412f4258797\", \"message_type\": 4, \"method\": \"Run\", \"equipment_id\": \"ID2023\", \"workflow_id\": \"\", \"experiment_id\": \"60b75190-b9ef-4936-935c-f8d824d0b166\", \"process_info\": {}, \"timestamp\": \"2023-09-25T13:52:27.8776083+08:00\"}#!HxSEP!#\r\n");
|
strResult.Add("{ \"message_id\": \"02bb3628-0a29-48d7-8614-3412f4258797\", \"message_type\": 5, \"method\": \"Run\", \"equipment_id\": \"ID2023\", \"workflow_id\": \"\", \"experiment_id\": \"60b75190-b9ef-4936-935c-f8d824d0b166\", \"data\": { \"json\": \"http://192.168.0.238:8099/upload/20230926_143909_238_000005_38_GUID_YS12.json\", \"image\": \"http://192.168.0.238:8099/upload/20230926_143909_238_000005_38_GUID_YS12.jpg\" }, \"process_info\": {}, \"method_status\": 2, \"error\": { \"error_code\": \"\", \"error_text\": \"\", \"troubleshoot\": 0 }, \"timestamp\": \"2023-09-25T13:53:12.2100249+08:00\"}#!HxSEP!#\r\n");
|
}
|
return strResult;
|
}
|
#endregion
|
|
/// <summary>
|
/// 获取拍照请求字符串
|
/// </summary>
|
/// <param name="xmlNode"></param>
|
/// <param name="dtChoiceParams"></param>
|
/// <param name="softwareDeviceNumber"></param>
|
/// <param name="bacteriaInfo"></param>
|
/// <returns></returns>
|
public string GenerateTakePhotoReq(XmlNode xmlNode, DataTable dtChoiceParams, string softwareDeviceNumber, Bacteria bacteriaInfo)
|
{
|
string strCommand = string.Empty;
|
try
|
{
|
if (xmlNode != null && dtChoiceParams != null)
|
{
|
string experimentid = dtChoiceParams.Rows[0]["属性值"].ToString();
|
string barcode = dtChoiceParams.Rows[1]["属性值"].ToString();
|
string bacterias = dtChoiceParams.Rows[2]["属性值"].ToString();
|
string shape = dtChoiceParams.Rows[3]["属性值"].ToString();
|
string edge = dtChoiceParams.Rows[4]["属性值"].ToString();
|
string color = dtChoiceParams.Rows[5]["属性值"].ToString();
|
float min_diam = float.Parse(dtChoiceParams.Rows[6]["属性值"].ToString());
|
float max_diam = float.Parse(dtChoiceParams.Rows[7]["属性值"].ToString());
|
float prox = float.Parse(dtChoiceParams.Rows[8]["属性值"].ToString());
|
string choicemode = dtChoiceParams.Rows[9]["属性值"].ToString();
|
string choice_distance_mode = dtChoiceParams.Rows[10]["属性值"].ToString();
|
string choicebottomdistance = dtChoiceParams.Rows[11]["属性值"].ToString();
|
string choicexAxisoffsite = dtChoiceParams.Rows[12]["属性值"].ToString();
|
string choiceyAxisoffsite = dtChoiceParams.Rows[13]["属性值"].ToString();
|
string coatingbottomdistance = dtChoiceParams.Rows[14]["属性值"].ToString();
|
string coatingxAxisoffsite = dtChoiceParams.Rows[15]["属性值"].ToString();
|
string coatingyAxisoffsite = dtChoiceParams.Rows[16]["属性值"].ToString();
|
string coating_mode = dtChoiceParams.Rows[17]["属性值"].ToString();
|
string coating_speed = dtChoiceParams.Rows[18]["属性值"].ToString();
|
int model_type = Convert.ToInt32(dtChoiceParams.Rows[19]["属性值"].ToString());
|
string merge_masks = dtChoiceParams.Rows[20]["属性值"].ToString();
|
float ds_ratio = float.Parse(dtChoiceParams.Rows[21]["属性值"].ToString());
|
float mean_diam = float.Parse(dtChoiceParams.Rows[22]["属性值"].ToString());
|
float dist_to_edge = float.Parse(dtChoiceParams.Rows[23]["属性值"].ToString());
|
string mark_color = dtChoiceParams.Rows[24]["属性值"].ToString();
|
string draw_label = dtChoiceParams.Rows[25]["属性值"].ToString();
|
string fontsize = dtChoiceParams.Rows[26]["属性值"].ToString();
|
string top_light = dtChoiceParams.Rows[27]["属性值"].ToString();
|
string bottom_light = dtChoiceParams.Rows[28]["属性值"].ToString();
|
int Ismanualconfig = Convert.ToInt32(xmlNode.SelectSingleNode("ismanualconfig").InnerText);
|
string strBacteriaids = xmlNode.SelectSingleNode("bacteriaids").InnerText; // 挑菌的种类
|
string strGuid = Guid.NewGuid().ToString();
|
|
if (Ismanualconfig == 1)//手动配置,从数据库中读取本次拍照已选中菌落的数据信息
|
{
|
string[] bacteria = strBacteriaids.Split(',');
|
if (bacteria.Length > 1) //多个菌落 TODO暂未实现
|
{
|
#region Del
|
//string strJson = "";
|
//string strSubJson = "";
|
|
//for (int i = 0; i < bacteria.Length; i++)
|
//{
|
// Bacteria bacteria1 = bacteriaBll.GetABacteria(bacteria[i]);
|
// strSubJson += "{" + "orgType:\"" + bacteria1.bacteria_name +
|
// "\",mindiameterSize:" + bacteria1.bacteria_min_size.ToString() +
|
// ",maxdiameterSize:" + bacteria1.bacteria_max_size.ToString() +
|
// ",proximity:" + prox.ToString() +
|
// ",shape:\"" + bacteria1.bacteria_shape.ToString() +
|
// "\",edge:\"" + bacteria1.bacteria_edge.ToString() +
|
// "\",color:\"" + bacteria1.bacteria_color.ToString() +
|
// "\"}";
|
//}
|
|
//strJson = "{" + "message_id:\"" + strGuid +
|
// "\",message_type:2" +
|
// ",method:\"Run\"" +
|
// ",equipment_id:\"ID2023\"" +
|
// ",\"workflow_id\":\"" + "workflow_id_" + strGuid + "\"" +
|
// ",\"experiment_id\":\"" + "experiment_id_" + strGuid + "\"" +
|
// "\",parameters:" +
|
// strSubJson +
|
// ",process_info:{}" +
|
// ",estimate_time:5" +
|
// ",timeout:60" +
|
// ",description:\"NO DESC\"" +
|
// ",timestamp:\"" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "\"}#!HxSEP!#";
|
//strCommand = strJson;
|
#endregion
|
}
|
else if (bacteria.Length == 1)//单个菌落
|
{
|
string strBottomLight = string.Empty;
|
|
#region Del
|
//string strJson = "{" + "\"message_id\":\"" + strGuid +
|
// "\",\"message_type\":2" +
|
// ",\"method\":\"Run\"" +
|
// ",\"equipment_id\":\"ID2023\"" +
|
// ",\"workflow_id\":\"" + "workflow_id_" + strGuid + "\"" +
|
// ",\"experiment_id\":\"" + "experiment_id_" + strGuid + "\"" +
|
|
// ",\"parameters\":" +
|
// "{" +
|
// "\"model\":{" + "\"model_type\":" + model_type.ToString() +
|
// "}," +
|
// "\"params\":{" +
|
// "\"merge_masks\":\"" + merge_masks.ToString()+ "\"" +
|
// ",\"ds_ratio\":" + ds_ratio.ToString() +
|
// ",\"mean_diam\":" + mean_diam.ToString() +
|
// //",prox:" + dtChoiceParams.Rows[8]["属性值"].ToString() + // 临近度
|
// ",\"prox\":" + prox + // 临近度
|
// ",\"max_diam\":" + max_diam.ToString() +
|
// ",\"min_diam\":" + min_diam.ToString() +
|
// ",\"dist_to_edge\":" + dist_to_edge.ToString() +
|
// ",\"segments\":" + 1 +
|
// ",\"barcode\":\"" + barcode + "\"" +
|
// "}," +
|
// "\"filter\":{" + "\"check_prox\":\"" + "True" +
|
// "\",\"check_diam_range\":\"" + "True" +
|
// "\",\"check_roundness\":\"" + (model_type.Equals("7") ? "False" : "True") +
|
// "\",\"check_near_edge\":\"" + "True" +
|
// "\"}," +
|
// "\"paint\":{" + "\"draw_dish_edge\":\"" + "True" +
|
// "\",\"draw_mark\":\"" + "True" +
|
// //"\",\"fontsize\":" + fontsize +
|
// //",\"mark_color\":\"" + mark_color +
|
// //"\",\"draw_label\":\"" + draw_label +
|
// "\",\"draw_cell_edge\":\"" + "True" +
|
// "\",\"cell_edge_color\":\"" + "(0,255,0)" +
|
// "\"}," +
|
// "\"optional\":{" + "\"channel_1\" :\"" + "True" +
|
// "\"}," +
|
// "\"light\":{" +
|
// //"\"top_light\":" + top_light +
|
// //strBottomLight +
|
// "}" +
|
// "}" +
|
// ",\"process_info\":{}" +
|
// ",\"estimate_time\":5" +
|
// ",\"timeout\":60" +
|
// ",\"description\":\"NO DESC\"" +
|
// ",\"timestamp\":\"" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "\"}";
|
//strCommand = strJson;
|
#endregion
|
|
#region 拍照参数
|
TakePhotoRequestObject req = new TakePhotoRequestObject();
|
req.SetBaseVal(EQUIPMENT_ID, "Run");
|
|
TakePhotoParameter parameters = new TakePhotoParameter();
|
#region Model
|
Model model = new Model();
|
model.model_type = model_type;
|
parameters.model = model;
|
#endregion
|
|
#region Params
|
Params param = new Params();
|
param.merge_masks = merge_masks;
|
param.ds_ratio = ds_ratio;
|
param.mean_diam = mean_diam;
|
param.prox = prox;
|
param.max_diam = max_diam;
|
param.min_diam = min_diam;
|
param.dist_to_edge = dist_to_edge;
|
//param.segments = 1;
|
param.barcode = barcode;
|
parameters.param = param;
|
#endregion
|
|
#region filter
|
//Filter filter = new Filter();
|
//filter.check_prox = "True";
|
//filter.check_diam_range = "True";
|
//filter.check_roundness = (model_type.Equals("7") ? "False" : "True");
|
//filter.check_near_edge = "True";
|
//parameters.filter = filter;
|
#endregion
|
|
#region paint
|
//Paint paint = new Paint();
|
//paint.draw_dish_edge = "True";
|
//paint.draw_mark = "True";
|
//paint.draw_cell_edge = "True";
|
//paint.cell_edge_color = "(0,255,0)";
|
//parameters.paint = paint;
|
#endregion
|
|
#region optional
|
Optional optional = new Optional();
|
optional.channel_1 = bacteriaInfo.chanel1_color;
|
optional.channel_2 = bacteriaInfo.chanel2_color;
|
parameters.optional = optional;
|
#endregion
|
|
#region light
|
Light light = new Light();
|
parameters.light = light;
|
#endregion
|
|
req.parameters = parameters;
|
#endregion
|
|
strCommand = JsonConvert.SerializeObject(req);
|
}
|
}
|
else if (Ismanualconfig == 2) //自动配置,从固定目录的文件中读取数据
|
{
|
string strJson = "";
|
//if (dtChoiceParams != null)
|
{
|
strJson = "{" + "message_id:\"" + Guid.NewGuid().ToString() +
|
"\",message_type:2" +
|
",method:\"Run\"" +
|
",equipment_id:\"ID2023\"" +
|
",workflow_id:\"\"" +
|
",experiment_id:\"" + experimentid +
|
"\",parameters:" +
|
"{" +
|
"model:{" + "model_type:" + model_type +
|
",model_name:\"" + "YS12" +
|
"\",flow_threshold:" + "0.4" +
|
",batch_size:" + "16" +
|
",min_size:" + "1" +
|
",merge_masks:\"" + merge_masks +
|
"\"}," +
|
"params:{" + "ds_ratio:" + ds_ratio +
|
",mean_diam:" + mean_diam +
|
",prox:" + prox +
|
",max_diam:" + max_diam +
|
",min_diam:" + min_diam +
|
",dist_to_edge:" + dist_to_edge +
|
",barcode:\"" + barcode +
|
"\"}," +
|
"filter:{" + "check_prox:\"" + "True" +
|
"\",check_diam_range:\"" + "True" +
|
"\",check_roundness:\"" + (model_type.Equals("7") ? "False" : "True") +
|
"\",check_near_edge:\"" + "True" +
|
"\"}," +
|
"paint:{" + "draw_dish_edge:\"" + "True" +
|
"\",draw_mark:\"" + "True" +
|
//"\",fontsize:" + fontsize +
|
//",mark_color:\"" + mark_color +
|
//"\",draw_label:\"" + draw_label +
|
"\",draw_cell_edge:\"" + "True" +
|
"\",cell_edge_color:\"" + "(0,255,0)" +
|
"\"}," +
|
//"optional:{" + "save_last_setting :\"" + "True" +
|
//"\"}," +
|
"light:{" +
|
//"top_light:" + top_light +
|
// ",bottom_light:" + bottom_light +
|
"}" +
|
"}" +
|
",process_info:{}" +
|
",estimate_time:5" +
|
",timeout:60" +
|
",description:\"NO DESC\"" +
|
",timestamp:\"" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "\"}";
|
}
|
strCommand = strJson;
|
}
|
|
}
|
}
|
catch (Exception ex)
|
{
|
LoggerHelper.ErrorLog("ERROR:", ex);
|
}
|
return strCommand;
|
}
|
|
#region 从命令文件的xml节点构建拍照命令属性集合对象
|
/// <summary>
|
/// 从命令文件的xml节点构建拍照命令属性集合对象
|
/// </summary>
|
/// <param name="xmlNode">拍照xml节点</param>
|
/// <returns>拍照命令属性集合对象</returns>
|
public MethodTakePhoto GenerateMethodTakePhotoDataByXmlNode(XmlNode xmlNode)
|
{
|
MethodTakePhoto methodTakePhoto = new MethodTakePhoto();
|
|
methodTakePhoto.isrun = xmlNode.SelectSingleNode("isrun").InnerText;
|
methodTakePhoto.status = xmlNode.SelectSingleNode("status").InnerText;
|
methodTakePhoto.name = xmlNode.SelectSingleNode("name").InnerText;
|
methodTakePhoto.label = xmlNode.SelectSingleNode("label").InnerText;
|
methodTakePhoto.strIndex = xmlNode.SelectSingleNode("strIndex").InnerText;
|
methodTakePhoto.ismanualconfig = Convert.ToInt32(xmlNode.SelectSingleNode("ismanualconfig").InnerText);
|
methodTakePhoto.bacteriaids = xmlNode.SelectSingleNode("bacteriaids").InnerText;
|
methodTakePhoto.gapValue = xmlNode.SelectSingleNode("gapValue").InnerText;
|
methodTakePhoto.colorText = xmlNode.SelectSingleNode("bacteriacolor/text").InnerText;
|
methodTakePhoto.colorValue = xmlNode.SelectSingleNode("bacteriacolor/value").InnerText;
|
methodTakePhoto.identification = Convert.ToInt32(xmlNode.SelectSingleNode("identification").InnerText);
|
methodTakePhoto.choiceTimes = Convert.ToInt32(xmlNode.SelectSingleNode("choiceTimes").InnerText);
|
//methodTakePhoto.barcode = xmlNode.SelectSingleNode("barcode").InnerText;
|
if (xmlNode.SelectSingleNode("labware/text") != null)
|
{
|
methodTakePhoto.coatingLabwareText = xmlNode.SelectSingleNode("labware/text").InnerText;
|
methodTakePhoto.coatingLabwareValue = xmlNode.SelectSingleNode("labware/value").InnerText;
|
}
|
|
return methodTakePhoto;
|
}
|
/// <summary>
|
/// 从命令文件的xml节点构建拍照电泳命令属性集合对象
|
/// </summary>
|
/// <param name="xmlNode">拍照xml节点</param>
|
/// <returns>拍照命令属性集合对象</returns>
|
public MethodTakePhotoForElectro GenerateMethodTakePhotoForElectroDataByXmlNode(XmlNode xmlNode)
|
{
|
MethodTakePhotoForElectro methodTakePhotoForElectro = new MethodTakePhotoForElectro();
|
|
methodTakePhotoForElectro.isrun = xmlNode.SelectSingleNode("isrun").InnerText;
|
methodTakePhotoForElectro.status = xmlNode.SelectSingleNode("status").InnerText;
|
methodTakePhotoForElectro.name = xmlNode.SelectSingleNode("name").InnerText;
|
methodTakePhotoForElectro.label = xmlNode.SelectSingleNode("label").InnerText;
|
methodTakePhotoForElectro.strIndex = xmlNode.SelectSingleNode("strIndex").InnerText;
|
methodTakePhotoForElectro.identification = Convert.ToInt32(xmlNode.SelectSingleNode("identification").InnerText);
|
if (xmlNode.SelectSingleNode("labware/text") != null)
|
{
|
methodTakePhotoForElectro.gumLabwareText = xmlNode.SelectSingleNode("labware/text").InnerText;
|
methodTakePhotoForElectro.gumLabwareValue = xmlNode.SelectSingleNode("labware/value").InnerText;
|
}
|
|
return methodTakePhotoForElectro;
|
}
|
#endregion
|
|
#region 检查成像点位是否已有板
|
/// <summary>
|
/// 检查成像点位是否已有板
|
/// </summary>
|
/// <returns></returns>
|
public bool DoCheckSafe()
|
{
|
LoggerHelper.InfoLog("[TakePhotoBll][DoCheckSafe] Start");
|
bool bIsError = false;
|
|
try
|
{
|
// 发送请求
|
List<string> strResult = socketTcpListener.SendMessage(GetCheckSafeReq());
|
string rtnData = socketTcpListener.CheckData(strResult);
|
if (string.IsNullOrEmpty(rtnData))
|
{
|
bIsError = false;
|
}
|
else
|
{
|
CheckSafeResponseObject rtData = JsonConvert.DeserializeObject<CheckSafeResponseObject>(rtnData);
|
bIsError = CheckSafeResponseData.SAFE.Equals(rtData.data.result) ? false : true;
|
}
|
}
|
catch (Exception ex)
|
{
|
LoggerHelper.ErrorLog("ERROR:", ex);
|
}
|
finally
|
{
|
LoggerHelper.InfoLog("[TakePhotoBll][DoCheckSafe] End");
|
}
|
return bIsError;
|
}
|
|
/// <summary>
|
/// 获取检查成像点位是否已有板的请求
|
/// </summary>
|
/// <returns></returns>
|
private string GetCheckSafeReq()
|
{
|
CheckSafeRequestObject req = new CheckSafeRequestObject();
|
req.SetBaseVal(EQUIPMENT_ID, "CheckSafe");
|
|
return JsonConvert.SerializeObject(req);
|
}
|
#endregion
|
}
|
}
|