优化相机配置和图像获取逻辑
在 `2DCameraForm.cs` 中添加了对相机品牌的检查,确保只有在品牌不是 `LBCamera` 时才设置触发模式并开始抓取图像。
在 `LBCamera.cs` 中引入了多个私有字段以存储图像处理相关的句柄和数据,并移除了未实现的方法 `GetCamConfig` 和 `GetExpouseTime`,添加了新的实现以支持相机配置和曝光时间的获取。
新增了相机信息查找逻辑,通过序列号或 IP 地址匹配相机。
修改了图像获取逻辑,使用 `RetrieveDataAndGenerateImage` 方法处理图像数据,并确保线程安全。
添加了 `StartSingleGrab` 和 `StartContinuousGrab` 方法以支持线扫相机的不同采集模式。
移除了未实现的 `GetImage` 和 `GetImageWithSoftTrigger` 方法,并提供了新的实现。
更新了 `OnAcquisitionCompleted` 方法以兼容不同的采集完成状态。
添加了多个参数设置和获取的方法,支持曝光时间、增益、触发模式等配置选项。
整体简化了类的结构,提高了代码的可读性和可维护性。
增强通讯器功能,改善用户界面和数据库支持
在多个文件中进行了重要更改,包括:
- 添加了 `CsvRecordProductData` 类以支持CSV映射。
- 引入 `LB_SmartVision.SQL` 以支持数据库操作。
- 更新了 `CommunicatorForm` 的事件处理和控件可见性逻辑。
- 修改了连接通讯器的逻辑,确保连接成功后启用相关按钮。
- 重构了相机类方法以支持不同类型的相机实现。
- 更新了界面布局和控件属性,以提升用户体验。
- 添加了数据库连接和初始化逻辑,支持数据记录功能。
这些更改旨在提升系统的功能性和用户友好性。
已重命名1个文件
已添加5个文件
已修改21个文件
已删除1个文件
| ¶Ô±ÈÐÂÎļþ |
| | |
| | | using LB_SmartVisionCommon; |
| | | using System; |
| | | using System.Collections.Generic; |
| | | using System.ComponentModel; |
| | | using System.Linq; |
| | | using System.Text; |
| | | using System.Threading.Tasks; |
| | | |
| | | namespace LB_SmartVision.CSV |
| | | { |
| | | /// <summary> |
| | | /// ç¨äºCSVæ å°çç±» |
| | | /// </summary> |
| | | public class CsvRecordProductData |
| | | { |
| | | /// <summary> |
| | | /// SKU ç©æå·æäº§ååç§° |
| | | /// </summary> |
| | | public string ProductName { get; set; } |
| | | |
| | | /// <summary> |
| | | /// 产åSNå· |
| | | /// </summary> |
| | | public string ProductSN { get; set; } |
| | | |
| | | /// <summary> |
| | | /// æ£æµä½ä¸å |
| | | /// </summary> |
| | | public string InspectionOperator { get; set; } |
| | | |
| | | /// <summary> |
| | | /// NGç±»å |
| | | /// </summary> |
| | | public string NGType { get; set; } |
| | | |
| | | /// <summary> |
| | | /// NGå¤§å° |
| | | /// </summary> |
| | | public string NGSize { get; set; } |
| | | |
| | | /// <summary> |
| | | /// æ£æµæ¶é´ |
| | | /// </summary> |
| | | public string DetectionTime { get; set; } |
| | | |
| | | /// <summary> |
| | | /// æ£æµç¸æº |
| | | /// </summary> |
| | | public string CameraInspection { get; set; } |
| | | } |
| | | |
| | | } |
| | |
| | |  |
| | | using LB_SmartVision.SQL; |
| | | using Newtonsoft.Json; |
| | | using Newtonsoft.Json.Linq; |
| | | using ReaLTaiizor.Forms; |
| | |
| | | txtAddress.Name = "txtAddress"; |
| | | txtAddress.Size = new Size(100, 21); |
| | | txtAddress.TabIndex = 9; |
| | | txtAddress.TextChanged += txtAddress_TextChanged; |
| | | // |
| | | // cmbType |
| | | // |
| | |
| | | using LB_VisionProcesses.Communicators.TCom; |
| | | using ReaLTaiizor.Forms; |
| | | using RJCP.IO.Ports; |
| | | using S7.Net; |
| | | using System.Diagnostics; |
| | | using System.Linq; |
| | | |
| | | namespace LB_SmartVision.Forms.Pages.CommunicatorPage |
| | | { |
| | | public delegate void CommunicatorChange(BaseCommunicator communicator); |
| | | public partial class CommunicatorForm : Form |
| | | { |
| | | BaseCommunicator communicator { get; set; } |
| | | |
| | | public event CommunicatorChange CommunicatorChanged; |
| | | |
| | | private void communicatorChanged(BaseCommunicator communicator) |
| | | { |
| | | if (CommunicatorChanged != null) |
| | | { |
| | | CommunicatorChanged(communicator); |
| | | } |
| | | } |
| | | |
| | | public CommunicatorForm() |
| | | { |
| | |
| | | txtIP.Visible = false; |
| | | cmbIP.Visible = true; |
| | | |
| | | this.btnRuleSend.Visible = true; |
| | | |
| | | |
| | | lblType.Visible = false; |
| | | lblAddress.Visible = false; |
| | | cmbType.Visible = false; |
| | |
| | | txtPort.SelectedText = communicator.CommunicatorConnections["端å£"]?.ToString(); |
| | | txtIP.Visible = true; |
| | | cmbIP.Visible = false; |
| | | |
| | | this.btnRuleSend.Visible = false; |
| | | |
| | | |
| | | lblType.Visible = false; |
| | | lblAddress.Visible = false; |
| | |
| | | if (!string.IsNullOrEmpty(communicator.CommunicatorConnections["åå·"]?.ToString())) |
| | | { |
| | | cmbType.Items.Add(communicator.CommunicatorConnections["åå·"]?.ToString()); |
| | | } |
| | | cmbType.Text = communicator.CommunicatorConnections["åå·"]?.ToString(); |
| | | } |
| | | if (!string.IsNullOrEmpty(communicator.CommunicatorConnections["åéå°å"]?.ToString())) |
| | | { |
| | | txtAddress.Text = communicator.CommunicatorConnections["åéå°å"]?.ToString(); |
| | | } |
| | | txtIP.Visible = true; |
| | | cmbIP.Visible = false; |
| | | this.btnRuleSend.Visible = false; |
| | | |
| | | lblType.Visible = true; |
| | | lblAddress.Visible = true; |
| | |
| | | return; |
| | | //åæ¶åè°å½æ° |
| | | communicator.MessageReceived -= ShowReceiveMsg; |
| | | if (communicator != null) |
| | | { |
| | | communicatorChanged(communicator); |
| | | if (GlobalVar.dicCommunicators != null && GlobalVar.dicCommunicators.Keys.Count > 0 && GlobalVar.dicCommunicators.Keys.Contains(communicator.CommunicatorName)) |
| | | { |
| | | GlobalVar.dicCommunicators[communicator.CommunicatorName] = communicator; |
| | | } |
| | | } |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | |
| | | if (communicator.SendMessage(SendMsg)) |
| | | ShowSendMsg(SendMsg); |
| | | } |
| | | |
| | | private void txtAddress_TextChanged(object sender, EventArgs e) |
| | | { |
| | | if (communicator != null && !communicator.CommunicatorConnections.Contains("åéå°å")) |
| | | { |
| | | communicator.CommunicatorConnections.Add("åéå°å", txtAddress.Text); |
| | | } |
| | | else if (communicator != null) |
| | | { |
| | | communicator.CommunicatorConnections["åéå°å"] = txtAddress.Text; |
| | | communicatorChanged(communicator); |
| | | } |
| | | } |
| | | } |
| | | } |
| | |
| | | |
| | | if (GlobalVar.dicCommunicators.ContainsKey(name)) |
| | | { |
| | | CommunicatorForm cameraForm = new CommunicatorForm(GlobalVar.dicCommunicators[name], name); |
| | | cameraForm.Show(); |
| | | CommunicatorForm communicatorFForm = new CommunicatorForm(GlobalVar.dicCommunicators[name], name); |
| | | communicatorFForm.CommunicatorChanged += CommunicatorFForm_CommunicatorChanged; |
| | | communicatorFForm.Show(); |
| | | } |
| | | } |
| | | } |
| | | |
| | | private void CommunicatorFForm_CommunicatorChanged(BaseCommunicator communicator) |
| | | { |
| | | |
| | | } |
| | | |
| | | // ç§»é¤éè®¯å£ |
| | | private void DeleteEvent(string Name, string Text) |
| | | { |
| | |
| | | MessageBox.Show("æªéæ©é讯类å!", "å¼å¸¸"); |
| | | return; |
| | | } |
| | | if (!communicator.Connect()) |
| | | if (communicator.Connect()) |
| | | { |
| | | uiButtonCreate.Enabled = true; |
| | | communicator.Disconnect(); |
| | |
| | | |
| | | private void uiButtonCreate_Click(object sender, EventArgs e) |
| | | { |
| | | if (!communicator.Connect()) |
| | | if (communicator.Connect()) |
| | | { |
| | | bCreate = true; |
| | | this.Close(); |
| | |
| | | </ItemGroup> |
| | | |
| | | <ItemGroup> |
| | | <ProjectReference Include="..\LB_SmartVisionCommon\LB_SmartVisionCommon.csproj" /> |
| | | <ProjectReference Include="..\LB_SmartVisionLoginUI\LB_SmartVisionLoginUI.csproj" /> |
| | | <ProjectReference Include="..\LB_VisionControl\LB_VisionControl.csproj" /> |
| | | <ProjectReference Include="..\LB_VisionFlowNode\LB_VisionFlowNode.csproj" /> |
| | |
| | | [Node("Halcon2Dæç¹å·¥å
·", "Haclon2Då·¥å
·", "Basic", "Halcon2Dæç¹å·¥å
·")] |
| | | public void Halcon2Dæç¹å·¥å
·(FlowNode node) { RunNodeAsync(node); } |
| | | |
| | | [Node("é讯模å", "é讯工å
·", "Basic", "é讯模å")] |
| | | public void é讯模å(FlowNode node) { RunNodeAsync(node); } |
| | | |
| | | #endregion |
| | | |
| ¶Ô±ÈÐÂÎļþ |
| | |
| | | using LB_SmartVisionCommon; |
| | | using MySql.Data.MySqlClient; |
| | | using System; |
| | | using System.Collections.Generic; |
| | | using System.Linq; |
| | | using System.Text; |
| | | using System.Threading.Tasks; |
| | | |
| | | namespace LB_SmartVision.SQL |
| | | { |
| | | public class DatabaseRecordProductDataHelper |
| | | { |
| | | private static string connectionString = "Server=localhost;Database=product_db;Uid=root;Pwd=root;"; |
| | | private static object databaseRecordProductDataHelperObject = new object(); |
| | | public static MySqlConnection GetConnection() |
| | | { |
| | | return new MySqlConnection(connectionString); |
| | | } |
| | | // åå»ºæ°æ®åºå表 |
| | | public static void InitializeDatabase() |
| | | { |
| | | lock (databaseRecordProductDataHelperObject) |
| | | { |
| | | try |
| | | { |
| | | using (var connection = GetConnection()) |
| | | { |
| | | connection.Open(); |
| | | // åå»ºæ°æ®åº |
| | | string createDbSql = @"CREATE DATABASE IF NOT EXISTS product_db;"; |
| | | using (var cmd = new MySqlCommand(createDbSql, connection)) |
| | | { |
| | | cmd.ExecuteNonQuery(); |
| | | } |
| | | // ä½¿ç¨æ°æ®åº |
| | | string useDbSql = @"USE product_db;"; |
| | | using (var cmd = new MySqlCommand(useDbSql, connection)) |
| | | { |
| | | cmd.ExecuteNonQuery(); |
| | | } |
| | | // å建表ï¼å¢å ç´¢å¼ä»¥æé«æ¥è¯¢æ§è½ï¼ |
| | | string createTableSql = @" |
| | | CREATE TABLE IF NOT EXISTS RecordProductData ( |
| | | Id INT AUTO_INCREMENT PRIMARY KEY, |
| | | ProductName VARCHAR(255) NOT NULL, |
| | | ProductSN VARCHAR(255) NOT NULL, |
| | | InspectionOperator VARCHAR(255), |
| | | NGType VARCHAR(255), |
| | | NGSize VARCHAR(255), |
| | | DetectionTime VARCHAR(255)), |
| | | CameraInspection VARCHAR(255), |
| | | CreatedDate DATETIME DEFAULT CURRENT_TIMESTAMP, |
| | | INDEX idx_created_date (CreatedDate), |
| | | INDEX idx_product_number (ProductSN), |
| | | INDEX idx_operator (InspectionOperator) |
| | | );"; |
| | | using (var cmd = new MySqlCommand(createTableSql, connection)) |
| | | { |
| | | cmd.ExecuteNonQuery(); |
| | | AsyncLogHelper.Info("æ°æ®åºå表å建æåï¼"); |
| | | } |
| | | } |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | AsyncLogHelper.Error($"æ°æ®åºåå§å失败: {ex.Message}"); |
| | | throw; |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |
| ÎļþÃû´Ó LB_SmartVision/LB_Collections.cs ÐÞ¸Ä |
| | |
| | | using System.Text; |
| | | using System.Threading.Tasks; |
| | | |
| | | namespace LB_SmartVision |
| | | namespace LB_SmartVision.SQL |
| | | { |
| | | [Serializable] |
| | | public class LB_Collections<T> : ICollection<CollectionItem<T>> |
| ¶Ô±ÈÐÂÎļþ |
| | |
| | | using MySql.Data.MySqlClient; |
| | | using System; |
| | | using System.Collections.Generic; |
| | | using System.Data; |
| | | using System.Data.SqlClient; |
| | | using System.Diagnostics; |
| | | using System.Linq; |
| | | using System.Text; |
| | | using System.Threading.Tasks; |
| | | |
| | | namespace LB_SmartVision.SQL |
| | | { |
| | | public class LB_SqlCommand |
| | | { |
| | | /// <summary> |
| | | /// è¿æ¥åç¬¦ä¸²ï¼æå® MySQL å®ä¾åæ°æ®åº(å®é
ä¼è¯»ådll.configä¸ç弿¥æ´æ°è¿æ¥å符串) |
| | | /// </summary> |
| | | public static string ConnectionString = "Server=localhost;Database=product_mes;Uid=root;Pwd=root;"; |
| | | |
| | | /// <summary> |
| | | /// 夿æå®åæ¯å¦åå¨æå¼ |
| | | /// </summary> |
| | | /// <param name="tableName">表å</param> |
| | | /// <param name="columnName">æå®åå</param> |
| | | /// <param name="value">æå®å¼</param> |
| | | /// <param name="connectionString"></param> |
| | | /// <returns>å¼åå¨True</returns> |
| | | public static bool IsExist(string tableName, string columnName, string value, string connectionString = "") |
| | | { |
| | | if (string.IsNullOrEmpty(connectionString)) |
| | | connectionString = ConnectionString; |
| | | |
| | | // MySQL æ¥è¯¢è¯å¥ï¼æ£æ¥æå®åæ¯å¦å卿å®çå¼ |
| | | string sqlQuery = string.Format("SELECT CASE WHEN EXISTS (SELECT 1 FROM `{0}` " + |
| | | "WHERE `{1}` = @Value) THEN 1 ELSE 0 END", tableName, columnName); |
| | | |
| | | // å建 MySQL è¿æ¥ |
| | | using (MySqlConnection connection = new MySqlConnection(connectionString)) |
| | | { |
| | | // å建 MySQL å½ä»¤ |
| | | using (MySqlCommand command = new MySqlCommand(sqlQuery, connection)) |
| | | { |
| | | // æ·»å åæ°ï¼é²æ¢ SQL 注å
¥ |
| | | command.Parameters.AddWithValue("@Value", value); |
| | | |
| | | // æå¼è¿æ¥ |
| | | connection.Open(); |
| | | |
| | | // æ§è¡æ¥è¯¢å¹¶è·åç»æ |
| | | int result = Convert.ToInt32(command.ExecuteScalar()); |
| | | |
| | | // 妿 result == 1ï¼è¡¨ç¤ºåå¨è¯¥å¼ï¼å¦åä¸åå¨ |
| | | return result == 1; |
| | | } |
| | | } |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 夿æå®è¡¨æ¯å¦åå¨ |
| | | /// </summary> |
| | | /// <param name="tableName">表å</param> |
| | | /// <param name="connectionString"></param> |
| | | /// <returns>å¼åå¨True</returns> |
| | | public static bool IsExistTable(string tableName, string connectionString = "") |
| | | { |
| | | if (string.IsNullOrEmpty(connectionString)) |
| | | connectionString = ConnectionString; |
| | | |
| | | // MySQL æ¥è¯¢è¯å¥ï¼æ£æ¥è¡¨æ¯å¦åå¨ |
| | | string sqlQuery = $@" |
| | | SELECT COUNT(*) |
| | | FROM INFORMATION_SCHEMA.TABLES |
| | | WHERE TABLE_SCHEMA = DATABASE() |
| | | AND TABLE_NAME = @TableName"; |
| | | |
| | | // å建 MySQL è¿æ¥ |
| | | using (MySqlConnection connection = new MySqlConnection(connectionString)) |
| | | { |
| | | // å建 MySQL å½ä»¤ |
| | | using (MySqlCommand command = new MySqlCommand(sqlQuery, connection)) |
| | | { |
| | | // æ·»å 表ååæ° |
| | | command.Parameters.AddWithValue("@TableName", tableName); |
| | | |
| | | // æå¼è¿æ¥ |
| | | connection.Open(); |
| | | |
| | | // æ§è¡æ¥è¯¢å¹¶è·åç»æ |
| | | int result = Convert.ToInt32(command.ExecuteScalar()); |
| | | |
| | | // 妿 result > 0ï¼è¡¨ç¤ºåå¨è¯¥è¡¨ï¼å¦åä¸åå¨ |
| | | return result > 0; |
| | | } |
| | | } |
| | | } |
| | | |
| | | /// <summary> |
| | | /// éå½å表 |
| | | /// </summary> |
| | | /// <param name="oldTableName"></param> |
| | | /// <param name="newTableName"></param> |
| | | /// <param name="connectionString"></param> |
| | | /// <returns></returns> |
| | | public static bool RenameTable(string oldTableName, string newTableName, string connectionString = "") |
| | | { |
| | | if (string.IsNullOrEmpty(connectionString)) |
| | | connectionString = ConnectionString; |
| | | |
| | | if (!IsExistTable(oldTableName)) |
| | | return false; |
| | | |
| | | // MySQL éå½åè¡¨è¯æ³ |
| | | string sqlQuery = $"ALTER TABLE `{oldTableName}` RENAME TO `{newTableName}`"; |
| | | |
| | | // å建 MySQL è¿æ¥ |
| | | using (MySqlConnection connection = new MySqlConnection(connectionString)) |
| | | { |
| | | // å建 MySQL å½ä»¤ |
| | | using (MySqlCommand command = new MySqlCommand(sqlQuery, connection)) |
| | | { |
| | | // æå¼è¿æ¥ |
| | | connection.Open(); |
| | | |
| | | try |
| | | { |
| | | // æ§è¡æ¥è¯¢å¹¶è·åç»æ |
| | | command.ExecuteNonQuery(); |
| | | return true; |
| | | } |
| | | catch |
| | | { |
| | | return false; |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | /// <summary> |
| | | /// å 餿å®è¡¨ |
| | | /// </summary> |
| | | /// <param name="tableName">表å</param> |
| | | /// <param name="connectionString"></param> |
| | | /// <returns>å 餿åTrue</returns> |
| | | public static bool DeleteTable(string tableName, string connectionString = "") |
| | | { |
| | | if (string.IsNullOrEmpty(connectionString)) |
| | | connectionString = ConnectionString; |
| | | |
| | | // MySQL å é¤è¡¨è¯å¥ |
| | | string sqlQuery = $"DROP TABLE IF EXISTS `{tableName}`"; |
| | | |
| | | // å建 MySQL è¿æ¥ |
| | | using (MySqlConnection connection = new MySqlConnection(connectionString)) |
| | | { |
| | | // å建 MySQL å½ä»¤ |
| | | using (MySqlCommand command = new MySqlCommand(sqlQuery, connection)) |
| | | { |
| | | // æå¼è¿æ¥ |
| | | connection.Open(); |
| | | |
| | | try |
| | | { |
| | | // æ§è¡å é¤æä½ |
| | | command.ExecuteNonQuery(); |
| | | return true; |
| | | } |
| | | catch |
| | | { |
| | | return false; |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | /// <summary> |
| | | /// è·åæéçå¼éè¿ç´¢å¼æå®åçæå®å¼å®ä½å°æå¨è¡çæå®å |
| | | /// </summary> |
| | | /// <param name="tableName">表å</param> |
| | | /// <param name="indexName">æå®åå</param> |
| | | /// <param name="indexValue">æå®åå¼</param> |
| | | /// <param name="columnName">æéå¼çåå</param> |
| | | /// <param name="connectionString"></param> |
| | | /// <returns>æéåå¼</returns> |
| | | public static string FindValueFromIndexName(string tableName, string indexName, string indexValue, string columnName, string connectionString = "") |
| | | { |
| | | try |
| | | { |
| | | if (string.IsNullOrEmpty(connectionString)) |
| | | connectionString = ConnectionString; |
| | | |
| | | // MySQL æ¥è¯¢è¯å¥ |
| | | string sqlQuery = $"SELECT `{columnName}` FROM `{tableName}` WHERE `{indexName}` = @IndexValue"; |
| | | string resultValue = string.Empty; |
| | | |
| | | // è¿æ¥æ°æ®åºå¹¶æ§è¡æ¥è¯¢ |
| | | using (MySqlConnection connection = new MySqlConnection(connectionString)) |
| | | { |
| | | using (MySqlCommand command = new MySqlCommand(sqlQuery, connection)) |
| | | { |
| | | // æ·»å 忰以鲿¢ SQL 注å
¥ |
| | | command.Parameters.AddWithValue("@IndexValue", indexValue); |
| | | |
| | | // æå¼è¿æ¥ |
| | | connection.Open(); |
| | | |
| | | // æ§è¡æ¥è¯¢å¹¶è·åç»æ |
| | | var result = command.ExecuteScalar(); |
| | | |
| | | if (result != null) |
| | | { |
| | | resultValue = result.ToString(); |
| | | } |
| | | } |
| | | } |
| | | return resultValue; |
| | | } |
| | | catch |
| | | { |
| | | return string.Empty; |
| | | } |
| | | } |
| | | |
| | | /// <summary> |
| | | /// å 餿å®è¡éè¿ç´¢å¼æå®åçæå®å¼ |
| | | /// </summary> |
| | | /// <param name="tableName">表å</param> |
| | | /// <param name="indexName">æå®åå</param> |
| | | /// <param name="indexValue">æå®åå¼</param> |
| | | /// <param name="connectionString"></param> |
| | | /// <returns>å 餿åTrue</returns> |
| | | public static bool DeleteRowFromIndexName(string tableName, string indexName, string indexValue, string connectionString = "") |
| | | { |
| | | try |
| | | { |
| | | if (string.IsNullOrEmpty(connectionString)) |
| | | connectionString = ConnectionString; |
| | | |
| | | using (MySqlConnection conn = new MySqlConnection(connectionString)) |
| | | { |
| | | conn.Open(); |
| | | |
| | | // å 餿å®è¡ |
| | | string deleteQuery = string.Format("DELETE FROM `{0}` WHERE `{1}` = @indexValue", tableName, indexName); |
| | | using (MySqlCommand cmd = new MySqlCommand(deleteQuery, conn)) |
| | | { |
| | | cmd.Parameters.AddWithValue("@indexValue", indexValue); |
| | | cmd.ExecuteNonQuery(); |
| | | } |
| | | |
| | | // MySQL 䏿´æ°è¡å·çåæ³ï¼å设indexNameæ¯èªå¢åï¼ |
| | | string updateQuery = string.Format(@" |
| | | SET @row_number = 0; |
| | | UPDATE `{0}` |
| | | SET `{1}` = @row_number := @row_number + 1 |
| | | ORDER BY `{1}`;", tableName, indexName); |
| | | |
| | | using (MySqlCommand cmd = new MySqlCommand(updateQuery, conn)) |
| | | { |
| | | cmd.ExecuteNonQuery(); |
| | | } |
| | | return true; |
| | | } |
| | | } |
| | | catch |
| | | { |
| | | return false; |
| | | } |
| | | } |
| | | |
| | | /// <summary> |
| | | /// äº¤æ¢æå®è¡çææå¼éè¿ç´¢å¼æå®åçæå®å¼ |
| | | /// </summary> |
| | | /// <param name="tableName">表å</param> |
| | | /// <param name="swapName">åå</param> |
| | | /// <param name="swapValue1">交æ¢çåå¼</param> |
| | | /// <param name="swapValue2">被交æ¢çåå¼</param> |
| | | /// <param name="connectionString"></param> |
| | | /// <returns>äº¤æ¢æåTrue</returns> |
| | | public static bool SwapRowFromIndexName(string tableName, string swapName, string swapValue1, string swapValue2, string connectionString = "") |
| | | { |
| | | if (string.IsNullOrEmpty(connectionString)) |
| | | connectionString = ConnectionString; |
| | | |
| | | using (MySqlConnection conn = new MySqlConnection(connectionString)) |
| | | { |
| | | conn.Open(); |
| | | |
| | | // å¼å§äºå¡ |
| | | MySqlTransaction transaction = conn.BeginTransaction(); |
| | | try |
| | | { |
| | | // MySQL 交æ¢è¡å¼çåæ³ |
| | | string swapQuery = string.Format(@" |
| | | UPDATE `{0}` |
| | | SET `{1}` = CASE |
| | | WHEN `{1}` = @SwapValue1 THEN @SwapTempValue |
| | | WHEN `{1}` = @SwapValue2 THEN @SwapValue1 |
| | | WHEN `{1}` = @SwapTempValue THEN @SwapValue2 |
| | | END |
| | | WHERE `{1}` IN (@SwapValue1, @SwapValue2, @SwapTempValue);", tableName, swapName); |
| | | |
| | | using (MySqlCommand cmd = new MySqlCommand(swapQuery, conn, transaction)) |
| | | { |
| | | // æ·»å åæ° |
| | | cmd.Parameters.AddWithValue("@SwapValue1", swapValue1); |
| | | cmd.Parameters.AddWithValue("@SwapValue2", swapValue2); |
| | | cmd.Parameters.AddWithValue("@SwapTempValue", Guid.NewGuid().ToString()); |
| | | |
| | | // æ§è¡æ¥è¯¢ |
| | | cmd.ExecuteNonQuery(); |
| | | } |
| | | |
| | | // æäº¤äºå¡ |
| | | transaction.Commit(); |
| | | return true; |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | Debug.WriteLine("交æ¢å¤±è´¥,åå æ¯:" + ex.Message.ToString()); |
| | | // åºç°å¼å¸¸æ¶åæ»äºå¡ |
| | | transaction.Rollback(); |
| | | return false; |
| | | } |
| | | } |
| | | } |
| | | |
| | | /// <summary> |
| | | /// æ´æ°æå®åçå¼éè¿ç´¢å¼æå®åçæå®å¼ |
| | | /// </summary> |
| | | /// <param name="tableName"></param> |
| | | /// <param name="oriValue"></param> |
| | | /// <param name="newValue"></param> |
| | | /// <param name="columnName"></param> |
| | | /// <param name="connectionString"></param> |
| | | /// <returns></returns> |
| | | public static bool UpdateValueFromIndexName(string tableName, string oriValue, string newValue, string columnName, string connectionString = "") |
| | | { |
| | | // ä¿®æ£åæ¹æ³åæ¼åé误 Updata -> Update |
| | | if (string.IsNullOrEmpty(connectionString)) |
| | | connectionString = ConnectionString; |
| | | |
| | | // MySQL æ´æ°è¯å¥ |
| | | string sqlQuery = string.Format("UPDATE `{0}` SET `{1}` = @NewValue WHERE `{1}` = @OriValue", tableName, columnName); |
| | | |
| | | // è¿æ¥æ°æ®åºå¹¶æ§è¡æ¥è¯¢ |
| | | using (MySqlConnection connection = new MySqlConnection(connectionString)) |
| | | { |
| | | using (MySqlCommand command = new MySqlCommand(sqlQuery, connection)) |
| | | { |
| | | // åæ°åæ¥è¯¢ï¼é²æ¢ SQL 注å
¥ |
| | | command.Parameters.AddWithValue("@OriValue", oriValue); // è¦æ¿æ¢çåå§å¼ |
| | | command.Parameters.AddWithValue("@NewValue", newValue); // æ¿æ¢åçæ°å¼ |
| | | |
| | | // æå¼è¿æ¥ |
| | | connection.Open(); |
| | | |
| | | // æ§è¡æ´æ°æä½ |
| | | int rowsAffected = command.ExecuteNonQuery(); |
| | | |
| | | return rowsAffected > 0; |
| | | } |
| | | } |
| | | } |
| | | |
| | | /// <summary> |
| | | /// æ£æ¥æ°æ®åºæ¯å¦åå¨ |
| | | /// </summary> |
| | | /// <param name="connectionString"></param> |
| | | /// <param name="databaseName"></param> |
| | | /// <returns></returns> |
| | | public static bool DatabaseExists(string connectionString, string databaseName) |
| | | { |
| | | string query = "SELECT SCHEMA_NAME FROM INFORMATION_SCHEMA.SCHEMATA WHERE SCHEMA_NAME = @databaseName"; |
| | | |
| | | using (MySqlConnection connection = new MySqlConnection(connectionString)) |
| | | { |
| | | connection.Open(); |
| | | using (MySqlCommand command = new MySqlCommand(query, connection)) |
| | | { |
| | | command.Parameters.AddWithValue("@databaseName", databaseName); |
| | | var result = command.ExecuteScalar(); |
| | | return result != null; |
| | | } |
| | | } |
| | | } |
| | | |
| | | /// <summary> |
| | | /// åå»ºæ°æ®åº |
| | | /// </summary> |
| | | /// <param name="connectionString"></param> |
| | | /// <param name="databaseName"></param> |
| | | /// <returns></returns> |
| | | public static bool CreateDatabase(string connectionString, string databaseName) |
| | | { |
| | | if (string.IsNullOrEmpty(connectionString)) |
| | | connectionString = ConnectionString; |
| | | |
| | | try |
| | | { |
| | | string createQuery = $"CREATE DATABASE IF NOT EXISTS `{databaseName}` CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci"; |
| | | |
| | | using (MySqlConnection connection = new MySqlConnection(connectionString)) |
| | | { |
| | | connection.Open(); |
| | | using (MySqlCommand command = new MySqlCommand(createQuery, connection)) |
| | | { |
| | | command.ExecuteNonQuery(); |
| | | } |
| | | } |
| | | return true; |
| | | } |
| | | catch |
| | | { |
| | | return false; |
| | | } |
| | | } |
| | | |
| | | /// <summary> |
| | | /// å 餿°æ®åº |
| | | /// </summary> |
| | | /// <param name="databaseName"></param> |
| | | /// <param name="connectionString"></param> |
| | | /// <returns></returns> |
| | | public static bool DeleteDatabase(string databaseName, string connectionString) |
| | | { |
| | | if (string.IsNullOrEmpty(connectionString)) |
| | | connectionString = ConnectionString; |
| | | |
| | | // MySQL å 餿°æ®åºè¯å¥ |
| | | string dropDatabaseQuery = $"DROP DATABASE IF EXISTS `{databaseName}`"; |
| | | |
| | | using (MySqlConnection connection = new MySqlConnection(connectionString)) |
| | | { |
| | | try |
| | | { |
| | | // æå¼æ°æ®åºè¿æ¥ |
| | | connection.Open(); |
| | | |
| | | // å建 MySqlCommand 对象 |
| | | using (MySqlCommand cmd = new MySqlCommand(dropDatabaseQuery, connection)) |
| | | { |
| | | // æ§è¡å 餿°æ®åºæä½ |
| | | cmd.ExecuteNonQuery(); |
| | | Debug.WriteLine("Database dropped successfully."); |
| | | return true; |
| | | } |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | Debug.WriteLine("Error: " + ex.Message); |
| | | return false; |
| | | } |
| | | } |
| | | } |
| | | |
| | | /// <summary> |
| | | /// å¤å¶è¡¨ç»æåæ°æ® |
| | | /// </summary> |
| | | /// <param name="connectionString"></param> |
| | | /// <param name="sourceDatabase"></param> |
| | | /// <param name="targetDatabase"></param> |
| | | /// <returns></returns> |
| | | public static bool CopyDatabaseData(string connectionString, string sourceDatabase, string targetDatabase) |
| | | { |
| | | if (string.IsNullOrEmpty(connectionString)) |
| | | connectionString = ConnectionString; |
| | | |
| | | try |
| | | { |
| | | // å
åå»ºç®æ æ°æ®åºï¼å¦æä¸åå¨ï¼ |
| | | CreateDatabase(connectionString, targetDatabase); |
| | | |
| | | using (var connection = new MySqlConnection(connectionString)) |
| | | { |
| | | connection.Open(); |
| | | |
| | | // è·åæºæ°æ®åºä¸ææè¡¨çå表 |
| | | string getTablesQuery = $"SELECT table_name FROM INFORMATION_SCHEMA.TABLES WHERE table_schema = @sourceDb"; |
| | | using (var cmd = new MySqlCommand(getTablesQuery, connection)) |
| | | { |
| | | cmd.Parameters.AddWithValue("@sourceDb", sourceDatabase); |
| | | using (var reader = cmd.ExecuteReader()) |
| | | { |
| | | while (reader.Read()) |
| | | { |
| | | string tableName = reader.GetString(0); |
| | | Debug.WriteLine($"å¤å¶è¡¨: {tableName}"); |
| | | |
| | | // å
³éreaderæè½æ§è¡åç»æä½ |
| | | reader.Close(); |
| | | |
| | | // å¤å¶è¡¨ç»æåæ°æ®ï¼MySQL ç®ååæ³ï¼ |
| | | string copyTableQuery = $"CREATE TABLE `{targetDatabase}`.`{tableName}` LIKE `{sourceDatabase}`.`{tableName}`; " + |
| | | $"INSERT INTO `{targetDatabase}`.`{tableName}` SELECT * FROM `{sourceDatabase}`.`{tableName}`;"; |
| | | |
| | | using (var cmdCopy = new MySqlCommand(copyTableQuery, connection)) |
| | | { |
| | | cmdCopy.ExecuteNonQuery(); |
| | | } |
| | | |
| | | // éæ°æå¼readerç»§ç»è¯»åä¸ä¸ä¸ªè¡¨ |
| | | reader.NextResult(); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | return true; |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | Debug.WriteLine($"å¤å¶å¤±è´¥: {ex.Message}"); |
| | | return false; |
| | | } |
| | | } |
| | | |
| | | /// <summary> |
| | | /// è·åç¨æ·æ°æ®åºå表 |
| | | /// </summary> |
| | | /// <returns></returns> |
| | | public static List<string> GetUserDatabases() |
| | | { |
| | | List<string> databases = new List<string>(); |
| | | string connectionString = "Server=localhost;Database=user_pt;Uid=root;Pwd=root;"; |
| | | |
| | | using (MySqlConnection connection = new MySqlConnection(connectionString)) |
| | | { |
| | | try |
| | | { |
| | | connection.Open(); |
| | | string query = @" |
| | | SELECT SCHEMA_NAME |
| | | FROM INFORMATION_SCHEMA.SCHEMATA |
| | | WHERE SCHEMA_NAME NOT IN ('mysql', 'information_schema', 'performance_schema', 'sys')"; |
| | | |
| | | using (MySqlCommand command = new MySqlCommand(query, connection)) |
| | | using (MySqlDataReader reader = command.ExecuteReader()) |
| | | { |
| | | while (reader.Read()) |
| | | { |
| | | databases.Add(reader["SCHEMA_NAME"]?.ToString()); |
| | | } |
| | | } |
| | | } |
| | | catch (MySqlException ex) |
| | | { |
| | | Debug.WriteLine($"æ°æ®åºæ¥è¯¢å¤±è´¥: {ex.Message}"); |
| | | } |
| | | } |
| | | return databases; |
| | | } |
| | | } |
| | | } |
| ¶Ô±ÈÐÂÎļþ |
| | |
| | | using LB_SmartVisionCommon; |
| | | using Newtonsoft.Json; |
| | | using System; |
| | | using System.Collections.Generic; |
| | | using System.ComponentModel; |
| | | using System.Linq; |
| | | using System.Text; |
| | | using System.Threading.Tasks; |
| | | |
| | | namespace LB_SmartVision.SQL |
| | | { |
| | | /// <summary> |
| | | /// è®°å½çäº§æ°æ® |
| | | /// </summary> |
| | | [JsonObject(MemberSerialization.OptOut)] |
| | | [TypeConverter(typeof(PropertySorter))] |
| | | public class RecordProductData |
| | | { |
| | | /// <summary> |
| | | /// SKU ç©æå·æäº§ååç§° |
| | | /// </summary> |
| | | [Category("RecordProductData"), PropertyOrder(0)] |
| | | [DisplayName("SKU")] |
| | | [Browsable(true)] |
| | | public string ProductName { get; set; } |
| | | |
| | | /// <summary> |
| | | /// 产åSNå· |
| | | /// </summary> |
| | | [Category("RecordProductData"), PropertyOrder(1)] |
| | | [DisplayName("SN")] |
| | | [Browsable(true)] |
| | | public string ProductSN { get; set; } |
| | | |
| | | /// <summary> |
| | | /// æ£æµä½ä¸å |
| | | /// </summary> |
| | | [Category("RecordProductData"), PropertyOrder(2)] |
| | | [DisplayName("æ£æµä½ä¸å")] |
| | | [Browsable(true)] |
| | | public string InspectionOperator { get; set; } |
| | | |
| | | /// <summary> |
| | | /// NGç±»å |
| | | /// </summary> |
| | | [Category("RecordProductData"), PropertyOrder(3)] |
| | | [DisplayName("NGç±»å")] |
| | | [Browsable(true)] |
| | | public string NGType { get; set; } |
| | | |
| | | /// <summary> |
| | | /// NGå¤§å° |
| | | /// </summary> |
| | | [Category("RecordProductData"), PropertyOrder(4)] |
| | | [DisplayName("NG大å°")] |
| | | [Browsable(true)] |
| | | public string NGSize { get; set; } |
| | | |
| | | /// <summary> |
| | | /// æ£æµæ¶é´ |
| | | /// </summary> |
| | | [Category("RecordProductData"), PropertyOrder(5)] |
| | | [DisplayName("æ£æµæ¶é´")] |
| | | [Browsable(true)] |
| | | public string DetectionTime { get; set; } |
| | | |
| | | /// <summary> |
| | | /// æ£æµç¸æº |
| | | /// </summary> |
| | | [Category("RecordProductData"), PropertyOrder(6)] |
| | | [DisplayName("æ£æµç¸æº")] |
| | | [Browsable(true)] |
| | | public string CameraInspection { get; set; } |
| | | } |
| | | } |
| ¶Ô±ÈÐÂÎļþ |
| | |
| | | using LB_SmartVisionCommon; |
| | | using MySql.Data.MySqlClient; |
| | | using System; |
| | | using System.Collections.Generic; |
| | | using System.Diagnostics; |
| | | using System.Linq; |
| | | using System.Text; |
| | | using System.Threading.Tasks; |
| | | |
| | | namespace LB_SmartVision.SQL |
| | | { |
| | | /// <summary> |
| | | /// æ°æ®è®¿é®å± |
| | | /// </summary> |
| | | public class RecordProductDataRepository |
| | | { |
| | | private static object recordProductDataRepositoryObject = new object(); |
| | | /// <summary> |
| | | /// æ·»å æ°æ® |
| | | /// </summary> |
| | | /// <param name="record">çäº§æ°æ®è®°å½</param> |
| | | /// <returns>æ¯å¦æ·»å æå</returns> |
| | | public static bool AddRecord(RecordProductData record) |
| | | { |
| | | Stopwatch stopwatch = Stopwatch.StartNew(); |
| | | lock (recordProductDataRepositoryObject) |
| | | { |
| | | stopwatch.Start(); |
| | | try |
| | | { |
| | | using (var connection = DatabaseRecordProductDataHelper.GetConnection()) |
| | | { |
| | | connection.Open(); |
| | | string sql = @" |
| | | INSERT INTO RecordProductData |
| | | (ProductName, ProductSN, InspectionOperator, NGType, NGSize,DetectionTime,CameraInspection) |
| | | VALUES |
| | | (@ProductName, @ProductSN, @InspectionOperator, @NGType, @NGSize, @DetectionTime, @CameraInspection)"; |
| | | using (var cmd = new MySqlCommand(sql, connection)) |
| | | { |
| | | cmd.Parameters.AddWithValue("@ProductName", record.ProductName); |
| | | cmd.Parameters.AddWithValue("@ProductSN", record.ProductSN); |
| | | cmd.Parameters.AddWithValue("@InspectionOperator", record.InspectionOperator); |
| | | cmd.Parameters.AddWithValue("@NGType", record.NGType); |
| | | cmd.Parameters.AddWithValue("@NGSize", record.NGSize); |
| | | cmd.Parameters.AddWithValue("@DetectionTime", record.DetectionTime); |
| | | cmd.Parameters.AddWithValue("@CameraInspection", record.CameraInspection); |
| | | int rowsAffected = cmd.ExecuteNonQuery(); |
| | | stopwatch.Stop(); |
| | | Task.Factory.StartNew(() => |
| | | { |
| | | LogHelper.Info($"æ·»å ä¿¡æ¯èæ¶: {stopwatch.ElapsedMilliseconds}ms"); |
| | | }); |
| | | return rowsAffected > 0; |
| | | } |
| | | } |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | AsyncLogHelper.Error($"æ·»å è®°å½å¤±è´¥: {ex.Message}"); |
| | | return false; |
| | | } |
| | | } |
| | | } |
| | | /// <summary> |
| | | /// æ¥è¯¢æææ°æ® |
| | | /// </summary> |
| | | /// <returns>List<RecordProductData></returns> |
| | | public static List<RecordProductData> GetAllRecords() |
| | | { |
| | | lock (recordProductDataRepositoryObject) |
| | | { |
| | | var records = new List<RecordProductData>(); |
| | | try |
| | | { |
| | | using (var connection = DatabaseRecordProductDataHelper.GetConnection()) |
| | | { |
| | | connection.Open(); |
| | | string sql = "SELECT * FROM RecordProductData ORDER BY CreatedDate DESC"; |
| | | using (var cmd = new MySqlCommand(sql, connection)) |
| | | using (var reader = cmd.ExecuteReader()) |
| | | { |
| | | while (reader.Read()) |
| | | { |
| | | records.Add(MapReaderToRecord(reader)); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | AsyncLogHelper.Error($"æ¥è¯¢è®°å½å¤±è´¥: {ex.Message}"); |
| | | } |
| | | return records; |
| | | } |
| | | } |
| | | /// <summary> |
| | | /// æ ¹æ®äº§åç¼å·æ¥è¯¢ |
| | | /// </summary> |
| | | /// <param name="productSN">产åç¼å·</param> |
| | | /// <returns>List<RecordProductData></returns> |
| | | public static List<RecordProductData> GetRecordsByProductNumber(string productSN) |
| | | { |
| | | lock (recordProductDataRepositoryObject) |
| | | { |
| | | var records = new List<RecordProductData>(); |
| | | try |
| | | { |
| | | using (var connection = DatabaseRecordProductDataHelper.GetConnection()) |
| | | { |
| | | connection.Open(); |
| | | string sql = "SELECT * FROM RecordProductData WHERE productSN = @productSN ORDER BY CreatedDate DESC"; |
| | | using (var cmd = new MySqlCommand(sql, connection)) |
| | | { |
| | | cmd.Parameters.AddWithValue("@productSN", productSN); |
| | | using (var reader = cmd.ExecuteReader()) |
| | | { |
| | | while (reader.Read()) |
| | | { |
| | | records.Add(MapReaderToRecord(reader)); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | AsyncLogHelper.Error($"æ ¹æ®äº§åç¼å·æ¥è¯¢å¤±è´¥: {ex.Message}"); |
| | | } |
| | | return records; |
| | | } |
| | | } |
| | | /// <summary> |
| | | /// æ ¹æ®æä½è
æ¥è¯¢ |
| | | /// </summary> |
| | | /// <param name="inspectionOperator">æä½è
</param> |
| | | /// <returns>List<RecordProductData></returns> |
| | | public static List<RecordProductData> GetRecordsByOperator(string inspectionOperator) |
| | | { |
| | | lock (recordProductDataRepositoryObject) |
| | | { |
| | | var records = new List<RecordProductData>(); |
| | | try |
| | | { |
| | | using (var connection = DatabaseRecordProductDataHelper.GetConnection()) |
| | | { |
| | | connection.Open(); |
| | | string sql = "SELECT * FROM RecordProductData WHERE InspectionOperator = @InspectionOperator ORDER BY CreatedDate DESC"; |
| | | using (var cmd = new MySqlCommand(sql, connection)) |
| | | { |
| | | cmd.Parameters.AddWithValue("@InspectionOperator", inspectionOperator); |
| | | using (var reader = cmd.ExecuteReader()) |
| | | { |
| | | while (reader.Read()) |
| | | { |
| | | records.Add(MapReaderToRecord(reader)); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | AsyncLogHelper.Error($"æ ¹æ®æä½è
æ¥è¯¢å¤±è´¥: {ex.Message}"); |
| | | } |
| | | return records; |
| | | } |
| | | } |
| | | /// <summary> |
| | | /// æ ¹æ®æ¶é´æ®µæ¥è¯¢ - 使ç¨CreatedDate |
| | | /// </summary> |
| | | /// <param name="startTime">èµ·å§æ¶é´</param> |
| | | /// <param name="endTime">ç»ææ¶é´</param> |
| | | /// <returns>List<RecordProductData></returns> |
| | | public static List<RecordProductData> GetRecordsByTimeRange(DateTime startTime, DateTime endTime) |
| | | { |
| | | lock (recordProductDataRepositoryObject) |
| | | { |
| | | var records = new List<RecordProductData>(); |
| | | try |
| | | { |
| | | using (var connection = DatabaseRecordProductDataHelper.GetConnection()) |
| | | { |
| | | connection.Open(); |
| | | string sql = @" |
| | | SELECT * FROM RecordProductData |
| | | WHERE CreatedDate BETWEEN @StartTime AND @EndTime |
| | | ORDER BY CreatedDate DESC"; |
| | | using (var cmd = new MySqlCommand(sql, connection)) |
| | | { |
| | | cmd.Parameters.AddWithValue("@StartTime", startTime); |
| | | cmd.Parameters.AddWithValue("@EndTime", endTime.AddDays(1).AddSeconds(-1)); // å
å«ç»ææ¥æçå
¨å¤© |
| | | using (var reader = cmd.ExecuteReader()) |
| | | { |
| | | while (reader.Read()) |
| | | { |
| | | records.Add(MapReaderToRecord(reader)); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | AsyncLogHelper.Error($"æ ¹æ®æ¶é´æ®µæ¥è¯¢å¤±è´¥: {ex.Message}"); |
| | | } |
| | | return records; |
| | | } |
| | | } |
| | | |
| | | /// <summary> |
| | | /// ç»åæ¥è¯¢ï¼äº§åç¼å· + æ¶é´æ®µ |
| | | /// </summary> |
| | | /// <param name="productSN">产åç¼å·</param> |
| | | /// <param name="startTime">èµ·å§æ¶é´</param> |
| | | /// <param name="endTime">ç»ææ¶é´</param> |
| | | /// <returns>List<RecordProductData></returns> |
| | | public static List<RecordProductData> GetRecordsByProductAndTimeRange(string productSN, DateTime startTime, DateTime endTime) |
| | | { |
| | | lock (recordProductDataRepositoryObject) |
| | | { |
| | | var records = new List<RecordProductData>(); |
| | | try |
| | | { |
| | | using (var connection = DatabaseRecordProductDataHelper.GetConnection()) |
| | | { |
| | | connection.Open(); |
| | | string sql = @" |
| | | SELECT * FROM RecordProductData |
| | | WHERE productSN = @productSN |
| | | AND CreatedDate BETWEEN @StartTime AND @EndTime |
| | | ORDER BY CreatedDate DESC"; |
| | | using (var cmd = new MySqlCommand(sql, connection)) |
| | | { |
| | | cmd.Parameters.AddWithValue("@productSN", productSN); |
| | | cmd.Parameters.AddWithValue("@StartTime", startTime); |
| | | cmd.Parameters.AddWithValue("@EndTime", endTime.AddDays(1).AddSeconds(-1)); |
| | | using (var reader = cmd.ExecuteReader()) |
| | | { |
| | | while (reader.Read()) |
| | | { |
| | | records.Add(MapReaderToRecord(reader)); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | AsyncLogHelper.Error($"ç»åæ¥è¯¢å¤±è´¥: {ex.Message}"); |
| | | } |
| | | return records; |
| | | } |
| | | } |
| | | /// <summary> |
| | | /// ç»åæ¥è¯¢ï¼æä½è
+ æ¶é´æ®µ |
| | | /// </summary> |
| | | /// <param name="inspectionOperator">æä½è
</param> |
| | | /// <param name="startTime">èµ·å§æ¶é´</param> |
| | | /// <param name="endTime">ç»ææ¶é´</param> |
| | | /// <returns>List<RecordProductData></returns> |
| | | public static List<RecordProductData> GetRecordsByOperatorAndTimeRange(string inspectionOperator, DateTime startTime, DateTime endTime) |
| | | { |
| | | lock (recordProductDataRepositoryObject) |
| | | { |
| | | var records = new List<RecordProductData>(); |
| | | try |
| | | { |
| | | using (var connection = DatabaseRecordProductDataHelper.GetConnection()) |
| | | { |
| | | connection.Open(); |
| | | string sql = @" |
| | | SELECT * FROM RecordProductData |
| | | WHERE InspectionOperator = @InspectionOperator |
| | | AND CreatedDate BETWEEN @StartTime AND @EndTime |
| | | ORDER BY CreatedDate DESC"; |
| | | using (var cmd = new MySqlCommand(sql, connection)) |
| | | { |
| | | cmd.Parameters.AddWithValue("@InspectionOperator", inspectionOperator); |
| | | cmd.Parameters.AddWithValue("@StartTime", startTime); |
| | | cmd.Parameters.AddWithValue("@EndTime", endTime.AddDays(1).AddSeconds(-1)); |
| | | using (var reader = cmd.ExecuteReader()) |
| | | { |
| | | while (reader.Read()) |
| | | { |
| | | records.Add(MapReaderToRecord(reader)); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | AsyncLogHelper.Error($"ç»åæ¥è¯¢å¤±è´¥: {ex.Message}"); |
| | | } |
| | | return records; |
| | | } |
| | | } |
| | | /// <summary> |
| | | /// é«çº§ç»åæ¥è¯¢ï¼æ¯æå¤ä¸ªæ¡ä»¶ |
| | | /// </summary> |
| | | /// <param name="productSN">产åç¼å·</param> |
| | | /// <param name="operatorName">æä½è
</param> |
| | | /// <param name="startTime">èµ·å§æ¶é´</param> |
| | | /// <param name="endTime">ç»ææ¶é´</param> |
| | | /// <returns>List<RecordProductData></returns> |
| | | public static List<RecordProductData> GetRecordsByMultipleConditions( |
| | | string productSN = null, |
| | | string operatorName = null, |
| | | DateTime? startTime = null, |
| | | DateTime? endTime = null) |
| | | { |
| | | lock (recordProductDataRepositoryObject) |
| | | { |
| | | var records = new List<RecordProductData>(); |
| | | try |
| | | { |
| | | using (var connection = DatabaseRecordProductDataHelper.GetConnection()) |
| | | { |
| | | connection.Open(); |
| | | var sql = "SELECT * FROM RecordProductData WHERE 1=1"; |
| | | var parameters = new List<MySqlParameter>(); |
| | | if (!string.IsNullOrEmpty(productSN)) |
| | | { |
| | | sql += " AND ProductSN = @ProductSN"; |
| | | parameters.Add(new MySqlParameter("@ProductSN", productSN)); |
| | | } |
| | | if (!string.IsNullOrEmpty(operatorName)) |
| | | { |
| | | sql += " AND MeasurementOperator = @InspectionOperator"; |
| | | parameters.Add(new MySqlParameter("@InspectionOperator", operatorName)); |
| | | } |
| | | if (startTime.HasValue) |
| | | { |
| | | sql += " AND CreatedDate >= @StartTime"; |
| | | parameters.Add(new MySqlParameter("@StartTime", startTime.Value)); |
| | | } |
| | | if (endTime.HasValue) |
| | | { |
| | | sql += " AND CreatedDate <= @EndTime"; |
| | | parameters.Add(new MySqlParameter("@EndTime", endTime.Value.AddDays(1).AddSeconds(-1))); |
| | | } |
| | | sql += " ORDER BY CreatedDate DESC"; |
| | | using (var cmd = new MySqlCommand(sql, connection)) |
| | | { |
| | | foreach (var param in parameters) |
| | | { |
| | | cmd.Parameters.Add(param); |
| | | } |
| | | using (var reader = cmd.ExecuteReader()) |
| | | { |
| | | while (reader.Read()) |
| | | { |
| | | records.Add(MapReaderToRecord(reader)); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | AsyncLogHelper.Error($"é«çº§ç»åæ¥è¯¢å¤±è´¥: {ex.Message}"); |
| | | } |
| | | return records; |
| | | } |
| | | } |
| | | /// <summary> |
| | | /// ç»è®¡æ¥è¯¢ï¼è·åæä¸ªæ¶é´æ®µå
çè®°å½æ°é |
| | | /// </summary> |
| | | /// <param name="startTime">èµ·å§æ¶é´</param> |
| | | /// <param name="endTime">ç»ææ¶é´</param> |
| | | /// <returns>è®°å½æ°é</returns> |
| | | public static int GetRecordCountByTimeRange(DateTime startTime, DateTime endTime) |
| | | { |
| | | lock (recordProductDataRepositoryObject) |
| | | { |
| | | try |
| | | { |
| | | using (var connection = DatabaseRecordProductDataHelper.GetConnection()) |
| | | { |
| | | connection.Open(); |
| | | string sql = @" |
| | | SELECT COUNT(*) FROM RecordProductData |
| | | WHERE CreatedDate BETWEEN @StartTime AND @EndTime"; |
| | | using (var cmd = new MySqlCommand(sql, connection)) |
| | | { |
| | | cmd.Parameters.AddWithValue("@StartTime", startTime); |
| | | cmd.Parameters.AddWithValue("@EndTime", endTime.AddDays(1).AddSeconds(-1)); |
| | | return Convert.ToInt32(cmd.ExecuteScalar()); |
| | | } |
| | | } |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | AsyncLogHelper.Error($"ç»è®¡æ¥è¯¢å¤±è´¥: {ex.Message}"); |
| | | return 0; |
| | | } |
| | | } |
| | | } |
| | | /// <summary> |
| | | /// è¾
婿¹æ³ï¼å°æ°æ®è¯»å卿 å°å°RecordProductData对象 |
| | | /// </summary> |
| | | /// <param name="reader">MySqlDataReader reader</param> |
| | | /// <returns>RecordProductData</returns> |
| | | private static RecordProductData MapReaderToRecord(MySqlDataReader reader) |
| | | { |
| | | return new RecordProductData |
| | | { |
| | | ProductName = reader["ProductName"]?.ToString() ?? string.Empty, |
| | | ProductSN = reader["ProductSN"]?.ToString() ?? string.Empty, |
| | | InspectionOperator = reader["InspectionOperator"]?.ToString() ?? string.Empty, |
| | | NGType = reader["NGType"]?.ToString() ?? string.Empty, |
| | | NGSize = reader["NGSize"]?.ToString() ?? string.Empty, |
| | | DetectionTime = reader["DetectionTime"]?.ToString() ?? string.Empty, |
| | | CameraInspection = reader["CameraInspection"]?.ToString() ?? string.Empty, |
| | | }; |
| | | } |
| | | } |
| | | } |
| | |
| | | theme_VisionForm.Font = new Font("Microsoft YaHei UI", 12F, FontStyle.Regular, GraphicsUnit.Point, 0); |
| | | theme_VisionForm.Image = (Image)resources.GetObject("theme_VisionForm.Image"); |
| | | theme_VisionForm.Location = new Point(0, 0); |
| | | theme_VisionForm.Margin = new Padding(4); |
| | | theme_VisionForm.Name = "theme_VisionForm"; |
| | | theme_VisionForm.Padding = new Padding(12, 88, 12, 11); |
| | | theme_VisionForm.Padding = new Padding(10, 70, 10, 9); |
| | | theme_VisionForm.RoundCorners = true; |
| | | theme_VisionForm.Sizable = true; |
| | | theme_VisionForm.Size = new Size(1440, 880); |
| | | theme_VisionForm.Size = new Size(1152, 704); |
| | | theme_VisionForm.SmartBounds = true; |
| | | theme_VisionForm.StartPosition = FormStartPosition.WindowsDefaultLocation; |
| | | theme_VisionForm.TabIndex = 0; |
| | |
| | | // |
| | | sc_VisionForm.Dock = DockStyle.Fill; |
| | | sc_VisionForm.FixedPanel = FixedPanel.Panel2; |
| | | sc_VisionForm.Location = new Point(12, 88); |
| | | sc_VisionForm.Margin = new Padding(4); |
| | | sc_VisionForm.Location = new Point(10, 70); |
| | | sc_VisionForm.Name = "sc_VisionForm"; |
| | | sc_VisionForm.Orientation = Orientation.Horizontal; |
| | | // |
| | |
| | | // sc_VisionForm.Panel2 |
| | | // |
| | | sc_VisionForm.Panel2.Controls.Add(grb_Info); |
| | | sc_VisionForm.Size = new Size(1416, 781); |
| | | sc_VisionForm.SplitterDistance = 593; |
| | | sc_VisionForm.SplitterWidth = 5; |
| | | sc_VisionForm.Size = new Size(1132, 625); |
| | | sc_VisionForm.SplitterDistance = 476; |
| | | sc_VisionForm.TabIndex = 1; |
| | | // |
| | | // tlp_MainView |
| | |
| | | tlp_MainView.Margin = new Padding(2); |
| | | tlp_MainView.Name = "tlp_MainView"; |
| | | tlp_MainView.RowCount = 3; |
| | | tlp_MainView.RowStyles.Add(new RowStyle(SizeType.Absolute, 60F)); |
| | | tlp_MainView.RowStyles.Add(new RowStyle(SizeType.Absolute, 39F)); |
| | | tlp_MainView.RowStyles.Add(new RowStyle(SizeType.Absolute, 48F)); |
| | | tlp_MainView.RowStyles.Add(new RowStyle(SizeType.Absolute, 31F)); |
| | | tlp_MainView.RowStyles.Add(new RowStyle(SizeType.Percent, 100F)); |
| | | tlp_MainView.Size = new Size(1416, 593); |
| | | tlp_MainView.Size = new Size(1132, 476); |
| | | tlp_MainView.TabIndex = 1; |
| | | tlp_MainView.TagString = null; |
| | | // |
| | |
| | | materialTabControl.AccessibleRole = AccessibleRole.Sound; |
| | | materialTabControl.Depth = 0; |
| | | materialTabControl.Dock = DockStyle.Fill; |
| | | materialTabControl.Location = new Point(2, 101); |
| | | materialTabControl.Location = new Point(2, 81); |
| | | materialTabControl.Margin = new Padding(2); |
| | | materialTabControl.MouseState = MaterialSkin.MouseState.HOVER; |
| | | materialTabControl.Name = "materialTabControl"; |
| | | materialTabControl.SelectedIndex = 0; |
| | | materialTabControl.Size = new Size(1412, 490); |
| | | materialTabControl.Size = new Size(1128, 393); |
| | | materialTabControl.TabIndex = 0; |
| | | // |
| | | // tlp_VisionMainOperator |
| | |
| | | tlp_VisionMainOperator.Controls.Add(btn_GlobalVar, 7, 0); |
| | | tlp_VisionMainOperator.Controls.Add(com_ProductName, 8, 0); |
| | | tlp_VisionMainOperator.Dock = DockStyle.Fill; |
| | | tlp_VisionMainOperator.Location = new Point(4, 64); |
| | | tlp_VisionMainOperator.Margin = new Padding(4); |
| | | tlp_VisionMainOperator.Location = new Point(3, 51); |
| | | tlp_VisionMainOperator.Name = "tlp_VisionMainOperator"; |
| | | tlp_VisionMainOperator.RowCount = 1; |
| | | tlp_VisionMainOperator.RowStyles.Add(new RowStyle(SizeType.Percent, 100F)); |
| | | tlp_VisionMainOperator.Size = new Size(1408, 31); |
| | | tlp_VisionMainOperator.Size = new Size(1126, 25); |
| | | tlp_VisionMainOperator.TabIndex = 0; |
| | | tlp_VisionMainOperator.TagString = null; |
| | | // |
| | | // ckb_AllowRun |
| | | // |
| | | ckb_AllowRun.Dock = DockStyle.Fill; |
| | | ckb_AllowRun.Font = new Font("å®ä½", 12F, FontStyle.Regular, GraphicsUnit.Point, 134); |
| | | ckb_AllowRun.Font = new Font("å®ä½", 10.5F, FontStyle.Regular, GraphicsUnit.Point, 134); |
| | | ckb_AllowRun.ForeColor = SystemColors.Control; |
| | | ckb_AllowRun.Location = new Point(4, 4); |
| | | ckb_AllowRun.Margin = new Padding(4); |
| | | ckb_AllowRun.Location = new Point(3, 3); |
| | | ckb_AllowRun.MinimumSize = new Size(1, 1); |
| | | ckb_AllowRun.Name = "ckb_AllowRun"; |
| | | ckb_AllowRun.Size = new Size(148, 23); |
| | | ckb_AllowRun.Size = new Size(119, 19); |
| | | ckb_AllowRun.TabIndex = 2; |
| | | ckb_AllowRun.Text = "è¿è¡æ¨¡å¼"; |
| | | // |
| | |
| | | btn_Login.Dock = DockStyle.Fill; |
| | | btn_Login.EnteredBorderColor = Color.FromArgb(165, 37, 37); |
| | | btn_Login.EnteredColor = Color.FromArgb(32, 34, 37); |
| | | btn_Login.Font = new Font("Microsoft Sans Serif", 12F); |
| | | btn_Login.Font = new Font("å®ä½", 10.5F, FontStyle.Regular, GraphicsUnit.Point, 134); |
| | | btn_Login.Image = null; |
| | | btn_Login.ImageAlign = ContentAlignment.MiddleLeft; |
| | | btn_Login.InactiveColor = Color.FromArgb(32, 34, 37); |
| | | btn_Login.Location = new Point(160, 4); |
| | | btn_Login.Margin = new Padding(4); |
| | | btn_Login.Location = new Point(128, 3); |
| | | btn_Login.Name = "btn_Login"; |
| | | btn_Login.PressedBorderColor = Color.FromArgb(165, 37, 37); |
| | | btn_Login.PressedColor = Color.FromArgb(165, 37, 37); |
| | | btn_Login.Size = new Size(148, 23); |
| | | btn_Login.Size = new Size(119, 19); |
| | | btn_Login.TabIndex = 3; |
| | | btn_Login.Text = "ç¨æ·ç»å½"; |
| | | btn_Login.TextAlignment = StringAlignment.Center; |
| | |
| | | btn_GlobalVar.Dock = DockStyle.Fill; |
| | | btn_GlobalVar.EnteredBorderColor = Color.FromArgb(165, 37, 37); |
| | | btn_GlobalVar.EnteredColor = Color.FromArgb(32, 34, 37); |
| | | btn_GlobalVar.Font = new Font("Microsoft Sans Serif", 12F); |
| | | btn_GlobalVar.Font = new Font("å®ä½", 10.5F, FontStyle.Regular, GraphicsUnit.Point, 0); |
| | | btn_GlobalVar.Image = null; |
| | | btn_GlobalVar.ImageAlign = ContentAlignment.MiddleLeft; |
| | | btn_GlobalVar.InactiveColor = Color.FromArgb(32, 34, 37); |
| | | btn_GlobalVar.Location = new Point(1096, 4); |
| | | btn_GlobalVar.Margin = new Padding(4); |
| | | btn_GlobalVar.Location = new Point(878, 3); |
| | | btn_GlobalVar.Name = "btn_GlobalVar"; |
| | | btn_GlobalVar.PressedBorderColor = Color.FromArgb(165, 37, 37); |
| | | btn_GlobalVar.PressedColor = Color.FromArgb(165, 37, 37); |
| | | btn_GlobalVar.Size = new Size(148, 23); |
| | | btn_GlobalVar.Size = new Size(119, 19); |
| | | btn_GlobalVar.TabIndex = 4; |
| | | btn_GlobalVar.Text = "å
¨å±åé"; |
| | | btn_GlobalVar.TextAlignment = StringAlignment.Center; |
| | |
| | | com_ProductName.DrawMode = DrawMode.OwnerDrawFixed; |
| | | com_ProductName.DropDownStyle = ComboBoxStyle.DropDownList; |
| | | com_ProductName.EnabledCalc = true; |
| | | com_ProductName.Font = new Font("å®ä½", 10.5F, FontStyle.Regular, GraphicsUnit.Point, 134); |
| | | com_ProductName.FormattingEnabled = true; |
| | | com_ProductName.ItemHeight = 20; |
| | | com_ProductName.Location = new Point(1252, 4); |
| | | com_ProductName.Margin = new Padding(4); |
| | | com_ProductName.Location = new Point(1003, 3); |
| | | com_ProductName.Name = "com_ProductName"; |
| | | com_ProductName.Size = new Size(152, 26); |
| | | com_ProductName.Size = new Size(120, 26); |
| | | com_ProductName.TabIndex = 5; |
| | | com_ProductName.SelectedValueChanged += com_ProductName_SelectedValueChanged; |
| | | // |
| | |
| | | materialTabSelector.BaseTabControl = null; |
| | | materialTabSelector.Depth = 0; |
| | | materialTabSelector.Dock = DockStyle.Fill; |
| | | materialTabSelector.Location = new Point(4, 4); |
| | | materialTabSelector.Margin = new Padding(4); |
| | | materialTabSelector.Location = new Point(3, 3); |
| | | materialTabSelector.MouseState = MaterialSkin.MouseState.HOVER; |
| | | materialTabSelector.Name = "materialTabSelector"; |
| | | materialTabSelector.Size = new Size(1408, 52); |
| | | materialTabSelector.Size = new Size(1126, 42); |
| | | materialTabSelector.TabIndex = 1; |
| | | // |
| | | // grb_Info |
| | |
| | | grb_Info.Font = new Font("å®ä½", 12F, FontStyle.Regular, GraphicsUnit.Point, 134); |
| | | grb_Info.ForeColor = SystemColors.Control; |
| | | grb_Info.Location = new Point(0, 0); |
| | | grb_Info.Margin = new Padding(5, 6, 5, 6); |
| | | grb_Info.Margin = new Padding(4, 5, 4, 5); |
| | | grb_Info.MinimumSize = new Size(1, 1); |
| | | grb_Info.Name = "grb_Info"; |
| | | grb_Info.Padding = new Padding(0, 40, 0, 0); |
| | | grb_Info.Size = new Size(1416, 183); |
| | | grb_Info.Padding = new Padding(0, 32, 0, 0); |
| | | grb_Info.Size = new Size(1132, 145); |
| | | grb_Info.TabIndex = 1; |
| | | grb_Info.Text = "æ¥å¿æ¾ç¤ºåºï¼"; |
| | | grb_Info.TextAlignment = ContentAlignment.MiddleLeft; |
| | |
| | | rich_Info.Dock = DockStyle.Fill; |
| | | rich_Info.FillColor = Color.FromArgb(32, 41, 50); |
| | | rich_Info.Font = new Font("å®ä½", 12F, FontStyle.Regular, GraphicsUnit.Point, 134); |
| | | rich_Info.Location = new Point(0, 40); |
| | | rich_Info.Location = new Point(0, 32); |
| | | rich_Info.Margin = new Padding(4, 5, 4, 5); |
| | | rich_Info.MinimumSize = new Size(1, 1); |
| | | rich_Info.Name = "rich_Info"; |
| | | rich_Info.Padding = new Padding(2); |
| | | rich_Info.ShowText = false; |
| | | rich_Info.Size = new Size(1416, 143); |
| | | rich_Info.Size = new Size(1132, 113); |
| | | rich_Info.TabIndex = 0; |
| | | rich_Info.TextAlignment = ContentAlignment.MiddleLeft; |
| | | // |
| | |
| | | cb_VisionForm.EnableMaximizeButton = true; |
| | | cb_VisionForm.EnableMinimizeButton = true; |
| | | cb_VisionForm.ForeColor = Color.FromArgb(155, 155, 155); |
| | | cb_VisionForm.Location = new Point(1315, 18); |
| | | cb_VisionForm.Margin = new Padding(4); |
| | | cb_VisionForm.Location = new Point(1072, 14); |
| | | cb_VisionForm.MaximizeHoverColor = Color.FromArgb(74, 74, 74); |
| | | cb_VisionForm.MinimizeHoverColor = Color.FromArgb(63, 63, 65); |
| | | cb_VisionForm.Name = "cb_VisionForm"; |
| | |
| | | // |
| | | // VisionForm |
| | | // |
| | | AutoScaleDimensions = new SizeF(120F, 120F); |
| | | AutoScaleDimensions = new SizeF(96F, 96F); |
| | | AutoScaleMode = AutoScaleMode.Dpi; |
| | | ClientSize = new Size(1440, 880); |
| | | ClientSize = new Size(1152, 704); |
| | | Controls.Add(theme_VisionForm); |
| | | FormBorderStyle = FormBorderStyle.None; |
| | | Icon = (Icon)resources.GetObject("$this.Icon"); |
| | | Margin = new Padding(4); |
| | | MinimumSize = new Size(326, 76); |
| | | MinimumSize = new Size(261, 61); |
| | | Name = "VisionForm"; |
| | | Text = "è½®èå¤è§è§è§æ£æµç³»ç»"; |
| | | TransparencyKey = Color.Fuchsia; |
| | |
| | | using LB_VisionProcesses.Cameras.HRCameras; |
| | | using LB_VisionProcesses.Cameras.LBCameras; |
| | | using LB_VisionProcesses.Communicators; |
| | | using LB_VisionProcesses.Communicators.SiemensS7; |
| | | using LB_VisionProcesses.Communicators.TCom; |
| | | using LB_VisionProcesses.Forms; |
| | | using log4net.Config; |
| | |
| | | { |
| | | string CommunicatorName = CommunicatorConnectionString.Key; |
| | | string CommunicatorAddress = CommunicatorConnectionString.Value; |
| | | if (!string.IsNullOrEmpty(CommunicatorAddress) && CommunicatorAddress.Contains("SiemensLBS7")) |
| | | { |
| | | // å®ä¹æ£å表达å¼ä»¥æååè®®ãIP å°ååç«¯å£ |
| | | //1. \((.*?)\)ï¼\(å \) æ¯ç¨äºå¹é
æ¬å·ç转ä¹å符ã |
| | | // (.*?) æ¯ä¸ä¸ªé贪婪çå¹é
ï¼ç¨æ¥å¹é
ç±»åï¼MyProcesses.Communicators.TCPServer æ MyProcesses.Communicators.UARTPortï¼ã |
| | | //2. ([^:] +)ï¼å¹é
åå·ä¹åçé¨åï¼å³å°åï¼127.0.0.1 æ COM5ï¼ãè¿é使ç¨äº[^:] æ¥å¹é
é¤äºåå·ä¹å¤çä»»æå符ã |
| | | //3. (\d +) ï¼å¹é
端å£å·ï¼ç¡®ä¿å®å¹é
ä¸ä¸ªæå¤ä¸ªæ°åã |
| | | |
| | | string pattern = @"^\((?<ClassName>[^)]+)\)\[(?<IP>[^]]+)\]\[(?<Slot>[^]]+)\]\[(?<CpuType>[^]]+)\]\[(?<PlcAddress>[^]]+)\]$"; |
| | | Match match = Regex.Match(CommunicatorAddress, pattern); |
| | | |
| | | if (match.Success) |
| | | { |
| | | string ClassName = match.Groups["ClassName"].Value; // "TCP" |
| | | string IP = match.Groups["IP"].Value; // "127.0.0.1" |
| | | string Slot = match.Groups["Slot"].Value; // "1111" |
| | | string CpuType= match.Groups["CpuType"].Value; |
| | | string PlcAddress = match.Groups["PlcAddress"].Value; |
| | | if (string.IsNullOrEmpty(ClassName) || string.IsNullOrEmpty(IP) || string.IsNullOrEmpty(Slot) || string.IsNullOrEmpty(CpuType) || string.IsNullOrEmpty(PlcAddress)) |
| | | break; |
| | | |
| | | //å©ç¨åå°å建å®ä¾ |
| | | Type type = IProcess.GetExecutingAssembly().GetType(ClassName); |
| | | if (type == null) |
| | | { |
| | | Debug.WriteLine("Class not found."); |
| | | return false; |
| | | } |
| | | var Communicator = Activator.CreateInstance(type, CommunicatorName) as BaseCommunicator; |
| | | |
| | | if (Communicator == null) |
| | | { |
| | | Debug.WriteLine("BaseCommunicator not found."); |
| | | return false; |
| | | } |
| | | |
| | | Communicator.CommunicatorConnections.Add("å°å", IP); |
| | | Communicator.CommunicatorConnections.Add("端å£", Slot); |
| | | Communicator.CommunicatorConnections.Add("åå·", CpuType); |
| | | Communicator.CommunicatorConnections.Add("åéå°å", PlcAddress); |
| | | Communicator.CommunicatorName = CommunicatorName; |
| | | if (!Communicator.Connect()) |
| | | { |
| | | LogInfo($"åå§åé讯å£[{CommunicatorName}]失败,åå æ¯{Communicator.Msg}", LogInfoType.ERROR); |
| | | } |
| | | else |
| | | { |
| | | LogInfo($"åå§åé讯å£[{CommunicatorName}]æå", LogInfoType.PASS); |
| | | } |
| | | GlobalVar.dicCommunicators.TryAdd(CommunicatorName, Communicator); |
| | | } |
| | | else |
| | | { |
| | | Debug.WriteLine("No match found."); |
| | | } |
| | | } |
| | | else |
| | | { |
| | | // å®ä¹æ£å表达å¼ä»¥æååè®®ãIP å°ååç«¯å£ |
| | | //1. \((.*?)\)ï¼\(å \) æ¯ç¨äºå¹é
æ¬å·ç转ä¹å符ã |
| | | // (.*?) æ¯ä¸ä¸ªé贪婪çå¹é
ï¼ç¨æ¥å¹é
ç±»åï¼MyProcesses.Communicators.TCPServer æ MyProcesses.Communicators.UARTPortï¼ã |
| | |
| | | { |
| | | Debug.WriteLine("No match found."); |
| | | } |
| | | |
| | | } |
| | | } |
| | | |
| | | //TCP客æ·ç«¯æåè¿æ¥ |
| | |
| | | string ClassName = item.Value.GetType().FullName;// "TCP" |
| | | string IP = item.Value.CommunicatorConnections["å°å"].ToString();//"127.0.0.1" |
| | | string PORT = item.Value.CommunicatorConnections["端å£"].ToString();//"1111" |
| | | |
| | | if (!string.IsNullOrEmpty(ClassName) && ClassName.Contains("SiemensLBS7")) |
| | | { |
| | | string CpuType = item.Value.CommunicatorConnections["åå·"].ToString(); |
| | | string PlcAddress = item.Value.CommunicatorConnections["åéå°å"].ToString(); |
| | | if (string.IsNullOrEmpty(ClassName) || string.IsNullOrEmpty(IP) || string.IsNullOrEmpty(PORT) || string.IsNullOrEmpty(CpuType) || string.IsNullOrEmpty(PlcAddress)) |
| | | { |
| | | break; |
| | | } |
| | | string CommunicatorConnectionString = $"({ClassName})[{IP}][{PORT}][{CpuType}][{PlcAddress}]"; |
| | | GlobalVar.allCommunicatorsConnectionString.TryAdd(item.Key, CommunicatorConnectionString); |
| | | } |
| | | else |
| | | { |
| | | if (string.IsNullOrEmpty(ClassName) || string.IsNullOrEmpty(IP) || string.IsNullOrEmpty(PORT)) |
| | | { |
| | | break; |
| | |
| | | string CommunicatorConnectionString = $"({ClassName})[{IP}][{PORT}]"; |
| | | GlobalVar.allCommunicatorsConnectionString.TryAdd(item.Key, CommunicatorConnectionString); |
| | | } |
| | | } |
| | | var settings = new JsonSerializerSettings |
| | | { |
| | | Formatting = Formatting.Indented, |
| | |
| | | /// åå·¥è´¦å· |
| | | /// </summary> |
| | | [Category("RecordUserData"), PropertyOrder(3)] |
| | | [DisplayName("è´¦å·")] |
| | | [DisplayName("å工账å·")] |
| | | [Browsable(true)] |
| | | public string EmployeeAccount { get; set; } |
| | | /// <summary> |
| | | /// åå·¥å¯ç |
| | | /// </summary> |
| | | [Category("RecordUserData"), PropertyOrder(4)] |
| | | [DisplayName("åå·¥å¯ç ")] |
| | | [Browsable(false)] |
| | | public string EmployeePassword { get; set; } |
| | | /// <summary> |
| | |
| | | [Node("Halcon2Dæç¹å·¥å
·", "Haclon2Då·¥å
·", "Basic", "Halcon2Dæç¹å·¥å
·")] |
| | | public void Halcon2Dæç¹å·¥å
·(FlowNode node) { RunNodeAsync(node); } |
| | | |
| | | [Node("é讯模å", "é讯模åå·¥å
·", "Basic", "é讯模å")] |
| | | public void é讯模å(FlowNode node) { RunNodeAsync(node); } |
| | | |
| | | |
| | | #endregion |
| | | |
| | |
| | | Task.Factory.StartNew(() => |
| | | { |
| | | camera.StopGrabbing(); |
| | | if (brand != CameraBrand.LBCamera) |
| | | { |
| | | camera.SetTriggerMode(TriggerMode.On, TriggerSource.Software); |
| | | camera.StartGrabbing(); |
| | | } |
| | | }); |
| | | } |
| | | |
| | |
| | | protected BaseCamera() { } |
| | | |
| | | #region Parm |
| | | /// <summary> |
| | | /// ç¸æºSNå· |
| | | /// </summary> |
| | | public string SN { get; set; } = string.Empty; |
| | | |
| | | /// <summary> |
| | | /// ç¸æºåç§° |
| | | /// </summary> |
| | | public string CameraName { get; set; } = string.Empty; |
| | | public CameraBrand Brand { get; set; } = CameraBrand.UNSUPPORTED; |
| | | |
| | | public bool isGrabbing = false; |
| | |
| | | |
| | | public abstract bool InitDevice(string SN, object Handle = null); |
| | | |
| | | public bool StartWith_SoftTriggerModel() |
| | | { |
| | | SetTriggerMode(TriggerMode.Off, TriggerSource.Software); |
| | | return StartGrabbing(); |
| | | } |
| | | public abstract bool StartWith_SoftTriggerModel(); |
| | | |
| | | public bool StartWith_HardTriggerModel(TriggerSource hardtriggeritem = TriggerSource.Line0) |
| | | { |
| | | if (hardtriggeritem == TriggerSource.Software) hardtriggeritem = TriggerSource.Line0; |
| | | SetTriggerMode(TriggerMode.On, hardtriggeritem); |
| | | return StartGrabbing(); |
| | | } |
| | | public abstract bool StartWith_HardTriggerModel(TriggerSource hardtriggeritem = TriggerSource.Line0); |
| | | |
| | | /// <summary> |
| | | /// çå¾
硬触åè·åå¾å |
| | | /// çå¾
软/硬触åè·åå¾å |
| | | /// </summary> |
| | | /// <param name="bitmap"></param> |
| | | /// <param name="outtime"></param> |
| | | /// <returns></returns> |
| | | public bool GetImage(out Bitmap bitmap, int outtime = 3000) |
| | | { |
| | | bitmap = null; |
| | | |
| | | try |
| | | { |
| | | // 设置è¶
æ¶æ¶é´ |
| | | DateTime lastTime = DateTime.Now.AddMilliseconds(outtime); |
| | | // 夿æ¯å¦è¶
æ¶ |
| | | while (lastTime > DateTime.Now)// 设置è¶
æ¶æ¶é´ä¸º 3 ç§ |
| | | { |
| | | if (CallBackImg != null) |
| | | { |
| | | lock (CallBackImg) |
| | | { |
| | | // ä¿åæ§ Bitmap å¹¶éæ¾ |
| | | bitmap = CallBackImg.Clone() as Bitmap; // åå»ºå¯æ¬ |
| | | } |
| | | |
| | | // éæ¾æ§èµæº |
| | | CallBackImg.Dispose(); |
| | | CallBackImg = null; |
| | | return true; |
| | | } |
| | | } |
| | | |
| | | return false; |
| | | } |
| | | catch { return bitmap == null ? false : true; } |
| | | } |
| | | |
| | | public abstract bool GetImage(out Bitmap bitmap, int outtime = 3000); |
| | | /// <summary> |
| | | /// 软触åè·åå¾å |
| | | /// </summary> |
| | | /// <param name="bitmap"></param> |
| | | /// <param name="outtime"></param> |
| | | /// <returns></returns> |
| | | public bool GetImageWithSoftTrigger(out Bitmap bitmap, int outtime = 3000) |
| | | { |
| | | if (!isGrabbing) |
| | | StartGrabbing(); |
| | | |
| | | GetTriggerMode(out TriggerMode triggerMode, out TriggerSource triggerSource); |
| | | |
| | | if (triggerMode != TriggerMode.On && triggerSource != TriggerSource.Software) |
| | | SetTriggerMode(TriggerMode.On, TriggerSource.Software); |
| | | |
| | | bitmap = null; |
| | | CallBackImg = null; |
| | | |
| | | if (!SoftTrigger()) |
| | | return false; |
| | | |
| | | // å¼å§æ¶é´ |
| | | DateTime startTime = DateTime.Now; // å½åæ¶é´ |
| | | |
| | | // 夿æ¯å¦è¶
æ¶ |
| | | while (DateTime.Now < startTime.AddMilliseconds(outtime))// 设置è¶
æ¶æ¶é´ä¸º 3 ç§ |
| | | { |
| | | GetImage(out bitmap, 50); |
| | | if (bitmap != null) |
| | | break; |
| | | |
| | | Thread.Sleep(10); |
| | | } |
| | | |
| | | if (triggerMode != TriggerMode.On) |
| | | SetTriggerMode(TriggerMode.On, triggerSource); |
| | | |
| | | return (bitmap != null); |
| | | } |
| | | public abstract bool GetImageWithSoftTrigger(out Bitmap bitmap, int outtime = 3000); |
| | | |
| | | /// <summary> |
| | | /// 软触å |
| | |
| | | #endregion |
| | | |
| | | #region SettingConfig |
| | | public void SetCamConfig(CameraConfig config) |
| | | { |
| | | if (Enum.TryParse(config.Params.Inputs["è§¦åæ¨¡å¼"].ToString(), out TriggerMode TriggerMode) |
| | | && Enum.TryParse(config.Params.Inputs["è§¦åæ¹å¼"].ToString(), out TriggerSource TriggerSource) |
| | | && Enum.TryParse(config.Params.Inputs["è§¦åææ§"].ToString(), out TriggerPolarity TriggerPolarity) |
| | | ) |
| | | { |
| | | SetTriggerMode(TriggerMode, TriggerSource); |
| | | SetTriggerPolarity(TriggerPolarity); |
| | | SetTriggerFliter(Convert.ToDouble(config.Params.Inputs["è§¦åæ¶æ"].ToString())); |
| | | SetTriggerDelay(Convert.ToDouble(config.Params.Inputs["触åå»¶æ¶"].ToString())); |
| | | SetExpouseTime(Convert.ToDouble(config.Params.Inputs["æå
æ¶é´"].ToString())); |
| | | SetGain(Convert.ToDouble(config.Params.Inputs["å¢ç"].ToString())); |
| | | } |
| | | } |
| | | |
| | | public void GetCamConfig(out CameraConfig config) |
| | | { |
| | | GetTriggerMode(out TriggerMode triggerMode, out TriggerSource triggerSource); |
| | | GetTriggerPolarity(out TriggerPolarity triggerPolarity); |
| | | GetTriggerFliter(out double triggerfilter); |
| | | GetTriggerDelay(out double triggerdelay); |
| | | GetExpouseTime(out double expouseTime); |
| | | GetGain(out double gain); |
| | | |
| | | config = new CameraConfig(null); |
| | | config.Params.Inputs.Add("è§¦åæ¨¡å¼", triggerMode); |
| | | config.Params.Inputs.Add("è§¦åæ¹å¼", triggerSource); |
| | | config.Params.Inputs.Add("è§¦åææ§", triggerPolarity); |
| | | config.Params.Inputs.Add("è§¦åæ¶æ", triggerfilter); |
| | | config.Params.Inputs.Add("触åå»¶æ¶", triggerdelay); |
| | | config.Params.Inputs.Add("æå
æ¶é´", expouseTime); |
| | | config.Params.Inputs.Add("å¢ç", gain); |
| | | } |
| | | public abstract void SetCamConfig(CameraConfig config); |
| | | public abstract void GetCamConfig(out CameraConfig config); |
| | | |
| | | /// <summary> |
| | | /// è®¾ç½®è§¦åæ¨¡å¼åè§¦åæº |
| | |
| | | GC.SuppressFinalize(this); |
| | | } |
| | | |
| | | public override bool StartWith_SoftTriggerModel() |
| | | { |
| | | SetTriggerMode(TriggerMode.Off, TriggerSource.Software); |
| | | return StartGrabbing(); |
| | | } |
| | | |
| | | |
| | | public override bool StartWith_HardTriggerModel(TriggerSource hardtriggeritem = TriggerSource.Line0) |
| | | { |
| | | if (hardtriggeritem == TriggerSource.Software) hardtriggeritem = TriggerSource.Line0; |
| | | SetTriggerMode(TriggerMode.On, hardtriggeritem); |
| | | return StartGrabbing(); |
| | | } |
| | | |
| | | public override bool GetImage(out Bitmap bitmap, int outtime = 3000) |
| | | { |
| | | bitmap = null; |
| | | |
| | | try |
| | | { |
| | | // 设置è¶
æ¶æ¶é´ |
| | | DateTime lastTime = DateTime.Now.AddMilliseconds(outtime); |
| | | // 夿æ¯å¦è¶
æ¶ |
| | | while (lastTime > DateTime.Now)// 设置è¶
æ¶æ¶é´ä¸º 3 ç§ |
| | | { |
| | | if (CallBackImg != null) |
| | | { |
| | | lock (CallBackImg) |
| | | { |
| | | // ä¿åæ§ Bitmap å¹¶éæ¾ |
| | | bitmap = CallBackImg.Clone() as Bitmap; // åå»ºå¯æ¬ |
| | | } |
| | | |
| | | // éæ¾æ§èµæº |
| | | CallBackImg.Dispose(); |
| | | CallBackImg = null; |
| | | return true; |
| | | } |
| | | } |
| | | |
| | | return false; |
| | | } |
| | | catch { return bitmap == null ? false : true; } |
| | | } |
| | | |
| | | |
| | | public override bool GetImageWithSoftTrigger(out Bitmap bitmap, int outtime = 3000) |
| | | { |
| | | if (!isGrabbing) |
| | | StartGrabbing(); |
| | | |
| | | GetTriggerMode(out TriggerMode triggerMode, out TriggerSource triggerSource); |
| | | |
| | | if (triggerMode != TriggerMode.On && triggerSource != TriggerSource.Software) |
| | | SetTriggerMode(TriggerMode.On, TriggerSource.Software); |
| | | |
| | | bitmap = null; |
| | | CallBackImg = null; |
| | | |
| | | if (!SoftTrigger()) |
| | | return false; |
| | | |
| | | // å¼å§æ¶é´ |
| | | DateTime startTime = DateTime.Now; // å½åæ¶é´ |
| | | |
| | | // 夿æ¯å¦è¶
æ¶ |
| | | while (DateTime.Now < startTime.AddMilliseconds(outtime))// 设置è¶
æ¶æ¶é´ä¸º 3 ç§ |
| | | { |
| | | GetImage(out bitmap, 50); |
| | | if (bitmap != null) |
| | | break; |
| | | |
| | | Thread.Sleep(10); |
| | | } |
| | | |
| | | if (triggerMode != TriggerMode.On) |
| | | SetTriggerMode(TriggerMode.On, triggerSource); |
| | | |
| | | return (bitmap != null); |
| | | } |
| | | |
| | | public override void SetCamConfig(CameraConfig config) |
| | | { |
| | | if (Enum.TryParse(config.Params.Inputs["è§¦åæ¨¡å¼"].ToString(), out TriggerMode TriggerMode) |
| | | && Enum.TryParse(config.Params.Inputs["è§¦åæ¹å¼"].ToString(), out TriggerSource TriggerSource) |
| | | && Enum.TryParse(config.Params.Inputs["è§¦åææ§"].ToString(), out TriggerPolarity TriggerPolarity) |
| | | ) |
| | | { |
| | | SetTriggerMode(TriggerMode, TriggerSource); |
| | | SetTriggerPolarity(TriggerPolarity); |
| | | SetTriggerFliter(Convert.ToDouble(config.Params.Inputs["è§¦åæ¶æ"].ToString())); |
| | | SetTriggerDelay(Convert.ToDouble(config.Params.Inputs["触åå»¶æ¶"].ToString())); |
| | | SetExpouseTime(Convert.ToDouble(config.Params.Inputs["æå
æ¶é´"].ToString())); |
| | | SetGain(Convert.ToDouble(config.Params.Inputs["å¢ç"].ToString())); |
| | | } |
| | | } |
| | | |
| | | |
| | | public override void GetCamConfig(out CameraConfig config) |
| | | { |
| | | GetTriggerMode(out TriggerMode triggerMode, out TriggerSource triggerSource); |
| | | GetTriggerPolarity(out TriggerPolarity triggerPolarity); |
| | | GetTriggerFliter(out double triggerfilter); |
| | | GetTriggerDelay(out double triggerdelay); |
| | | GetExpouseTime(out double expouseTime); |
| | | GetGain(out double gain); |
| | | |
| | | config = new CameraConfig(null); |
| | | config.Params.Inputs.Add("è§¦åæ¨¡å¼", triggerMode); |
| | | config.Params.Inputs.Add("è§¦åæ¹å¼", triggerSource); |
| | | config.Params.Inputs.Add("è§¦åææ§", triggerPolarity); |
| | | config.Params.Inputs.Add("è§¦åæ¶æ", triggerfilter); |
| | | config.Params.Inputs.Add("触åå»¶æ¶", triggerdelay); |
| | | config.Params.Inputs.Add("æå
æ¶é´", expouseTime); |
| | | config.Params.Inputs.Add("å¢ç", gain); |
| | | } |
| | | |
| | | #endregion |
| | | } |
| | | } |
| | |
| | | bool StartWith_HardTriggerModel(TriggerSource hardtriggeritem = TriggerSource.Line0); |
| | | |
| | | /// <summary> |
| | | /// çå¾
硬触åè·åå¾å |
| | | /// çå¾
软/硬触åè·åå¾å |
| | | /// </summary> |
| | | /// <param name="bitmap"></param> |
| | | /// <param name="outtime"></param> |
| | |
| | | private readonly object _bufferLock = new object(); |
| | | private int _currentLineCount = 0; |
| | | |
| | | // æ¾ç¤ºå¥æå彿°ï¼ä¸LLSystem示ä¾ä¿æä¸è´ï¼ |
| | | private IntPtr _lightPic = IntPtr.Zero; |
| | | private IntPtr _deepPic = IntPtr.Zero; |
| | | private IntPtr _pointPic = IntPtr.Zero; |
| | | private IntPtr _outlinePic = IntPtr.Zero; |
| | | |
| | | public LBCamera() |
| | | { |
| | | Brand = CameraBrand.LBCamera; |
| | |
| | | |
| | | if (!found) |
| | | { |
| | | // å¦ææ²¡æ¾å°ä½ sn æ¬èº«çèµ·æ¥å IPï¼å°è¯ç´æ¥è¿æ¥ï¼å
¼å®¹æ§é»è¾ï¼ |
| | | // å¦ææ²¡æ¾å°ä½ sn æ¬èº«çèµ·æ¥å IPï¼å°è¯ç´æ¥è¿æ¥ |
| | | if (System.Net.IPAddress.TryParse(sn, out _)) |
| | | { |
| | | targetIp = sn; |
| | |
| | | _acquisitionCallback = new AcquisitionCallbackZA(OnLineReceived); |
| | | _acquisitionCompletedCallback = new AcquisitionCompletedCallback(OnAcquisitionCompleted); |
| | | |
| | | PHM6000Profiler.SetAcquisitionCallbackZA(_cameraHandle, _acquisitionCallback, IntPtr.Zero); |
| | | //PHM6000Profiler.SetAcquisitionCallbackZA(_cameraHandle, _acquisitionCallback, IntPtr.Zero); |
| | | PHM6000Profiler.RegisterAcquisitionCompletedCallback(_cameraHandle, _acquisitionCompletedCallback, IntPtr.Zero); |
| | | |
| | | return true; |
| | |
| | | _currentLineCount = 0; |
| | | } |
| | | |
| | | // ç¦ç¨è¡åè° |
| | | PHM6000Profiler.SetAcquisitionCallbackZA(_cameraHandle, IntPtr.Zero, IntPtr.Zero); |
| | | |
| | | // 设置é鿍¡å¼ï¼1=æ«ææ¨¡å¼ï¼1=è¿ç»æ¨¡å¼ |
| | | PHM6000Profiler.SetAcquisitionMode(_cameraHandle, 1, 1); |
| | | int result = PHM6000Profiler.StartAcquisition(_cameraHandle, 0, 0, 0.0); |
| | | if (result == 0) |
| | | { |
| | | isGrabbing = true; |
| | | return true; |
| | | } |
| | | return false; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 忬¡é鿍¡å¼ï¼éç¨äºçº¿æ«ç¸æºï¼ |
| | | /// 设置é鿍¡å¼ä¸ºæ«ææ¨¡å¼ï¼å次触å |
| | | /// </summary> |
| | | public bool StartSingleGrab() |
| | | { |
| | | if (!_isConnected) return false; |
| | | lock (_bufferLock) |
| | | { |
| | | _lineDataBuffer.Clear(); |
| | | _currentLineCount = 0; |
| | | } |
| | | |
| | | // ç¦ç¨è¡åè°ï¼ä¸ç¤ºä¾ä¸è´ï¼ |
| | | PHM6000Profiler.SetAcquisitionCallbackZA(_cameraHandle, IntPtr.Zero, IntPtr.Zero); |
| | | |
| | | // 设置é鿍¡å¼ï¼1=æ«ææ¨¡å¼ï¼0=忬¡æ¨¡å¼ |
| | | PHM6000Profiler.SetAcquisitionMode(_cameraHandle, 1, 0); |
| | | int result = PHM6000Profiler.StartAcquisition(_cameraHandle, 0, 0, 0.0); |
| | | if (result == 0) |
| | | { |
| | | isGrabbing = true; |
| | | return true; |
| | | } |
| | | return false; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// è¿ç»é鿍¡å¼ï¼éç¨äºçº¿æ«ç¸æºï¼ |
| | | /// 设置é鿍¡å¼ä¸ºæ«ææ¨¡å¼ï¼è¿ç»è§¦å |
| | | /// </summary> |
| | | public bool StartContinuousGrab() |
| | | { |
| | | if (!_isConnected) return false; |
| | | lock (_bufferLock) |
| | | { |
| | | _lineDataBuffer.Clear(); |
| | | _currentLineCount = 0; |
| | | } |
| | | |
| | | // ç¦ç¨è¡åè°ï¼ä¸ç¤ºä¾ä¸è´ï¼ |
| | | PHM6000Profiler.SetAcquisitionCallbackZA(_cameraHandle, IntPtr.Zero, IntPtr.Zero); |
| | | |
| | | // 设置é鿍¡å¼ï¼1=æ«ææ¨¡å¼ï¼1=è¿ç»æ¨¡å¼ |
| | | PHM6000Profiler.SetAcquisitionMode(_cameraHandle, 1, 1); |
| | | int result = PHM6000Profiler.StartAcquisition(_cameraHandle, 0, 0, 0.0); |
| | |
| | | PHM6000Profiler.StopAcquisition(_cameraHandle); |
| | | isGrabbing = false; |
| | | return true; |
| | | } |
| | | |
| | | public override bool StartWith_SoftTriggerModel() |
| | | { |
| | | // 对äºLBCameraï¼çº¿æ«ç¸æºï¼ï¼è½¯ä»¶è§¦åè¿ç»éé使ç¨è¿ç»é鿍¡å¼ |
| | | return StartContinuousGrab(); |
| | | } |
| | | |
| | | public override bool StartWith_HardTriggerModel(TriggerSource hardtriggeritem = TriggerSource.Line0) |
| | | { |
| | | // 对äºLBCameraï¼çº¿æ«ç¸æºï¼ï¼ç¡¬ä»¶è§¦åä¹ä½¿ç¨è¿ç»é鿍¡å¼ |
| | | // å¤é¨ç¡¬ä»¶ä¿¡å·ä¼è§¦åç¸æºå¼å§éé |
| | | return StartContinuousGrab(); |
| | | } |
| | | |
| | | public override bool SoftTrigger() |
| | |
| | | public override bool SetLineStatus(IOLines line, LineStatus linestatus) => true; |
| | | public override bool GetLineStatus(IOLines line, out LineStatus lineStatus) { lineStatus = LineStatus.Low; return true; } |
| | | public override bool AutoBalanceWhite() => true; |
| | | |
| | | // ä¸å®ç°çæ¹æ³ |
| | | public override void SetCamConfig(CameraConfig config) { } |
| | | public override void GetCamConfig(out CameraConfig config) { config = new CameraConfig(null); } |
| | | public override bool GetImage(out Bitmap bitmap, int outtime = 3000) { bitmap = null; return false; } |
| | | public override bool GetImageWithSoftTrigger(out Bitmap bitmap, int outtime = 3000) |
| | | { |
| | | bitmap = null; |
| | | if (!_isConnected) return false; |
| | | |
| | | using (AutoResetEvent waitHandle = new AutoResetEvent(false)) |
| | | { |
| | | Bitmap captured = null; |
| | | EventHandler<CameraEventArgs> handler = (s, e) => |
| | | { |
| | | try |
| | | { |
| | | if (e.Bitmap != null) |
| | | { |
| | | captured = e.Bitmap.Clone() as Bitmap; |
| | | } |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | AsyncLogHelper.Error($"LBCamera: GetImageWithSoftTrigger clone error - {ex.Message}"); |
| | | } |
| | | waitHandle.Set(); |
| | | }; |
| | | |
| | | this.ImageGrabbed += handler; |
| | | |
| | | try |
| | | { |
| | | if (StartSingleGrab()) |
| | | { |
| | | if (waitHandle.WaitOne(outtime)) |
| | | { |
| | | bitmap = captured; |
| | | return bitmap != null; |
| | | } |
| | | } |
| | | } |
| | | finally |
| | | { |
| | | this.ImageGrabbed -= handler; |
| | | StopGrabbing(); |
| | | } |
| | | } |
| | | return false; |
| | | } |
| | | |
| | | public PHM6000SensorConfig GetSensorConfig() |
| | | { |
| | |
| | | |
| | | private void OnAcquisitionCompleted(IntPtr pInstance, int nOption) |
| | | { |
| | | // nOption: 0=䏿¹æ°æ®ç»æ, 1=å
¨é¨å®æ, 2=ç¹äºå°±ç»ª |
| | | if (nOption == 1 || nOption == 0) |
| | | // æ ¹æ®SDKææ¡£ï¼nOption为0æ¶è¡¨ç¤ºä¸æ¹æ°æ®ç»æï¼ä¸º1æ¶è¡¨ç¤ºå
¨é¨éé宿 |
| | | // 为äºå
¼å®¹æ§ï¼ä¹å¤çnOption == 2ï¼ç¹äºå°±ç»ªï¼ |
| | | // æ¤æ¶ä½¿ç¨ä¸»å¨è·åæ¹å¼æ¿ä»£å¯è½ä¼å¯¼è´crashçGenerateIntensityMap |
| | | if (nOption == 0 || nOption == 1 || nOption == 2) |
| | | { |
| | | GenerateIntensityMap(); |
| | | RetrieveDataAndGenerateImage(); |
| | | } |
| | | } |
| | | |
| | | private void GenerateIntensityMap() |
| | | private void RetrieveDataAndGenerateImage() |
| | | { |
| | | if (_cameraHandle == IntPtr.Zero) return; |
| | | |
| | | int width = 0; |
| | | int height = 0; |
| | | |
| | | // ç´æ¥ä» SDK è·ååå¹¶åçå¼ºåº¦æ°æ®æé (unsigned char*) |
| | | IntPtr pIntensity = PHM6000Profiler.GetIntensityData(_cameraHandle, ref width, ref height); |
| | | |
| | | if (pIntensity == IntPtr.Zero || width <= 0 || height <= 0) return; |
| | | |
| | | try |
| | | { |
| | | List<byte[]> lineBuffers = new List<byte[]>(); |
| | | ulong index = 0; |
| | | IntPtr ptr = IntPtr.Zero; |
| | | |
| | | // å示ä¾ä¸æ ·éè¿ç´¢å¼è·åè¡æ°æ® |
| | | while ((ptr = PHM6000Profiler.GetLineDataByIndex(_cameraHandle, index)) != IntPtr.Zero) |
| | | { |
| | | try |
| | | { |
| | | LBLineDataZA lineData = PHM6000Profiler.ConvertToLBLineDataZA(ptr); |
| | | |
| | | // æåå¼ºåº¦æ°æ® (Alphaéé) |
| | | if (lineData.data != null && lineData.data.Length > 0) |
| | | { |
| | | int lineWidth = lineData.data.Length; |
| | | byte[] intensityLine = new byte[lineWidth]; |
| | | for (int i = 0; i < lineWidth; i++) |
| | | { |
| | | intensityLine[i] = lineData.data[i].alpha; |
| | | } |
| | | lineBuffers.Add(intensityLine); |
| | | } |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | // 忽ç¥åè¡è½¬æ¢é误 |
| | | } |
| | | index++; |
| | | } |
| | | |
| | | if (lineBuffers.Count == 0) return; |
| | | |
| | | int height = lineBuffers.Count; |
| | | int width = lineBuffers[0].Length; |
| | | |
| | | if (width <= 0 || height <= 0) return; |
| | | |
| | | Bitmap bmp = new Bitmap(width, height, PixelFormat.Format8bppIndexed); |
| | | |
| | | // 设置ç°åº¦è°è²æ¿ |
| | |
| | | |
| | | BitmapData bmpData = bmp.LockBits(new Rectangle(0, 0, width, height), ImageLockMode.WriteOnly, PixelFormat.Format8bppIndexed); |
| | | |
| | | // 髿§è½å
åæ·è´ |
| | | int size = width * height; |
| | | byte[] managedData = new byte[size]; |
| | | Marshal.Copy(pIntensity, managedData, 0, size); |
| | | Marshal.Copy(managedData, 0, bmpData.Scan0, size); |
| | | try |
| | | { |
| | | int stride = bmpData.Stride; |
| | | IntPtr scan0 = bmpData.Scan0; |
| | | |
| | | for (int y = 0; y < height; y++) |
| | | { |
| | | if (lineBuffers[y].Length == width) // ç¡®ä¿å®½åº¦ä¸è´ |
| | | { |
| | | Marshal.Copy(lineBuffers[y], 0, scan0 + y * stride, width); |
| | | } |
| | | } |
| | | } |
| | | finally |
| | | { |
| | | bmp.UnlockBits(bmpData); |
| | | } |
| | | |
| | | // 触åäºä»¶éç¥ UI æ´æ°äº®åº¦å¾ |
| | | ImageGrabbed?.Invoke(this, new CameraEventArgs(SN, bmp)); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | AsyncLogHelper.Error($"LBCamera: çæäº®åº¦å¾å¼å¸¸ - {ex.Message}"); |
| | | AsyncLogHelper.Error($"LBCamera: çæå¾åå¼å¸¸ - {ex.Message}"); |
| | | } |
| | | } |
| | | |
| | |
| | | namespace LB_VisionProcesses.Communicators |
| | | { |
| | | [Serializable] |
| | | [Process("é讯æµè¯", Category = "é讯工å
·", Description = "å建é讯æµè¯å·¥å
·")] |
| | | [Process("é讯模å", Category = "é讯工å
·", Description = "å建é讯模åå·¥å
·")] |
| | | public class CommunicatorConfig : IProcess |
| | | { |
| | | /// <summary> |
| | |
| | | { |
| | | this.dicCommunicators = dicCommunicators; |
| | | |
| | | strProcessName = "é讯æµè¯"; |
| | | strProcessName = "é讯模å"; |
| | | strProcessClass = "LB_VisionProcesses.Communicators.CommunicatorConfig"; |
| | | |
| | | Params.Inputs.Add("é讯å£å", ""); |
| | |
| | | label6 = new Label(); |
| | | themeForm1 = new ReaLTaiizor.Forms.ThemeForm(); |
| | | controlBox1 = new ReaLTaiizor.Controls.ControlBox(); |
| | | lblAddress = new Label(); |
| | | txtAddress = new TextBox(); |
| | | grpSetting.SuspendLayout(); |
| | | grpReceive.SuspendLayout(); |
| | | grpTest.SuspendLayout(); |
| | |
| | | // |
| | | // btnDisconnect |
| | | // |
| | | btnDisconnect.ForeColor = SystemColors.WindowText; |
| | | btnDisconnect.ForeColor = SystemColors.Control; |
| | | btnDisconnect.Location = new Point(118, 109); |
| | | btnDisconnect.Name = "btnDisconnect"; |
| | | btnDisconnect.Size = new Size(75, 23); |
| | |
| | | // |
| | | // btnConnect |
| | | // |
| | | btnConnect.ForeColor = SystemColors.WindowText; |
| | | btnConnect.ForeColor = SystemColors.Control; |
| | | btnConnect.Location = new Point(14, 109); |
| | | btnConnect.Name = "btnConnect"; |
| | | btnConnect.Size = new Size(75, 23); |
| | |
| | | // grpTest |
| | | // |
| | | grpTest.Controls.Add(lblCom); |
| | | grpTest.Controls.Add(txtAddress); |
| | | grpTest.Controls.Add(ckbRuleCheck); |
| | | grpTest.Controls.Add(cmbCom); |
| | | grpTest.Controls.Add(cmbType); |
| | | grpTest.Controls.Add(lblType); |
| | | grpTest.Controls.Add(btnRun); |
| | | grpTest.Controls.Add(lblAddress); |
| | | grpTest.Controls.Add(lblMsg); |
| | | grpTest.Controls.Add(txtMsg); |
| | | grpTest.ForeColor = SystemColors.Control; |
| | |
| | | // |
| | | txtMsg.Location = new Point(59, 76); |
| | | txtMsg.Name = "txtMsg"; |
| | | txtMsg.ReadOnly = true; |
| | | txtMsg.Size = new Size(245, 23); |
| | | txtMsg.TabIndex = 0; |
| | | // |
| | |
| | | controlBox1.TabIndex = 0; |
| | | controlBox1.Text = "controlBox1"; |
| | | // |
| | | // lblAddress |
| | | // |
| | | lblAddress.AutoSize = true; |
| | | lblAddress.Location = new Point(20, 115); |
| | | lblAddress.Name = "lblAddress"; |
| | | lblAddress.Size = new Size(32, 17); |
| | | lblAddress.TabIndex = 0; |
| | | lblAddress.Text = "å°å"; |
| | | // |
| | | // txtAddress |
| | | // |
| | | txtAddress.Location = new Point(59, 112); |
| | | txtAddress.Name = "txtAddress"; |
| | | txtAddress.ReadOnly = true; |
| | | txtAddress.Size = new Size(94, 23); |
| | | txtAddress.TabIndex = 6; |
| | | // |
| | | // CommunicatorForm |
| | | // |
| | | AutoScaleDimensions = new SizeF(96F, 96F); |
| | |
| | | private Label label6; |
| | | private ReaLTaiizor.Forms.ThemeForm themeForm1; |
| | | private ReaLTaiizor.Controls.ControlBox controlBox1; |
| | | private TextBox txtAddress; |
| | | private Label lblAddress; |
| | | } |
| | | } |
| | |
| | | cmbType.Text = type.ToString(); |
| | | ckbRuleCheck.Checked = bRuleCheck; |
| | | txtMsg.Text = Msg; |
| | | this.grpSetting.ForeColor= SystemColors.Control; |
| | | } |
| | | } |
| | | |
| | |
| | | |
| | | cmbIP.Visible = true; |
| | | txtIP.Visible = false; |
| | | this.lblAddress.Visible = false; |
| | | this.txtAddress.Visible = false; |
| | | |
| | | |
| | | lblIP.Text = "串å£å·"; |
| | | lblIP.Text = "æ³¢ç¹ç"; |
| | | |
| | | cmbIP.Text = communicator.CommunicatorConnections["å°å"].ToString(); |
| | | txtPort.Text = communicator.CommunicatorConnections["端å£"].ToString(); |
| | | this.grpSetting.ForeColor = SystemColors.Control; |
| | | } |
| | | else if (communicator is LocalMonitor) |
| | | { |
| | |
| | | |
| | | cmbIP.Visible = false; |
| | | txtIP.Visible = true; |
| | | this.lblAddress.Visible = false; |
| | | this.txtAddress.Visible = false; |
| | | |
| | | |
| | | lblIP.Text = "çæ§æä»¶"; |
| | | lblIP.Text = "åå
¥æä»¶"; |
| | | |
| | | txtIP.Text = communicator.CommunicatorConnections["å°å"].ToString(); |
| | | txtPort.Text = communicator.CommunicatorConnections["端å£"].ToString(); |
| | | this.grpSetting.ForeColor = SystemColors.Control; |
| | | } |
| | | else if (communicator is SiemensLBS7) |
| | | { |
| | | btnSend.Enabled = communicator.bConnected; |
| | | btnRuleSend.Enabled = communicator.bConnected; |
| | | |
| | | cmbIP.Visible = false; |
| | | txtIP.Visible = true; |
| | | |
| | | this.lblAddress.Visible = true; |
| | | this.txtAddress.Visible = true; |
| | | lblIP.Text = "IP"; |
| | | lblIP.Text = "æ§½"; |
| | | |
| | | txtIP.Text = communicator.CommunicatorConnections["å°å"].ToString(); |
| | | txtPort.Text = communicator.CommunicatorConnections["æ§½"].ToString(); |
| | | txtPort.Text = communicator.CommunicatorConnections["端å£"].ToString(); |
| | | this.txtAddress.Text = communicator.CommunicatorConnections["åéå°å"]?.ToString(); |
| | | this.grpSetting.ForeColor = SystemColors.Control; |
| | | btnRuleSend.Visible = false; |
| | | } |
| | | else |
| | | { |
| | | btnSend.Enabled = communicator.bConnected; |
| | | btnRuleSend.Enabled = false; |
| | | this.lblAddress.Visible = false; |
| | | this.txtAddress.Visible = false; |
| | | |
| | | cmbIP.Visible = false; |
| | | txtIP.Visible = true; |
| | |
| | | <data name="themeForm1.Image" type="System.Drawing.Bitmap, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64"> |
| | | <value> |
| | | iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAABGdBTUEAALGPC/xhBQAAAAlwSFlzAAAO |
| | | wgAADsIBFShKgAAAA+JJREFUWEftVkuIHGUQbt34iMEoq2S2q3p3yTJsuqpnJ+L6WBRdwaigohfFgEou |
| | | wQAADsEBuJFr7QAAA+JJREFUWEftVkuIHGUQbt34iMEoq2S2q3p3yTJsuqpnJ+L6WBRdwaigohfFgEou |
| | | BkVBUPCBCEG8BXNQ48GLeImCehIJxMsqhsSZruod46K4HtSIGjU+4iOr0c1I9fSsM3/PLNtCPO0H36m/ |
| | | evz/X11VnreKVRTAHPOZumkY6lFwqURws3BwZ8ywTQnuiCP/+iTCzY1qaUPzdm/Atf3PaHre6XPsjyQM |
| | | 2xLGV4XwIyX4QRj+UMK/lPFvJTyhBMeV8IgQvmRJuH4Ko+l5p9UjGBbCJ5RxTgj+VMZmXxKcSAjekHE/ |
| | |
| | | short slot; |
| | | short.TryParse(CommunicatorConnections["端å£"].ToString(), out slot); |
| | | S7.Net.CpuType cpuType = (CpuType)CommunicatorConnections["åå·"]; |
| | | variable = CommunicatorConnections["åéå°å"].ToString(); |
| | | plc = new Plc(cpuType, IP, 0, slot); |
| | | plc.Open(); |
| | | return true; |
| | |
| | | { |
| | | try |
| | | { |
| | | if (plc!=null) |
| | | { |
| | | if (string.IsNullOrEmpty(variable)) |
| | | { |
| | | variable = CommunicatorConnections["åéå°å"].ToString(); |
| | | } |
| | | plc.Write(variable, message); |
| | | return true; |
| | | } |
| | | else |
| | | { |
| | | return false; |
| | | } |
| | | } |
| | | catch |
| | | { |
| | | return false; |