0

I am learning to use TWINCAT 3 with C++ and as my first work, I decided open a .txt file and get a number inside, and put on an string or an integer.

I have read all the documentation and have many questions. I discovered that I can't use the C++ libraries, just the TWINCAT functions. Then I got lost.

First: What are the exacts steps to Open a file in TWINCAT 3 with C++?

Second: How can I read the data in the file and put in an string or integer?

I would like to do that in a CycleUpdate.

I am sorry if it is a noob question.

Charlie Joynt
  • 4,411
  • 1
  • 24
  • 46
  • Hi and welcome to Stack Overflow. You'll get better help if you can focus your post into just one question, and include any code you have written while trying to solve your problem. – Charlie Joynt Aug 08 '18 at 23:22
  • 1
    Just out of curiosity, why C++? Is it not possible to do in with any of the IEC61131-3 languages, such as structured text? Although it is possible to use C++ in TwinCAT, it generally comes with some caveats, so if you do not have any specific requirements or reason to go with C++ I would advise to use ST, in which case you would use the FB_FileOpen, FB_FileWrite, FB_FileClose function blocks in TwinCAT. – Jakob Aug 11 '18 at 15:49

1 Answers1

0

As a first step, you have to understand that TwinCAT is providing you a PLC with real-time capabilities. Which means each task you program will need to be executed at every cycle: your task must NOT exceed a certain duration.

Many accesses to the operating system require a lot of wait times, that you would not keep in a real-time system. For that, most of function blocks you will find are equipped with an "Execute" boolean input (or similar) and outputs like "Busy", "Done" and "Error" (even "ErrorID"). These are here in order to start a process and check periodically (i.e. in each cycle) whether the process is complete.

You cannot manage a file opening, reading, writing or closing (OS functions) within a single CycleUpdate. This is the cost for assuring real-time capabilities besides.

Teuxe
  • 43
  • 1
  • 6