Use python instead of Structured Text - codesys

I have a Codesys Project which becomes more and more complex.
Now I’m wondering if there is a python library that lets me do the programming part, I’m usually doing with Structured Text via Python?
Thank you
A

If you were using the Beckhoff platform which is very similar to Codesys I would have advised you to look into the ADS interface which helps interface PLC's with user space programs.
For Codesys there is also a proprietary interface called the PLC-Handler but it's not free of cost.
Since you have to pay one way or the other the approach I suggest is to buy the MQTT-Client for Codesys and write a Python-Client with one of the freely available libraries like the one of the eclipse foundatation: https://www.eclipse.org/paho/index.php?page=clients/python/index.php
The advantage of this approach is that once you've written the user space client you can interface with all PLC brands, since every major PLC brand offers an MQTT-Client library which you can use to write a small command and control PLC-Library for your PLC's.

Related

easy to create DSP app maker?

I am making an EEG bio-feedback'product' for a friend and I need a simple but DSP-powerful application builder.
Here is my situation:
I have built the HW to measure the brainwave signals and need to create a user panel for my friend to use it. The HW sends a stream of ascii out a serial port. The data packets send the amplitude value at a rate of 250 packets per second. Brain waves of interest are below 30 HZ so this is more than fast enough sampling.
I am prototyping the DSP user panel in LabVIEW which makes it incredibly easy to do sophisticated DSP with a custom control panel. However, my friend just wants a plug and play product and I can hardly install LabVIEW on his PC, so here is my challenge: I am wondering if there is a design application that I can use to create the final application for him.
I have no problem if it is text based but I don't have the capacity to sit down with a full-on programming language to make the front panel controls, internal DSP and serial port processor, so the application would hopefully provide the designer easy to tool-up GUI and easy to access DSP library. I am up to coding stuff to interpret the serial data format and manage the general flow of the data to get it processed and sent to the front panel, but all the fussy details of setting up some programming IDE and installing a bunch of libraries to make the front panel is more than I can take on right now.
BTW, I also put this together in a private edition of Matlab but again that is no good for my friend.
Any ideas? I know there are high-level application builders around but they usually target beginners. I am so spoiled by Labview! I have no problem with the actual coding like in C, Basic, or maybe Python, it's all the environment-building I don't want to get pulled into.
If you want a stand alone executable, you can use LabVIEW's application builder to create one. The app builder ships with LV pro, but can be purchased separately for cheaper versions. This won't let your friend modify the code, but I understand that's what you want.
There are also numerous ways to create plugin systems, if that's needed in your case. You can find various tutorials on that.
Be aware that some toolkits and modules require that you purchase distribution licenses as well. You would need to check whether you're using such a module.

Custom Programming Language ~ How to interact with the Operating System

I am trying to create my own programming language but I am already thinking ahead a little.
Of course when I can compile a little program I won't have a Standart Library at that time,
and you'd have to create one yourself. Now take for example I'd like to add some functionality to print a string to the screen, I am pretty sure I'd have to do a few System Calls to the operating system to get this displayed.
So to the point: What would be the best way to interact with the Operating System?
Possibilities I came up with myself:
- Generate Object Files and link those to the (for example) C Standart Library
- Writing the files with embedded assembly language containing System Calls
I have a feeling there are better possibilities!
I hope you can help me,
Christian
EDIT: It's a compiled language I am creating!
You have basically two options, like you say yourself. You can link your standard library with the standard C library, so that the I/O functions in your standard library can use C functions. Alternatively you can make system calls to the operating system directly.
The second approach seems like it's going to be more work: The system calls will be different on each operating system, so you'll have to put a lot of work into porting your system. The system calls may not be well documented, causing many frustrations.
You could start by linking your standard library to the C standard library and worry about other aspects of your language for the moment. Later you can look into replacing the C functions you use with syscalls.
Stdin and stdout are pretty much the minimum - if you are using a Unix environment you can then gain access to they keyboard, command line and also pipe text in and out to files.
If you are writing a new language - then StdError may also be worth considering too!

