11/5/2014 3:50 PM | |
Posts: 81 Rating: (0) |
Hello Friends, I need to translate libraries that were written for C to SCL, Please help me
|
11/5/2014 6:10 PM | |
Joined: 1/17/2007 Last visit: 10/21/2024 Posts: 1547 Rating: (537)
|
As 'c' is entirely based on functions, you could just convert it on a function to function basis (1 to 1). Well from a simple data structure point-of-view the 2 languages are fairly analogous:- Structures - Present in both Unions - Can use the AT construct to mimic this Arrays - Present in both. 'c' is zero based so all array definitions in SCL would have to be [0..n] Pointers - This will be the biggest challenge. SCL does have pointers but they are nothing like as powerful as their 'c' equivalents. You would have to make these ANY pointers. Pointer initialisation (e.g. int *ptr = MyInt;) would have to be replace by the runtime code ANYPtr := MyInt as static initailisation of pointers is not possible. Any pointer arithmatic such as ptr = ptr + 1, would have to be mimiced by manipulating the ANY address by the correct ammount (byte = 8, short = 16, long = 32). To do this you would have to have a dissambled ANY pointer to allow you to access the ANY pointer address data. There are many examples of this using code I have produced (e.g. https://www.automation.siemens.com/tf/WW/en/Posts/94234#top). Dereferencing the pointer to gain access to a value (e.g. i = *ptr) would have to be replaced with BLKMOV calls. Pointers to structures (e.g. ptr->MyStruct) would be a nightmare to translate. You would have to point the ANY pointer at the base address of the structure and have offsets for the structure members that you add on before deferenecing the ANY pointer. Not nice as you would have to store them somewhere in a lookup table, and keep this updated with any changes to the structure. I suppose you could work out the address at runtime and them populate a lookup table (e.g. offset = element address - structure base address repeating for each element in the structure). As are the data types:- Signed char = CHAR in SCL Unsigned char = BYTE in SCL Signed short int (16 bit) = INT in SCL Unsigned short int (16 bit) = WORD in SCL Signed long int (32 bit) = DINT in SCL Unsigned long int (32 bit) = DWORD in SCL Float (single precision) = REAL in SCL Double (double precision) = not supported in SCL Variable scope maps quite well too. Auto variables = TEMP variables in SCL static variables = VAR variables in SCL The function argument list would translate to the function input, inout and output parameters and the function return would be equivalent to the c function return value. The RETURN instruction would be replaced thus:- RETURN (x / 10); ----> FCXXX := 10; RETURN; If I were doing it it would approach it thus:- 1) Make a note of any library / external functions that you call (e.g. strlen, strcpy etc.). Then write replacement functions that have the same call structure and return values. Then add code into the functions to mimic the library function it replaces. 2) Then start converting your user functions to equivalent SCL functions. Functions that do not have any static data can use an FC, whereby functions with static have to use an FB as FC'c have no static static capability. Just a few thoughts from a mad old programmer - but I hope they are of some help. |
Programming today is the race between software engineers building bigger and better idiot proof programs, and the universe producing bigger and better idiots. |
|
This contribution was helpful to4 thankful Users |
11/5/2014 8:34 PM | |
Joined: 7/7/2010 Last visit: 11/19/2024 Posts: 15406 Rating: (2446) |
Since you are trying to track using a solar panel, why not instead look for a working solution to do just that? /tf/WW/en/Posts/56278 You can also contact your Siemens distributor for assistance locating a solar tracking setup that should take the inclinometer input, provided you convert to either rs485, rs232, or some other compatible interface for the s7-1200. Getting a CAN communications module may be a problem for the s7-1200 family. Am I right you are using the s7-1200 family for this project? And to answer your C library question, I am not aware of any S7-1200/1500 that would allow you to link with an external library file of the form you mention. The library files that work are basically offline storage of code snippets, hardware configurations, or even complete mini or starter projects store as a special library file. You would also need to translate the library source code. After reading what you are looking for, writing your own SCL code to accomplish the task would likely be a lot simpler, especially if you refer to your existing code as a guiding principles document rather than as a source code conversion task. |
science guy |
|
Follow us on