Penguins and PLC's (TuxPLC)

dmroeder

Lifetime Supporting Member
Join Date
Apr 2006
Location
Vancouver, WA
Posts
3,604
I have seen a few threads lately (and read some old ones) with people talking about using TuxPLC. I've been an amateur Linux user at home for about 2 years now, but not quite the level of taking some source code and putting it to use. I have done some work with Eclipse and Android as well as with OpenCV, but there are a ton of tutorials that helped me get what I needed from those projects.

So does anyone feel like sharing some basic steps on how to put TuxPLC to some basic use? I have downloaded the source, what does it take to read a simple tag in a ControlLogix PLC over Ethernet (for example)? I think once I understand the process of getting it to the point of reading a tag, then I can run with it...

Thanks,

Dustin
 
I thought I’d update what it took me to compile one of the examples in tuxeip (test1.c). This should work in any of the Debian based distributions (Debian, Ubuntu, Mint, etc). Just a FYI, if you find yourself saying “why the heck did he do it that way”, it’s because I don’t know what I’m doing! Stephane (library author) was a huge help in getting me in the right direction.

Prerequisites:
  • TuxPLC files
  • Build Essential
  • CMake
  • gcc

The basic idea will be install the appropriate prerequisites, compile the tuxeip library, place the header files and library in the appropriate directories then compile one of the examples and run it. There are probably other ways to do it, if you have a better way feel free to enlighten me. This is just how I got it to work for me.

Note: You can copy and paste the commands in the terminal. Right click then select paste, CTRL+V won’t do it

Open the terminal
Download the files
Code:
wget  https://github.com/leicht/TuxPLC/archive/master.zip
Extract the files
Code:
unzip master.zip
Change to the tuxeip directory
Code:
cd TuxPLC-master/tuxeip
Do some CMake wizardry
Code:
cmake CMakeLists.txt
Build the library
Code:
make

This should have built you a library in TuxPLC-master/tuxeip/lib called libtuxeip.a. You need to move this into /usr/lib. Because this is in the root part of the drive, you must use root privileges to move it. You then need to get all the .h files from /TuxPLC-master/tuxeip/src and put them in /usr/include.

Now that we got the bits and pieces in the right place we can try to compile one of the examples in TuxPLC-master/tuxeip/test. We'll try test1.c. I had to edit the line that points to TuxEIP.h because the path is incorrect for the way that I was doing it. Mine now says: #include “/usr/include/TuxEIP.h”. You will also want to edit the IP address and the path to match your project (around line 37 and 38). If you need help with the path, refer to TuxPLC-master/tuxeip/documentation/TuxEip.pdf

In the terminal, navigate to TuxPLC-master/tuxeip/test. Compile
Code:
gcc test1.c -ltuxeip -o superduper
Note: superduper will be our compiled file

To run our new shiny compiled program:
Code:
./superduper tagname

Hope this helps...
 
Funny, I looked at this thread a couple of hours ago because I was going to download the source code again. An hour later you post!

I don't really have any code to send you but I can try to help you with your problem. I only have the test samples that come with it (which you would have as well). Are you trying to get those test files to read or did you write your own?

Maybe you could tell me a little about your setup and what you are trying to read. Seeing your source code might help too. Also it would help to know what errors you are getting and when.
 
[FONT=&quot]Thank you for your response.[/FONT]
[FONT=&quot]I am using a Micrologix 1000 connected to the Ethernet trough a 1761-NET-ENI to a local private network with no firewall. I am able to connect, program an get online from Windows, (even AdvancedHMI works perfect), but from Linux, the error is constant, I am convinced that is something I am doing Wrong either in the code, (example test2.c), or in the usage.[/FONT]
[FONT=&quot]It says it connects and opens the session, but when reading it goes into the error.[/FONT]

[FONT=&quot][/FONT]
[FONT=&quot]$./superduper I:0/0[/FONT]
[FONT=&quot]
[/FONT]
[FONT=&quot]Starting, Pid = 1265[/FONT]
[FONT=&quot]Entering OpenSession[/FONT]
[FONT=&quot]OpenSession Ok[/FONT]
[FONT=&quot]Entering RegisterSession[/FONT]
[FONT=&quot]RegisterSession Ok[/FONT]
[FONT=&quot]Entering ConnectPLCOverCNET[/FONT]
[FONT=&quot]ConnectPLCOverCNET Ok,[/FONT]
[FONT=&quot]Reading I:0/0
[/FONT]
[FONT=&quot]Error : ReadPLCData Illegal command or format (16:0)[/FONT]
[FONT=&quot]Entering Forward_Close[/FONT]
[FONT=&quot]Forward_Close Success[/FONT]
[FONT=&quot]UnRegister : Success[/FONT]
[FONT=&quot]Entering CloseSession[/FONT]
[FONT=&quot] [/FONT]
[FONT=&quot]This is what I have in code [/FONT]
[FONT=&quot] [/FONT]
[FONT=&quot]char *IP="192.168.1.4\0";[/FONT]
[FONT=&quot] BYTE path[]={1,0};[/FONT]

[FONT=&quot]printf("entering RegisterSession \n");[/FONT]
[FONT=&quot] res=RegisterSession(session);[/FONT]

