Open and write into TXT File

so ByteArray35 is a specific arbitrarily pre-defined array ?

> I haven't yet figured out how to declare arrays in general such as INT(2) WORD(5) etc...  
> Does one require a secret incantation ? ;-)  
> Is it correct to assume that a STRING is a byte array with the first element containing the string length ?  
> I believe BASIC strings are like this  
> And when the STRING_TO_BUF is executed, is the result a null-terminated "unix" string ?  
> or an open-ended byte-array which requires the length to be specified in an external variable ?  
>

Oh… I meant to also inquire about the mechanism of multiple sequential file writes…

> On the other platform I am familiar with, the actual WRITE command must be always executed  
> and an ENABLE boolean controls the actual operation...  
> To write multiple files sequentially, one had to one had to monitor the status of the currently active  
> write command, and when it had completed, then disable that write command and enable the next one  
> and sequentiallly propagate the enables while checking the statuses  
> Is there an equivalent paradigm here ?  
> One must create one write "package"/program for each filename and then juggle the enables ?  
>   
>

Hello Martin,

> I also tested your code, and it worked. However, I need to write multiple strings to the file for my application. Unfortunately, this hasn't worked as expected—only the first string is being written to the file.  
> Here is the code I have so far. The StringsToSave[] array is already populated beforehand:  
> // Datei öffnen  
>  FILE_OPEN(  
>     Execute := OpenCommand,  
>     Name := '/opt/plcnext/my-file.txt', // Pfad zur Datei  
>     Done => str_to_buf,  
>     Handle => FileHandle);  
>   
> // Strings in einer Schleife schreiben  
>  FOR i := 1 TO NumStrings DO  
> // Länge des Strings ermitteln  
>     NumChars := LEN(StringsToSave[i]);  
>   
> // String in den Puffer umwandeln  
>     STRING_TO_BUF(  
>         REQ := str_to_buf,  
>         SRC := StringsToSave[i],  
>         BUF_CNT := NumChars,  
>         DONE => WriteCommand,  
>         BUFFER := CharsToWrite);  
>   
> // CRLF hinzufügen  
>     CharsToWrite[NumChars] := 16#0D; // CR  
>     CharsToWrite[NumChars + 1] := 16#0A; // LF  
>   
> // In die Datei schreiben  
>     FILE_WRITE(  
>         Execute := WriteCommand,  
>         Handle := FileHandle,  
>         Buffer := CharsToWrite,  
>         Done => write_done,  
>         Length := NumChars + 2); // Stringlänge + CRLF  
>  END_FOR  
>   
> // Datei schliessen  
>  FILE_CLOSE(  
>     Execute := CloseCommand,  
>     Handle := FileHandle,  
>     Done => file_closed);  
>   
>    
>

Hello dwi,

> please try to combine the strings of the array with CONCAT blocks into one.  
> The write commands may be sent faster than the Linux system can / may react.  
>

Hello Tim,

> Thanks for your quick reply!  
> I tried it with the concat block and it worked.   
> Thank you very much for your help!  
> David  
>