Need help in Communication from IndraWorks MLC to PC over TCP/IP sockets

arjunitedred

Member
Join Date
Oct 2015
Location
Lohr am Main
Posts
5
Hi all,

My objective is to send data of type int, bool, string etc from the PLC to PC via TCP sockets. I have used the client/server codes to establish a connection and send the data over sockets but I am not sure how I can extract this data from the PC side so that I can insert into a database. I have a written a Python API to do this but I haven't got much success so far. Below are the codes for server/client on the PLC.

Could you please help me out and point out where exactly I am going wrong?

Code:
 Server: 
PROGRAM PLC_PRG
VAR
fbTCPConnectionAsync: IL_TCPConnectionAsync;
fbTCPSendAsync: IL_TCPSendAsync;

udiSocket: UDINT; 
strHello: STRING := 'Hello World!$r$n'; (* text to send *)
END_VAR

 IF fbTCPConnectionAsync.Done = FALSE THEN
fbTCPConnectionAsync(Enable:=TRUE, Server:=TRUE, Port:=27017, Socket=>udiSocket);

IF fbTCPConnectionAsync.Error = TRUE THEN
fbTCPConnectionAsync(Enable:=FALSE, Socket=>udiSocket);
END_IF
ELSE
fbTCPSendAsync(Enable:=TRUE, Socket:=udiSocket, ValueAdr:=ADR(strHello), NoOfBytes:=LEN(strHello));
IF fbTCPSendAsync.Done=TRUE OR fbTCPSendAsync.Error=TRUE THEN
fbTCPSendAsync(Enable:=FALSE);
fbTCPConnectionAsync(Enable:=FALSE, Socket=>udiSocket);
END_IF
END_IF

Client:
PROGRAM PLC_PRG
VAR
fbConnection: IL_TCPConnectionAsync;
fbSend: IL_TCPSendAsync;
fbRecv: IL_TCPRecvAsync;

udiSocket: UDINT := SOCKET_INVALID;

strSend: STRING := 'Hello';
strRecv: STRING;

iState: INT := 0;
END_VAR

CASE iState OF

0:
    fbConnection(Enable:=FALSE);
    fbSend(Enable:=FALSE);
    fbRecv(Enable:=FALSE);
    diSocket := SOCKET_INVALID;
    iState := 1;

1:
    fbConnection(Enable:=TRUE, Server:=FALSE, Address:='127.0.0.1', Port:=27017);
    IF fbConnection.Done=TRUE THEN
      (* Connection established *)
      udiSocket := fbConnection.Socket;
      iState := 2;
    END_IF

2:
    (* Send some data *)
    fbSend(Enable:=TRUE, Socket:=udiSocket, ValueAdr:=ADR(strSend), NoOfBytes:=LEN(strSend));
    IF fbSend.Done=TRUE THEN
(* Send done *)
      fbSend(Enable:=FALSE);
      iState := 3;
    END_IF

3:
    (* Receive some data *)
    fbRecv(Enable:=TRUE, Socket:=udiSocket, ValueAdr:=ADR(strRecv), NoOfBytes:=SIZEOF(strRecv)-1);
    IF fbRecv.Done=TRUE THEN
      (* Received some data *)
      strRecv := LEFT(strRecv, UDINT_TO_INT(fbRecv.NoOfRecBytes)); (* end of string marker *)
      fbRecv(Enable:=FALSE);
      iState := 4;
    END_IF

4:
    (* Close the connection *)
    fbConnection(Enable:=FALSE);
    diSocket := SOCKET_INVALID;

END_CASE
 
Last edited:
I think the best way to do this will be withd the Bosch Rexroth Opencore API.

IF You can switch to Vb or c# it should be very easy.

Just google Rexroth Opencore.

As of now the API tools are free and there is a support forum for it.
 
Hi ndzied1,

Thank you for the reply. Open Core seems a good option. However, there has been a slight development in what I did in the last 1 hour. I just used the aforementioned Server Code to open a port, and wrote a Python API which acts like a client connecting to the same port and now I see the same PLC data (Hello World string) on the Python shell.
 

Similar Topics

Hello there, I'm practically new to the PLC world, I'm quite familiar with Siemens TIA Portal but I'm currently tasked to program Schneider PLCs...
Replies
5
Views
1,854
Hi; We have Allen Bradley Power Flex750 inverter drive. I want to establish communication between Laptop and drive for which I have a set of...
Replies
1
Views
1,839
hello guys... I have done communication with omron cp1l plc and yasakawa v1000 ac drive now I'm able to write drive parameter from plc program...
Replies
5
Views
3,065
This Problem happened many times, is it only because the wrong type DB10Q0 should be DB1010 or any other possible cause? HMI log file ...
Replies
6
Views
8,541
Hello everyone, M using micrologix 1200 and it is connected to net-aic using pm02 cable, then net-aic is connected to my laptop using pm02 and a...
Replies
15
Views
3,937
Back
Top Bottom