409 lines
16 KiB
C#
409 lines
16 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace AuroraHeightSensor.Keyence
|
|
{
|
|
enum e_HS_ERROR_CODE
|
|
{
|
|
ERROR_DIFFERENT_RETURN_COUNT = -3, // add new error
|
|
ERROR_DIFFERENT_MAIN_COMMAND = -2, // add new error
|
|
ERROR_NO = -1,
|
|
ERROR_COMMAND = 0,
|
|
ERROR_STATUS = 1,
|
|
ERROR_COMMAND_LENGTH = 20,
|
|
ERROR_PARAMETER_COUNT = 21,
|
|
ERROR_INDIVIDUAL_PARAMETER = 22,
|
|
ERROR_TIMEOVER = 88,
|
|
ERROR_OTHER = 99
|
|
};
|
|
|
|
enum e_HS_OUTPUT
|
|
{
|
|
CH_OUT_DUAL = 0,
|
|
CH_OUT1 = 1,
|
|
CH_OUT2 = 2
|
|
};
|
|
|
|
enum e_HS_HEAD
|
|
{
|
|
HEAD_A = 1,
|
|
HEAD_B = 2
|
|
};
|
|
|
|
enum e_HS_MEASUREMENT_MODE
|
|
{
|
|
NORMAL = 0,
|
|
TRANSLUCENT = 1,
|
|
TRANSPARENT = 2,
|
|
TRANSPARENT2 = 3,
|
|
MULTIREFRECTIVE = 4
|
|
};
|
|
|
|
enum e_HS_FILTER_MODE
|
|
{
|
|
FILTER_AVERAGE = 0,
|
|
FILTER_LOWPASS = 1,
|
|
FILTER_HIGHPASS = 2
|
|
}
|
|
|
|
public partial class HeightSensorLKG85 {
|
|
private bool CMD_MeasureControl_GetMeasureValue(int channel, ref double value) {
|
|
if (!CheckRange(channel, (int)e_HS_OUTPUT.CH_OUT1, (int)e_HS_OUTPUT.CH_OUT2)) {
|
|
return false;
|
|
}
|
|
|
|
string strSendCommand = string.Empty;
|
|
strSendCommand = string.Format("M{0}", (int)(e_HS_OUTPUT)channel);
|
|
|
|
string strReceiveValue = string.Empty;
|
|
if (ReceiveValue(strSendCommand, ref strReceiveValue) == false) {
|
|
return false;
|
|
}
|
|
|
|
// receive
|
|
// TODO : receive value 에 'CR' 이 붙어 있을 수 있음. check 필요
|
|
var splitedStr = strReceiveValue.Split(',');
|
|
if (splitedStr.Length < 2) {
|
|
return false;
|
|
}
|
|
|
|
if (GetFormatMeasureData(splitedStr[1], ref value) == false) {
|
|
return false;
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
// BOOL CHeightSensorCom::cmdGetMeasureValue(int iCH,double& dValue)
|
|
private bool CMD_MeasureControl_GetMeasureValueDual(ref double value1, ref double value2) {
|
|
string strSendCommand = string.Empty;
|
|
strSendCommand = string.Format("M{0}", (int)e_HS_OUTPUT.CH_OUT_DUAL);
|
|
|
|
string strReceiveValue = string.Empty;
|
|
if (ReceiveValue(strSendCommand, ref strReceiveValue) == false) {
|
|
return false;
|
|
}
|
|
|
|
// receive
|
|
// TODO : receive value 에 'CR' 이 붙어 있을 수 있음. check 필요
|
|
var splitedStr = strReceiveValue.Split(',');
|
|
if (splitedStr.Length < 3) {
|
|
return false;
|
|
}
|
|
|
|
if (GetFormatMeasureData(splitedStr[1], ref value1) == false) {
|
|
return false;
|
|
}
|
|
if (GetFormatMeasureData(splitedStr[2], ref value2) == false) {
|
|
return false;
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
// BOOL CHeightSensorCom::cmdSetAutoZeroOn(int iCH,BOOL bOn)
|
|
private bool CMD_MeasureControl_SetAutoZero(int channel, bool flagOn) {
|
|
if (!CheckRange(channel, (int)e_HS_OUTPUT.CH_OUT_DUAL, (int)e_HS_OUTPUT.CH_OUT2)) {
|
|
return false;
|
|
}
|
|
|
|
string strSendCommand = string.Empty;
|
|
if (flagOn == true) {
|
|
strSendCommand = string.Format("V{0}", channel);
|
|
} else {
|
|
strSendCommand = string.Format("W{0}", channel);
|
|
}
|
|
|
|
return SendCommand(strSendCommand);
|
|
}
|
|
|
|
// BOOL CHeightSensorCom::cmdSetTimingOn(int iCH,BOOL bOn)
|
|
private bool CMD_MeasureControl_SetTiming(int channel, bool flagOn) {
|
|
if (!CheckRange(channel, (int)e_HS_OUTPUT.CH_OUT_DUAL, (int)e_HS_OUTPUT.CH_OUT2)) {
|
|
return false;
|
|
}
|
|
|
|
string strSendCommand = string.Empty;
|
|
strSendCommand = string.Format("T{0},{1}", flagOn ? 1 : 0, channel);
|
|
|
|
return SendCommand(strSendCommand);
|
|
}
|
|
|
|
// BOOL CHeightSensorCom::cmdSetReset(int iCH)
|
|
bool CMD_MeasureControl_SetReset(int channel) {
|
|
if (!CheckRange(channel, (int)e_HS_OUTPUT.CH_OUT_DUAL, (int)e_HS_OUTPUT.CH_OUT2)) {
|
|
return false;
|
|
}
|
|
|
|
string strSendCommand = string.Empty;
|
|
strSendCommand = string.Format("VR,{0}", channel);
|
|
|
|
return SendCommand(strSendCommand);
|
|
}
|
|
|
|
// BOOL CHeightSensorCom::cmdSetPanelLockOn(BOOL bOn)
|
|
private bool CMD_MeasureControl_SetPanelLock(bool flagOn) {
|
|
string strSendCommand = string.Empty;
|
|
strSendCommand = string.Format("KL,{0}", flagOn ? 1 : 0);
|
|
|
|
return SendCommand(strSendCommand);
|
|
}
|
|
|
|
// BOOL CHeightSensorCom::cmdSetDisplayPanel(int iCH)
|
|
bool CMD_SettingChange_SetDisplayPanel(int channel) {
|
|
if (!CheckRange(channel, (int)e_HS_OUTPUT.CH_OUT_DUAL, (int)e_HS_OUTPUT.CH_OUT2)) {
|
|
return false;
|
|
}
|
|
|
|
string strSendCommand = string.Empty;
|
|
strSendCommand = string.Format("DC,{0}", channel);
|
|
|
|
return SendCommand(strSendCommand);
|
|
}
|
|
|
|
// limit setting, tolerance setting
|
|
// BOOL CHeightSensorCom::cmdSetLimit(int iCH,double dUpperLimit,double dLowLimit,double dHysteresis)
|
|
private bool CMD_SettingChange_SetLimit(int channel, double maxLimit, double minLimit, double hysteresis) {
|
|
if (!CheckRange(channel, (int)e_HS_OUTPUT.CH_OUT1, (int)e_HS_OUTPUT.CH_OUT2)) {
|
|
return false;
|
|
}
|
|
|
|
string strSendCommand = string.Empty;
|
|
strSendCommand = string.Format("SW,LM,{0},{1}{2},{3}{4},0{5}{6}", channel
|
|
, GetSign(maxLimit), GetMeasureDoubleFormat(maxLimit, 6)
|
|
, GetSign(minLimit), GetMeasureDoubleFormat(minLimit, 6)
|
|
, GetSign(hysteresis), GetMeasureDoubleFormat(hysteresis, 5));
|
|
return SendCommand(strSendCommand);
|
|
}
|
|
|
|
// BOOL CHeightSensorCom::cmdSetABLE(int iHead,BOOL bAutoMode)
|
|
private bool CMD_SettingChange_SetHead_ABLE(int head, bool flagAutoMode) {
|
|
if (!CheckRange(head, (int)e_HS_HEAD.HEAD_A, (int)e_HS_HEAD.HEAD_B)) {
|
|
return false;
|
|
}
|
|
|
|
string strSendCommand = string.Empty;
|
|
strSendCommand = string.Format("SW,HA,M,{0},{1}", head, flagAutoMode ? 0 : 1);
|
|
|
|
return SendCommand(strSendCommand);
|
|
}
|
|
|
|
// BOOL CHeightSensorCom::cmdSetABLEControlRange(int iHead,int iUpperLimit,int iLowLimit)
|
|
private bool CMD_SettingChange_SetHead_ABLEControlRange(int head, int minLimit, int maxLimit) {
|
|
if (!CheckRange(head, (int)e_HS_HEAD.HEAD_A, (int)e_HS_HEAD.HEAD_B)) {
|
|
return false;
|
|
}
|
|
if (!CheckRange(minLimit, 1, 99)) {
|
|
return false;
|
|
}
|
|
if (!CheckRange(maxLimit, 1, 99)) {
|
|
return false;
|
|
}
|
|
|
|
string strSendCommand = string.Empty;
|
|
strSendCommand = string.Format("SW,HA,R,{0},{1},{2}", head
|
|
, GetMeasureDoubleFormat(maxLimit, 2), GetMeasureDoubleFormat(minLimit, 2));
|
|
|
|
return SendCommand(strSendCommand);
|
|
}
|
|
|
|
// BOOL CHeightSensorCom::cmdSetMeasurementMode(int iHead,int iMode)
|
|
private bool CMD_SettingChange_SetHead_SetMeasurementMode(int head, int mode) {
|
|
if (!CheckRange(head, (int)e_HS_HEAD.HEAD_A, (int)e_HS_HEAD.HEAD_B)) {
|
|
return false;
|
|
}
|
|
if (!CheckRange(mode, (int)e_HS_MEASUREMENT_MODE.NORMAL, (int)e_HS_MEASUREMENT_MODE.MULTIREFRECTIVE)) {
|
|
return false;
|
|
}
|
|
|
|
string strSendCommand = string.Empty;
|
|
strSendCommand = string.Format("SW,HB,{0},{1}", head, mode);
|
|
|
|
return SendCommand(strSendCommand);
|
|
}
|
|
|
|
// BOOL CHeightSensorCom::cmdSetNumberOfAlarmProcessing(int iHead,int iTime)
|
|
private bool CMD_SettingChange_SetHead_SetAlarmProcessingNumber(int head, int time) {
|
|
if (!CheckRange(head, (int)e_HS_HEAD.HEAD_A, (int)e_HS_HEAD.HEAD_B)) {
|
|
return false;
|
|
}
|
|
if (!CheckRange(time, 0, 999)) {
|
|
return false;
|
|
}
|
|
|
|
string strSendCommand = string.Empty;
|
|
strSendCommand = string.Format("SW,HC,N,{0},{1}", head, GetMeasureDoubleFormat(time, 3));
|
|
|
|
return SendCommand(strSendCommand);
|
|
}
|
|
|
|
// BOOL CHeightSensorCom::cmdSetAlarmLevel(int iHead,int iLevel)
|
|
private bool CMD_SettingChange_SetHead_SetAlarmLevel(int head, int level) {
|
|
if (!CheckRange(head, (int)e_HS_HEAD.HEAD_A, (int)e_HS_HEAD.HEAD_B)) {
|
|
return false;
|
|
}
|
|
if (!CheckRange(level, 0, 9)) {
|
|
return false;
|
|
}
|
|
|
|
string strSendCommand = string.Empty;
|
|
strSendCommand = string.Format("SW,HC,L,{0},{1}", head, level);
|
|
|
|
return SendCommand(strSendCommand);
|
|
}
|
|
|
|
// BOOL CHeightSensorCom::cmdSetABLECalibrationStart(int iHead)
|
|
private bool CMD_SettingChange_SetHead_ABLECalibrationStart(int head) {
|
|
if (!CheckRange(head, (int)e_HS_HEAD.HEAD_A, (int)e_HS_HEAD.HEAD_B)) {
|
|
return false;
|
|
}
|
|
|
|
string strSendCommand = string.Empty;
|
|
strSendCommand = string.Format("SW,HD,S,{0}", head);
|
|
|
|
return SendCommand(strSendCommand);
|
|
}
|
|
|
|
// BOOL CHeightSensorCom::cmdSetABLECalibrationFinish()
|
|
private bool CMD_SettingChange_SetHead_ABLECalibrationFinish() {
|
|
string strSendCommand = string.Empty;
|
|
strSendCommand = string.Format("SW,HD,P");
|
|
|
|
return SendCommand(strSendCommand);
|
|
}
|
|
|
|
// BOOL CHeightSensorCom::cmdSetABLECalibrationStop()
|
|
private bool CMD_SettingChange_SetHead_ABLECalibrationStop() {
|
|
string strSendCommand = string.Empty;
|
|
strSendCommand = string.Format("SW,HD,C");
|
|
|
|
return SendCommand(strSendCommand);
|
|
}
|
|
|
|
// bDiffuse reflection = 0
|
|
// Mirror reflection = 1
|
|
// BOOL CHeightSensorCom::cmdSetMountingMode(int iHead,BOOL bDiffuse)
|
|
private bool CMD_SettingChange_SetHead_ABLECalibrationStop(int head, bool flagDiffuseReflection) {
|
|
if (!CheckRange(head, (int)e_HS_HEAD.HEAD_A, (int)e_HS_HEAD.HEAD_B)) {
|
|
return false;
|
|
}
|
|
|
|
string strSendCommand = string.Empty;
|
|
strSendCommand = string.Format("SW,HE,{0},{1}", head, flagDiffuseReflection ? 0 : 1);
|
|
|
|
return SendCommand(strSendCommand);
|
|
}
|
|
|
|
// BOOL CHeightSensorCom::cmdSetCalcurationMethod(int iCalMethod,int iWaveForm)
|
|
private bool CMD_SettingChange_SetOut_SetCalcurationMethod(int channel, int calcurationMethod, int waveForm) {
|
|
// Not Implement Yet
|
|
return false;
|
|
}
|
|
|
|
|
|
// BOOL CHeightSensorCom::cmdSetScaling(int iHead,int iCH,double dMeasVal1,double dDispVal1,double dMeasVal2,double dDispVal2)
|
|
// TODO : command 의 설정값 format 은 spec 문서에 맞게 변경함. (확인 필요)
|
|
private bool CMD_SettingChange_SetOut_SetScaling(int head, int channel
|
|
, double measurementValue1, double displayValue1
|
|
, double measurementValue2, double displayValue2) {
|
|
if (!CheckRange(head, (int)e_HS_HEAD.HEAD_A, (int)e_HS_HEAD.HEAD_B)) {
|
|
return false;
|
|
}
|
|
if (!CheckRange(channel, (int)e_HS_OUTPUT.CH_OUT1, (int)e_HS_OUTPUT.CH_OUT2)) {
|
|
return false;
|
|
}
|
|
|
|
//1 : Head A of OUT1
|
|
//2 : Head B of OUT1
|
|
//3 : Head A of OUT2
|
|
//4 : Head B of OUT2
|
|
int requestChannelHead = (channel == (int)e_HS_OUTPUT.CH_OUT1) ? head : (head + (int)e_HS_OUTPUT.CH_OUT2);
|
|
|
|
string strSendCommand = string.Empty;
|
|
strSendCommand = string.Format("SW,OB,{0},{1}{2},{3}{4},{5}{6},{7}{8}", requestChannelHead
|
|
, GetSign(measurementValue1), GetMeasureDoubleFormat(measurementValue1, 6)
|
|
, GetSign(displayValue1), GetMeasureDoubleFormat(displayValue1, 6)
|
|
, GetSign(measurementValue2), GetMeasureDoubleFormat(measurementValue2, 6)
|
|
, GetSign(displayValue2), GetMeasureDoubleFormat(displayValue2, 6));
|
|
|
|
return SendCommand(strSendCommand);
|
|
}
|
|
|
|
// BOOL CHeightSensorCom::cmdSetAnalogOutputScaling(int iCH,double dDispVal1,double dOutputVal1,double dDispVal2,double dOutputVal2)
|
|
// TODO : command 의 설정값 format 은 spec 문서에 맞게 변경함. (확인 필요)
|
|
private bool CMD_SettingChange_SetOut_SetScaling(int channel, double measurementValue1, double displayValue1
|
|
, double measurementValue2, double displayValue2) {
|
|
if (!CheckRange(channel, (int)e_HS_OUTPUT.CH_OUT1, (int)e_HS_OUTPUT.CH_OUT2)) {
|
|
return false;
|
|
}
|
|
|
|
string strSendCommand = string.Empty;
|
|
strSendCommand = string.Format("SW,OH,{0},{1}{2},{3}{4},{5}{6},{7}{8}", channel
|
|
, GetSign(measurementValue1), GetMeasureDoubleFormat(measurementValue1 * 1000, 6)
|
|
, GetSign(displayValue1), GetMeasureDoubleFormat(displayValue1 * 1000, 6)
|
|
, GetSign(measurementValue2), GetMeasureDoubleFormat(measurementValue2 * 1000, 6)
|
|
, GetSign(displayValue2), GetMeasureDoubleFormat(displayValue2 * 1000, 6));
|
|
|
|
return SendCommand(strSendCommand);
|
|
}
|
|
|
|
//Number of times of averaging , Cutoff frequency
|
|
//0 : 1 times 0 : 1000Hz
|
|
//1 : 4 times 1 : 300Hz
|
|
//2 : 16 times 2 : 100Hz
|
|
//3 : 64 times 3 : 30Hz
|
|
//4 : 256 times 4 : 10Hz
|
|
//5 : 1024 times 5 : 3Hz
|
|
//6 : 4096 times 6 : 1Hz
|
|
//7 : 16384 times 7 : 0.3Hz
|
|
//8 : 65536 times 8 : 0.1Hz
|
|
//9 : 262144 times
|
|
// BOOL CHeightSensorCom::cmdSetFilter(int iCH,int iFilterMode,int iFilterVal)
|
|
private bool CMD_SettingChange_SetOut_SetFilter(int channel, int filterMode, int filterFrequency) {
|
|
if (!CheckRange(channel, (int)e_HS_OUTPUT.CH_OUT1, (int)e_HS_OUTPUT.CH_OUT2)) {
|
|
return false;
|
|
}
|
|
if (!CheckRange(filterMode, (int)e_HS_FILTER_MODE.FILTER_AVERAGE, (int)e_HS_FILTER_MODE.FILTER_HIGHPASS)) {
|
|
return false;
|
|
}
|
|
if (!CheckRange(filterFrequency, 0, 9)) {
|
|
return false;
|
|
}
|
|
|
|
string strSendCommand = string.Empty;
|
|
strSendCommand = string.Format("SW,OC,{0},{1},{2}", channel, filterMode, filterFrequency);
|
|
|
|
return SendCommand(strSendCommand);
|
|
}
|
|
|
|
private bool CMD_SettingChange_SetOut_SetTriggerMode(int channel, int triggerMode) {
|
|
if (!CheckRange(channel, (int)e_HS_OUTPUT.CH_OUT1, (int)e_HS_OUTPUT.CH_OUT2)) {
|
|
return false;
|
|
}
|
|
if (!CheckRange(triggerMode, 0, 1)) {
|
|
return false;
|
|
}
|
|
|
|
string strSendCommand = string.Empty;
|
|
strSendCommand = string.Format("SW,OE,M,{0},{1}", channel, triggerMode);
|
|
|
|
return SendCommand(strSendCommand);
|
|
}
|
|
|
|
// BOOL CHeightSensorCom::cmdSetOffset(int iCH,double dOffset)
|
|
private bool CMD_SettingChange_SetOut_SetOffset(int channel, double value) {
|
|
if (!CheckRange(channel, (int)e_HS_OUTPUT.CH_OUT1, (int)e_HS_OUTPUT.CH_OUT2)) {
|
|
return false;
|
|
}
|
|
|
|
string strSendCommand = string.Empty;
|
|
strSendCommand = string.Format("SW,OF,{0},{1}{2}", channel, GetSign(value), GetMeasureDoubleFormat(value, 6));
|
|
|
|
return SendCommand(strSendCommand);
|
|
}
|
|
}
|
|
}
|