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")]

View File

@@ -265,6 +265,10 @@
<None Include="Resources\OFF.png" /> <None Include="Resources\OFF.png" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\LibComm\LibComm.csproj">
<Project>{e44b1774-093e-4617-af7a-474a88b89100}</Project>
<Name>LibComm</Name>
</ProjectReference>
<ProjectReference Include="..\LibDataBase\LibDataBase.csproj"> <ProjectReference Include="..\LibDataBase\LibDataBase.csproj">
<Project>{d03a85cc-a53b-4434-a560-7a89563292e8}</Project> <Project>{d03a85cc-a53b-4434-a560-7a89563292e8}</Project>
<Name>LibDataBase</Name> <Name>LibDataBase</Name>

View File

@@ -15,6 +15,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LibDataBase", "LibDataBase\
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TestPackOCR", "TestPackOCR\TestPackOCR.csproj", "{717BA61B-8C31-473F-8A02-626337A90A5E}" Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TestPackOCR", "TestPackOCR\TestPackOCR.csproj", "{717BA61B-8C31-473F-8A02-626337A90A5E}"
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LibComm", "LibComm\LibComm.csproj", "{E44B1774-093E-4617-AF7A-474A88B89100}"
EndProject
Global Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU Debug|Any CPU = Debug|Any CPU
@@ -63,6 +65,14 @@ Global
{717BA61B-8C31-473F-8A02-626337A90A5E}.Release|Any CPU.Build.0 = Release|Any CPU {717BA61B-8C31-473F-8A02-626337A90A5E}.Release|Any CPU.Build.0 = Release|Any CPU
{717BA61B-8C31-473F-8A02-626337A90A5E}.Release|x64.ActiveCfg = Release|Any CPU {717BA61B-8C31-473F-8A02-626337A90A5E}.Release|x64.ActiveCfg = Release|Any CPU
{717BA61B-8C31-473F-8A02-626337A90A5E}.Release|x64.Build.0 = Release|Any CPU {717BA61B-8C31-473F-8A02-626337A90A5E}.Release|x64.Build.0 = Release|Any CPU
{E44B1774-093E-4617-AF7A-474A88B89100}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{E44B1774-093E-4617-AF7A-474A88B89100}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E44B1774-093E-4617-AF7A-474A88B89100}.Debug|x64.ActiveCfg = Debug|Any CPU
{E44B1774-093E-4617-AF7A-474A88B89100}.Debug|x64.Build.0 = Debug|Any CPU
{E44B1774-093E-4617-AF7A-474A88B89100}.Release|Any CPU.ActiveCfg = Release|Any CPU
{E44B1774-093E-4617-AF7A-474A88B89100}.Release|Any CPU.Build.0 = Release|Any CPU
{E44B1774-093E-4617-AF7A-474A88B89100}.Release|x64.ActiveCfg = Release|Any CPU
{E44B1774-093E-4617-AF7A-474A88B89100}.Release|x64.Build.0 = Release|Any CPU
EndGlobalSection EndGlobalSection
GlobalSection(SolutionProperties) = preSolution GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE HideSolutionNode = FALSE
@@ -70,6 +80,7 @@ Global
GlobalSection(NestedProjects) = preSolution GlobalSection(NestedProjects) = preSolution
{B88B2FA9-0D9D-4EBB-A87A-4DE2DC2DD70F} = {C0079401-F420-4256-B991-3BF16D3296C7} {B88B2FA9-0D9D-4EBB-A87A-4DE2DC2DD70F} = {C0079401-F420-4256-B991-3BF16D3296C7}
{D03A85CC-A53B-4434-A560-7A89563292E8} = {C0079401-F420-4256-B991-3BF16D3296C7} {D03A85CC-A53B-4434-A560-7A89563292E8} = {C0079401-F420-4256-B991-3BF16D3296C7}
{E44B1774-093E-4617-AF7A-474A88B89100} = {C0079401-F420-4256-B991-3BF16D3296C7}
EndGlobalSection EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {F550CA1D-FC09-446C-B501-170B642AAC00} SolutionGuid = {F550CA1D-FC09-446C-B501-170B642AAC00}