140 lines
6.8 KiB
C#
140 lines
6.8 KiB
C#
using Hermes;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using WeldingCommon.Devices;
|
|
|
|
namespace ILSOS_PrismaticScanner.Device
|
|
{
|
|
partial class PLCControllerPrismaticScanner
|
|
{
|
|
public (int err, bool data) ReadBit(eBitInput address) => ReadBit((ushort)address, ePLCDevice.M);
|
|
public (int err, bool data) ReadOutBit(eBitOutput address) => ReadBit((ushort)address, ePLCDevice.M, isInput: false);
|
|
public int WriteBit(eBitOutput addrOffset, bool onOff, ePLCDevice device = ePLCDevice.M, bool isOutput = true) => base.WriteBit((int)addrOffset, onOff, ePLCDevice.M, isOutput);
|
|
public (int err, short data) ReadWord(eWordInput address) => base.ReadWord((ushort)address, ePLCDevice.D);
|
|
public int WriteWord(eWordOutput addrOffset, short data, ePLCDevice device = ePLCDevice.D, bool isOutput = true) => base.WriteWord((int)addrOffset, data, ePLCDevice.D, isOutput);
|
|
|
|
public (int err, int data) ReadDWord(eWordInput address) => base.ReadDWord((ushort)address, ePLCDevice.D);
|
|
public int WriteDWord(eWordOutput addrOffset, int data, ePLCDevice device = ePLCDevice.D, bool isOutput = true) => base.WriteDWord((int)addrOffset, data, ePLCDevice.D, isOutput);
|
|
public (int err, short[] datas) ReadWords(eWordInput startAddress, eWordInput endAddress) => base.ReadWordBlock((int)startAddress, endAddress - startAddress + 1, ePLCDevice.D);
|
|
public int WriteWords(eWordOutput startAddress, eWordOutput endAddress, short[] data, ePLCDevice device = ePLCDevice.D, bool isOutput = true) => base.WriteWordBlock((int)startAddress, endAddress - startAddress, data, ePLCDevice.D, isOutput);
|
|
|
|
|
|
#region Word Bitmasking >> 워드 영역을 비트마스킹으로 사용하는 경우
|
|
public int WriteWordToBit((eWordOutput addrOffset, int bitNo) address, bool on)
|
|
{
|
|
var value = base.ReadWord((int)address.addrOffset, ePLCDevice.D, false);
|
|
short current = value.data;
|
|
|
|
if (on) {
|
|
current |= (short)(1 << address.bitNo);
|
|
} else {
|
|
current &= (short)~(1 << address.bitNo);
|
|
}
|
|
|
|
return base.WriteWord((int)address.addrOffset, current, ePLCDevice.D);
|
|
}
|
|
|
|
public bool ReadWordToBit((eWordInput addrOffset, int bitNo) address)
|
|
{
|
|
var value = base.ReadWord((int)address.addrOffset, ePLCDevice.D);
|
|
short current = value.data;
|
|
|
|
return (current & (1 << address.bitNo)) != 0;
|
|
}
|
|
#endregion
|
|
|
|
public double ReadDWordByDivision(eWordInput input)
|
|
{
|
|
var result = ReadDWord((int)input);
|
|
if (result.err != E1.OK) {
|
|
// 로그 에러 넣기
|
|
//Log.E("Error While Reading Double Word Division {0}", result.err.ToString());
|
|
}
|
|
int divisionIndex = ConvertTo2WordDivisionIndex(input);
|
|
|
|
return (double)(result.data / divisionIndex);
|
|
}
|
|
|
|
public int ConvertTo2WordDivisionIndex(eWordInput input)
|
|
{
|
|
var id = input.ToString();
|
|
if (id.Contains("RAMPING_START_POWER") || id.Contains("RAMPING_END_POWER") || id.Contains("NUM") || id.Contains("TIME"))
|
|
return 1;
|
|
else if (id.Contains("SPEED") || id.Contains("POWER_CORE") || id.Contains("POWER_RING"))
|
|
return 10;
|
|
//else if (id.Contains("POWER_CORE") || id.Contains("POWER_RING"))
|
|
// return 100;
|
|
else// if (id.Contains("DIST"))
|
|
return 1000;
|
|
|
|
//if (id == "PLC_HOR_WELDING_RECIPE_NUM1" ||
|
|
// id == "PLC_VER_WELDING_MAIN_POWER_CORE1" ||
|
|
// id == "PLC_VER_WELDING_MAIN_POWER_RING1" ||
|
|
// id == "PLC_VER_WELDING_MAIN_RAMPING_START_POWER1" ||
|
|
// id == "PLC_VER_WELDING_MAIN_RAMPING_END_POWER1" ||
|
|
// id == "PLC_VER_WELDING_SUB_POWER_CORE1" ||
|
|
// id == "PLC_VER_WELDING_SUB_POWER_RING1" ||
|
|
// id == "PLC_VER_WELDING_RECIPE_NUM1" ||
|
|
// id == "PLC_HOR_WELDING_MAIN_POWER_CORE1" ||
|
|
// id == "PLC_HOR_WELDING_MAIN_POWER_RING1" ||
|
|
|
|
// id == "PC_HOR_WELDING_RECIPE_NUM1" ||
|
|
// id == "PC_HOR_WELDING_MAIN_POWER_CORE1" ||
|
|
// id == "PC_HOR_WELDING_MAIN_POWER_RING1" ||
|
|
// id == "PC_VER_WELDING_RECIPE_NUM1" ||
|
|
// id == "PC_VER_WELDING_MAIN_POWER_CORE1" ||
|
|
// id == "PC_VER_WELDING_MAIN_POWER_RING1" ||
|
|
// id == "PC_VER_WELDING_SUB_POWER_CORE1" ||
|
|
// id == "PC_VER_WELDING_SUB_POWER_RING1" ||
|
|
// id == "PC_VER_WELDING_MAIN_RAMPING_START_POWER1"||
|
|
// id == "PC_VER_WELDING_MAIN_RAMPING_END_POWER1"
|
|
// )
|
|
// return true;
|
|
//else
|
|
// return false;
|
|
}
|
|
|
|
public int ConvertTo2WordDivisionIndex(eWordOutput input)
|
|
{
|
|
var id = input.ToString();
|
|
if (id.Contains("RAMPING_START_POWER") || id.Contains("RAMPING_END_POWER") || id.Contains("NUM") || id.Contains("TIME"))
|
|
return 1;
|
|
else if (id.Contains("SPEED") || id.Contains("POWER_CORE") || id.Contains("POWER_RING"))
|
|
return 10;
|
|
//else if (id.Contains("POWER_CORE") || id.Contains("POWER_RING"))
|
|
// return 100;
|
|
else// if (id.Contains("DIST"))
|
|
return 1000;
|
|
|
|
//if (id == "PLC_HOR_WELDING_RECIPE_NUM1" ||
|
|
// id == "PLC_VER_WELDING_MAIN_POWER_CORE1" ||
|
|
// id == "PLC_VER_WELDING_MAIN_POWER_RING1" ||
|
|
// id == "PLC_VER_WELDING_MAIN_RAMPING_START_POWER1" ||
|
|
// id == "PLC_VER_WELDING_MAIN_RAMPING_END_POWER1" ||
|
|
// id == "PLC_VER_WELDING_SUB_POWER_CORE1" ||
|
|
// id == "PLC_VER_WELDING_SUB_POWER_RING1" ||
|
|
// id == "PLC_VER_WELDING_RECIPE_NUM1" ||
|
|
// id == "PLC_HOR_WELDING_MAIN_POWER_CORE1" ||
|
|
// id == "PLC_HOR_WELDING_MAIN_POWER_RING1" ||
|
|
|
|
// id == "PC_HOR_WELDING_RECIPE_NUM1" ||
|
|
// id == "PC_HOR_WELDING_MAIN_POWER_CORE1" ||
|
|
// id == "PC_HOR_WELDING_MAIN_POWER_RING1" ||
|
|
// id == "PC_VER_WELDING_RECIPE_NUM1" ||
|
|
// id == "PC_VER_WELDING_MAIN_POWER_CORE1" ||
|
|
// id == "PC_VER_WELDING_MAIN_POWER_RING1" ||
|
|
// id == "PC_VER_WELDING_SUB_POWER_CORE1" ||
|
|
// id == "PC_VER_WELDING_SUB_POWER_RING1" ||
|
|
// id == "PC_VER_WELDING_MAIN_RAMPING_START_POWER1"||
|
|
// id == "PC_VER_WELDING_MAIN_RAMPING_END_POWER1"
|
|
// )
|
|
// return true;
|
|
//else
|
|
// return false;
|
|
}
|
|
}
|
|
}
|