Nice Cool 의 칠러 제어 (CM Series)
국내 나이스 쿨의 칠러 제어를 위한 코드 입니다. RS232통신을 통해 제어를 합니다.
Modbus RTU 방식으로 처리하고 라이브러리는 NModbus4를 사용하였습니다.
NModbus4 는 Nuget을 통해 설치하시면 됩니다.
/****************************************************************************************************
* Device : Chiller(CM SERIES)
* Manufacture : NiceCool
* Devicce Interface : RS232(Modbus RTU)
* Version : 1.0.0
* Program : Sihwan Kim
*****************************************************************************************************/
public class NiceCool_CMSeries
{
public bool Active { get; set; } = false;
public int ReadTimeout
{
set { modbusSerialMaster.Transport.ReadTimeout = value; }
get { return modbusSerialMaster.Transport.ReadTimeout; }
}
public int WriteTimeout
{
set { modbusSerialMaster.Transport.WriteTimeout = value; }
get { return modbusSerialMaster.Transport.WriteTimeout; }
}
private byte address;
private SerialPort commPort ;
private ModbusSerialMaster modbusSerialMaster ;
public NiceCool_CMSeries(byte Address, ModbusSerialMaster modbusSerial)
{
address = Address;
modbusSerialMaster = modbusSerial;
}
//---------------------------------------------------------------------------
public NiceCool_CMSeries(byte Address, SerialPort serialPort)
{
address = Address;
commPort = serialPort ;
modbusSerialMaster = ModbusSerialMaster.CreateRtu(commPort) ;
}
//---------------------------------------------------------------------------
public NiceCool_CMSeries(byte Address, string portNumber)
{
address = Address;
try
{
commPort = new SerialPort() ;
commPort.PortName = portNumber ;
commPort.BaudRate = 4800;
commPort.Parity = Systehttp://m.IO.Ports.Parity.Even;
commPort.Open();
modbusSerialMaster = ModbusSerialMaster.CreateRtu(commPort) ;
}
catch
{
}
}
//---------------------------------------------------------------------------
public bool Initialize(bool control)
{
bool result = true ;
double temp = 0;
ReadTimeout = 300;
WriteTimeout = 300;
commPort.ReadTimeout = 300;
commPort.WriteTimeout = 300;
if (control) result = WaterTemperature(ref temp) ;
return result;
}
//---------------------------------------------------------------------------
public bool WaterTemperature(ref double Temperature)
{
bool result = true;
try
{
var value = modbusSerialMaster.ReadHoldingRegisters(address, 259, 1) ;
Temperature = value[0] / 10.0 ;
}
catch
{
result = false ;
}
return result;
}
//---------------------------------------------------------------------------
public void SetWaterTemperature(double Temperature)
{
ushort setTemp = (ushort)(Temperature * 10) ;
try
{
modbusSerialMaster.WriteSingleRegister(address, 271, setTemp) ;
}
catch { }
}
//---------------------------------------------------------------------------
public bool Run(bool Status)
{
bool result = true;
try
{
ushort action = 0 ;
if(Status == true) action = 257 ;
else action = 256 ;
modbusSerialMaster.WriteSingleRegister(address, 270, action) ;
Active = Status ;
}
catch
{
result= false ;
}
return result ;
}
//---------------------------------------------------------------------------
public bool WaterFlow(ref double FlowValue)
{
bool result = true;
try
{
var value = modbusSerialMaster.ReadHoldingRegisters(address, 266, 1) ;
FlowValue = value[0] / 10.0 ;
}
catch
{
result = false ;
}
return result;
}
}
'Software > C#' 카테고리의 다른 글
C#으로 만들어 보는 Sokoban Game(WPF) (0) | 2024.04.18 |
---|---|
2차원 배열의 크기를 동적으로 변경 - C# (0) | 2024.04.18 |
C#으로 만들어 보는 Sokoban Game(Winform) (0) | 2024.03.13 |
ScottPlot Multi Axis 그리기 - C# (0) | 2024.01.18 |
사칙연산을 통해 알아보는 Lambda 와 Func 델리게이트 활용 - C# (0) | 2023.12.23 |