資源簡介
源碼支持PLC200/300/400與上位機進行通訊,采用S7協議

代碼片段和文件信息
/*
?Part?of?multithreaded?network?servers.?The?servers?MAIN?thread?is?started?by
?the?main?program.?It?starts?in?turn?the?ACCEPTER?thread?which?accepts?a
?connection?and?passes?the?file?descriptor?to?the?MAIN?thread.?The?server?MAIN
?thread?starts?a?PORT?SERVER?thread?to?handle?the?connection.?Thus?the?
?PORT?SERVER?thread?is?NOT?a?child?of?ACCEPTER?but?a?brother?and?SIGCHILD?goes
?to?the?server?MAIN.?If?it?would?go?to?ACCEPTER?which?is?blocked?in?the?
?accept()?system?call?we?would?get?“process?interrupted?in?system?call“?and?
?that‘s?it.?Maybe?its?different?with?pthread?library..?
?Part?of?Libnodave?a?free?communication?libray?for?Siemens?S7?300/400.
?
?(C)?Thomas?Hergenhahn?(thomas.hergenhahn@web.de)?2001..2005.
?LIBNDAVE?is?free?software;?you?can?redistribute?it?and/or?modify
?it?under?the?terms?of?the?GNU?General?Public?License?as?published?by
?the?Free?Software?Foundation;?either?version?2?or?(at?your?option)
?any?later?version.
?LIBNODAVE?is?distributed?in?the?hope?that?it?will?be?useful
?but?WITHOUT?ANY?WARRANTY;?without?even?the?implied?warranty?of
?MERCHANTABILITY?or?FITNESS?FOR?A?PARTICULAR?PURPOSE.??See?the
?GNU?General?Public?License?for?more?details.
?You?should?have?received?a?copy?of?the?GNU?General?Public?License
?along?with?this;?see?the?file?COPYING.??If?not?write?to
?the?Free?Software?Foundation?675?Mass?Ave?Cambridge?MA?02139?USA.??
*/
typedef?struct??{
????int?fd;
????int?port;
}?accepter_info;
void?*accepter(void?*arg)
{
????int?s;
????int?newfd?pipefd;
????socklen_t?addrlen;
????struct?sockaddr_in?addr;
????int?i;
????int?opt;
????usleep(10000);
????pipefd?=?((accepter_info?*)?arg)->fd;
????LOG2(ThisModule?“Accepter?:?My?pipe?is:%d\n“?pipefd);
????FLUSH;
????s?=?socket(AF_INET?SOCK_STREAM?0);
????if?(errno?!=?0)?{
LOG2(ThisModule?“Accepter?:?socket?%s\n“?strerror(errno));
FLUSH;
????}
????LOG2(ThisModule?“Accepter?:?port?%d\n“
???((accepter_info?*)?arg)->port);
????addr.sin_family?=?AF_INET;
????addr.sin_port?=htons(((accepter_info?*)?arg)->port);
// (((((accepter_info?*)?arg)->port)?&?0xff)?<8)?|
// (((((accepter_info?*)?arg)->port)?&?0xff00)?>>?8);
//????LOG2(ThisModule“Accepter?:?port?%d\n“addr.sin_port);
????inet_aton(“0.0.0.0“?&addr.sin_addr);
????opt?=?1;
????i?=?setsockopt(s?SOL_SOCKET?SO_REUSEADDR?&opt?4);
????LOG2(ThisModule?“Accepter?:?setsockopt?%s\n“?strerror(errno));
????addrlen?=?sizeof(addr);
????bind(s?(struct?sockaddr?*)?&?addr?addrlen);
????LOG2(ThisModule?“Accepter?:?bind?%s\n“?strerror(errno));
????listen(s?1);
????LOG2(ThisModule?“Accepter?:?listen:?%s\n“?strerror(errno));
????while?(1)?{
addrlen?=?sizeof(addr);
LOG1(ThisModule?“Accepter?:?before?accept\n“);
newfd?=?(accept(s?(struct?sockaddr?*)?&?addr?&addrlen));
LOG2(ThisModule?“Accepter:?after?accept.?New?fd:%d\n“?newfd);
FLUSH;
LOG3(ThisModule?“Accepter:?PID(%d)?client:%s\n“?getpid()
???????inet_ntoa(addr.sin_addr));
FLUSH;
write(pipefd?&newfd?sizeof(newfd));
????}
????shutdown(s?2);
????LO
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件???????3127??2018-02-02?19:02??libnodave-0.8.5(初始稿)\accepter.c
?????文件???????4935??2018-02-02?19:02??libnodave-0.8.5(初始稿)\benchmark.c
?????文件????????411??2018-02-02?19:02??libnodave-0.8.5(初始稿)\buildall
?????文件???????7226??2018-02-02?19:02??libnodave-0.8.5(初始稿)\ChangeLog
?????文件??????50036??2018-02-02?19:02??libnodave-0.8.5(初始稿)\contributions\LotTrack-103.zip
?????文件??????17445??2018-02-02?19:02??libnodave-0.8.5(初始稿)\contributions\PowerBasic\Dave.bas
?????文件??????76288??2018-02-02?19:02??libnodave-0.8.5(初始稿)\contributions\PowerBasic\Dave.exe
?????文件??????35834??2018-02-02?19:02??libnodave-0.8.5(初始稿)\contributions\PowerBasic\Dave.inc
?????文件?????????52??2018-02-02?19:02??libnodave-0.8.5(初始稿)\DelphiComponent\Demo\Delphi\Editor.ddp
?????文件???????5747??2018-02-02?19:02??libnodave-0.8.5(初始稿)\DelphiComponent\Demo\Delphi\Editor.dfm
?????文件???????5392??2018-02-02?19:02??libnodave-0.8.5(初始稿)\DelphiComponent\Demo\Delphi\Editor.pas
?????文件?????????52??2018-02-02?19:02??libnodave-0.8.5(初始稿)\DelphiComponent\Demo\Delphi\Main.ddp
?????文件???????9126??2018-02-02?19:02??libnodave-0.8.5(初始稿)\DelphiComponent\Demo\Delphi\Main.dfm
?????文件???????9756??2018-02-02?19:02??libnodave-0.8.5(初始稿)\DelphiComponent\Demo\Delphi\Main.pas
?????文件????????374??2018-02-02?19:02??libnodave-0.8.5(初始稿)\DelphiComponent\Demo\Delphi\NoDaveDemo.cfg
?????文件???????2117??2018-02-02?19:02??libnodave-0.8.5(初始稿)\DelphiComponent\Demo\Delphi\NoDaveDemo.dof
?????文件???????1402??2018-02-02?19:02??libnodave-0.8.5(初始稿)\DelphiComponent\Demo\Delphi\NoDaveDemo.dpr
?????文件????????766??2018-02-02?19:02??libnodave-0.8.5(初始稿)\DelphiComponent\Demo\Delphi\NoDaveDemo.ico
?????文件???????1680??2018-02-02?19:02??libnodave-0.8.5(初始稿)\DelphiComponent\Demo\Delphi\NoDaveDemo.res
?????文件???????2569??2018-02-02?19:02??libnodave-0.8.5(初始稿)\DelphiComponent\Demo\Delphi\SZLView.dfm
?????文件???????2879??2018-02-02?19:02??libnodave-0.8.5(初始稿)\DelphiComponent\Demo\Delphi\SZLView.pas
?????文件???????6625??2018-02-02?19:02??libnodave-0.8.5(初始稿)\DelphiComponent\Demo\Lazarus\Editor.lfm
?????文件???????6793??2018-02-02?19:02??libnodave-0.8.5(初始稿)\DelphiComponent\Demo\Lazarus\Editor.lrs
?????文件???????5526??2018-02-02?19:02??libnodave-0.8.5(初始稿)\DelphiComponent\Demo\Lazarus\Editor.pas
?????文件???????7809??2018-02-02?19:02??libnodave-0.8.5(初始稿)\DelphiComponent\Demo\Lazarus\Main.lfm
?????文件???????8357??2018-02-02?19:02??libnodave-0.8.5(初始稿)\DelphiComponent\Demo\Lazarus\Main.lrs
?????文件???????9352??2018-02-02?19:02??libnodave-0.8.5(初始稿)\DelphiComponent\Demo\Lazarus\Main.pas
?????文件??????10542??2018-02-02?19:02??libnodave-0.8.5(初始稿)\DelphiComponent\Demo\Lazarus\NoDaveDemo.lpi
?????文件????????323??2018-02-02?19:02??libnodave-0.8.5(初始稿)\DelphiComponent\Demo\Lazarus\NoDaveDemo.lpr
?????文件?????606720??2018-02-02?19:02??libnodave-0.8.5(初始稿)\DelphiComponent\Demo\NoDaveDemo.exe
............此處省略325個文件信息
- 上一篇:高等電磁場理論--科大
- 下一篇:bootstrap-文件上傳模板
評論
共有 條評論