Commit 977f565e authored by Claes Sjofors's avatar Claes Sjofors

IO libnodave for Siemens PLC added

parent c1b0bc4c
/*
Part of Libnodave, a free communication libray for Siemens S7 300/400.
(C) Thomas Hergenhahn (thomas.hergenhahn@web.de) 2002, 2003.2004
Libnodave 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 Libnodave; see the file COPYING. If not, write to
the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#ifndef opensocket__
#define opensocket__
#ifdef __cplusplus
extern "C" {
#endif
#ifdef BCCWIN
#ifdef DOEXPORT
#define EXPORTSPEC __declspec (dllexport)
#else
#define EXPORTSPEC __declspec (dllimport)
#endif
EXPORTSPEC HANDLE __stdcall openSocket(const int port, const char * peer);
EXPORTSPEC int __stdcall closeSocket(HANDLE h);
#endif
#ifdef LINUX
#define EXPORTSPEC
int openSocket(const int port, const char * peer);
int closeSocket(int h);
#endif
#ifdef __cplusplus
}
#endif
#endif //opensocket__
/*
Changes:
07/12/03 moved openSocket to it's own file, because it can be reused in other TCP clients
04/07/04 ported C++ version to C
12/17/04 additonal defines for WIN32
04/09/05 removed CYGWIN defines. As there were no more differences against LINUX, it should
work with LINUX defines.
Version 0.8.4.5
07/10/09 Added closeSocket()
*/
......@@ -23,7 +23,7 @@ all : init copy lib
init :
copy : $(inc_dir)/libusbio.h $(inc_dir)/pwr_arduino_uno.pde
copy : $(inc_dir)/libusbio.h $(inc_dir)/openSocket.h $(inc_dir)/setport.h $(inc_dir)/pwr_arduino_uno.pde
lib :
......@@ -43,6 +43,14 @@ $(inc_dir)/libusbio.h : ../../libusbio.h
@ echo "Copying libusbio.h"
@ $(cp) $(cpflags) $(source) $(target)
$(inc_dir)/openSocket.h : ../../openSocket.h
@ echo "Copying openSocket.h"
@ $(cp) $(cpflags) $(source) $(target)
$(inc_dir)/setport.h : ../../setport.h
@ echo "Copying setport.h"
@ $(cp) $(cpflags) $(source) $(target)
$(inc_dir)/pwr_arduino_uno.pde : ../../pwr_arduino_uno.pde
@ echo "Copying pwr_arduino_uno.pde"
@ $(cp) $(cpflags) $(source) $(target)
......
/*
Part of Libnodave, a free communication libray for Siemens S7 300/400.
(C) Thomas Hergenhahn (thomas.hergenhahn@web.de) 2001.
Libnodave 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 Libnodave; see the file COPYING. If not, write to
the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#ifndef setport__
#define setport__
#ifdef __cplusplus
extern "C" {
#endif
#ifdef BCCWIN
#ifdef DOEXPORT
#define EXPORTSPEC __declspec (dllexport)
#else
#define EXPORTSPEC __declspec (dllimport)
#endif
EXPORTSPEC HANDLE __stdcall setPort(char * name, char* baud,char parity);
EXPORTSPEC int __stdcall closePort(HANDLE port);
#endif
#ifdef LINUX
int setPort(char * name, char* baud, char parity);
int closePort(int port);
#endif
#ifdef __cplusplus
}
#endif
#endif // setport__
/*
01/08/07 Put __cplusplus directive as where suggested by Keith Harrison.
*/
/*
Dummy for libnodave
*/
#include <stdint.h>
#define DECL2
#define EXPORTSPEC
typedef void * _daveOSserialType;
typedef void * daveInterface;
typedef void * daveConnection;
int openSocket(const int port, const char * peer) { return -1;}
int closeSocket(int h) { return -1;}
int setPort(char * name, char* baud, char parity) { return -1;}
int closePort(int port) { return -1;}
EXPORTSPEC int DECL2 daveInitAdapter(daveInterface * di) { return -1;}
EXPORTSPEC int DECL2 daveConnectPLC(daveConnection * dc) { return -1;}
EXPORTSPEC int DECL2 daveDisconnectPLC(daveConnection * dc) { return -1;}
EXPORTSPEC int DECL2 daveDisconnectAdapter(daveInterface * di) { return -1;}
EXPORTSPEC int DECL2 daveListReachablePartners(daveInterface * di, char * buf) { return -1;}
EXPORTSPEC daveInterface * DECL2 daveNewInterface(_daveOSserialType nfd, char * nname, int localMPI, int protocol, int speed) { return 0;}
EXPORTSPEC daveConnection * DECL2 daveNewConnection(daveInterface * di, int MPI,int rack, int slot) { return 0;}
EXPORTSPEC int DECL2 daveReadBytes(daveConnection * dc, int area, int DB, int start, int len, void * buffer) { return -1;}
EXPORTSPEC int DECL2 daveWriteBytes(daveConnection * dc,int area, int DB, int start, int len, void * buffer) { return -1;}
EXPORTSPEC char * DECL2 daveStrerror(int code) {
static char r[] = "Not build with libnodave";
return r;
}
EXPORTSPEC void DECL2 daveSetTimeout(daveInterface * di, int tmo) {}
include $(pwre_dir_symbols)
-include $(pwre_kroot)/tools/bld/src/$(os_name)/$(hw_name)/$(type_name)_generic.mk
ifeq ($($(type_name)_generic_mk),)
-include $(pwre_kroot)/tools/bld/src/$(os_name)/$(type_name)_generic.mk
endif
ifeq ($($(type_name)_generic_mk),)
include $(pwre_kroot)/tools/bld/src/$(type_name)_generic.mk
endif
-include ../../special.mk
-include ../special.mk
-include special.mk
/* ra_io_m_motioncontrol_usb.h -- I/O methods for class MotionControl_USBIO. */
/* ra_io_m_gpio.h -- I/O methods for GPIO. */
#ifndef ra_io_m_gpio_h
#define ra_io_m_gpio_h
#ifndef rt_io_m_gpio_h
#define rt_io_m_gpio_h
#define GPIO_MAX_CHANNELS 32
......
/* ra_io_m_motioncontrol_usb.h -- I/O methods for class MotionControl_USBIO. */
/* rt_io_m_motioncontrol_usb.h -- I/O methods for class MotionControl_USBIO. */
#ifndef ra_io_m_motioncontrol_usb_h
#define ra_io_m_motioncontrol_usb_h
#ifndef rt_io_m_motioncontrol_usb_h
#define rt_io_m_motioncontrol_usb_h
#define USB_MAX_CARDS 50
......
/* ra_io_m_nodave.h -- I/O methods for libnodave. */
#ifndef rt_io_m_nodave_h
#define rt_io_m_nodave_h
typedef struct {
_daveOSserialType fds;
daveInterface *di;
daveConnection *dc;
int status;
int reset_inputs;
char *input_area;
char *output_area;
unsigned int input_size;
unsigned int output_size;
} io_sRackLocal;
typedef struct {
int status;
int interval_cnt;
int has_read_method;
unsigned int input_size;
unsigned int output_size;
int op_read;
int op_write;
char *input_area;
char *output_area;
} io_sCardLocal;
#endif
This diff is collapsed.
/*
* Proview Open Source Process Control.
* Copyright (C) 2005-2012 SSAB EMEA AB.
*
* This file is part of Proview.
*
* This program 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 of
* the License, or (at your option) any later version.
*
* This program 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 Proview. If not, see <http://www.gnu.org/licenses/>
*
* Linking Proview statically or dynamically with other modules is
* making a combined work based on Proview. Thus, the terms and
* conditions of the GNU General Public License cover the whole
* combination.
*
* In addition, as a special exception, the copyright holders of
* Proview give you permission to, from the build function in the
* Proview Configurator, combine Proview with modules generated by the
* Proview PLC Editor to a PLC program, regardless of the license
* terms of these modules. You may copy and distribute the resulting
* combined work under the terms of your choice, provided that every
* copy of the combined work is accompanied by a complete copy of
* the source code of Proview (the version used to produce the
* combined work), being distributed under the terms of the GNU
* General Public License plus this exception.
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <math.h>
#include "pwr.h"
#include "pwr_baseclasses.h"
#include "pwr_basecomponentclasses.h"
#include "pwr_otherioclasses.h"
#include "rt_io_base.h"
#include "rt_io_msg.h"
#include "rt_errh.h"
#include "rt_io_bus.h"
#include "rt_mb_msg.h"
#if defined PWRE_CONF_NODAVE
#if defined OS_LINUX
#define LINUX
#endif
#include "nodave.h"
#include "rt_io_m_nodave.h"
/*----------------------------------------------------------------------------*\
Init method for the Modbus module
\*----------------------------------------------------------------------------*/
static pwr_tStatus IoCardInit (
io_tCtx ctx,
io_sAgent *ap,
io_sRack *rp,
io_sCard *cp
)
{
io_sCardLocal *local;
pwr_sClass_Nodave_Transaction *op;
op = (pwr_sClass_Nodave_Transaction *) cp->op;
local = (io_sCardLocal *) cp->Local;
local->interval_cnt = 0;
local->status = 1;
strcpy( op->Status, "Initialized");
return IO__SUCCESS;
}
/*----------------------------------------------------------------------------*\
Read method for libnodave transaction
\*----------------------------------------------------------------------------*/
static pwr_tStatus IoCardRead (
io_tCtx ctx,
io_sAgent *ap,
io_sRack *rp,
io_sCard *cp
)
{
io_sCardLocal *local = (io_sCardLocal *) cp->Local;
io_sRackLocal *local_rack = (io_sRackLocal *)rp->Local;
pwr_sClass_Nodave_Transaction *op = (pwr_sClass_Nodave_Transaction *) cp->op;
pwr_sClass_Nodave_PLC *plcp = (pwr_sClass_Nodave_PLC *) rp->op;
int res;
if ( op->Continous == pwr_eYesNoEnum_No) {
/* Only read if triggered by op */
if ( !op->SendOp)
return IO__SUCCESS;
else if ( local->op_write) {
op->SendOp = 0;
local->op_read = 0;
local->op_write = 0;
}
else
local->op_read = 1;
}
if ( local->input_size == 0)
return IO__SUCCESS;
if ( op->ScanInterval > 1) {
local->has_read_method = 1;
if ( local->interval_cnt != 0) {
local->interval_cnt++;
if ( local->interval_cnt >= op->ScanInterval)
local->interval_cnt = 0;
return IO__SUCCESS;
}
local->interval_cnt++;
}
if (local_rack->status == IO__SUCCESS || local_rack->reset_inputs) {
if ( local_rack->reset_inputs)
memset( local->input_area, 0, local->input_size);
else {
res = daveReadBytes( local_rack->dc, op->Area, op->DataBlock, op->Address,
local->input_size, local->input_area);
if ( res != 0) {
strncpy( op->Status, daveStrerror(res), sizeof(op->Status));
plcp->ErrorCount++;
local->status = res;
if ( plcp->ErrorCount >= plcp->ErrorLimit) {
if ( plcp->StallAction == pwr_eStallActionEnum_ResetInputs) {
memset( local->input_area, 0, local->input_size);
local_rack->reset_inputs = 1;
}
else if ( plcp->StallAction == pwr_eStallActionEnum_EmergencyBreak) {
errh_Error( "IO Card ErrorLimit reached '%s', IO stopped", cp->Name);
ctx->Node->EmergBreakTrue = 1;
return IO__ERRDEVICE;
}
}
}
else if ( local->status != 0) {
strncpy( op->Status, "Success", sizeof(op->Status));
local->status = res;
}
}
if ( res == 0 || local_rack->reset_inputs)
io_bus_card_read(ctx, rp, cp, local->input_area, NULL, plcp->ByteOrdering,
plcp->FloatRepresentation);
}
return IO__SUCCESS;
}
/*----------------------------------------------------------------------------*\
Write method for the Nodave transaction
\*----------------------------------------------------------------------------*/
static pwr_tStatus IoCardWrite (
io_tCtx ctx,
io_sAgent *ap,
io_sRack *rp,
io_sCard *cp
)
{
io_sCardLocal *local = (io_sCardLocal *) cp->Local;
io_sRackLocal *local_rack = (io_sRackLocal *)rp->Local;
pwr_sClass_Nodave_Transaction *op = (pwr_sClass_Nodave_Transaction *) cp->op;
pwr_sClass_Nodave_PLC *plcp = (pwr_sClass_Nodave_PLC *) rp->op;
int res;
if ( op->Continous == pwr_eYesNoEnum_No) {
/* Only write if triggered by op */
if ( !op->SendOp)
return IO__SUCCESS;
else if ( local->op_read) {
op->SendOp = 0;
local->op_read = 0;
local->op_write = 0;
}
else
local->op_write = 1;
}
if ( local->output_size == 0)
return IO__SUCCESS;
if ( op->ScanInterval > 1) {
if ( !local->has_read_method) {
if ( local->interval_cnt != 0) {
local->interval_cnt++;
if ( local->interval_cnt >= op->ScanInterval)
local->interval_cnt = 0;
return IO__SUCCESS;
}
local->interval_cnt++;
}
else if ( local->interval_cnt != 1)
return IO__SUCCESS;
}
if ( local_rack->status == IO__SUCCESS) {
io_bus_card_write(ctx, cp, local->output_area, plcp->ByteOrdering,
plcp->FloatRepresentation);
res = daveWriteBytes( local_rack->dc, op->Area, op->DataBlock, op->Address,
local->output_size, local->output_area);
if ( res != 0) {
strncpy( op->Status, daveStrerror(res), sizeof(op->Status));
plcp->ErrorCount++;
local->status = res;
if ( plcp->ErrorCount >= plcp->ErrorLimit) {
if ( plcp->StallAction == pwr_eStallActionEnum_ResetInputs) {
local_rack->reset_inputs = 1;
}
else if ( plcp->StallAction == pwr_eStallActionEnum_EmergencyBreak) {
errh_Error( "IO Card ErrorLimit reached '%s', IO stopped", cp->Name);
ctx->Node->EmergBreakTrue = 1;
return IO__ERRDEVICE;
}
}
}
else if ( local->status != 0) {
strncpy( op->Status, "Success", sizeof(op->Status));
local->status = res;
}
}
return IO__SUCCESS;
}
#else
static pwr_tStatus IoCardInit( io_tCtx ctx, io_sAgent *ap) { return IO__RELEASEBUILD;}
static pwr_tStatus IoCardRead( io_tCtx ctx, io_sAgent *ap) { return IO__RELEASEBUILD;}
static pwr_tStatus IoCardWrite( io_tCtx ctx, io_sAgent *ap) { return IO__RELEASEBUILD;}
#endif
/*----------------------------------------------------------------------------*\
Every method to be exported to the workbench should be registred here.
\*----------------------------------------------------------------------------*/
pwr_dExport pwr_BindIoMethods(Nodave_Transaction) = {
pwr_BindIoMethod(IoCardInit),
pwr_BindIoMethod(IoCardRead),
pwr_BindIoMethod(IoCardWrite),
pwr_NullMethod
};
......@@ -26,4 +26,6 @@ Hilscher_cifX_Module
USB_Joystick
UDP_IO
SPI_Slave
Nodave_PLC
Nodave_Transaction
#endif
\ No newline at end of file
This diff is collapsed.
......@@ -244,6 +244,7 @@ sub build_kernel # args: flavour
_build("lib","usbio_dummy","src","init lib");
_build("lib","usb_dummy","src","init lib");
_build("lib","cifx_dummy","src","init lib");
_build("lib","nodave_dummy","src","init lib");
merge();
_module("xtt");
build_all("exe", $flavour);
......@@ -354,6 +355,7 @@ sub ebuild # args: pass flavour
_build("lib","usbio_dummy","src","init lib");
_build("lib","usb_dummy","src","init lib");
_build("lib","cifx_dummy","src","init lib");
_build("lib","nodave_dummy","src","init lib");
merge();
_module("rt");
_build("exe", "rt*", "src", "all");
......
......@@ -389,6 +389,7 @@ else
pwre_config_check_include mq MQ 0 "/usr/local/dmq/include/p_entry.h"
pwre_config_check_include wmq WMQ 1 "/opt/mqm/inc/cmqc.h"
pwre_config_check_include cifx CIFX 1 "/usr/local/include/cifx/cifxlinux.h"
pwre_config_check_include nodave NODAVE 1 "/usr/include/nodave.h"
export pwre_conf_alsa=1
......@@ -410,7 +411,7 @@ else
echo "export pwre_conf_libpwrco=\"-lpwr_co\"" >> $cfile
echo "export pwre_conf_libpwrrt=\"-lpwr_rt -lpwr_co -lpwr_statussrv -lpwr_msg_dummy\"" >> $cfile
echo "export pwre_conf_libpwrdtt=\"-lpwr_dtt\"" >> $cfile
echo "export pwre_conf_libpwrotherio=\"-lpwr_usbio_dummy -lpwr_usb_dummy -lpwr_cifx_dummy\"" >> $cfile
echo "export pwre_conf_libpwrotherio=\"-lpwr_usbio_dummy -lpwr_usb_dummy -lpwr_cifx_dummy -lpwr_nodave_dummy\"" >> $cfile
echo "export pwre_conf_libpwrprofibus=\"-lpwr_pnak_dummy\"" >> $cfile
echo "export pwre_conf_libpwrxtt=\"-lpwr_xtt -lpwr_ge -lpwr_cow -lpwr_flow -lpwr_glow\"" >> $cfile
echo "export pwre_conf_libpwrxttgtk=\" -lpwr_xtt_gtk -lpwr_ge_gtk -lpwr_cow_gtk -lpwr_flow_gtk -lpwr_glow_gtk\"" >> $cfile
......
......@@ -151,6 +151,16 @@ SObject pwrb:Type
Attr Value = 524288
EndBody
EndObject
!/**
! Nodave archive.
!*/
Object Nodave $Bit
Body SysBody
Attr PgmName = "Nodave"
Attr Text = "Nodave"
Attr Value = 1048576
EndBody
EndObject
EndObject
EndSObject
......
......@@ -252,7 +252,9 @@ palette NavigatorPalette
class ChanAit
class ChanAo
class ChanBi
class ChanBiBlob
class ChanBo
class ChanBoBlob
class ChanCo
class ChanD
class ChanDi
......@@ -389,6 +391,11 @@ palette NavigatorPalette
class BaseIORack
}
}
menu Nodave
{
class Nodave_PLC
class Nodave_Transaction
}
}
menu Remote
{
......
......@@ -2093,6 +2093,11 @@ pwr_tStatus lfu_SaveDirectoryVolume(
else
sprintf( &str[strlen(str)], "-lpwr_usbio_dummy ");
if ( bop->SystemModules & pwr_mBuildOptionsMask_Nodave)
sprintf( &str[strlen(str)], "-lnodave ");
else
sprintf( &str[strlen(str)], "-lpwr_nodave_dummy ");
free( (char *)bop);
if ( os == pwr_mOpSys_CustomBuild)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment