Welcome to our new forum
All users of the legacy CODESYS Forums, please create a new account at account.codesys.com. But make sure to use the same E-Mail address as in the old Forum. Then your posts will be matched. Close

Read Linux USB

2022-07-23
2023-06-13
  • Reinier Geers - 2022-07-23

    I want to read an Smartmeter cable. Its USB on a Linux device. With cu -l /dev/ttyUSB0 -s 115200 --parity=none -E q i could read. But the Codesys command " SysProcessExecuteCommand2 " its output is a string. But the data is 1024 bytes. So to long for a String. Is there a command to read it in a Array ?

     
  • sgronchi - 2022-07-23

    You should look into SysCom or CAA SerialCom libraries, since it appears as a (virtual) serial port.

     
  • Reinier Geers - 2022-07-24

    I can read it in a string (1024). But after that every string command is based of 255 so i lose data. Codesys always misses the last step.

     
  • hermsen

    hermsen - 2022-07-24

    The new StringUtils library is based on pointers so, there is no limitation of a numbers of chars.
    https://content.helpme-codesys.com/en/libs/StringUtils/Current/Public-Parts/fld-Public-Parts.html

    So don't blame CODESYS ;-)

    PS you should use the ANSI functions for ASCII handling, alternatively you can use the UTF8 or UNICODE functions.

    PSS Feel free to share your DSMR-P1 message parser here, we can help you optimize it ;-)

     

    Last edit: hermsen 2022-07-24
    • Reinier Geers - 2023-06-13

      Im back at seriel again. at a timeout of 1000 i get 1024 bytes. But it starts not at the begin. It should start with /XMX5 . The meter is sending every second. should i use Comsettingsex bOutxDSRFlow ? To get the right moment to read ? I cant find any axample
      ui_Timeout: UINT:=1000;
      arrDataRec: ARRAY[1.. 1024] OF BYTE ;

      SysComSetSettings(handle, ADR(Settings), ADR(SettingsEx));

      udiDataRead:=SysComRead(handle, ADR(arrDataRec), 1024, ui_Timeout, ADR(ErrorResult));
      /

       
  • Reinier Geers - 2022-07-27

    Why are there 3 types for the same string command??
    DSMR-P1.. You meen a Wifi adapter ? Ive got a USB cable With a FTDI. With a linux Command ls / dev/tty* i find the '/dev/ttyUSB0'
    then set speed 'cu -l /dev/ttyUSB0 -s 115200 --parity=none'
    open it for read/write 'chmod o+rw /dev/ttyUSB0' But still can find a command that reads the data. Tried several

     
  • sgronchi - 2022-07-28

    Well, you can use the built-in stuff to read from a serial port (see my previous message) or you can continue to abuse SysProcess* functions to do the same in a more fragile and inconvenient manner via Linux commands. If your smartmeter sends bytes that have value 0, the string functions will assume that as the end of the string, whereas the serial port functions will happily continue to work correctly.

    It's up to you to shoot yourself in the foot like you are doing.

    StringUtils are for working with string of arbitrary length (even megabytes), and they work great (since they're basically the C standard library string functions...). Since there are many encodings (ways to translate a string to bytes in memory), you need different functions to work with them. There is ANSI (1 character = 1 byte), UNICODE / UCS-2 (1 character = 2 bytes), UTF8 (1 character = from 1 to 4 byte). If you call e.g. StrLenA on a UNICODE-encoded string it will give you a wrong answer. If you call StrToUpperW on an ANSI string, you'll probably fool up everything.

     
  • Reinier Geers - 2022-07-28

    Ive got it allready in a Windows version with a real Serial port. With a home bild cable. So the string is not a problem anymore. Now i want it in a Linux device with a Fix cable. But Ive read in the forum i have to change the CodesysControl.cfg to let linux know its a serielport. But i can't copy the CodesysControl.cfg. So i tried to read with a Linux command. But Witch one ? Every forum i googled the read command seems a problem.

     
  • hermsen

    hermsen - 2022-07-28

    You intentions are good but you are asking the wrong questions. You should ask WHY you cant edit codesyscontrol.cfg. This is because CODESYS has split the file into 2 parts, a user configurable one and the default configuration. If you wish to edit it, use the user config file. There more then enough hints about this topic on the forum.

    The string libraries are an evolution over time. Anything CAA related is considered deprecated but usable if it fits your needs. Somehow the CODESYS Automation Allience (CAA) is inactive for over 5 years or so. I wonder what has happened to it?

    The standard 255 char length is from the 8/16 bit era when cpu power and memory was more scarce, but obviously this has evolved way beyond 255chars and 8bits per char.

     

Log in to post a comment.