What languages can be used to make dynamic websites?

So, there are several languages which will allow you to create a website, as long as you configure the server(s) well enough.
To my knowledge, there is:
PHP
ASP.NET
Ruby(on rails, what is
that all about?)
And thusly, my knowledge is limited. Ruby and ASP, I've only heard of, never worked with. If there are other languages, I suppose they have some way to make files containing the needed html. It would then suffice to add a line to the Apache config to associate the file-extension.
And if other languages: are there any notable characteristics about the one(s) you mention?
ANY language can be use to make a dynamic website - you could do it in COBOL or FORTRAN if you were twisted enough. Back in the olden days (about 10 years ago) most dynamic websites were done with CGI scripts - all you needed was a program that could read data from standard input and write data (usually HTML) to standard output.
Most modern languages have libraries and frameworks to make it easier. As well as the languages you have already mentioned, Java, C# and Python are probably the most common in use today.
Typically a web framework will have:
a way of mapping URLs to a class or function to handle the request
a mechanism for extracting data from a request and converting it into an easy to use form
a template system to easily create HTML by filling in the blanks
an easy way to access a database, such as an ORM
mechanisms to handle caching, redirections, errors etc
You can find a comparison of popular web frameworks on wikipedia.
How can you forget Java ? :)
Python
It runs on Windows, Linux/Unix, Mac OS X, and has been ported to the Java and .NET virtual machines.
Python is a perfect scripting language for web applications, e.g. via mod_python for the Apache web server. With Web Server Gateway Interface a standard API has been developed to facilitate these applications. Web application frameworks or application servers like Django, Pylons, TurboGears, web2py and Zope support developers in the design and maintenance of complex applications. Around libraries like NumPy, Scipy and Matplotlib, Python is a standard in scientific computing.
Among the users of Python are YouTube and the original BitTorrent client. Large organizations that make use of Python include Google, Yahoo!, CERN, NASA,and ITA.
This could be for your interest.
Virtually thru CGI all programming languages that produce output may use for web page generation.
Basically, you can use any language (if you are hosting your own server)
Very closely related and very interesting is this article where LISP has been used to build a very succesfull website.
Python has a 3rd party module CherryPy which can be used with or without a http server.
Amongst others: Erlang (YAWS, Mochiweb), Python
JSP has the advantage that it automatically wraps your code in a servlet, compiles that to bytecodes, then uses the just-in-time Java compiler to recompile critical sections into native object code. Not aware of any alternative which allows optimizes your work automatically in this way.
Also allows you to develop and deploy on any combination of Windows, Mac OS X, or Linux.
If you'd like to choose one for the beginning, you should check out PHP first. It gives you the basic clues about how dynamic sites work in general.
After you've become familiar with the basics, I recommend ASP.NET.
Fist off, you should know that ASP.NET is a technology and not a language. (It actually supports any language that can be used on the .NET platform.) Also it is not to be confused with classic ASP. (The old ASP was much more like PHP.)
ASP.NET is very easy to begin with, and after you have some clues about its concepts, you can always dig deeper and customize everything in it. The http://asp.net site is a very good starting point, if you are to learn it. I think it is really worth the effort, because even if you choose not to stick to it, it will give you some interesting ideas and concepts.
I tell you its most important advantages:
The code is compiled (and NOT interpreted like PHP), and it has a very good performance. (In a performace comparsion, it is 10-15 times faster. http://www.misfitgeek.com/pages/Perf_Stat_0809.htm)
It can be run on Windows without effort, and on Linux / Mac / etc using the Mono project.
It implements the Separation of Concerns principle very well.
It has most of the general functionality you'll need built-in. (Such as membership, roles, database management, and so on.)

OLPC development choices

What are my options for developing a piece of software for the OLPC project. From looking at the various sites and wikis, I can honestly say that I am still totally confused. Is it to be sugar, c++, smalltalk or python? HELP!
Thanks,
First, the short answer: You want to use Python, and you want to make your python programs "sugarized".
Sugar is not a programming language or development toolkit. It's a GUI environment and "activity" framework. The applications that kids use on OLPC laptops are called "activities", and Sugar provides a bunch of tools for them to use so that they can store their information in the versioned object database (the "journal" from the user's perspective), can show up in the list of available activities, etc.
To make sugarized applications, you write them in python, using the pygtk and/or pygames APIs for graphical work and the Sugar APIs for other Sugar services (like storage, access to the camera, mic, the very cool networking stuff, etc.). You also use a Sugar API to make the program available as a Sugar activity.
You can write C++ code for the OLPC, but Python is the preferred language.
As for Smalltalk, the OLPC project does provide a Squeak environment, but it's intended primarily for kids to play with Smalltalk programming, rather than as a tool for building activities intended to be distributed for use on the OLPC. Not that you couldn't use it that way (I think sugarization of Smalltalk apps is possible -- not sure), but it would be a memory hog. Smalltalk isn't inherently more memory-hungry than Python, but the OLPC devs have done some clever things to optimize Python memory usage. Basically, nearly all of the memory consumed by the Python interpreter is shared among all Python-based activities. Adding a Smalltalk activity to the mix would mean running another interpreter.
You can find lots of activities to look at (with source code) at http://activities.sugarlabs.org. If you develop anything for the OLPC, it's highly recommended that you get a Sugarlabs account and use their git infrastructure (http://git.sugarlabs.org).
I'd also highly recommend that you join the Sugar development mailing list. It's intended primarily for discussion of development of the Sugar platform, but there are very helpful and very knowledgeable people there who can answer questions and point you to the right resources. http://lists.sugarlabs.org/listinfo/sugar-devel
EDIT: Another useful resource for getting started is:
http://wiki.sugarlabs.org/go/Development_Team/Quickstart
Faisal Anwar and JediErik developed the excellent Sugar Almanac, which covers a lot of what you need to know to develop for Sugar. It has library descriptions and sample code for topics such as
creating a valid Sugar activity bundle
handling presence, threading and internationalization
interfacing with the Journal and other Sugar-specific system-wide features.
handling mouse, video, and other inputs
Swillden's post is excellent. I will just add a few more points:
People have successfully created Sugarized Squeak activities (see several games from Potsdam University as well as the work by OLE Nepal). OLE Nepal credits the rapid-prototyping aspects of the Squeak environment for their ability to quickly create a curriculum satisfying the desires of the Nepal teachers. I believe that these activities take longer to load, though; as Swillden points out, they lack the "home field" advantage of Python.
I recommend using Python, unless you are significantly more comfortable with the Squeak environment. The approach I used when I developed a Sugar activity (Implode) was to first develop the activity as an application using just Python/pygtk on a standard desktop (Windows or Ubuntu), then port it to Sugar. The code/debug cycle is faster on the desktop since you don't have to switch to an emulator or check error messages in the "Log" activity. If you architect the code right, you can isolate most of the desktop/Sugar differences to a couple modules, so that you can continue to develop and test in both environments. I wrote a pygtk activity, but I expect a pygame-based activity could be created in a similar manner. Of course, if your activity relies on access to certain Sugar-specific features -- like speech synthesis or mesh networking -- this approach may not work as well.
If you want to code in C or C++, whether for performance-critical or legacy code, I recommend writing it as a Python extension module called from a Python-based activity. I believe this is how the Write activity (wrapping Abiword) and Browse activity (wrapping Firefox) are implemented. If you have an existing X application in C/C++, it is possible to make it run under Sugar (see the SimCity, Etoys, and XaoS activities), but it will lack the look and feel of the other Sugar activities.
Finally, I've found the easiest way to add some particular functionality to a Sugar activity is to first find an existing activity that already does it, then read the code to find out how they did it. The Sugar system is not particularly well-documented yet; in some cases the only documentation is the code itself. As Swillden points out, the code for most activities -- as well as for Sugar itself -- is available in the SugarLabs git repository.

