Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
P
proview
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Esteban Blanc
proview
Commits
b851d56d
Commit
b851d56d
authored
Jun 06, 2010
by
claes
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
IO methods and objects for temperature sensor Maxim DS18B20
parent
390e8fb2
Changes
6
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
387 additions
and
11 deletions
+387
-11
otherio/lib/rt/src/os_linux/rt_io_m_maxim_ds18b20.c
otherio/lib/rt/src/os_linux/rt_io_m_maxim_ds18b20.c
+160
-0
otherio/lib/rt/src/os_linux/rt_io_m_onewire.h
otherio/lib/rt/src/os_linux/rt_io_m_onewire.h
+11
-0
otherio/lib/rt/src/rt_io_otherio.meth
otherio/lib/rt/src/rt_io_otherio.meth
+1
-0
otherio/wbl/mcomp/src/otherio.wb_load
otherio/wbl/mcomp/src/otherio.wb_load
+160
-11
src/lib/rt/src/rt_io_base.c
src/lib/rt/src/rt_io_base.c
+49
-0
src/lib/rt/src/rt_io_base.h
src/lib/rt/src/rt_io_base.h
+6
-0
No files found.
otherio/lib/rt/src/os_linux/rt_io_m_maxim_ds18b20.c
0 → 100644
View file @
b851d56d
/*
* Proview $Id$
* Copyright (C) 2005 SSAB Oxelsund AB.
*
* 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 the program, if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
/* rt_io_m_maxim_ds18b20.c -- I/O methods for class Maxim_DS18B20. */
#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_read.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_Maxim_DS18B20
*
op
=
(
pwr_sClass_Maxim_DS18B20
*
)
cp
->
op
;
io_sLocalDS18B20
*
local
;
pwr_tStatus
sts
;
char
name
[
40
];
pwr_tFileName
fname
;
if
(
cp
->
chanlist
[
0
].
cop
)
{
local
=
(
io_sLocalDS18B20
*
)
calloc
(
1
,
sizeof
(
io_sLocalDS18B20
));
cp
->
Local
=
local
;
sprintf
(
name
,
"%d-%012x"
,
op
->
Family
,
op
->
Super
.
Address
);
sprintf
(
fname
,
"/sys/bus/w1/devices/w1 bus master/%s/w1_slave"
,
name
);
local
->
value_fp
=
fopen
(
fname
,
"r"
);
if
(
!
local
->
value_fp
)
{
errh_Error
(
"Maxim_DS18B20 Unable op open %s, '%ux'"
,
cp
->
Name
,
op
->
Super
.
Address
);
sts
=
IO__INITFAIL
;
op
->
Status
=
sts
;
return
sts
;
}
io_AiRangeToCoef
(
&
cp
->
chanlist
[
0
]);
errh_Info
(
"Init of Maxim_DS18B20 '%s'"
,
cp
->
Name
);
}
return
IO__SUCCESS
;
}
static
pwr_tStatus
IoCardClose
(
io_tCtx
ctx
,
io_sAgent
*
ap
,
io_sRack
*
rp
,
io_sCard
*
cp
)
{
io_sLocalDS18B20
*
local
=
(
io_sLocalDS18B20
*
)
cp
->
Local
;
if
(
cp
->
chanlist
[
0
].
cop
)
{
fclose
(
local
->
value_fp
);
}
free
(
cp
->
Local
);
return
IO__SUCCESS
;
}
static
pwr_tStatus
IoCardRead
(
io_tCtx
ctx
,
io_sAgent
*
ap
,
io_sRack
*
rp
,
io_sCard
*
cp
)
{
io_sLocalDS18B20
*
local
=
(
io_sLocalDS18B20
*
)
cp
->
Local
;
pwr_sClass_Maxim_DS18B20
*
op
=
(
pwr_sClass_Maxim_DS18B20
*
)
cp
->
op
;
char
str
[
80
];
char
*
s
;
pwr_tUInt32
error_count
=
op
->
Super
.
ErrorCount
;
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
)
{
io_sChannel
*
chanp
=
&
cp
->
chanlist
[
0
];
pwr_sClass_ChanAi
*
cop
=
(
pwr_sClass_ChanAi
*
)
chanp
->
cop
;
pwr_sClass_Ai
*
sop
=
(
pwr_sClass_Ai
*
)
chanp
->
sop
;
pwr_tInt32
ivalue
;
pwr_tFloat32
actvalue
;
if
(
cop
->
CalculateNewCoef
)
// Request to calculate new coefficients
io_AiRangeToCoef
(
chanp
);
fflush
(
local
->
value_fp
);
fgets
(
str
,
sizeof
(
str
),
local
->
value_fp
);
fgets
(
str
,
sizeof
(
str
),
local
->
value_fp
);
rewind
(
local
->
value_fp
);
s
=
strstr
(
str
,
"t="
);
if
(
s
)
{
sscanf
(
s
+
2
,
"%d"
,
&
ivalue
);
io_ConvertAi32
(
cop
,
ivalue
,
&
actvalue
);
// Filter
if
(
sop
->
FilterType
==
1
&&
sop
->
FilterAttribute
[
0
]
>
0
&&
sop
->
FilterAttribute
[
0
]
>
ctx
->
ScanTime
)
{
actvalue
=
*
(
pwr_tFloat32
*
)
chanp
->
vbp
+
ctx
->
ScanTime
/
sop
->
FilterAttribute
[
0
]
*
(
actvalue
-
*
(
pwr_tFloat32
*
)
chanp
->
vbp
);
}
*
(
pwr_tFloat32
*
)
chanp
->
vbp
=
actvalue
;
sop
->
SigValue
=
cop
->
SigValPolyCoef1
*
ivalue
+
cop
->
SigValPolyCoef0
;
sop
->
RawValue
=
ivalue
;
}
else
{
op
->
Super
.
ErrorCount
++
;
}
}
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
(
Maxim_DS18B20
)
=
{
pwr_BindIoMethod
(
IoCardInit
),
pwr_BindIoMethod
(
IoCardClose
),
pwr_BindIoMethod
(
IoCardRead
),
pwr_NullMethod
};
otherio/lib/rt/src/os_linux/rt_io_m_onewire.h
0 → 100644
View file @
b851d56d
/* ra_io_m_onewire.h -- I/O methods for class OneWire. */
#ifndef ra_io_m_onewire_h
#define ra_io_m_onewire_h
typedef
struct
{
FILE
*
value_fp
;
int
interval_cnt
;
}
io_sLocalDS18B20
;
#endif
otherio/lib/rt/src/rt_io_otherio.meth
View file @
b851d56d
...
...
@@ -7,5 +7,6 @@ Modbus_TCP_Server
Modbus_TCP_ServerModule
GPIO
GPIO_Module
Maxim_DS18B20
USB_Agent
Velleman_K8055_Board
otherio/wbl/mcomp/src/otherio.wb_load
View file @
b851d56d
Volume OtherIO $ClassVolume 0.0.250.10
Body SysBody 01-JAN-1970 01:00:00.00
Attr NextOix = "_X1
11
"
Attr NextCix = "_X1
3
"
Attr NextOix = "_X1
22
"
Attr NextCix = "_X1
5
"
Attr NextTix[0] = "_X5"
EndBody
Object Type $TypeHier 1 15-NOV-2007 14:35:37.90
...
...
@@ -487,7 +487,7 @@ Volume OtherIO $ClassVolume 0.0.250.10
! Super class.
!*/
Object Super $Attribute 7 15-NOV-2007 14:36:59.65
Body SysBody
15-NOV-2007 14:36:59.65
Body SysBody
06-JUN-2010 14:27:15.66
Attr PgmName = "Super"
Attr Flags = 393216
Attr TypeRef = "BaseComponent:Class-BaseIOCard"
...
...
@@ -1627,6 +1627,155 @@ Volume OtherIO $ClassVolume 0.0.250.10
EndBody
EndObject
EndObject
Object OneWire $ClassDef 13 06-JUN-2010 13:05:35.38
Body SysBody 06-JUN-2010 13:05:26.98
Attr Editor = 0
Attr Method = 0
Attr Flags = 10320
EndBody
Object RtBody $ObjBodyDef 1 06-JUN-2010 13:05:26.98
Body SysBody 06-JUN-2010 13:05:43.85
Attr StructName = "OneWire"
Attr NextAix = "_X21"
EndBody
Object Description $Attribute 17 06-JUN-2010 13:05:26.98
Body SysBody 06-JUN-2010 13:05:26.98
Attr PgmName = "Description"
Attr TypeRef = "pwrs:Type-$String80"
EndBody
EndObject
Object Process $Attribute 18 06-JUN-2010 13:05:26.98
Body SysBody 06-JUN-2010 13:05:26.98
Attr PgmName = "Process"
Attr TypeRef = "pwrb:Type-IoProcessMask"
EndBody
EndObject
Object ThreadObject $Attribute 19 06-JUN-2010 13:05:26.98
Body SysBody 06-JUN-2010 13:05:26.98
Attr PgmName = "ThreadObject"
Attr TypeRef = "pwrs:Type-$Objid"
EndBody
EndObject
Object Status $Attribute 20 06-JUN-2010 13:05:26.98
Body SysBody 06-JUN-2010 13:05:26.98
Attr PgmName = "Status"
Attr Flags = 1040
Attr TypeRef = "pwrs:Type-$Status"
EndBody
EndObject
EndObject
Object ConfiguratorPoson $Menu 112 06-JUN-2010 13:05:26.98
Object Pointed $Menu 113 06-JUN-2010 13:05:26.98
Object Connect $MenuButton 114 06-JUN-2010 13:05:26.98
Body SysBody 06-JUN-2010 13:05:26.98
Attr ButtonName = "Connect PlcThread"
Attr MethodName = "$Objid-Connect"
Attr MethodArguments[0] = "ThreadObject"
Attr MethodArguments[1] = "PlcThread"
Attr FilterName = "$Objid-IsOkConnect"
Attr FilterArguments[0] = "ThreadObject"
Attr FilterArguments[1] = "PlcThread"
EndBody
EndObject
EndObject
EndObject
Object Template OneWire 2151120896 01-JAN-1970 01:00:00.00
Body RtBody 06-JUN-2010 18:34:08.77
Attr Process = 1
EndBody
EndObject
EndObject
Object Maxim_DS18B20 $ClassDef 14 06-JUN-2010 13:53:40.68
Body SysBody 06-JUN-2010 13:05:26.98
Attr Editor = 0
Attr Method = 0
Attr Flags = 18512
EndBody
Object RtBody $ObjBodyDef 1 06-JUN-2010 13:05:26.98
Body SysBody 06-JUN-2010 13:53:51.81
Attr StructName = "Maxim_DS18B20"
Attr NextAix = "_X24"
EndBody
Object Super $Attribute 15 06-JUN-2010 14:27:43.39
Body SysBody 06-JUN-2010 14:27:21.38
Attr PgmName = "Super"
Attr Flags = 393216
Attr TypeRef = "BaseComponent:Class-BaseIOCard"
EndBody
EndObject
Object Status $Attribute 18 06-JUN-2010 13:05:26.98
Body SysBody 06-JUN-2010 13:05:26.98
Attr PgmName = "Status"
Attr TypeRef = "pwrs:Type-$Status"
EndBody
EndObject
Object Family $Attribute 22 06-JUN-2010 13:56:28.16
Body SysBody 06-JUN-2010 13:56:08.04
Attr PgmName = "Family"
Attr TypeRef = "pwrs:Type-$UInt32"
EndBody
EndObject
Object Resolution $Attribute 21 06-JUN-2010 13:54:53.59
Body SysBody 06-JUN-2010 13:13:46.70
Attr PgmName = "Resolution"
Attr TypeRef = "pwrs:Type-$UInt32"
EndBody
EndObject
Object ScanInterval $Attribute 19 06-JUN-2010 13:05:26.98
Body SysBody 06-JUN-2010 13:05:26.98
Attr PgmName = "ScanInterval"
Attr TypeRef = "pwrs:Type-$UInt32"
EndBody
EndObject
Object ChAi $Attribute 20 06-JUN-2010 13:08:41.78
Body SysBody 06-JUN-2010 13:09:01.03
Attr PgmName = "ChAi"
Attr Flags = 131072
Attr TypeRef = "pwrb:Class-ChanAi"
EndBody
EndObject
EndObject
Object IoMethods $RtMethod 118 06-JUN-2010 13:05:26.98
Object IoCardInit $Method 119 06-JUN-2010 13:05:26.98
Body SysBody 06-JUN-2010 13:54:01.89
Attr MethodName = "Maxim_DS18B20-IoCardInit"
EndBody
EndObject
Object IoCardClose $Method 120 06-JUN-2010 13:05:26.98
Body SysBody 06-JUN-2010 13:54:09.79
Attr MethodName = "Maxim_DS18B20-IoCardClose"
EndBody
EndObject
Object IoCardRead $Method 121 06-JUN-2010 13:05:26.98
Body SysBody 06-JUN-2010 13:54:16.51
Attr MethodName = "Maxim_DS18B20-IoCardRead"
EndBody
EndObject
EndObject
Object Template Maxim_DS18B20 2151383040 01-JAN-1970 01:00:00.00
Body RtBody 06-JUN-2010 18:34:27.07
Attr Super.Specification = "Maxim 1-Wire temperature sensor DS18B10"
Attr Super.Process = 1
Attr Super.ErrorSoftLimit = 50
Attr Super.ErrorHardLimit = 100
Attr Super.MaxNoOfChannels = 1
Attr Family = 28
Attr Resolution = 12
Attr ChAi.ConversionOn = 1
Attr ChAi.ScanInterval = 1
Attr ChAi.RawValRangeLow = -5.500000e+04
Attr ChAi.RawValRangeHigh = 1.250000e+05
Attr ChAi.ChannelSigValRangeLow = -5.500000e+04
Attr ChAi.ChannelSigValRangeHigh = 1.250000e+05
Attr ChAi.SigValueUnit = "C"
Attr ChAi.SensorPolyType = 1
Attr ChAi.SensorSigValRangeLow = -5.500000e+04
Attr ChAi.SensorSigValRangeHigh = 1.250000e+05
Attr ChAi.ActValRangeLow = -5.500000e+01
Attr ChAi.ActValRangeHigh = 1.250000e+02
EndBody
EndObject
EndObject
!/**
! @Version 1.0
! @Group IO
...
...
src/lib/rt/src/rt_io_base.c
View file @
b851d56d
...
...
@@ -3009,6 +3009,55 @@ void io_ConvertAi (
}
}
void
io_ConvertAi32
(
pwr_sClass_ChanAi
*
cop
,
pwr_tInt32
rawvalue
,
pwr_tFloat32
*
actvalue_p
)
{
pwr_tFloat32
sigvalue
;
pwr_tFloat32
actvalue
;
pwr_tFloat32
*
polycoef_p
;
int
i
;
switch
(
cop
->
SensorPolyType
)
{
case
0
:
*
actvalue_p
=
cop
->
SigValPolyCoef0
+
cop
->
SigValPolyCoef1
*
rawvalue
;
break
;
case
1
:
*
actvalue_p
=
cop
->
SensorPolyCoef0
+
cop
->
SensorPolyCoef1
*
rawvalue
;
break
;
case
2
:
sigvalue
=
cop
->
SigValPolyCoef0
+
cop
->
SigValPolyCoef1
*
rawvalue
;
polycoef_p
=
&
cop
->
SensorPolyCoef2
;
actvalue
=
0
;
for
(
i
=
0
;
i
<
3
;
i
++
)
{
actvalue
=
sigvalue
*
actvalue
+
*
polycoef_p
;
polycoef_p
--
;
}
*
actvalue_p
=
actvalue
;
break
;
case
3
:
sigvalue
=
cop
->
SigValPolyCoef0
+
cop
->
SigValPolyCoef1
*
rawvalue
;
actvalue
=
cop
->
SensorPolyCoef0
+
cop
->
SensorPolyCoef1
*
sigvalue
;
if
(
actvalue
>=
0
)
*
actvalue_p
=
cop
->
SensorPolyCoef2
*
sqrt
(
actvalue
);
else
*
actvalue_p
=
0
;
break
;
case
4
:
sigvalue
=
cop
->
SigValPolyCoef0
+
cop
->
SigValPolyCoef1
*
rawvalue
;
actvalue
=
cop
->
SensorPolyCoef0
+
cop
->
SensorPolyCoef1
*
sigvalue
;
if
(
actvalue
>=
0
)
*
actvalue_p
=
cop
->
SensorPolyCoef2
*
sqrt
(
actvalue
);
else
*
actvalue_p
=
-
cop
->
SensorPolyCoef2
*
sqrt
(
-
actvalue
);
break
;
}
}
/*----------------------------------------------------------------------------*\
Convert ait from rawvalue to actualvalue.
...
...
src/lib/rt/src/rt_io_base.h
View file @
b851d56d
...
...
@@ -240,6 +240,12 @@ void io_ConvertAi (
pwr_tFloat32
*
actvalue_p
);
void
io_ConvertAi32
(
pwr_sClass_ChanAi
*
cop
,
pwr_tInt32
rawvalue
,
pwr_tFloat32
*
actvalue_p
);
void
io_ConvertAit
(
pwr_sClass_ChanAit
*
cop
,
pwr_tInt16
rawvalue
,
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment