Autor Thema: IP_CONTROL problem  (Gelesen 10550 mal)

0 Mitglieder und 1 Gast betrachten dieses Thema.

hells1ng

  • Gast
IP_CONTROL problem
« am: 16. Februar 2015, 15:23:17 »
Hi all!
i'm newbie in codesys and oscat library, but i have to communicate my PC's program with PLC via TCP/UDP(look at picture)
So i can send data from PLC every 10s(look at attached picture on ctrl_pwm), but i cannot receive data. Please tell me, where i did mistake?
thanks a lot!

[gelöscht durch Administrator]

Offline peewit

  • Moderator
  • *****
  • Beiträge: 2 378
    • Profil anzeigen
Re: IP_CONTROL problem
« Antwort #1 am: 16. Februar 2015, 15:47:21 »
it is not possible to program a clean program in kop or fup
you must programm your module in ST (strucure text)


the ip_control block has a state machine

1. connect
2. send data
3. receive data  (alternately to send !)
4. evaluate and acknowledge error and reconnect....


watch the blocks in the network library (directory 'demo') , there are some examples
or
http://www.oscat.de/community/index.php/topic,1071.msg6404.html#msg6404

hells1ng

  • Gast
Re: IP_CONTROL problem
« Antwort #2 am: 16. Februar 2015, 16:29:41 »
ok, but here http://www.oscat.de/community/index.php/topic,1071.msg6404.html#msg6404
only examples Telnet Send, but i have problem with receive data.
tell me please, can i use Modbus Client and Server function blocks for send/receive via UDP protocol ?

hells1ng

  • Gast
Re: IP_CONTROL problem
« Antwort #3 am: 16. Februar 2015, 16:47:03 »
am i right that for receiving data i have to:
ip_c1.mode:=3;
ip_c1.enable:=true;
ip_c1.time_reset:=true;
ip_c1.r_observe:=true;
r_buf1.size:=0;
?

Offline peewit

  • Moderator
  • *****
  • Beiträge: 2 378
    • Profil anzeigen
Re: IP_CONTROL problem
« Antwort #4 am: 16. Februar 2015, 23:52:16 »
ok, but here http://www.oscat.de/community/index.php/topic,1071.msg6404.html#msg6404
only examples Telnet Send, but i have problem with receive data.
tell me please, can i use Modbus Client and Server function blocks for send/receive via UDP protocol ?

yes, you can use the code from modbus client/server


hells1ng

  • Gast
Re: IP_CONTROL problem
« Antwort #5 am: 17. Februar 2015, 12:09:10 »
ok, i write program in ST, can you tell me where i did the mistake? thanks..
---------------------------------------------------------
CTRL_PWM(CI:=0.5,F:=1);
IP_CONTROL2(IP_C:=IP_C,S_BUF:=S_BUF,R_BUF:=R_BUF);
   CASE state OF
0: (* On Wait for release *)
   IF CTRL_PWM.Q THEN
      state := 10;
      IP_STATE  := 1;(* Sign on *)
   END_IF;
10: (* Wait for clearance to access for connection and sending content *)
      IF IP_STATE = 1 THEN (* access permitted? *)
   (* IP set up data traffic *)
   IP_C.C_PORT := 1201; (* enter port number *)
   IP_C.C_IP := IP4_DECODE('192.168.0.5'); (* Enter IP *)
   IP_C.C_MODE := 1; (* Mode: UDP+ACTIVE+Port+IP *)
   IP_C.C_ENABLE := TRUE; (* Release connection *)
   IP_C.TIME_RESET := TRUE; (*Reset TIME monitoring * *)
   IP_C.R_OBSERVE := TRUE; (* Monitor data receive *)
   R_BUF.SIZE:= 0; (* Reset Home length *)
   (* Send data register *)
   S_BUF.BUFFER[0] := BYTE#16#11;
   S_BUF.BUFFER[1] := BYTE#16#11;
   (* Etc. ... *)
   S_BUF.SIZE := 2; (* enter send length *)
   state := 30;
   END_IF;
30:
   IF IP_C.ERROR <> 0 THEN
   error:=IP_C.ERROR;
   state := 00;
   IP_STATE := 2;
   ELSIF S_BUF.SIZE = 0 AND R_BUF.SIZE >= 0 THEN
   R_BUF1.BUFFER := R_BUF.BUFFER;
   (* evaluate received data *)
   (* Logout - release access for other *)
   IP_STATE := 2;
   state := 00; (* process end *)
END_IF;
END_CASE;

IP_FIFO(FIFO:=IP_C.FIFO,STATE:=IP_STATE,ID:=IP_ID);
(*IP_C.FIFO:=IP_FIFO.FIFO;
IP_STATE := IP_FIFO.STATE;
IP_ID:=IP_FIFO.ID;*)