Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » 4DIAC - Framework for Distributed Industrial Automation and Control » SIFB SIGPIPE Handler(Communication)
SIFB SIGPIPE Handler [message #1764928] Sun, 04 June 2017 06:00 Go to next message
Felipe Adriano is currently offline Felipe AdrianoFriend
Messages: 12
Registered: February 2017
Location: Brazil
Junior Member
Hi there,

I am trying to implement a block to read/write CIP Unconnected messages to communicate with a control logix PLC., using libplctag.

I know that is not the best solution for now, the better solution is to implement the client block like modbus (is in progress, but Im trying to understand better the FORTE network layer), but I would like to know if is possible to handle SIGPIPE signal into the Function Block Thread, because in my stress tests when I stop the server with the client trying to read/write data in the broken pipe this signal hangs FORTE.

I tried to manage the SIGPIPE signal in main function (src/arch/posix/main.cpp) where is managed also SIGINT, SIGTERM, SIGHUP, but this not work, the handler never is executed.

Thanks.

Felipe

Re: SIFB SIGPIPE Handler [message #1764943 is a reply to message #1764928] Sun, 04 June 2017 13:49 Go to previous messageGo to next message
Alois Zoitl is currently offline Alois ZoitlFriend
Messages: 454
Registered: January 2014
Senior Member
Hi,

as this is the first time that I heard of the SIGPIPE in the context of network programming I googled a bit. And in general the suggestions are to ignore sigpipe at all and better handle the broken pipe in the return codes from send an recv. I found the discussion in this stackoverflow article [1] quite good. I hope this helps.

[1] https://stackoverflow.com/questions/108183/how-to-prevent-sigpipes-or-handle-them-properly
Re: SIFB SIGPIPE Handler [message #1764957 is a reply to message #1764943] Mon, 05 June 2017 04:50 Go to previous messageGo to next message
Felipe Adriano is currently offline Felipe AdrianoFriend
Messages: 12
Registered: February 2017
Location: Brazil
Junior Member
Thanks by the fast answer.

Well this seems resolved the problem, but another problem appeared...

Do you see some problem in the SIFB create other threads? because to the SIFB block read/write CIP Tags in a non-blocking way (when the REQ event is triggered) I am using a thread to manage the tag connection and try to recreate the tag if the server don't answer in the stipulated timeout.
The libplctag internally also create some threads to communicate.

In other words, the SIFB read/write tags create other threads in the FORTE when te INIT event is triggered (I made it based on modbus client FB that create thread to poll registers and read data triggering CNF events).

To contextualize the problem:

The libplctag tags recreation in the occurrence of communication errors works out of FORTE (https://github.com/Felipeasg/retryTags). I wrote the program trying to use forte thread to reproduce the error, and the tag.cpp works out of FORTE, but using this class in FORTE function block it not work well when the server do not respond and I need to recreate the connection.

[Updated on: Mon, 05 June 2017 05:04]

Report message to a moderator

Re: SIFB SIGPIPE Handler [message #1765180 is a reply to message #1764957] Wed, 07 June 2017 09:57 Go to previous message
Alois Zoitl is currently offline Alois ZoitlFriend
Messages: 454
Registered: January 2014
Senior Member
In principle it is no problem to create threads from SIFBs. The only thing I would consider is if you can make some upper bound on the thread. For example in some protocols (like the generic TCP/UDP handling) we have one thread that is doing all this delayed and waiting work and based on the recieved data or errors informs the right FB so that it can process the information and send output events. However this is a little bit tricky. The reason is that you are not allowed to send output events from the threads you created. The method sendOutputEvent will only work when the FB is invoked from the EventChainExecutionThread. If you want to trigger the fB from your own thread you need to use the method startNewEventChain offered by the class CExternalEventHandler. Which will perform all the event synchronisation necessary and delivers an event called CGExternalEvent to the FB. In your SIFB you can then wait for this event and respond accordingly (i.e., send out an ind event).
Previous Topic:There are some differences between my ide and document.
Next Topic:Has anyone tried a broker-based pub-sub implementation?
Goto Forum:
  


Current Time: Wed Feb 21 19:25:15 GMT 2018

Powered by FUDForum. Page generated in 0.02208 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software