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 ?
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
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 ;
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
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
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.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
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.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
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.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
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 ?
You should look into SysCom or CAA SerialCom libraries, since it appears as a (virtual) serial port.
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.
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
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));
/
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
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.
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.
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.
Where can i find the user config?
search for
CODESYSControl_User.cfg
via google:
https://www.google.com/search?q=CODESYSControl_User.cfg&source=hp&oq=CODESYSControl_User.cfg
Last edit: hermsen 2022-08-03