SteinOv opened a new issue, #710:
URL: https://github.com/apache/plc4x/issues/710

   This is a bug that is new in release 0.10.0 and did not exist in 0.9.1.
   
   When doing a write request for a modbus coil, the coil is always set to 
false, no matter the value given.
   
   it can be reproduced by running the plc4j-hello-world-plc4x-write example 
with the following arguments:
   `--connection-string "modbus-tcp:tcp://localhost:502" --field-addresses 
coil:100 coil:101 --field-values true true`
   Even though both values are set to true, the actual coils will be set to 
false. At first I tried it with code I wrote myself, where I encountered the 
issue, so the problem is not in the example code.
   
   
   It occurred both when using an actual modbus slave and another library that 
emulates a slave:
   ```
   import java.util.Arrays;
   
   import com.ghgande.j2mod.modbus.procimg.ProcessImage;
   import com.ghgande.j2mod.modbus.procimg.SimpleDigitalOut;
   import com.ghgande.j2mod.modbus.procimg.SimpleProcessImage;
   import com.ghgande.j2mod.modbus.slave.ModbusSlave;
   import com.ghgande.j2mod.modbus.slave.ModbusSlaveFactory;
   
   import lombok.extern.slf4j.Slf4j;
   
   @Slf4j
   public class Slave {
       private static final boolean[] state = new boolean[1000];
   
       public static void main(String[] args) {
           Arrays.fill(state, true);
           
           ModbusSlave slave = null;
           try {
               ProcessImage image = createProcessImage();
               slave = ModbusSlaveFactory.createTCPSlave(502, 5);
               slave.addProcessImage(1, image);
   
               // Start the slave listening on the port
               slave.open();
               while (true) {
                   try {
                       Thread.sleep(100);
                       for (int i = 0; i < 1000; i++) {
                           // Log if coil changed
                           if (image.getDigitalOut(i).isSet() != state[i]) {
                               state[i] = !state[i];
                               log.info("\n===\naddr {} changed to: 
[{}]\n===\n", i, state[i]);
                           }
   
                       }
                   } catch (InterruptedException e) {
                       Thread.currentThread().interrupt();
                   }
               }
   
           } catch (Exception e) {
               log.error("Modbus Slave error", e);
           } finally {
               if (slave != null) {
                   // Close the slave
                   slave.close();
               }
           }
       }
   
       private static ProcessImage createProcessImage() {
           SimpleProcessImage image = new SimpleProcessImage();
           // Create coils 0-999
           for (int i = 0; i < 1000; i++) {
               image.addDigitalOut(i, new SimpleDigitalOut(state[i]));
           }
           return image;
       }
   }
   
   ```
   
   I used the following modbus library:
   ```
           <dependency>
               <groupId>com.ghgande</groupId>
               <artifactId>j2mod</artifactId>
               <version>3.1.1</version>
           </dependency>
   ```
   
   I tried investigating the plc4j-driver-modbus package:
   The classes in org.apacge.plc4x.java.modbus.base.field have not changed 
between the releases. 
   ModbusProtocolLogic has been refactored into separate abstract 
ModbusProtocolLogic and regular ModbusTcpProtocolLogic classes. But 
functionally not much has changed. 
   - Generated ModbusTcpADU class (renamed from ModbusADU.java) which is used 
in the write() (and read) method has changed. - I could not find any changes 
that could explain the bug, but I may be overlooking something.
   - readCoilBooleanList() method (renamed from readCoilList()) has changed 
somewhat - is not the cause, I tried reverting it to the old version and this 
did not fix it.
   - Generated DataItem class (renamed from DataItemIO) - I could not find any 
changes that could explain the bug, but I may be overlooking something.
   
   I also tried going through the call stack and figuring out where the bug 
could have arisen. But it is quite complex with CompletableFutures and a lot of 
interfaces.
   
   I would appreciate it if someone could help me point to the right place 
where I should look.
   
   
   
   
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to