Suggestions for Adding Plugin Capability?

Is there a general procedure for programming extensibility capability into your code?
I am wondering what the general procedure is for adding extension-type capability to a system you are writing so that functionality can be extended through some kind of plugin API rather than having to modify the core code of a system.
Do such things tend to be dependent on the language the system was written in, or is there a general method for allowing for this?
I've used event-based APIs for plugins in the past. You can insert hooks for plugins by dispatching events and providing access to the application state.
For example, if you were writing a blogging application, you might want to raise an event just before a new post is saved to the database, and provide the post HTML to the plugin to alter as needed.
This is generally something that you'll have to expose yourself, so yes, it will be dependent on the language your system is written in (though often it's possible to write wrappers for other languages as well).
If, for example, you had a program written in C, for Windows, plugins would be written for your program as DLLs. At runtime, you would manually load these DLLs, and expose some interface to them. For example, the DLLs might expose a gimme_the_interface() function which could accept a structure filled with function pointers. These function pointers would allow the DLL to make calls, register callbacks, etc.
If you were in C++, you would use the DLL system, except you would probably pass an object pointer instead of a struct, and the object would implement an interface which provided functionality (accomplishing the same thing as the struct, but less ugly). For Java, you would load class files on-demand instead of DLLs, but the basic idea would be the same.
In all cases, you'll need to define a standard interface between your code and the plugins, so that you can initialize the plugins, and so the plugins can interact with you.
P.S. If you'd like to see a good example of a C++ plugin system, check out the foobar2000 SDK. I haven't used it in quite a while, but it used to be really well done. I assume it still is.
I'm tempted to point you to the Design Patterns book for this generic question :p
Seriously, I think the answer is no. You can't write extensible code by default, it will be both hard to write/extend and awfully inefficient (Mozilla started with the idea of being very extensible, used XPCOM everywhere, and now they realized it was a mistake and started to remove it where it doesn't make sense).
what makes sense to do is to identify the pieces of your system that can be meaningfully extended and support a proper API for these cases (e.g. language support plug-ins in an editor). You'd use the relevant patterns, but the specific implementation depends on your platform/language choice.
IMO, it also helps to use a dynamic language - makes it possible to tweak the core code at run time (when absolutely necessary). I appreciated that Mozilla's extensibility works that way when writing Firefox extensions.
I think there are two aspects to your question:
The design of the system to be extendable (the design patterns, inversion of control and other architectural aspects) (http://www.martinfowler.com/articles/injection.html). And, at least to me, yes these patterns/techniques are platform/language independent and can be seen as a "general procedure".
Now, their implementation is language and platform dependend (for example in C/C++ you have the dynamic library stuff, etc.)
Several 'frameworks' have been developed to give you a programming environment that provides you pluggability/extensibility but as some other people mention, don't get too crazy making everything pluggable.
In the Java world a good specification to look is OSGi (http://en.wikipedia.org/wiki/OSGi) with several implementations the best one IMHO being Equinox (http://www.eclipse.org/equinox/)
Find out what minimum requrements you want to put on a plugin writer. Then make one or more Interfaces that the writer must implement for your code to know when and where to execute the code.
Make an API the writer can use to access some of the functionality in your code.
You could also make a base class the writer must inherit. This will make wiring up the API easier. Then use some kind of reflection to scan a directory, and load the classes you find that matches your requirements.
Some people also make a scripting language for their system, or implements an interpreter for a subset of an existing language. This is also a possible route to go.
Bottom line is: When you get the code to load, only your imagination should be able to stop you.
Good luck.
If you are using a compiled language such as C or C++, it may be a good idea to look at plugin support via scripting languages. Both Python and Lua are excellent languages that are used to script a large number of applications (Civ4 and blender use Python, Supreme Commander uses Lua, etc).
If you are using C++, check out the boost python library. Otherwise, python ships with headers that can be used in C, and does a fairly good job documenting the C/python API. The documentation seemed less complete for Lua, but I may not have been looking hard enough. Either way, you can offer a fairly solid scripting platform without a terrible amount of work. It still isn't trivial, but it provides you with a very good base to work from.