/// <summary> /// 向PLC中位软元件写入bool数组,返回值说明,比如你写入M100,values[0]对应M100 /// </summary> /// <param name="address">要写入的数据地址</param> /// <param name="values">要写入的实际数据,可以指定任意的长度</param> /// <example> /// <code lang="cs" source="Communication_Net45.Test\Documentation\Samples\Profinet\MelsecAscii.cs" region="WriteBool" title="Write示例" /> /// </example> /// <returns>返回写入结果</returns> public virtual OperateResult Write(string address, bool[] values) { // 解析指令 OperateResult <byte[]> coreResult = MelsecHelper.BuildAsciiWriteBitCoreCommand(address, values, McAnalysisAddress); if (!coreResult.IsSuccess) { return(coreResult); } // 核心交互 OperateResult <byte[]> read = ReadFromCoreServer(PackMcCommand(coreResult.Content, NetworkNumber, NetworkStationNumber)); if (!read.IsSuccess) { return(read); } // 错误码验证 ushort errorCode = Convert.ToUInt16(Encoding.ASCII.GetString(read.Content, 18, 4), 16); if (errorCode != 0) { return(new OperateResult <byte[]>(errorCode, StringResources.Language.MelsecPleaseReferToManulDocument)); } // 写入成功 return(OperateResult.CreateSuccessResult( )); }