You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

61 lines
1.3 KiB
C#

3 months ago
using System.IO.Ports;
namespace NDSD_Screwdriver.Tool
{
public class SerialPortFactory
{
private SerialPort serialPortModbus;
private hfIIReader reader;
public SerialPortFactory(string portName="COM13")
{
reader = new hfIIReader();
serialPortModbus = new SerialPort();
serialPortModbus.BaudRate = 9600;
serialPortModbus.PortName = portName;
serialPortModbus.ReadTimeout = 0;
}
public string Read()
{
3 months ago
if (!serialPortModbus.IsOpen)
{
serialPortModbus.Open();
}
var b = reader.Connect(serialPortModbus, 2000, 0);
3 months ago
string str2 = "";
ushort[] array6 = reader.ReadTagMemory(ref str2, 28, 4);
string text6 = "";
for (int j = 0; j < 4; j += 1)
{
text6 += array6[j].ToString("X").PadLeft(4, '0');
if (text6.Length > 0)
{
text6 += "";
}
}
return text6;
}
public void Disconnect()
{
if (!serialPortModbus.IsOpen)
{
serialPortModbus.Close();
}
reader.Disconnect();
}
}
}