点击或拖拽改变大小

MelsecFxSerialOverTcpReadBool 方法 (String, UInt16)

从三菱PLC中批量读取位软元件,返回读取结果,该读取地址最好从0,16,32...等开始读取,这样可以读取比较长的数据数组
Read bit devices in batches from Mitsubishi PLC and return the read results. The read address should preferably be read from 0, 16, 32... etc., so that a relatively long data array can be read

命名空间:  HslCommunication.Profinet.Melsec
程序集:  HslCommunication (在 HslCommunication.dll 中) 版本:12.1.2.0 (12.1.2.0)
语法
public override OperateResult<bool[]> ReadBool(
	string address,
	ushort length
)

参数

address
类型:SystemString
起始地址
length
类型:SystemUInt16
读取的长度

返回值

类型:OperateResultBoolean
带成功标志的结果数据对象

实现

IReadWriteNetReadBool(String, UInt16)
IReadWriteNetReadBool(String, UInt16)
示例
Bool类型示例
MelsecFxSerial melsecFx = new MelsecFxSerial( );
melsecFx.SerialPortInni( sp =>
{
    sp.PortName = "COM1";
    sp.BaudRate = 9600;
    sp.DataBits = 7;
    sp.StopBits = System.IO.Ports.StopBits.One;
    sp.Parity = System.IO.Ports.Parity.Even;
} );
melsecFx.Open( );

// 以下是简单的读取,没有仔细校验的方式
bool X1 = melsecFx.ReadBool( "X1" ).Content;
bool[] X1_10 = melsecFx.ReadBool( "X1", 10 ).Content;

// 如果需要判断是否读取成功
OperateResult<bool> R_X1 = melsecFx.ReadBool( "X1" );
if (R_X1.IsSuccess)
{
    // success
    bool value = R_X1.Content;
}
else
{
    // failed
}


OperateResult<bool[]> R_X1_10 = melsecFx.ReadBool( "X1", 10 );
if (R_X1_10.IsSuccess)
{
    // success
    bool x1 = R_X1_10.Content[0];
    bool x2 = R_X1_10.Content[1];
    bool x3 = R_X1_10.Content[2];
    bool x4 = R_X1_10.Content[3];
    bool x5 = R_X1_10.Content[4];
    bool x6 = R_X1_10.Content[5];
    bool x7 = R_X1_10.Content[6];
    bool x8 = R_X1_10.Content[7];
    bool x9 = R_X1_10.Content[8];
    bool xa = R_X1_10.Content[9];
}
else
{
    // failed
}
参见