CSV file write in TwinCAT

piash.ali

Member
Join Date
Sep 2017
Location
Germany
Posts
19
Hi
I was trying to write a csv in twincad and I used the sample code from beckhoff (https://infosys.beckhoff.com/englis...tml/TcPlcLibUtilities_ARG_TO_CSVFIELD.htm&id=) but it showing error in database .
I was wondering if anyone suggests me a small program.
Thanks!
MAX_CSV_ROWS:UDINT:=100;MAX_CSV_COLUMNS:UDINT:=5;MAX_CSV_FIELD_LENGTH:UDINT:=100;

database : ARRAY[0..MAX_CSV_ROWS, 0..MAX_CSV_COLUMNS ] OF STRING(MAX_CSV_FIELD_LENGTH) := (* Source PLC database *)
'0_0', '0_1', '0_2', '0_3', '0_4', '0_5',
'1_0', '1_1', '1_2', '1_3', '1_4', '1_5',
'2_0', '2_1', '2_2', '2_3', '2_4', '2_5',
'3_0', '3_1', '3_2', '3_3', '3_4', '3_5',
'4_0', '4_1', '4_2', '4_3', '4_4', '4_5',
'5_0', '5_1', '5_2', '5_3', '5_4', '5_5';


END_VAR
 
Hi Piash,

When I need to write data from a Beckhoff PLC to a CSV file, I use FB_FileOpen/FB_FileWrite/FB_FileClose.

If you need to read from a CSV file, just do the same but use FB_FileRead instead of FB_FileWrite.

At this moment, I do not have a sample program using this function that I can send. But you'll see, those function are pretty easy to use, try it and let me know if needs more help!

Best regards,
 
Hi Piash,

When I need to write data from a Beckhoff PLC to a CSV file, I use FB_FileOpen/FB_FileWrite/FB_FileClose.

If you need to read from a CSV file, just do the same but use FB_FileRead instead of FB_FileWrite.

At this moment, I do not have a sample program using this function that I can send. But you'll see, those function are pretty easy to use, try it and let me know if needs more help!

Best regards,

Thanks for your suggestion. I have fixed the error.
 
To use this sample program from beckhoff . We have to declare the variable MAX_CSV_COLUMNS, MAX_CSV_ROWS as constant. such as VAR CONSTANT.
for the data we have to use as
['0_0', '0_1', '0_2', '0_3', '0_4', '0_5',
'1_0', '1_1', '1_2', '1_3', '1_4', '1_5',
'2_0', '2_1', '2_2', '2_3', '2_4', '2_5',
'3_0', '3_1', '3_2', '3_3', '3_4', '3_5',
'4_0', '4_1', '4_2', '4_3', '4_4', '4_5',
'5_0', '5_1', '5_2', '5_3', '5_4', '5_5';]

then it will work
 
And you can copy those constants mentioned above from the sample program. I did exactly same mistake when i tried this same sample.

{attribute 'Tc2GvlVarNames'}
VAR_GLOBAL CONSTANT
MAX_CSV_ROWS : UDINT := 100;
MAX_CSV_COLUMNS : UDINT := 100;
MAX_CSV_FIELD_LENGTH : UDINT := 100;
END_VAR
 
Last edited:
And you can copy those constants mentioned above from the sample program. I did exactly same mistake when i tried this same sample.

{attribute 'Tc2GvlVarNames'}
VAR_GLOBAL CONSTANT
MAX_CSV_ROWS : UDINT := 100;
MAX_CSV_COLUMNS : UDINT := 100;
MAX_CSV_FIELD_LENGTH : UDINT := 100;
END_VAR

Thanks. I already did exactly as your suggestion.
 

Similar Topics

Hello! I have a question about a problem writing to a CSV file via twincat3. From the example code that beckhoff provides, I would like to be able...
Replies
0
Views
1,003
Hello, I have an application working on a TP700 Comfort panel (developped with WinCC Advanced on TIA Portal V11). In this application I am...
Replies
2
Views
1,905
Dear, I want to write data into a txt or csv file. This data contains text and numbers. Later I want to read some of that data into the...
Replies
0
Views
5,247
I am trying to import addresses and symbols from a PanelBuilder32 application into the RSLogix 5 Address/Symbol database - however each time I...
Replies
5
Views
521
Hi Everyone, I am hoping a Red Lion Expert can point me in the right direction. I am experimenting with data logging on a CR3000 10" screen...
Replies
4
Views
597
Back
Top Bottom