From feb09b14aed65a0c65564d7939994495d7d51d2b Mon Sep 17 00:00:00 2001
From: iioter <535915157@qq.com>
Date: Mon, 22 Aug 2022 12:45:49 +0800
Subject: [PATCH] =?UTF-8?q?=E8=A5=BF=E9=97=A8=E5=AD=90=E6=94=AF=E6=8C=81?=
=?UTF-8?q?=E4=B8=A4=E7=A7=8D=E5=AD=97=E7=AC=A6=E4=B8=B2=E8=AF=BB=E5=8F=96?=
=?UTF-8?q?=E5=92=8C=E4=B8=8B=E5=8F=91?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
IoTGateway/iotgateway.db | Bin 311296 -> 311296 bytes
Plugins/Drivers/DriverSiemensS7/SiemensS7.cs | 93 ++++++++++++++-----
2 files changed, 71 insertions(+), 22 deletions(-)
diff --git a/IoTGateway/iotgateway.db b/IoTGateway/iotgateway.db
index 5727705d0c922262b772fbf6d0cf440055169a8f..c24e360fab02b6d1b003f5a040e5fddc8f90f5f4 100644
GIT binary patch
delta 886
zcma))Pe>F|9LIOwzWq1un~64a6=8E-$u(zr^JZpeX2aN-o!Pb61xc1JYb5MuhFH2Q
z(ZN)*Iz(Xv4%xwu5||g^(V>$BMG)1+qEkXQ&z?FoZb@Jl;dl65e&6qhAD{X8$h
~Zs;W!Qw+YbMBuSaK8@1sBnntbO_z$KTplevevhtv^3TS23yY`|l
z;@<)MT|UG;;yTb1bUeHqKHc)RWt9El-wAyPT@9v#&jX(V>xZt$$6+SMQ+h^jOmG$QCE8~pH}p15w{U_mr-kb&@hOGr5q9Rc{MG_x|kO<3u8gD
zP0_-NWgDW!9Y9!r3E(~f{eA%^eSQ0epAw4Z%~OmS=Z7X*(loSDXu#JnQKr*G
zL6k<4i%2ZPiv}8$;3AV?;L;*mNKgb(D}z=Bg$wHs2p7HCwCD%KIot2~o^w9msj0dt
zyQjGdfN{Sc1#84Dp&o6bB{YHhP>=@VKxO@L@WeNdo7?B-W+DAC0K%+y5WMIK@Z3g?
zbIs|7XSof>8%Gm}=1MRiI-NXd2BQ2jR)frDEB-8oFqePg>{4tx~>xsbqyZLqrc<`|#x);U3}^>Cl25jqWkn!VM~>kx8eMvLtKTzwigz
s969cP@X+-O@D#^0=QykrY@h0Ntoyp{L+>90VJ<)?20 count)
- toWrite = ((byte[])toWrite).Take(count);
- plc?.Write(DataType.DataBlock, db, startAdr, toWrite);
-
- rpcResponse.IsSuccess = true;
- return rpcResponse;
+ var arrParams = ioarg.Address.Trim().Split(',');
+ if (arrParams.Length == 2)
+ {
+ var dataItem = DataItem.FromAddress(arrParams[0]);
+ plc?.Write(dataItem.DataType, dataItem.DB, dataItem.StartByteAdr, toWrite);
+ rpcResponse.IsSuccess = true;
+ return rpcResponse;
+ }
}
else
rpcResponse.Description = $"不支持写入:{method}";
@@ -303,5 +317,40 @@ namespace DriverSiemensS7
return rpcResponse;
}
+
+ private byte[]? GetStringBytes(DriverAddressIoArgModel ioarg)
+ {
+ var toWriteString = ioarg.Value.ToString();
+ try
+ {
+ var arrParams = ioarg.Address.Trim().Split(',');
+ int length = 0;//最大长度,因为字符串后面得补满'\0'
+ //直接读取byte[]的方式
+ if (arrParams.Length == 2)
+ {
+ //如DB100.DBW23,10
+ int.TryParse(arrParams[1], out length);
+ }
+ //使用西门子String读取
+ else
+ {
+ //如DB100.DBW23
+ var dataItem = DataItem.FromAddress(ioarg.Address);
+ var head = plc.ReadBytes(dataItem.DataType, dataItem.DB, dataItem.StartByteAdr, 2);
+ length = head[0];
+ }
+
+ if (toWriteString.Length > length)
+ toWriteString = toWriteString.Take(length).ToString();
+ if (toWriteString.Length < length)
+ toWriteString = toWriteString.PadRight(length, '\0');
+ }
+ catch (Exception e)
+ {
+ throw new Exception("字符串解析异常");
+ }
+
+ return Encoding.ASCII.GetBytes(toWriteString);
+ }
}
}
\ No newline at end of file