I'd like to read a file that'd be on the PLC memory to extract datas from it such as initial values for counters, host name, ip addresses, filenames and stuff like that so I could change propreties without compiling the program on CoDeSys.
I know that SysFileOpen/Read/Write exist but I don't see any function or programm that reads through the file and copies the datas from it.
Is it possible ?
Thank you for any help
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi. I have the some problem (Question).
I have a file (CVS) in the SD Card and I tried to read it, but I can't.
Do somebody help me with an example how to use the sysfilelib (sysfileread, sysfilewrite)
Thanks in advance
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Please find a small example to write a csv-File with help of SyslibFile:
PROGRAM PLC_PRG
VAR
hFile:DWORD;
dwWritten: DWORD;
szFilePath: STRING:= 'C:\test.csv';
szSeperator: STRING(1):= ';';
szCurrent: STRING(2);
wNewLine: WORD:= 2573; (16#0A0D)
iCounter1: INT;
bOnce: BOOL:= TRUE;
iCounter2: INT;
END_VAR
IF bOnce THEN
hFile:= SysFileOpen(szFilePath, 'w');
FOR iCounter2:= 1 TO 5 DO
FOR iCounter1:= 1 TO 5 DO
szCurrent:= CONCAT(INT_TO_STRING(iCounter2), INT_TO_STRING(iCounter1));
dwWritten:= SysFileWrite(hFile, ADR(szCurrent), 2);
IF iCounter1 <> 5 THEN
dwWritten:= SysFileWrite(hFile, ADR(szSeperator), 1);
ELSE
dwWritten:= SysFileWrite(hFile, ADR(wNewLine), SIZEOF(wNewLine));
END_IF
END_FOR
END_FOR
SysFileClose(hFile);
bOnce:= FALSE;
END_IF
READ can be done like this:
IF xDoRead THEN
dwReturn := SysFileRead(File:=hFile, Buffer:=ADR(sBufferIn), Size:=dwSize);
IF dwReturn <> 0 THEN
sBuffer := sBufferIn;
END_IF
xDoRead := FALSE;
END_IF
The read result must be adapted to the syntax of the written file.
Writing can be done also with help of SysfileStream library.
PROGRAM PLC_PRG
VAR
hFile: DWORD;
diReturn:DINT;
NeueZ:STRING:='$n'; ( Neue zeile )
Zeile: INT;
I don't need an example to write datas, I think mine works fine, I have trouble reading a file only.
I have an example to write/read datas with the application note that Wago made on how to use SysFileLib and WagoLibFtp (to send a file on a FTP) but...
What is my problem :
I have a program that writes measures in a file and then send the file on a FTP server. What I'd like to do is : using an FTP client or an SD card, read a configuration file that contains the host ip, password, name of sensors and that kind of a information so I can run the same program on different PLCs and using different sensors without editing the program and only compiling it.
what I can't do is reading the file line by line to extract the host ip, password, etc.
Did I explain well?
Thank you for your help.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
It says "The return value is the number of successfully read bytes" for the SysFileLib function. but I need the datas or the string that I'm reading...
Hi,
I'd like to read a file that'd be on the PLC memory to extract datas from it such as initial values for counters, host name, ip addresses, filenames and stuff like that so I could change propreties without compiling the program on CoDeSys.
I know that SysFileOpen/Read/Write exist but I don't see any function or programm that reads through the file and copies the datas from it.
Is it possible ?
Thank you for any help
Sorry, but I do not find out your exact problem.
Do you need an example how to read/wrie data from a file?
Hi. I have the some problem (Question).
I have a file (CVS) in the SD Card and I tried to read it, but I can't.
Do somebody help me with an example how to use the sysfilelib (sysfileread, sysfilewrite)
Thanks in advance
Please find a small example to write a csv-File with help of SyslibFile:
PROGRAM PLC_PRG
VAR
hFile:DWORD;
dwWritten: DWORD;
szFilePath: STRING:= 'C:\test.csv';
szSeperator: STRING(1):= ';';
szCurrent: STRING(2);
wNewLine: WORD:= 2573; (16#0A0D)
iCounter1: INT;
bOnce: BOOL:= TRUE;
iCounter2: INT;
END_VAR
IF bOnce THEN
hFile:= SysFileOpen(szFilePath, 'w');
FOR iCounter2:= 1 TO 5 DO
FOR iCounter1:= 1 TO 5 DO
szCurrent:= CONCAT(INT_TO_STRING(iCounter2), INT_TO_STRING(iCounter1));
dwWritten:= SysFileWrite(hFile, ADR(szCurrent), 2);
IF iCounter1 <> 5 THEN
dwWritten:= SysFileWrite(hFile, ADR(szSeperator), 1);
ELSE
dwWritten:= SysFileWrite(hFile, ADR(wNewLine), SIZEOF(wNewLine));
END_IF
END_FOR
END_FOR
SysFileClose(hFile);
bOnce:= FALSE;
END_IF
READ can be done like this:
IF xDoRead THEN
dwReturn := SysFileRead(File:=hFile, Buffer:=ADR(sBufferIn), Size:=dwSize);
IF dwReturn <> 0 THEN
sBuffer := sBufferIn;
END_IF
xDoRead := FALSE;
END_IF
The read result must be adapted to the syntax of the written file.
Writing can be done also with help of SysfileStream library.
PROGRAM PLC_PRG
VAR
hFile: DWORD;
diReturn:DINT;
NeueZ:STRING:='$n'; ( Neue zeile )
Zeile: INT;
END_VAR
IF bWriteSystemText THEN
END_IF;
Hi,
I don't need an example to write datas, I think mine works fine, I have trouble reading a file only.
I have an example to write/read datas with the application note that Wago made on how to use SysFileLib and WagoLibFtp (to send a file on a FTP) but...
What is my problem :
I have a program that writes measures in a file and then send the file on a FTP server. What I'd like to do is : using an FTP client or an SD card, read a configuration file that contains the host ip, password, name of sensors and that kind of a information so I can run the same program on different PLCs and using different sensors without editing the program and only compiling it.
what I can't do is reading the file line by line to extract the host ip, password, etc.
Did I explain well?
Thank you for your help.
little add-on to my explanation :
It says "The return value is the number of successfully read bytes" for the SysFileLib function. but I need the datas or the string that I'm reading...
To do something like that :