Home > Forum > IEC 61131 Programming (LogicLab) > FILEP assignment of a SysUdpClient object
- This topic has 3 replies, 2 participants and was last updated 4 years, 6 months ago da Sergio Bertana.
-
AuthorPost
-
October 19, 2019 at 7: 47 am #50229PaulParticipant
I should develop a function block to dialogue with objects according to a ascii oriented protocol. This FB would integrate a logic already developed in a project that was connected to devices with modbus protocol. I have a problem assigning the pointer file to the UDP client. To summarize, the logic is this.
1- are declared and instantiated n FB SysUdpClient.
2- a ModbusMaster FB is declared and instantiated.
3- the list of UDP clients is cycled, and from time to time the ModbusMaster FB is 'hooked' to access, one at a time, the devices in the fieldThis is, in a nutshell, the logic:
IF (SysFirstLoop) THEN index:=0; // Parametrizzo il ModbusMaster. mbd.SpyOn := FALSE; mbd.Type := 0; mbd.FCode := 3; mbd.IFTime := 1000; mbd.Timeout := 800; mbd.Delay := 1000; // Inizializzo strutture con parametri di connessione ai dispositivi Config[0].IP := ADR(MB_CONF_IP_TANK_01); Config[0].Buffer := ADR(MB_Memory_T01); Config[0].ConnState := ADR(Tank01_Conn); Config[0].Node := ADR(MB_CONF_ID_TANK_01); Config[0].Address := ADR(MB_CONF_AD_TANK_01); Config[0].Points := ADR(MB_CONF_LN_TANK_01); Config[0].Disabled := ADR(MB_Tank01_Disabled); Config[0].Type := ADR(MB_CONF_MODEL_TANK_01); .... END_IF; // Vengono istanziati i client udp FOR i:=0 TO 9 DO udp[i](); udp[i].FlushTm := 200; udp[i].LifeTm := 40; udp[i].PeerAdd := Config[i].IP; udp[i].PeerPort := 1000 +i; udp[i].LocalPort:= 1000 +i; udp[i].LocalAdd := ADR('0.0.0.0'); udp[i].RxSize := 128; udp[i].TxSize := 128; udp[i].Connect := NOT Config[i].@Disabled; END_FOR; // Eseguo il FB ModbusMaster mbd(); IF (NOT mbd.Enable) THEN index := index + 1; IF (index > 9) THEN index := 0; END_IF; //Associazione al FB per modbus e configurazione parametri. IF (NOT Config[index].@Disabled) THEN n := Config[index].@Type; // Carico indice tabella in base al modello mbd.File := udp[index].File; mbd.Buffer := ADR(buffer); mbd.Node := TO_BYTE (Config[index].@Node); mbd.Address := ADDRES_SETUP[n]; mbd.Points := POINTS_SETUP[n]; mbd.Enable := TRUE; udp[index].Connect := TRUE; ELSE Config[index].@ConnState := FALSE; END_IF; IF (mbd.Fault) THEN gestisco il fault END_IF; IF (mbd.Done) THEN mbd.Enable := FALSE; udp[index].Connect := FALSE; END_IF; IF (mbd.Ok) THEN //recupero i dati letti END_IF;
Now I should do something like this but replacing the modbusmaster FB and maintaining the logic of Udp clients, with the new FB Tec2000. I declared a Tec2000 object with
VAR_INPUT Enable : BOOL; SpyOn : BOOL; File : FILEP; //Dichiarazione file pointer Buffer : @USINT;
October 19, 2019 at 8: 02 am #50238Sergio BertanaAdministrator ForumI state that I did not understand your problem well, what you did in the declaration of the parameters of your function block is correct. Declare an input parameter of type FILEP which you will then pass to the FB ModbusMaster that you have instantiated in your function block.
Now you have an error in compiling, or is the program not working?
In mdb.Done disable the Connect UDP client. This is useless, UDP is not a socket like TCP that "remembers" the connection data, when you send data to the UDP client file it sends them to the other system and then releases the resources. So you can always keep it in active Connect condition, since you have defined a LifeTime, if data does not pass on that client for the time defined automatically it is disabled and re-enabled after a short time. But in your case you always have communication.
The value of IFTime of the ModbusMaster on UDP and TCP communications since the packets are small (<1Kb) so they are sent in a single frame, it can be set to “0” with advantages on the communication time.
October 21, 2019 at 6: 27 am #50256PaulParticipantThe compilation is Ok the problem lies in the fact that I am forced to assign the FILEP out of
// Controllo se devo accedere al dispositivo ed assegno il FILEP. IF (NOT Config[index].@Disabled) THEN ..... mbd.File := udp[index].File; //--riga incriminata ..... END_I
otherwise in my FB FILEP it is always 0. Now assigning it outside the IF is not a problem but I don't understand why in the case of the FB ModbusMaster this is not necessary.
regarding the connect recommendation of the UDP client (always keep the connect to true), this also applies in the case of reassignment of the PeerAddress with a different address each time? or in this case should it be disconnected and then reconnected?
October 21, 2019 at 6: 34 am #50263Sergio BertanaAdministrator ForumAs I said, the UDP client connection does not provide synchronization mechanisms with the server as in the case of TCP connections. So in your case I would see good to use a single SysUDPClient to manage all the connections, and you could instantiate it directly in your FB. So you pass to the FB only the IP address and the port to which it must connect.
Regarding the FILEP, when you enable the SysUDPClient FB it may take more program loops before the exit File is valued. In your previous program you always passed this output to the FB ModbusMaster, and therefore this was performed maybe some loops without correct FILEP (If you look at the log you will have errors) and then when it was valorized the FB worked correctly.
-
AuthorPost
- You must be logged in to reply to this topic.