Codesys 3.5 SP16 Modbus change port settings.

2021-01-12
2024-02-20
  • hence.persson - 2021-01-12

    According to the documentation there is now the possibility to change port settings.
    And so I found the method UpdateComPortSettings which works fine but i cannot change the number of stopbits.. Is this a miss from the Codesys gang or am I missing something?

     
    • jmauer - 2024-02-20

      Hello,

      I'm coming to you today because I'm trying to make the baudrate and the slave number dynamic.
      I've tried the "updateComPortSettings" method on the slave device but it doesn't work and gives the "Modbus_COM_Port" an error.

      Can you tell me how you got this method to work?

      Thanks in advance for your help

      jΓ©rΓ©my

       
  • Thomas - 2021-01-12

    Hi,
    it lokk like that the docu is wrong

    Regards

     
  • hence.persson - 2021-01-12

    Interesting but I am configured as an Device then I cant change that setting..

     
  • Thomas - 2021-01-12

    Hi,
    I am not able to test my code today.! I hope the ModbusServer will answer a request (see attachment)

    Basic is the FAQ (https://faq.codesys.com/display/CDSFAQ/Modbus+RTU%3A+Dynamic+Configuration)

    Regards

     
    • hence.persson - 2021-01-12

      Thanks for your time trying to help really appreciated.

      I used to do it like that but the opening of the comport isnt needed that is handled by the modbus server but with the new Codesys you should be able to use the configured Device according to the changelog. But apparently someone missed the possibility to change the number of stop bits. So guessing I will have to revert back to my old implementation..

      Example:

      byInternalUnitID := 10;
      stInternalComPortSettingsNew.ulBaudrate := SysCom.SYS_COM_BAUDRATE.SYS_BR_9600;
      stInternalComPortSettingsNew.byParity := SysCom.SYS_COM_PARITY.SYS_NOPARITY;
      stInternalComPortSettingsNew.byStopBits := SysCom.SYS_COM_STOPBITS.SYS_TWOSTOPBITS;
      stInternalComPortSettingsNew.sPort:=SysCom.SYS_COM_PORTS.SYS_COMPORT4;
      stInternalComPortSettingsNew.ulBufferSize := 1024;
      fbModbusServer(
          byUnitID:=byInternalUnitID , 
          comPortSettings:=stInternalComPortSettingsNew , 
          pInputData:=ADR(BMS_GVLmodbusRTUdata.aInputRegisters) , 
          pOutputData:=ADR(BMS_GVLmodbusRTUdata.aHoldingRegisters), 
          uiInputDataSize:=10 , 
          uiOutputDataSize:=2048 , 
          xEnable:= , 
          xReset:= , 
          tTimeout:=0 , 
          EOFDetectionTimeout:=0 , 
          xError=> );
      
       

Log in to post a comment.