Commit 078c6368 authored by Claes Sjofors's avatar Claes Sjofors

Plc function object Random added

parent cc65722b
......@@ -1084,6 +1084,21 @@ void Min_exec(plc_sThread* tp, pwr_sClass_Min* o)
o->ActVal = result;
}
/*_*
Random Random value generator.
@aref random Random
*/
void Random_exec(plc_sThread* tp, pwr_sClass_Random* o)
{
if ( o->CondP == &o->Cond)
o->ActVal = o->MinValue + (float)(rand())/RAND_MAX * (o->MaxValue - o->MinValue);
else {
if ( *o->CondP && !o->CondOld)
o->ActVal = o->MinValue + (float)(rand())/RAND_MAX * (o->MaxValue - o->MinValue);
o->CondOld = *o->CondP;
}
}
/*_*
BwShiftLeft Bitwise shift left.
@aref bwshiftleft BwShiftLeft
......
......@@ -90,6 +90,7 @@ void Sub_exec(plc_sThread* tp, pwr_sClass_Sub* object);
void Div_exec(plc_sThread* tp, pwr_sClass_Div* object);
void Max_exec(plc_sThread* tp, pwr_sClass_Max* object);
void Min_exec(plc_sThread* tp, pwr_sClass_Min* object);
void Random_exec(plc_sThread* tp, pwr_sClass_Random* o);
void BwShiftLeft_exec(plc_sThread* tp, pwr_sClass_BwShiftLeft* object);
void BwShiftRight_exec(plc_sThread* tp, pwr_sClass_BwShiftRight* object);
void BwRotateRight_exec(plc_sThread* tp, pwr_sClass_BwRotateRight* object);
......
!
! ProviewR Open Source Process Control.
! Copyright (C) 2005-2019 SSAB EMEA AB.
!
! This file is part of ProviewR.
!
! 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 ProviewR. If not, see <http://www.gnu.org/licenses/>
!
! Linking ProviewR statically or dynamically with other modules is
! making a combined work based on ProviewR. 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
! ProviewR give you permission to, from the build function in the
! ProviewR Configurator, combine ProviewR with modules generated by the
! ProviewR 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 ProviewR (the version used to produce the
! combined work), being distributed under the terms of the GNU
! General Public License plus this exception.
!
! pwrb_c_random.wb_load -- Defines the class Random.
!
SObject pwrb:Class
!/**
! @Version 1.0
! @Code rt_plc_arithm.c
! @Group Plc,PlcAnalog
! @Summary Random value generator
! Random value generator.
! @image orm_random_fo.png
!
! Generates a random analog value between the supplied min and max values.
! If the condition input is connected, a new value is generated on a leading edge
! on Cond. If Cond is not connected, a new value is generated every scan.
!*/
Object Random $ClassDef 711
Body SysBody
Attr Editor = pwr_eEditor_PlcEd
Attr Method = pwr_eMethod_Connections
Attr PopEditor = 2
EndBody
Object RtBody $ObjBodyDef 1
Body SysBody
Attr StructName = "Random"
EndBody
!/**
! Condition. If connected, a new value is generated on leading
! edge. If not connected, a new value is generated every scan.
!*/
Object Cond $Input 1
Body SysBody
Attr TypeRef = "pwrs:Type-$Boolean"
Attr Flags |= PWR_MASK_NOINVERT
Attr Flags |= PWR_MASK_STATE
Attr Flags |= PWR_MASK_NOEDIT
Attr GraphName = "Cond"
EndBody
EndObject
!/**
! Mininum value for the generated value.
!*/
Object MinValue $Intern 2
Body SysBody
Attr TypeRef = "pwrs:Type-$Float32"
EndBody
EndObject
!/**
! Maximum value for generated value.
!*/
Object MaxValue $Intern 3
Body SysBody
Attr TypeRef = "pwrs:Type-$Float32"
EndBody
EndObject
!/**
! Stored value of Cond.
!*/
Object CondOld $Intern 4
Body SysBody
Attr TypeRef = "pwrs:Type-$Boolean"
Attr Flags |= PWR_MASK_STATE
Attr Flags |= PWR_MASK_INVISIBLE
Attr Flags |= PWR_MASK_REDUTRANSFER
EndBody
EndObject
!/**
! Output that contains the random value.
!*/
Object ActVal $Output 5
Body SysBody
Attr Flags |= PWR_MASK_STATE
Attr Flags |= PWR_MASK_NOEDIT
Attr Flags |= PWR_MASK_REDUTRANSFER
Attr TypeRef = "pwrs:Type-$Float32"
Attr GraphName = "Val"
EndBody
EndObject
EndObject
Object DevBody $ObjBodyDef 2
Object PlcNode $Buffer 1
Body SysBody
Attr Class = pwr_eClass_PlcNode
Attr Flags |= PWR_MASK_INVISIBLE
EndBody
EndObject
EndObject
Object GraphPlcNode $GraphPlcNode
Body SysBody
Attr object_type = 11
Attr parameters[0] = 1
Attr parameters[1] = 3
Attr parameters[2] = 1
Attr parameters[3] = 0
Attr subwindows = 0
Attr graphmethod = 1
Attr graphindex = 0
Attr default_mask[0] = 0
Attr default_mask[1] = 1
Attr segname_annotation = 1
Attr compmethod = 4
Attr compindex = 0
Attr tracemethod = 0
Attr traceindex = 0
Attr executeordermethod = 2
Attr objname = "Random"
Attr graphname = "Random"
EndBody
EndObject
Object Template Random
Body RtBody
Attr MaxValue = 100
EndBody
EndObject
EndObject
EndSObject
......@@ -15,6 +15,7 @@ topobjects NavigatorW1
class $Hier
class $Alias
class $MountObject
class $MountDynObject
class $MountVolume
class ProjectReg
class VolumeReg
......@@ -72,6 +73,7 @@ palette NavigatorPalette
class DsFastCurve
class DsTrend
class DsTrendCurve
class SevExport
class SevHist
class SevHistObject
menu CircularBuffer
......@@ -239,7 +241,8 @@ palette NavigatorPalette
class PlcPgm
class Backup
class $LibHier
class $Mountobject
class $MountObject
class $MountDynObject
class $Alias
}
menu Node
......@@ -268,6 +271,7 @@ palette NavigatorPalette
class SimulateConfig
class SevHistMonitor
class SevHistThread
class SevImportServer
class SevServer
class StatusServerConfig
class SysMonConfig
......@@ -772,6 +776,7 @@ palette PlcEditorPalette
class NotEqual
class PiSpeed
class Ramp
class Random
class Select
class ScanTime
class Speed
......
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