Recipe handling with mod_dat

Hello,

in older projects we use the mod_dat in order to export data-structures as CSV-file on a file device.

Because of a special request from a customer, we would like to store the CSV-data als STRING into a variable (and eventually import/export it via OPC), so instead of using a file-device, use a big string variable.

Does anyone know if that is possible?

Many thanks in advance.

Hi,

the name ā€œmod_datā€ is not familiar to me.
I assume it’s not a library directly shipped from B&R together with Automation Studio, do you know who developped it, or do you have the source code?

In common I think it could be possible, depending on the size of the content, but it’s hard to say how to solve without knowing more about the functionality and the export format (Binary? Human readable?). Maybe creating the export as usual and reading the export back into a string (by FileIO, or by DataObj) could be possible, if the output already is in a readable format, but that’s just a guess.

If you have more details that can be shared, we could try to have a deeper look into.

Best regards!

The mod_dat is from our Library base (need to be logged in)

https://www.br-automation.com/de-de/downloads/library-base/legacy/?tx_brcdn_downloadshow[action]=show&tx_brcdn_downloadshow[controller]=Download&tx_brcdn_downloadshow[download]=31784&cHash=9f560a564f4c513ec244802e00cebadd

I used the library many years ago in a very old project, but I can’t answer that question.

1 Like

Hello,

i think the question did more go in the direction, how huge a String Variable can be. And how huge a String on OPCua can be?

I know that the String functions in ā€œSTANDARDā€ Library only support 255 Characters.
But there are other String functions from ā€œAsBrStrā€ which supports greater Strings.

I know a STRING can be much much larger in Automation Studio. Personaly i did never used something greater than STRING[65535]. But i think it can be greater.

I think it is possible, but we should know a rugh estimate which data amound you would need.

With OPCua i do not have knowledge if there is a STRING Size Limit.

Please give Feedback if i have thought in wrong direction.

Greetings
Michael

Hello,

maybe another hint… i think the Library already prepares the Data in some form of Variable. Probably an USINT-Array. Before writing it to the FileDevice. So redirecting the output should not be that much of a work.

If you use a USINT-Array or a STRING could be seen as almost the same.

Greetings
Michael

Hi @Torsten_K ,

thanks to @Samuel I found the libary now :wink:
I can’t check the source or functionality since the origin project on the library base is an AS2.5.x project, and I don’t have a suitable installation available right now.

But from what I see in the documentation (pls. see screenshot below), it doesn’t seems that a functionality to ā€œserialize the data directly into a stringā€ is implemented.
So I think, the best approach to follow could be:

  • check if the recipe file data size is suitable to be stored inside a string variable (like described by @michael.bertsch )
  • if yes, you could try to
    • 1.) use the dat_mod library as intended by creating a file export
    • 2.) use FileIO functions ā€œFileOpen, FileRead, FileCloseā€ to read the exported file content into the string variable
    • 3.) delete the export file via dat_mod functions to keep the database up-to-date

Last but not least here’s a ā€œsmall life hackā€ about string sizes, that I used here and there:

if you declare an array of strings, the whole array size is on block inside the memory.
So if you memcpy() string data to the first string element, where data is longer then one array element size, because of the overflow of the first string element the rest of the string data will be copied into the 2nd element, and so on…

… of course this is no ā€œnice programmingā€, and you still have to take care that the data size is not greater then the complete array memory to avoid page paults or other issues.
But sometimes using such overflow can be even useful: for example I used string arrays to make my whole string data available via Automation Studio Watch.
As the size of string data in the watch is limited to 80 characters, using a string array of element size 80 and memcpying the longer string to this string array makes it possible to watch more string content :wink:

Best regards!

1 Like

Thanks for all the hints and answers. Just to clarify: the main point of the question was, if I can ā€˜abuse’ mod_dat to store the generated csv data into a string instead of using a file device. If there is another lib that allows to import/export a nested structure into a csv-string than that would be another good solution for me. It doesnt have to be mod_dat.

Many thanks,

Torsten

Hi Thorsten,
I am glad that this library is still alive and used. I never put it up on Github because typically you would use mappRecipe now for handling recipes. Since the version on the library base is pretty outdated I attach the last version to this post. You can change the library in any way you like, but I am not sure is this is the best way of solving this issue. The libraries has some unique mechanisms. For example, there was and maybe still is an issue when you have really large numbers of files in one directory where reading the data becomes really slow. The library therefore splits the records over multiple folders of a maximum of 200 files each and handles the distribution across these folder automatically. This is something you would have to operate out of the library to make it work without just strings. Maybe mappData is a better fit for your application.

Stephan

ReleaseV1_41.zip (1.4 MB)

1 Like