[FONT=&quot] if (res!=Error)[/FONT]
[FONT=&quot] { int i,val_int,val_bool;[/FONT]
[FONT=&quot] float val_float;[/FONT]
[FONT=&quot] printf("RegisterSession Ok\n");[/FONT]
[FONT=&quot] printf("entering ConnectPLCOverCNET\n");[/FONT]
[FONT=&quot] Eip_Connection *connection=ConnectPLCOverCNET([/FONT]
[FONT=&quot] session, // session whe have open[/FONT]
[FONT=&quot] LGX, // plc type[/FONT]
[FONT=&quot] 0x12345678, // Target To Originator connection ID[/FONT]
[FONT=&quot] 0x6789, // Connection Serial Number[/FONT]
[FONT=&quot] 5000, // Request Packet Interval[/FONT]
[FONT=&quot] path, // Path to the ControlLogix[/FONT]
[FONT=&quot] sizeof(path) // path size[/FONT]
[FONT=&quot] );[/FONT]

[FONT=&quot] if (connection!=NULL)[/FONT]
[FONT=&quot] {[/FONT]
[FONT=&quot] printf("ConnectPLCOverCNET Ok, \n");[/FONT]
[FONT=&quot] [/FONT]
[FONT=&quot] printf("Reading %s\n",var);[/FONT]

[FONT=&quot] PLC_Read *data=ReadPLCData(session,connection,NULL,NULL,0,LGX,tns++,var,count);[/FONT]
[FONT=&quot] [/FONT]
 
Is this related to the Puffin PLC project? That was an open source PLC project that was related to the control dot com website many years ago. IIRC after a couple of years the project seemed to sort of die out, but I've been mildly surprised that there hasn't been more soft PLC work done for the Linux platform.
 
TConnolly, I'm not sure if they are related or not. From what I gathered Puffin PLC was supposed to be a ladder editor where TUXPLC is a library for reading/writing data.

Scolari, unfortunately I don't have a Micrologix or a NET-ENI to test. At first I thought that the LGX processor was the issue but it didn't matter with my SLC5/05. It doesn't appear to be able to read input data files but it does not produce the same error you had. Have you tried reading other data files? Not that it matters because it cannot read input data files but I:0/0 wouldn't exist, it would be I:1/0.

I chuckled that you left the name superduper!
 
I thought I’d update what it took me to compile one of the examples in tuxeip (test1.c). This should work in any of the Debian based distributions (Debian, Ubuntu, Mint, etc). Just a FYI, if you find yourself saying “why the heck did he do it that way”, it’s because I don’t know what I’m doing! Stephane (library author) was a huge help in getting me in the right direction.

Prerequisites:
  • TuxPLC files
  • Build Essential
  • CMake
  • gcc

The basic idea will be install the appropriate prerequisites, compile the tuxeip library, place the header files and library in the appropriate directories then compile one of the examples and run it. There are probably other ways to do it, if you have a better way feel free to enlighten me. This is just how I got it to work for me.

Note: You can copy and paste the commands in the terminal. Right click then select paste, CTRL+V won’t do it

Open the terminal
Download the files
Code:
wget  https://github.com/leicht/TuxPLC/archive/master.zip
Extract the files
Code:
unzip master.zip
Change to the tuxeip directory
Code:
cd TuxPLC-master/tuxeip
Do some CMake wizardry
Code:
cmake CMakeLists.txt
Build the library
Code:
make
This should have built you a library in TuxPLC-master/tuxeip/lib called libtuxeip.a. You need to move this into /usr/lib. Because this is in the root part of the drive, you must use root privileges to move it. You then need to get all the .h files from /TuxPLC-master/tuxeip/src and put them in /usr/include.

Now that we got the bits and pieces in the right place we can try to compile one of the examples in TuxPLC-master/tuxeip/test. We'll try test1.c. I had to edit the line that points to TuxEIP.h because the path is incorrect for the way that I was doing it. Mine now says: #include “/usr/include/TuxEIP.h”. You will also want to edit the IP address and the path to match your project (around line 37 and 38). If you need help with the path, refer to TuxPLC-master/tuxeip/documentation/TuxEip.pdf

In the terminal, navigate to TuxPLC-master/tuxeip/test. Compile
Code:
gcc test1.c -ltuxeip -o superduper
Note: superduper will be our compiled file

To run our new shiny compiled program:
Code:
./superduper tagname
Hope this helps...


Hi dmroeder, could you please make a similar guide for windows ? i am currently having problems to compile the examples of tuxeip for windows, i keep getting a lot of unresolved external symbol errors in visual studio..
 
dmroeder, thanks for the thorough, step-by-step tutorial of how to load the tuxplc library on Linux. Without your instructions, I probably would have spent a frustrated day just installing the code. I'm sure it took extra time for you to document the steps, but you saved me alot. Thanks again!
 
Cool, I'm glad it helped. I documented it here not only to help others but also for selfish reasons... I knew I'd forget!

I was pretty frustrated there for a while. I ended up contacting Stephane and she helped me figure it out. I need to learn more about make files, it would be nice to set that up so that the usual ./configure, make, make install would install the whole thing.
 

Similar Topics

The past week we received a new piece of equipment from Germany which utilizes siemens controls. Typically in our company we use A.B. controls for...
Replies
9
Views
210
the conveyor can stop because of a safety sensor or safety switch. And also it can stop because of an object jam detector sensor. If the conveyor...
Replies
5
Views
189
Good Day to all of you, this is my first post, i will try to explain as best as possible, english is not my natural language. I am performing an...
Replies
0
Views
42
Hi All, Someone at work has put a PLC system on my desk, that's just been taken off an idle production line. He said "It's an S7 PLC. We don't...
Replies
10
Views
253
I have a project to automate four generator sets. The system will monitor and store the load demand of the factory. Once there's Power outage, the...
Replies
0
Views
64
Back
Top Bottom