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

65 lines
1.6 KiB

namespace EC.Utils.SerialPortHelper
{
/// <summary>
/// EC 串口管理类
/// </summary>
public class SerialPortManager
{
/// <summary>
/// 根据参数对象创建
/// </summary>
/// <param name="serialCustomer"></param>
/// <returns></returns>
public static ECSerialPort CreateSerialPort(SerialCustomer serialCustomer)
{
return new ECSerialPort(serialCustomer);
}
/// <summary>
/// 获取默认参数串口
/// </summary>
/// <returns></returns>
public static ECSerialPort CreateDefaultSerialPort(string comName)
{
SerialCustomer serialCustomer = new SerialCustomer
{
ComName = comName
};
return new ECSerialPort(serialCustomer);
}
/// <summary>
/// 根据不同波特率创建串口
/// </summary>
/// <param name="comName"></param>
/// <param name="baudRate"></param>
/// <returns></returns>
public static ECSerialPort CreateSerialPort(string comName, int baudRate)
{
SerialCustomer serialCustomer = new SerialCustomer
{
ComName = comName,
BaudRate = baudRate
};
return new ECSerialPort(serialCustomer);
}
/// <summary>
/// 根据不同波特率创建串口
/// </summary>
/// <param name="comName"></param>
/// <param name="baudRate"></param>
/// <param name="receivedBytesThreshold"></param>
/// <returns></returns>
public static ECSerialPort CreateSerialPort(string comName, int baudRate, int receivedBytesThreshold)
{
SerialCustomer serialCustomer = new SerialCustomer
{
ComName = comName,
BaudRate = baudRate,
ReceivedBytesThreshold = receivedBytesThreshold
};
return new ECSerialPort(serialCustomer);
}
}
}