add libcomm for plc layer

This commit is contained in:
2025-12-24 14:46:43 +08:00
parent 6308aee750
commit 8d4774964c
6 changed files with 199 additions and 0 deletions

73
LibComm/CommWithCC24.cs Normal file
View File

@@ -0,0 +1,73 @@
using Bjcve.Comm.FFP;
using Cognex.VisionPro.Comm;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace LibComm
{
public class CommWithCC24 : ICommPLC
{
private CC24 cc24;
public event OnDataReceived OnDataReceived;
public event OnConnectStatus OnConnectStatus;
public event OnTrigCamera OnTrigCamera;
public event OnCameraStatus OnCameraStatus;
public void Initialize()
{
cc24 = new CC24();
cc24.VisionReceivedNewUserData += CC24_NewUserDataReceived;
cc24.PlcConnectionStatusChanged += CC24_PlcConnectionStatusChanged;
cc24.PlcTriggerCamAcqStart += CC24_PlcTriggerCamAcqStart;
cc24.PlcTriggerCamAcqStop += CC24_PlcTriggerCamAcqStop;
cc24.NotifyCamAcqEnabled += CC24_NotifyCamAcqEnabled;
cc24.NotifyCamAcqDisabled += CC24_NotifyCamAcqDisabled;
cc24.Initialize();
cc24.NotifyCamAcqEnable(0);
cc24.NotifyCamAcqEnable(1);
}
public void Stop()
{
cc24.VisionReceivedNewUserData -= CC24_NewUserDataReceived;
cc24.PlcConnectionStatusChanged -= CC24_PlcConnectionStatusChanged;
cc24.PlcTriggerCamAcqStart -= CC24_PlcTriggerCamAcqStart;
cc24.PlcTriggerCamAcqStop -= CC24_PlcTriggerCamAcqStop;
cc24.NotifyCamAcqEnabled -= CC24_NotifyCamAcqEnabled;
cc24.NotifyCamAcqDisabled -= CC24_NotifyCamAcqDisabled;
cc24.Shutdown();
}
public void NoticeCamComplete(int index, byte[] datax)
{
cc24?.NotifyCamInspectionComplete(index, datax);
cc24?.NotifyCamAcqComplete(index);
}
private void CC24_NewUserDataReceived(object sender, CogNdmNewUserDataEventArgs e)
{
OnDataReceived?.Invoke(cc24.ReadBytesFromPLC(0, 4));
}
private void CC24_PlcConnectionStatusChanged(object sender, CogNdmProtocolStatusChangedEventArgs e)
{
OnConnectStatus?.Invoke(e.ProtocolStatus == CogNdmConnectionStatusConstants.Connected);
}
private void CC24_PlcTriggerCamAcqStart(object sender, CogNdmTriggerAcquisitionEventArgs e)
{
OnTrigCamera?.Invoke(e.CameraIndex);
}
private void CC24_PlcTriggerCamAcqStop(object sender, CogNdmTriggerAcquisitionStopEventArgs e)
{
}
private void CC24_NotifyCamAcqEnabled(int cameraIndex, bool isEnabled)
{
OnCameraStatus?.Invoke(cameraIndex, isEnabled);
}
private void CC24_NotifyCamAcqDisabled(int cameraIndex, bool isEnabled)
{
OnCameraStatus?.Invoke(cameraIndex, isEnabled);
}
}
}

22
LibComm/ICommPLC.cs Normal file
View File

@@ -0,0 +1,22 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace LibComm
{
public delegate void OnDataReceived(byte[] data);
public delegate void OnConnectStatus(bool connected);
public delegate void OnTrigCamera(int index);
public delegate void OnCameraStatus(int index, bool enable);
public interface ICommPLC
{
event OnDataReceived OnDataReceived;
event OnConnectStatus OnConnectStatus;
event OnTrigCamera OnTrigCamera;
void Initialize();
void Stop();
void NoticeCamComplete(int index, byte[] datax);
}
}

56
LibComm/LibComm.csproj Normal file
View File

@@ -0,0 +1,56 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{E44B1774-093E-4617-AF7A-474A88B89100}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>LibComm</RootNamespace>
<AssemblyName>LibComm</AssemblyName>
<TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<Deterministic>true</Deterministic>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="Bjcve.Comm.FFP">
<HintPath>..\dll\Bjcve.Comm.FFP.dll</HintPath>
</Reference>
<Reference Include="Cognex.VisionPro.Comm, Version=59.2.0.0, Culture=neutral, PublicKeyToken=ef0f902af9dee505, processorArchitecture=AMD64">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\dll\Cognex.VisionPro.Comm.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="CommWithCC24.cs" />
<Compile Include="ICommPLC.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>

View File

@@ -0,0 +1,33 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// 有关程序集的一般信息由以下
// 控制。更改这些特性值可修改
// 与程序集关联的信息。
[assembly: AssemblyTitle("LibComm")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("HP")]
[assembly: AssemblyProduct("LibComm")]
[assembly: AssemblyCopyright("Copyright © HP 2025")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// 将 ComVisible 设置为 false 会使此程序集中的类型
//对 COM 组件不可见。如果需要从 COM 访问此程序集中的类型
//请将此类型的 ComVisible 特性设置为 true。
[assembly: ComVisible(false)]
// 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID
[assembly: Guid("e44b1774-093e-4617-af7a-474a88b89100")]
// 程序集的版本信息由下列四个值组成:
//
// 主版本
// 次版本
// 生成号
// 修订号
//
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]