Flow Meter(FML300-D SERIES) 제어 클래스 - C#
Software/C#2025. 3. 11. 15:35
반응형
public class FML300
{
private readonly SerialPort commPort ;
private readonly ModbusSerialMaster modbusSerialMaster ;
public FML300(ModbusSerialMaster modbusSerial)
{
modbusSerialMaster = modbusSerial;
}
//---------------------------------------------------------------------------
public FML300(SerialPort serialPort)
{
commPort = serialPort ;
modbusSerialMaster = ModbusSerialMaster.CreateRtu(commPort) ;
}
//---------------------------------------------------------------------------
public FML300(string portNumber)
{
try
{
commPort = new SerialPort(portNumber, 38400) ;
commPort.Parity = Parity.None;
commPort.StopBits = StopBits.One;
commPort.ReadTimeout = 100;
commPort.WriteTimeout = 100;
commPort.Open();
modbusSerialMaster = ModbusSerialMaster.CreateRtu(commPort) ;
}
catch
{
}
}
//---------------------------------------------------------------------------
public bool InstantaneousFlowRate(byte DeviceAddress, ref double FlowRate)
{
bool result = true ;
try
{
var buffer = modbusSerialMaster.ReadInputRegisters(DeviceAddress, 3, 1);
FlowRate = buffer[0] ;
}
catch
{
result = false ;
}
return result ;
}
//---------------------------------------------------------------------------
public bool FlowTemperature(byte DeviceAddress, ref double Temperature)
{
bool result = true ;
try
{
var buffer = modbusSerialMaster.ReadInputRegisters(DeviceAddress, 4, 1) ;
Temperature = buffer[0] ;
if(Temperature > 6000) Temperature = 0; // 물이 흐르지 않으면 온도가 큰값이 읽혀진다.
}
catch
{
result = false ;
}
return result ;
}
//---------------------------------------------------------------------------
public int FlowRateAndTemperature(byte DeviceAddress, ref double FlowRate, ref double Temperature)
{
int result = 0 ;
try
{
var buffer = modbusSerialMaster.ReadInputRegisters(DeviceAddress, 1, 4) ;
FlowRate = (double)buffer[1] / 100.0 ;
Temperature = (double)buffer[2] / 10.0 ;
if(Temperature > 6000) Temperature = 0; // 물이 흐르지 않으면 온도가 큰값이 읽혀진다.
}
catch
{
result = -1 ;
}
return result ;
}
//---------------------------------------------------------------------------
}반응형
'Software > C#' 카테고리의 다른 글
| IEEE754 단정밀(32Bit) 데이타와 float 형 변수의 상호 변환 - C# (0) | 2025.03.31 |
|---|---|
| YAML 로 프로그램 설정 데이타 저장 및 불러오기 - C# (0) | 2025.03.14 |
| Chroma IT 의 UPS(Rodem Series) 제어 클래스 - C# (0) | 2025.03.11 |
| Nice Cool 의 칠러 제어 (CM Series) (0) | 2024.10.29 |
| C#으로 만들어 보는 Sokoban Game(WPF) (0) | 2024.04.18 |
댓글()








