ortizvinicius
Member
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:
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);
}