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
e431ce45
Commit
e431ce45
authored
Oct 27, 2011
by
Claes Sjofors
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Modbus TCP module with both read and write
parent
5672a400
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
180 additions
and
0 deletions
+180
-0
otherio/lib/rt/src/os_linux/rt_io_m_mb_modulereadwrite.c
otherio/lib/rt/src/os_linux/rt_io_m_mb_modulereadwrite.c
+180
-0
No files found.
otherio/lib/rt/src/os_linux/rt_io_m_mb_modulereadwrite.c
0 → 100644
View file @
e431ce45
/*
* 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.
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <math.h>
#include <sys/file.h>
#include <sys/ioctl.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <sys/types.h>
#include <unistd.h>
#include <sys/socket.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"
#include "rt_io_mb_locals.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_Modbus_ModuleReadWrite
*
op
;
int
i
;
op
=
(
pwr_sClass_Modbus_ModuleReadWrite
*
)
cp
->
op
;
local
=
(
io_sCardLocal
*
)
cp
->
Local
;
for
(
i
=
0
;
i
<
IO_MAXCHAN
;
i
++
)
{
local
->
msg
[
0
].
scancount
[
i
]
=
0
;
local
->
msg
[
1
].
scancount
[
i
]
=
0
;
}
op
->
Read
.
Status
=
pwr_eModbusModule_StatusEnum_StatusUnknown
;
op
->
Write
.
Status
=
pwr_eModbusModule_StatusEnum_StatusUnknown
;
return
IO__SUCCESS
;
}
/*----------------------------------------------------------------------------*\
Read method for the Pb module
\*----------------------------------------------------------------------------*/
static
pwr_tStatus
IoCardRead
(
io_tCtx
ctx
,
io_sAgent
*
ap
,
io_sRack
*
rp
,
io_sCard
*
cp
)
{
io_sCardLocal
*
local
;
pwr_sClass_Modbus_ModuleReadWrite
*
op
;
pwr_sClass_Modbus_TCP_Slave
*
slave
;
op
=
(
pwr_sClass_Modbus_ModuleReadWrite
*
)
cp
->
op
;
local
=
(
io_sCardLocal
*
)
cp
->
Local
;
slave
=
(
pwr_sClass_Modbus_TCP_Slave
*
)
rp
->
op
;
if
(
op
->
Read
.
ScanInterval
>
1
)
{
local
->
msg
[
0
].
has_read_method
=
1
;
if
(
local
->
msg
[
0
].
interval_cnt
!=
0
)
{
local
->
msg
[
0
].
interval_cnt
++
;
if
(
local
->
msg
[
0
].
interval_cnt
>=
op
->
Read
.
ScanInterval
)
local
->
msg
[
0
].
interval_cnt
=
0
;
return
IO__SUCCESS
;
}
local
->
msg
[
0
].
interval_cnt
++
;
}
if
(
slave
->
Status
==
MB__NORMAL
)
{
io_bus_card_read
(
ctx
,
rp
,
cp
,
slave
->
Inputs
,
NULL
,
pwr_eByteOrderingEnum_BigEndian
,
pwr_eFloatRepEnum_FloatIntel
);
}
return
IO__SUCCESS
;
}
/*----------------------------------------------------------------------------*\
Write method for the Pb module
\*----------------------------------------------------------------------------*/
static
pwr_tStatus
IoCardWrite
(
io_tCtx
ctx
,
io_sAgent
*
ap
,
io_sRack
*
rp
,
io_sCard
*
cp
)
{
io_sCardLocal
*
local
;
pwr_sClass_Modbus_ModuleReadWrite
*
op
;
pwr_sClass_Modbus_TCP_Slave
*
slave
;
op
=
(
pwr_sClass_Modbus_ModuleReadWrite
*
)
cp
->
op
;
local
=
(
io_sCardLocal
*
)
cp
->
Local
;
slave
=
(
pwr_sClass_Modbus_TCP_Slave
*
)
rp
->
op
;
if
(
op
->
Write
.
ScanInterval
>
1
)
{
if
(
!
local
->
msg
[
1
].
has_read_method
)
{
if
(
local
->
msg
[
1
].
interval_cnt
!=
0
)
{
local
->
msg
[
1
].
interval_cnt
++
;
if
(
local
->
msg
[
1
].
interval_cnt
>=
op
->
Write
.
ScanInterval
)
local
->
msg
[
1
].
interval_cnt
=
0
;
return
IO__SUCCESS
;
}
local
->
msg
[
1
].
interval_cnt
++
;
}
else
if
(
local
->
msg
[
1
].
interval_cnt
!=
1
)
return
IO__SUCCESS
;
}
if
(
slave
->
Status
==
MB__NORMAL
)
{
io_bus_card_write
(
ctx
,
cp
,
slave
->
Outputs
,
pwr_eByteOrderingEnum_BigEndian
,
pwr_eFloatRepEnum_FloatIntel
);
}
// printf("Method Modbus_Module-IoCardWrite\n");
return
IO__SUCCESS
;
}
/*----------------------------------------------------------------------------*\
Every method to be exported to the workbench should be registred here.
\*----------------------------------------------------------------------------*/
pwr_dExport
pwr_BindIoMethods
(
Modbus_ModuleReadWrite
)
=
{
pwr_BindIoMethod
(
IoCardInit
),
pwr_BindIoMethod
(
IoCardRead
),
pwr_BindIoMethod
(
IoCardWrite
),
pwr_NullMethod
};
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