TuxPLC (tuxeip) - How to receive data in PLC?

ortizvinicius

Member
Join Date
Jun 2015
Location
Londrina
Posts
5
Hello,

I dont have any experience with PLCs, but i need to write a program that sends data to a PLC (basically, sequences of INTs), a CompactLogix L33ER.

So i searched and found this library, TuxPLC/TuxEip, compiled and installed without errors, I wrote a code and is everything all right.

But, in PLC side I dont know how to receive this data, I think is something simple but as I dont have experience with PLC its been a hard work.

So, you guys that already used this library knows how I see the data in PLC?

PS: This data on PLC will be used by other persons, my work is on the program side, but i need to go to then with a solution, so I need to see if it works and the rest are with they, i only need to see if this data was received.

My code:

Code:
#include <tuxeip/TuxEip.h>

#include <signal.h>
#include <errno.h>
#include <stdlib.h>
#include <stdio.h>

#define space printf("\n")
#define flush(header) _CipFlushBuffer(header,24+header->Length);

int main(int argc,char *argv[]) {

	cip_debuglevel=LogError; 

	char *IP="192.168.0.111\0";
    BYTE path[]={1,0};
    int res;
    char *var;
    var=argv[1]; 

	printf("entering OpenSession \n");

	Eip_Session *session=OpenSession(IP);
    if (session==NULL)
    {
        printf("Error : OpenSession %s (%d:%d)\n",cip_err_msg,cip_errno,cip_ext_errno);
        return(1);
        
    }
    printf("OpenSession Ok\n");
    printf("entering RegisterSession \n");
    
    res=RegisterSession(session);
    
    int i,val_int;
    float val_float;
    
    val_int = 1;
    
    printf("RegisterSession Ok\n");
    printf("entering ConnectPLCOverCNET\n");
    Eip_Connection *connection=ConnectPLCOverCNET(
      session, // session whe have open
      LGX, // plc type
      0x12345678, // Target To Originator connection ID
      0x6789, // Connection Serial Number
      5000, // Request Packet Interval
      path, // Path to the ControlLogix
      sizeof(path) // path size
      );
    
    printf("Writing %s=%d\n",var,val_int);
    WriteLgxData(session,connection,var,LGX_INT,&val_int,1);
    
    printf("entering Forward_Close\n");
    res=Forward_Close(connection);
    
    UnRegisterSession(session);
    printf("UnRegister : %s\n",cip_err_msg);
    
    printf("entering CloseSession\n");
    CloseSession(session);

}
 
If you want to use RSLogix to view what's in the PLC, you will need the major RSLogix revision installed on your computer that matches the major revision of the PLC that you are connecting to. For example if your PLC has V19 firmware in it, then you will need V19 installed on your computer. Having V20 installed on your computer will not work in my example above (no backwards compatibility).

You will also need the software package RSLinx installed. This is the communications driver that RSLogix will need to connect to the PLC. Make sure your IP address is set so that you are on the same subnet as the PLC. If I'm ever in doubt, I ping the PLC. No sense messing with RSLinx until you can successfully ping the PLC.

In RSLinx, add a the EthernetIP communications driver. Once the PLC shows up under your new driver, then you can switch over to RSLogix5000 to connect to the PLC. Open the offline copy of the project, go to Communications - Who Active, select the PLC and either Go Online or Upload (Download will overwrite what's in the PLC with your offline copy).

Once you are successfully online, you can go to Controller Tags and view any of the tag values.

Hopefully I did not misunderstand what you were asking for and this his helpful.
 
The code snippet you posted suggests that it's writing to an Integer type tag named "LGX_INT".

So be sure that you have a Controller-scope Tag named "LGX_INT", which is an INT datatype.

That TuxPLC implementation is... incomplete. Fixed connection IDs and connection serial numbers are not a proper way to implement CIP communications.
 
I believe the tag name in that write function is var, which comes from an argument passed when the code is ran (argv[1]). LGX_INT is a constant defined in LGX.c that gets the size of the INT data type.
 
Towards the end of /tuxeip/documentation/TuxEip.pdf describes some different configurations and how the path is defined.
 

Similar Topics

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...
Replies
11
Views
5,988
New to PLC stuff, and thought I'd ask if the following is possible before I spend too much time going down a dead-end. I'm trying to remotely...
Replies
6
Views
2,722
Hi guys, I am using asc protocol to communicate to a inkjet printer and having issues receiving response from printer. It send me data but plc...
Replies
0
Views
81
Currently,we are facing the communication go through with 422 tx+ and tx-. Mitsubishi fx5u series is used and using command rs2. But the package...
Replies
0
Views
91
Good Afternoon , Does Rockwell Automation have an Input Card , maybe in the 1734 series , or CompactLogix series that will receive signals...
Replies
15
Views
774
Back
Top Bottom