Commit 861b0a9b authored by Claes Sjofors's avatar Claes Sjofors

OneWire, generic ao device added

parent 3f561ce6
...@@ -13,4 +13,9 @@ typedef struct { ...@@ -13,4 +13,9 @@ typedef struct {
int interval_cnt; int interval_cnt;
} io_sLocalAiDevice; } io_sLocalAiDevice;
typedef struct {
FILE *value_fp;
int interval_cnt;
} io_sLocalAoDevice;
#endif #endif
/*
* Proview Open Source Process Control.
* Copyright (C) 2005-2011 SSAB Oxelosund 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.
*/
/* rt_io_m_onewire_aodevice.c -- I/O methods for class OneWire_AoDevice. */
#include <float.h>
#include <math.h>
#include "pwr.h"
#include "pwr_basecomponentclasses.h"
#include "pwr_otherioclasses.h"
#include "co_time.h"
#include "rt_io_base.h"
#include "rt_io_card_init.h"
#include "rt_io_card_close.h"
#include "rt_io_card_write.h"
#include "rt_io_msg.h"
#include "rt_io_m_onewire.h"
static pwr_tStatus IoCardInit( io_tCtx ctx,
io_sAgent *ap,
io_sRack *rp,
io_sCard *cp)
{
pwr_sClass_OneWire_AoDevice *op = (pwr_sClass_OneWire_AoDevice *)cp->op;
io_sLocalAoDevice *local;
pwr_tStatus sts;
char name[40];
pwr_tFileName fname, tmp;
int name_len;
char *s;
if ( cp->chanlist[0].cop) {
local = (io_sLocalAoDevice *) calloc( 1, sizeof(io_sLocalAoDevice));
cp->Local = local;
sprintf( name, "%d-%012x", op->Family, op->Super.Address);
name_len = strlen(name);
strncpy( fname, op->DataFile, sizeof(fname));
// Replace all '%s' with 'family-serialnumber'
s = fname;
while ( (s = strstr( s, "%s"))) {
strncpy( tmp, s+2, sizeof(tmp));
strcpy( s, name);
strncat( fname, tmp, sizeof(fname));
}
local->value_fp = fopen( fname, "w");
if (!local->value_fp) {
errh_Error( "OneWire_AoDevice Unable op open %s, '%ux'", cp->Name,
op->Super.Address);
sts = IO__INITFAIL;
op->Status = sts;
return sts;
}
io_AoRangeToCoef( &cp->chanlist[0]);
errh_Info( "Init of OneWire_AoDevice '%s'", cp->Name);
}
return IO__SUCCESS;
}
static pwr_tStatus IoCardClose( io_tCtx ctx,
io_sAgent *ap,
io_sRack *rp,
io_sCard *cp)
{
io_sLocalAoDevice *local = (io_sLocalAoDevice *)cp->Local;
if ( cp->chanlist[0].cop) {
fclose( local->value_fp);
}
free( cp->Local);
return IO__SUCCESS;
}
static pwr_tStatus IoCardWrite( io_tCtx ctx,
io_sAgent *ap,
io_sRack *rp,
io_sCard *cp)
{
io_sLocalAoDevice *local = (io_sLocalAoDevice *)cp->Local;
pwr_sClass_OneWire_AoDevice *op = (pwr_sClass_OneWire_AoDevice *)cp->op;
char str[80];
pwr_tUInt32 error_count = op->Super.ErrorCount;
int num;
if ( op->ScanInterval > 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 ( cp->chanlist[0].cop && cp->chanlist[0].sop) {
io_sChannel *chanp = &cp->chanlist[0];
pwr_sClass_ChanAo *cop = (pwr_sClass_ChanAo *)chanp->cop;
pwr_sClass_Ao *sop = (pwr_sClass_Ao *)chanp->sop;
if ( cop->CalculateNewCoef)
// Request to calculate new coefficients
io_AoRangeToCoef( chanp);
switch ( op->ChAo.Representation) {
case pwr_eDataRepEnum_Float32:
case pwr_eDataRepEnum_Float64: {
pwr_tFloat32 fvalue;
fvalue = *(pwr_tFloat32 *)cp->chanlist[0].vbp * cop->OutPolyCoef1 + cop->OutPolyCoef0;
if ( fvalue > cop->ActValRangeHigh)
fvalue = cop->ActValRangeHigh;
else if ( fvalue < cop->ActValRangeLow)
fvalue = cop->ActValRangeLow;
if ( fvalue > 0)
sop->RawValue = fvalue + 0.5;
else
sop->RawValue = fvalue - 0.5;
if ( strcmp( op->Format, "") == 0 )
num = snprintf( str, sizeof(str), "%f", fvalue);
else
num = snprintf( str, sizeof(str), op->Format, fvalue);
if ( num != 1)
op->Super.ErrorCount++;
break;
}
default: {
pwr_tInt32 ivalue;
pwr_tFloat32 fvalue;
fvalue = *(pwr_tFloat32 *)cp->chanlist[0].vbp * cop->OutPolyCoef1 + cop->OutPolyCoef0;
if ( fvalue > cop->ActValRangeHigh)
fvalue = cop->ActValRangeHigh;
else if ( fvalue < cop->ActValRangeLow)
fvalue = cop->ActValRangeLow;
if ( fvalue > 0)
ivalue = sop->RawValue = fvalue + 0.5;
else
ivalue = sop->RawValue = fvalue - 0.5;
if ( strcmp( op->Format, "") == 0 )
num = snprintf( str, sizeof(str), "%d", ivalue);
else
num = snprintf( str, sizeof(str), op->Format, ivalue);
if ( num != 1)
op->Super.ErrorCount++;
}
}
if ( num) {
fprintf( local->value_fp, "%s", str);
fflush( local->value_fp);
rewind( local->value_fp);
}
}
if ( op->Super.ErrorCount >= op->Super.ErrorSoftLimit &&
error_count < op->Super.ErrorSoftLimit) {
errh_Warning( "IO Card ErrorSoftLimit reached, '%s'", cp->Name);
}
if ( op->Super.ErrorCount >= op->Super.ErrorHardLimit) {
errh_Error( "IO Card ErrorHardLimit reached '%s', IO stopped", cp->Name);
ctx->Node->EmergBreakTrue = 1;
return IO__ERRDEVICE;
}
return IO__SUCCESS;
}
/* Every method should be registred here. */
pwr_dExport pwr_BindIoMethods(OneWire_AoDevice) = {
pwr_BindIoMethod(IoCardInit),
pwr_BindIoMethod(IoCardClose),
pwr_BindIoMethod(IoCardWrite),
pwr_NullMethod
};
...@@ -16,6 +16,7 @@ Arduino_Uno ...@@ -16,6 +16,7 @@ Arduino_Uno
GPIO GPIO
GPIO_Module GPIO_Module
OneWire_AiDevice OneWire_AiDevice
OneWire_AoDevice
Maxim_DS18B20 Maxim_DS18B20
USB_Agent USB_Agent
Velleman_K8055_Board Velleman_K8055_Board
......
Volume OtherIO $ClassVolume 0.0.250.10 Volume OtherIO $ClassVolume 0.0.250.10
Body SysBody 01-JAN-1970 01:00:00.00 Body SysBody 01-JAN-1970 01:00:00.00
Attr NextOix = "_X295" Attr NextOix = "_X300"
Attr NextCix = "_X34" Attr NextCix = "_X35"
Attr NextTix[0] = "_X10" Attr NextTix[0] = "_X10"
EndBody EndBody
Object Type $TypeHier 1 15-NOV-2007 14:35:37.90 Object Type $TypeHier 1 15-NOV-2007 14:35:37.90
...@@ -2113,7 +2113,8 @@ Volume OtherIO $ClassVolume 0.0.250.10 ...@@ -2113,7 +2113,8 @@ Volume OtherIO $ClassVolume 0.0.250.10
!*/ !*/
Object Debug $Attribute 17 27-OCT-2011 08:55:53.85 Object Debug $Attribute 17 27-OCT-2011 08:55:53.85
Body SysBody 27-OCT-2011 08:58:09.11 Body SysBody 27-OCT-2011 08:58:09.11
Attr Flags = 25167872 Attr PgmName = "Debug"
Attr Flags = 8390656
Attr TypeRef = "pwrs:Type-$Boolean" Attr TypeRef = "pwrs:Type-$Boolean"
EndBody EndBody
EndObject EndObject
...@@ -2806,7 +2807,8 @@ Volume OtherIO $ClassVolume 0.0.250.10 ...@@ -2806,7 +2807,8 @@ Volume OtherIO $ClassVolume 0.0.250.10
!*/ !*/
Object Debug $Attribute 60 27-OCT-2011 08:57:19.86 Object Debug $Attribute 60 27-OCT-2011 08:57:19.86
Body SysBody 27-OCT-2011 08:57:53.68 Body SysBody 27-OCT-2011 08:57:53.68
Attr Flags = 25167872 Attr PgmName = "Debug"
Attr Flags = 8390656
Attr TypeRef = "pwrs:Type-$Boolean" Attr TypeRef = "pwrs:Type-$Boolean"
EndBody EndBody
EndObject EndObject
...@@ -3423,7 +3425,7 @@ Volume OtherIO $ClassVolume 0.0.250.10 ...@@ -3423,7 +3425,7 @@ Volume OtherIO $ClassVolume 0.0.250.10
EndBody EndBody
EndObject EndObject
Object Template OneWire_AiDevice 2154266624 01-JAN-1970 01:00:00.00 Object Template OneWire_AiDevice 2154266624 01-JAN-1970 01:00:00.00
Body RtBody 08-JUN-2011 14:10:37.59 Body RtBody 01-NOV-2011 13:33:54.15
Attr Super.Process = 1 Attr Super.Process = 1
Attr Super.ErrorSoftLimit = 50 Attr Super.ErrorSoftLimit = 50
Attr Super.ErrorHardLimit = 100 Attr Super.ErrorHardLimit = 100
...@@ -3445,6 +3447,115 @@ Volume OtherIO $ClassVolume 0.0.250.10 ...@@ -3445,6 +3447,115 @@ Volume OtherIO $ClassVolume 0.0.250.10
EndBody EndBody
EndObject EndObject
EndObject EndObject
Object OneWire_AoDevice $ClassDef 34 01-NOV-2011 13:31:45.25
Body SysBody 01-NOV-2011 13:31:33.55
Attr Editor = 0
Attr Method = 0
Attr Flags = 51280
EndBody
Object RtBody $ObjBodyDef 1 01-NOV-2011 13:31:33.55
Body SysBody 01-NOV-2011 13:31:52.28
Attr StructName = "OneWire_AoDevice"
Attr NextAix = "_X42"
EndBody
Object Super $Attribute 33 01-NOV-2011 13:31:33.55
Body SysBody 01-NOV-2011 13:31:33.55
Attr PgmName = "Super"
Attr Flags = 393216
Attr TypeRef = "BaseComponent:Class-BaseIOCard"
EndBody
EndObject
Object Status $Attribute 34 01-NOV-2011 13:31:33.55
Body SysBody 01-NOV-2011 13:31:33.55
Attr PgmName = "Status"
Attr TypeRef = "pwrs:Type-$Status"
EndBody
EndObject
Object Family $Attribute 35 01-NOV-2011 13:31:33.55
Body SysBody 01-NOV-2011 13:31:33.55
Attr PgmName = "Family"
Attr TypeRef = "pwrs:Type-$UInt32"
EndBody
EndObject
Object Resolution $Attribute 36 01-NOV-2011 13:31:33.55
Body SysBody 01-NOV-2011 13:31:33.55
Attr PgmName = "Resolution"
Attr TypeRef = "pwrs:Type-$UInt32"
EndBody
EndObject
Object ScanInterval $Attribute 37 01-NOV-2011 13:31:33.55
Body SysBody 01-NOV-2011 13:31:33.55
Attr PgmName = "ScanInterval"
Attr TypeRef = "pwrs:Type-$UInt32"
EndBody
EndObject
Object DataFile $Attribute 38 01-NOV-2011 13:31:33.55
Body SysBody 01-NOV-2011 13:31:33.55
Attr PgmName = "DataFile"
Attr TypeRef = "pwrs:Type-$String256"
EndBody
EndObject
Object Format $Attribute 39 01-NOV-2011 13:32:10.45
Body SysBody 01-NOV-2011 13:32:11.28
Attr PgmName = "Format"
Attr TypeRef = "pwrs:Type-$String80"
EndBody
EndObject
Object ErrorValue $Attribute 40 01-NOV-2011 13:31:33.55
Body SysBody 01-NOV-2011 13:31:33.55
Attr PgmName = "ErrorValue"
Attr TypeRef = "pwrs:Type-$Float32"
EndBody
EndObject
Object ChAo $Attribute 41 01-NOV-2011 13:32:25.24
Body SysBody 01-NOV-2011 13:32:30.71
Attr PgmName = "ChAo"
Attr Flags = 131072
Attr TypeRef = "pwrb:Class-ChanAo"
EndBody
EndObject
EndObject
Object IoMethods $RtMethod 296 01-NOV-2011 13:31:33.55
Object IoCardInit $Method 297 01-NOV-2011 13:31:33.55
Body SysBody 01-NOV-2011 13:32:46.32
Attr MethodName = "OneWire_AoDevice-IoCardInit"
EndBody
EndObject
Object IoCardClose $Method 298 01-NOV-2011 13:31:33.55
Body SysBody 01-NOV-2011 13:32:52.67
Attr MethodName = "OneWire_AoDevice-IoCardClose"
EndBody
EndObject
Object IoCardWrite $Method 299 01-NOV-2011 13:33:10.62
Body SysBody 01-NOV-2011 15:49:42.73
Attr MethodName = "OneWire_AoDevice-IoCardWrite"
EndBody
EndObject
EndObject
Object PostCreate $DbCallBack 300 01-NOV-2011 13:31:33.55
Body SysBody 01-NOV-2011 13:31:33.55
Attr MethodName = "BaseIOCard-PostCreate"
EndBody
EndObject
Object Template OneWire_AoDevice 2156625920 01-JAN-1970 01:00:00.00
Body RtBody 01-NOV-2011 13:34:13.61
Attr Super.Process = 1
Attr Super.ErrorSoftLimit = 50
Attr Super.ErrorHardLimit = 100
Attr Super.MaxNoOfChannels = 1
Attr ScanInterval = 1
Attr DataFile = "/sys/bus/w1/devices/w1 bus master/%s/w1_slave"
Attr ChAo.OutPolyType = 1
Attr ChAo.ActValRangeLow = -1.000000e+02
Attr ChAo.ActValRangeHigh = 1.000000e+02
Attr ChAo.SensorSigValRangeLow = -5.000000e+00
Attr ChAo.SensorSigValRangeHigh = 5.000000e+00
Attr ChAo.SigValueUnit = "V"
Attr ChAo.ChannelSigValRangeLow = -5.000000e+00
Attr ChAo.ChannelSigValRangeHigh = 5.000000e+00
EndBody
EndObject
EndObject
!/** !/**
! @Version 1.0 ! @Version 1.0
! @Group IO ! @Group IO
......
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