Codesys 3.5 SP16 Modbus change port settings.

4 days ago
4 days ago
  • hence.persson

    hence.persson - 4 days ago

    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?

     
  • Thomas

    Thomas - 4 days ago

    Hi,
    it lokk like that the docu is wrong

    Regards

     
  • hence.persson

    hence.persson - 4 days ago

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

     
  • Thomas

    Thomas - 4 days ago

    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

      hence.persson - 4 days ago

      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.