82 lines
3.1 KiB
C#
82 lines
3.1 KiB
C#
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 Start()
|
|
{
|
|
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;
|
|
|
|
Task.Run(() =>
|
|
{
|
|
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, float data)
|
|
{
|
|
cc24?.NotifyCamInspectionComplete(index, DataConverter.FloatToByte(data, true));
|
|
cc24?.NotifyCamAcqComplete(index);
|
|
}
|
|
public void NoticeCamComplete(int index, List<float> data)
|
|
{
|
|
cc24?.NotifyCamInspectionComplete(index, DataConverter.FloatToByte(data, true));
|
|
cc24?.NotifyCamAcqComplete(index);
|
|
}
|
|
private void CC24_NewUserDataReceived(object sender, CogNdmNewUserDataEventArgs e)
|
|
{
|
|
OnDataReceived?.Invoke(DataConverter.ByteToFloat(cc24.ReadBytesFromPLC(0, 4), true));
|
|
}
|
|
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);
|
|
}
|
|
}
|
|
}
|