TDD - ST cross-compiler for Windows/DOS

2012-05-07
2012-06-11
  • stephanegeorget - 2012-05-07

    Hello,

    I’m investigating the feasibility of practicing TDD (Test Driven Development) for projects written in ST with CoDeSys, the target is usually an STW PLC (ESX family).

    TDD would involve the ability to compile and run ST code locally on the development computer (not the target). Specialized test programs would be created (that’s my business), and each program should just test a few things of production code (as per TDD approach), and then the output of this program (exclusively text messages) should be directed to a file on the hard drive or to a standard output like a DOS command line.

    1/
    Is it possible to build a project written in ST, for a PC target (as opposed to a STW ESX), in other words, the target would be:
    - A standard PC computer
    - With Windows 7 (or DOS, or some other operating system, you tell me)
    - With no hardware Input/Outputs
    - The only output would be the command line output or writing text to a file

    2/
    If it was possible to invoke the compiler directly from the command line, that would be even better:
    codesys_compiler.exe MySTFile1.EXP MySTFile2.EXP MySTFileN.EXP --target=PC_Computer --out=test_case.exe

    I know it is possible to do something similar with the so-called “command files”, I am already using this feature of CoDeSys to have a scripting environment export/import .EXP files (and automate things on these files, like changing version number or build date, etc.)

    Thanking you in advance for your help,

    -Stéphane G.

     
  • spfeif - 2012-06-11

    Interesting.

    Here are a few of my opinions.

    If you put most of your logic in POU's in a library then you can test changes quickly by having a TDD CoDeSys program that accesses the interfaces via the library. FYI you do not need a PLC / target to test anything. If you select under CoDeSys menu File-New and for target select none then that is it. Test away.

    So you can set up TTD_MyLogic1.pro program that tests against library_V100. So you create the test code that you want to run. You could use DDE (into excel/labview/C#) as an interface to get the results of the test. See CoDeSys DDE help. This would be using the CoDeSys gateway.

    So if you make changes to the internal code of your library_V100 to library_V101 then you would only need to change the referenced library in TTD_MyLogic1.pro to reference the new library V101. If you change any interface of any POU's in library_V101 to V102 then you would need to change the TTD_Program to match.

    Now I don't have experience with this but I was told it works. Another option would be to use the CoDeSys Soft PLC (basically your computer as the PLC). I was told that the standard libraries for say serial port, Ethernet work under the Soft PLC with the hardware of your computer. This is free but only runs for 1 or 2 hours until the PLC is put into STOP mode. But from here you can create your own communication interface (or maybe modbus that may or may not be built in) and connect to the PLC to get your messages. So you can output something like FUNCTION ID, FUNCTION CODE. Then your application can have a lookup table that retrieves the function under test and resulting code. OF USE DDE again in Excel and read from a test array that is index of the array is the function code and the result you get from the TDD is the value of the array at that index. Then reading this through DDE you can have the lookup table in excel and show the results.

     

Log in to post a comment.