引用 S7NetPlus
创建一个测试程序,此处创建的是一个控制台应用程序。
在 NuGet 下载 S7NetPlus,如下图所示,版本可按需选择
新建一个名为 PLCInstance 的类,创建 PLC 单例。
class PLCInstance
{
private PLCInstance()
{
plcObj = new Plc(CpuType.S71500, "192.168.10.230", 0, 1);
}
/// <summary>
/// PLC 单例
/// </summary>
public static PLCInstance Instance
{
get
{
return Nested.instance;
}
}
/// <summary>
/// 防止调用此类静态方法时,创建新的实例
/// </summary>
private class Nested
{
internal static readonly PLCInstance instance = null;
static Nested()
{
instance = new PLCInstance();
}
}
/// <summary>
/// 私有 PLC 单例对象
/// </summary>
private static Plc plcObj;
评论0