apache / plc4x

PLC4X The Industrial IoT adapter

Home Page:https://plc4x.apache.org/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[Feature Request]: S7_1500 String can be read, but cannot be written

cptjackwu opened this issue · comments

What would you like to happen?

image
image

When I write to the same address, I will report an error

image

image

So I'm not sure where the problem is right now. Can you help me point out the problem?

Programming Languages

  • plc4j
  • plc4go
  • plc4c
  • plc4net

Protocols

  • AB-Ethernet
  • ADS /AMS
  • BACnet/IP
  • CANopen
  • DeltaV
  • DF1
  • EtherNet/IP
  • Firmata
  • KNXnet/IP
  • Modbus
  • OPC-UA
  • S7

When I write like this, I also report the same error
dataTowrite[1] =(byte)7;

String value = "ac";
byte[] stringvalue = value.getBytes();
byte[] dataTowrite = new byte[stringvalue.length+2];
dataTowrite[0] = (byte)2;
dataTowrite[1] =(byte)2;
System.arraycopy(stringvalue,0 ,dataTowrite,2,stringvalue.length);

builder.addItem("value-3", "%DB5000:6:STRING(2)",dataTowrite);
or
builder.addItem("value-3", "%DB5000:6:STRING",dataTowrite);
or
builder.addItem("value-3", "%DB5000:6:STRING(2)",stringvalue );
or
builder.addItem("value-3", "%DB5000:6:STRING(2)",value);
or
builder.addItem("value-3", "%DB5000:6:STRING(4)",dataTowrite);
or
builder.addItem("value-3", "%DB5000:8:STRING(2)",stringvalue );
......

I have tried writing n types and all reported the same error。

Could you try my repository?

@spnettec: Please stop simply blindly guiding folks to your fork ... this is totally not a cool way to participate in an open-source project. If you find bugs, it would be nice if you would create PRs that address one issue at a time and if you would start accepting a discussion around your solution that goes beyond: "That's what I needed". Working on a project like PLC4X requires considering more than that one use-case you have. If you continue simply replying with "use my fork" on every issue here, I'll start removing them.

@spnettec I totally agree with Chris, this is the second time we've brought this up. Thanks anyway for your contribution to PLC4X.

As a workaround you could try to write the String as multiple USINT (as i had problems writing them as an array):

val db = 1000
val lengthOfStringInS7 = 30
val string: String = "abc"
val toWrite = (""+Char(lengthOfStringInS7)+Char(string.length)+string).take(lengthOfStringInS7+2).toCharArray().mapIndexed{ idx, chr ->
Triple("fancy_field_name_$idx", "${db+idx}:USINT" , chr.code)
}

val writeResponse = with(plcConnection.writeRequestBuilder()) {
toWrite.forEach { (name, fieldQuery, value) ->
addItem(name, fieldQuery, value)
}
build()
}.execute()[5000, TimeUnit.MILLISECONDS]

Code is Kotlin, and it's a stripped excerpt of a larger project, so expect some errors while substituting variable names. And better lookup the meaning of the first two bytes. For me it works, but it looks like its not checked by the S7 when written..?

Should be fixed now.