Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
U
uniset2
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
1
Issues
1
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
UniSet project repositories
uniset2
Commits
4fc054de
Commit
4fc054de
authored
Mar 29, 2015
by
Pavel Vainerman
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
(java): добился передачи сообщения об ошибке в java исключениях, доделал тестик UModbus
parent
24c33135
Hide whitespace changes
Inline
Side-by-side
Showing
17 changed files
with
181 additions
and
164 deletions
+181
-164
uniset2.files
uniset2.files
+33
-18
uniset2.includes
uniset2.includes
+3
-3
JUInterface.cc
wrappers/java/JUInterface.cc
+4
-4
JUInterface.h
wrappers/java/JUInterface.h
+4
-4
Makefile.am
wrappers/java/Makefile.am
+11
-8
UConnector.cc
wrappers/java/UConnector.cc
+4
-4
UConnector.h
wrappers/java/UConnector.h
+4
-4
UConnector.i
wrappers/java/UConnector.i
+3
-2
UExceptions.h
wrappers/java/UExceptions.h
+3
-3
UExceptions.i
wrappers/java/UExceptions.i
+19
-54
UInterface.i
wrappers/java/UInterface.i
+5
-3
UModbus.cc
wrappers/java/UModbus.cc
+41
-42
UModbus.h
wrappers/java/UModbus.h
+11
-10
UModbus.i
wrappers/java/UModbus.i
+4
-2
UTypes.h
wrappers/java/UTypes.h
+3
-3
mk.sh
wrappers/java/mk.sh
+4
-0
runme_modbus.java
wrappers/java/runme_modbus.java
+25
-0
No files found.
uniset2.files
View file @
4fc054de
...
...
@@ -668,24 +668,39 @@ include/UniXML.h
include/UTCPStream.h
include/WDTInterface.h
lib/Makefile.am
python/examples/test.xml
python/lib/pyUniSet/Makefile.am
python/lib/pyUniSet/PyUInterface.cc
python/lib/pyUniSet/PyUInterface.h
python/lib/pyUniSet/UConnector.cc
python/lib/pyUniSet/UConnector.h
python/lib/pyUniSet/UConnector_wrap.cxx
python/lib/pyUniSet/UExceptions.h
python/lib/pyUniSet/UExceptions_wrap.cxx
python/lib/pyUniSet/UInterface_wrap.cxx
python/lib/pyUniSet/UModbus.cc
python/lib/pyUniSet/UModbus.h
python/lib/pyUniSet/UModbus_wrap.cxx
python/lib/pyUniSet/UTypes.h
python/lib/Makefile.am
python/tests/UConnector/test.xml
python/tests/UInterface/test.xml
python/Makefile.am
wrappers/python/examples/test.xml
wrappers/python/lib/pyUniSet/Makefile.am
wrappers/python/lib/pyUniSet/PyUInterface.cc
wrappers/python/lib/pyUniSet/PyUInterface.h
wrappers/python/lib/pyUniSet/UConnector.cc
wrappers/python/lib/pyUniSet/UConnector.h
wrappers/python/lib/pyUniSet/UConnector_wrap.cxx
wrappers/python/lib/pyUniSet/UExceptions.h
wrappers/python/lib/pyUniSet/UExceptions_wrap.cxx
wrappers/python/lib/pyUniSet/UInterface_wrap.cxx
wrappers/python/lib/pyUniSet/UModbus.cc
wrappers/python/lib/pyUniSet/UModbus.h
wrappers/python/lib/pyUniSet/UModbus_wrap.cxx
wrappers/python/lib/pyUniSet/UTypes.h
wrappers/python/lib/Makefile.am
wrappers/python/tests/UConnector/test.xml
wrappers/python/tests/UInterface/test.xml
wrappers/python/Makefile.am
wrappers/java/Makefile.am
wrappers/java/JUInterface.cc
wrappers/java/JUInterface.h
wrappers/java/Makefile.am
wrappers/java/runme_modbus.java
wrappers/java/UConnector.cc
wrappers/java/UConnector.h
wrappers/java/UConnector.i
wrappers/java/UExceptions.h
wrappers/java/UExceptions.i
wrappers/java/UInterface.i
wrappers/java/UModbus.cc
wrappers/java/UModbus.h
wrappers/java/UModbus.i
wrappers/java/UTypes.h
src/Communications/Modbus/Makefile.am
src/Communications/Modbus/ModbusClient.cc
src/Communications/Modbus/ModbusHelpers.cc
...
...
uniset2.includes
View file @
4fc054de
...
...
@@ -17,9 +17,10 @@ extensions/UNetUDP
extensions/UniNetwork
include
include/modbus
python/lib/pyUniSet
wrappers/python/lib/pyUniSet
wrappers/java
src/Log
Utilities/codegen
Utilities/codegen/tests
Utilities/MBTester
Utilities/NullController
\ No newline at end of file
Utilities/NullController
wrappers/java/JUInterface.cc
View file @
4fc054de
...
...
@@ -10,13 +10,13 @@ using namespace std;
//---------------------------------------------------------------------------
static
UInterface
*
ui
=
0
;
//---------------------------------------------------------------------------
void
JUInterface
::
uniset_init_params
(
UTypes
::
Params
*
p
,
const
char
*
xmlfile
)
throw
(
UException
)
void
JUInterface
::
uniset_init_params
(
UTypes
::
Params
*
p
,
const
char
*
xmlfile
)
{
JUInterface
::
uniset_init
(
p
->
argc
,
p
->
argv
,
xmlfile
);
}
//---------------------------------------------------------------------------
void
JUInterface
::
uniset_init
(
int
argc
,
char
*
argv
[],
const
char
*
xmlfile
)
throw
(
UException
)
void
JUInterface
::
uniset_init
(
int
argc
,
char
*
argv
[],
const
char
*
xmlfile
)
{
try
{
...
...
@@ -34,7 +34,7 @@ void JUInterface::uniset_init( int argc, char* argv[], const char* xmlfile )thro
}
}
//---------------------------------------------------------------------------
long
JUInterface
::
getValue
(
long
id
)
throw
(
UException
)
long
JUInterface
::
getValue
(
long
id
)
{
auto
conf
=
UniSetTypes
::
uniset_conf
();
if
(
!
conf
||
!
ui
)
...
...
@@ -76,7 +76,7 @@ long JUInterface::getValue( long id )throw(UException)
throw
UException
(
"(getValue): unknown error"
);
}
//---------------------------------------------------------------------------
void
JUInterface
::
setValue
(
long
id
,
long
val
)
throw
(
UException
)
void
JUInterface
::
setValue
(
long
id
,
long
val
)
{
auto
conf
=
UniSetTypes
::
uniset_conf
();
...
...
wrappers/java/JUInterface.h
View file @
4fc054de
...
...
@@ -7,12 +7,12 @@
// --------------------------------------------------------------------------
namespace
JUInterface
{
void
uniset_init_params
(
UTypes
::
Params
*
p
,
const
char
*
xmlfile
)
throw
(
UException
)
;
void
uniset_init
(
int
argc
,
char
**
argv
,
const
char
*
xmlfile
)
throw
(
UException
)
;
void
uniset_init_params
(
UTypes
::
Params
*
p
,
const
char
*
xmlfile
);
void
uniset_init
(
int
argc
,
char
**
argv
,
const
char
*
xmlfile
);
//---------------------------------------------------------------------------
long
getValue
(
long
id
)
throw
(
UException
)
;
void
setValue
(
long
id
,
long
val
)
throw
(
UException
)
;
long
getValue
(
long
id
);
void
setValue
(
long
id
,
long
val
);
long
getSensorID
(
const
char
*
);
...
...
wrappers/java/Makefile.am
View file @
4fc054de
...
...
@@ -2,11 +2,12 @@ if DISABLE_JAVA
else
JAVA_CFLAGS
=
-I
/usr/lib/jdk/include
-I
/usr/lib/jdk/include/linux
JAVA_LIBS
=
#python_SCRIPTS = pyUniSet.java pyUConnector.java pyUModbus.java pyUExceptions.java
jUniSet.java
:
UInterface_wrap.cxx _jU
niSet
.la
jUniSet.java
:
UInterface_wrap.cxx _jU
Interface
.la
jUConnector.java
:
UConnector_wrap.cxx _jUConnector.la
...
...
@@ -18,12 +19,12 @@ jUModbus.java: _jUModbus.la UModbus_wrap.cxx
jUExceptions.java
:
_jUExceptions.la
lib_LTLIBRARIES
=
_jUConnector.la _jUModbus.la _jUExceptions.la _jU
niSet
.la
lib_LTLIBRARIES
=
_jUConnector.la _jUModbus.la _jUExceptions.la _jU
Interface
.la
_jU
niSet
_la_SOURCES
=
JUInterface.cc UInterface_wrap.cxx
_jU
niSet
_la_CXXFLAGS
=
$(UNISET_CFLAGS)
$(JAVA_CFLAGS)
_jU
niSet
_la_LDFLAGS
=
-module
-avoid-version
_jU
niSet
_la_LIBADD
=
$(UNISET_LIBS)
$(JAVA_LIBS)
_jU
Interface
_la_SOURCES
=
JUInterface.cc UInterface_wrap.cxx
_jU
Interface
_la_CXXFLAGS
=
$(UNISET_CFLAGS)
$(JAVA_CFLAGS)
_jU
Interface
_la_LDFLAGS
=
-module
-avoid-version
_jU
Interface
_la_LIBADD
=
$(UNISET_LIBS)
$(JAVA_LIBS)
UInterface_wrap.cxx
:
UInterface.i JUInterface.h
swig
-java
-c
++ UInterface.i
...
...
@@ -41,7 +42,7 @@ _jUModbus_la_CXXFLAGS = $(UNISET_CFLAGS) $(UNISET_EXT_CFLAGS) $(COMCPP_CFLAGS) $
_jUModbus_la_LDFLAGS
=
-module
-avoid-version
_jUModbus_la_LIBADD
=
$(UNISET_LIBS)
$(UNISET_EXT_LIBS)
$(COMCPP_LIBS)
$(JAVA_LIBS)
UModbus_wrap.cxx
:
UInterface.i UModbus.h
UModbus_wrap.cxx
:
UInterface.i UModbus.h
UModbus.i
swig
-java
-c
++ UModbus.i
_jUExceptions_la_SOURCES
=
UExceptions_wrap.cxx
...
...
@@ -53,6 +54,8 @@ UExceptions_wrap.cxx: UExceptions.i UExceptions.h
swig
-java
-c
++ UExceptions.i
clean-local
:
rm
-rf
*
.java
*
*
_wrap.cxx
*
.class
rm
-rf
*
_wrap.cxx
*
.class
rm
-rf
`
ls
*
.java |
$(GREP)
-v
runme
*
`
endif
wrappers/java/UConnector.cc
View file @
4fc054de
...
...
@@ -3,7 +3,7 @@
// --------------------------------------------------------------------------
using
namespace
std
;
// --------------------------------------------------------------------------
UConnector
::
UConnector
(
UTypes
::
Params
*
p
,
const
char
*
xfile
)
throw
(
UException
)
:
UConnector
::
UConnector
(
UTypes
::
Params
*
p
,
const
char
*
xfile
)
:
conf
(
0
),
ui
(
0
),
xmlfile
(
xfile
)
...
...
@@ -23,7 +23,7 @@ xmlfile(xfile)
}
}
//---------------------------------------------------------------------------
UConnector
::
UConnector
(
int
argc
,
char
**
argv
,
const
char
*
xfile
)
throw
(
UException
)
:
UConnector
::
UConnector
(
int
argc
,
char
**
argv
,
const
char
*
xfile
)
:
conf
(
0
),
ui
(
0
),
xmlfile
(
xfile
)
...
...
@@ -57,7 +57,7 @@ const char* UConnector::getConfFileName()
}
// --------------------------------------------------------------------------
long
UConnector
::
getValue
(
long
id
,
long
node
)
throw
(
UException
)
long
UConnector
::
getValue
(
long
id
,
long
node
)
{
if
(
!
conf
||
!
ui
)
throw
USysError
();
...
...
@@ -81,7 +81,7 @@ long UConnector::getValue( long id, long node )throw(UException)
throw
UException
(
"(getValue): unknown error"
);
}
//---------------------------------------------------------------------------
void
UConnector
::
setValue
(
long
id
,
long
val
,
long
node
)
throw
(
UException
)
void
UConnector
::
setValue
(
long
id
,
long
val
,
long
node
)
{
if
(
!
conf
||
!
ui
)
throw
USysError
();
...
...
wrappers/java/UConnector.h
View file @
4fc054de
...
...
@@ -11,15 +11,15 @@
class
UConnector
{
public
:
UConnector
(
int
argc
,
char
**
argv
,
const
char
*
xmlfile
)
throw
(
UException
)
;
UConnector
(
UTypes
::
Params
*
p
,
const
char
*
xmlfile
)
throw
(
UException
)
;
UConnector
(
int
argc
,
char
**
argv
,
const
char
*
xmlfile
);
UConnector
(
UTypes
::
Params
*
p
,
const
char
*
xmlfile
);
~
UConnector
();
inline
const
char
*
getUIType
(){
return
"uniset"
;
}
const
char
*
getConfFileName
();
long
getValue
(
long
id
,
long
node
)
throw
(
UException
)
;
void
setValue
(
long
id
,
long
val
,
long
node
)
throw
(
UException
)
;
long
getValue
(
long
id
,
long
node
);
void
setValue
(
long
id
,
long
val
,
long
node
);
long
getSensorID
(
const
char
*
);
long
getNodeID
(
const
char
*
);
...
...
wrappers/java/UConnector.i
View file @
4fc054de
...
...
@@ -4,6 +4,8 @@
%}
%include "UTypes.h"
%include UExceptions.i
%include "UConnector.h"
%pragma(java) jniclasscode=%{
...
...
@@ -15,4 +17,4 @@
System.exit(1);
}
}
%}
\ No newline at end of file
%}
wrappers/java/UExceptions.h
View file @
4fc054de
...
...
@@ -3,8 +3,8 @@
// --------------------------------------------------------------------------
#include <string>
// --------------------------------------------------------------------------
struct
UException
:
public
std
::
exception
struct
UException
// :
public std::exception
{
UException
(){}
UException
(
const
std
::
string
&
e
)
:
err
(
e
){}
...
...
@@ -12,7 +12,7 @@ struct UException:
virtual
~
UException
()
noexcept
{}
const
char
*
getError
(){
return
err
.
c_str
();
}
virtual
const
char
*
what
()
const
noexcept
{
return
err
.
c_str
();
}
//
virtual const char* what() const noexcept { return err.c_str(); }
std
::
string
err
;
};
...
...
wrappers/java/UExceptions.i
View file @
4fc054de
...
...
@@ -4,6 +4,25 @@
%}
%include "UExceptions.h"
%exception {
try {
$action
}
catch( const UException& e ) {
SWIG_JavaThrowException(jenv, SWIG_JavaRuntimeException, e.err.c_str());
}
catch (const std::exception & e)
{
SWIG_JavaThrowException(jenv, SWIG_JavaRuntimeException,std::string(std::string("C++ std::exception: ") + e.what()).c_str());
}
catch (...)
{
SWIG_JavaThrowException(jenv, SWIG_JavaRuntimeException,"C++ anonymous exception");
}
};
/*
%pragma(java) jniclasscode=%{
static {
...
...
@@ -16,56 +35,3 @@
}
%}
*/
/*
// Allow C++ exceptions to be handled in Java
%typemap(throws, throws="java.io.IOException") CustomException {
jclass excep = jenv->FindClass("java/io/IOException");
if (excep)
jenv->ThrowNew(excep, $1.what());
return $null;
}
// Force the CustomException Java class to extend java.lang.Exception
%typemap(javabase) CustomException "java.lang.Exception";
// Override getMessage()
%typemap(javacode) CustomException %{
public String getMessage() {
return what();
}
%}
*/
/*
%define WRAP_THROW_EXCEPTION( MATCH, CPPTYPE, JTYPE, JNITYPE )
%javaexception(JTYPE) MATCH {
try {
$action
}
catch ( CPPTYPE & e ) {
jclass eclass = jenv->FindClass(JNITYPE);
if ( eclass ) {
jenv->ThrowNew( eclass, e.what() );
}
}
}
%enddef
// Override getMessage()
%typemap(javacode) UException %{
public String getMessage() {
return getError();
}
%}
%typemap(javacode) UTimeout %{
public String getMessage() {
return getError();
}
%}
WRAP_THROW_EXCEPTION( UModbus::prepare, UTimeOut,"java/lang/Exception","java/lang/Exception");
WRAP_THROW_EXCEPTION( UModbus::mbread, UException,"java/lang/Exception","java/lang/Exception");
WRAP_THROW_EXCEPTION( UModbus::getWord, UException,"java/lang/Exception","java/lang/Exception");
*/
\ No newline at end of file
wrappers/java/UInterface.i
View file @
4fc054de
%module
UniSet
%module
mUInterface
%{
#include "JUInterface.h"
%}
%include "JUInterface.h"
%include "UTypes.h"
%include "UExceptions.h"
%include UExceptions.i
%include "JUInterface.h"
%pragma(java) jniclasscode=%{
static {
try {
System.loadLibrary("
UniSet
");
System.loadLibrary("
mUInterface
");
} catch (UnsatisfiedLinkError e) {
System.err.println("Native code library failed to load. \n" + e);
System.exit(1);
...
...
wrappers/java/UModbus.cc
View file @
4fc054de
#include <ostream>
#include <cmath>
#include <jni.h>
#include "UModbus.h"
// --------------------------------------------------------------------------
using
namespace
std
;
// --------------------------------------------------------------------------
#if 0
UModbus::UModbus( UTypes::Params* p )throw(UException):
mb(0),
port(502),
ip(""),
tout_msec(5000)
{
try
{
mb = new ModbusTCPMaster();
}
catch(...)
{
throw UException();
}
}
//---------------------------------------------------------------------------
UModbus::UModbus( int argc, char** argv )throw(UException):
mb(0),
port(502),
ip(""),
tout_msec(5000)
{
try
{
mb = new ModbusTCPMaster();
}
catch(...)
{
throw UException();
}
}
#endif
// --------------------------------------------------------------------------
UModbus
::
UModbus
()
:
mb
(
0
),
port
(
502
),
...
...
@@ -52,7 +19,7 @@ UModbus::~UModbus()
delete
mb
;
}
// --------------------------------------------------------------------------
void
UModbus
::
prepare
(
const
char
*
_ip
,
int
_port
)
throw
(
UException
)
void
UModbus
::
prepare
(
const
char
*
_ip
,
int
_port
)
{
if
(
!
mb
)
throw
UException
(
"(connect): mb=NULL?!"
);
...
...
@@ -72,7 +39,7 @@ void UModbus::prepare( const char* _ip, int _port )throw(UException)
port
=
_port
;
}
// --------------------------------------------------------------------------
void
UModbus
::
connect
(
const
char
*
_ip
,
int
_port
)
throw
(
UException
)
void
UModbus
::
connect
(
const
char
*
_ip
,
int
_port
)
{
if
(
!
mb
)
throw
UException
(
"(connect): mb=NULL?!"
);
...
...
@@ -108,23 +75,23 @@ void UModbus::connect( const char* _ip, int _port )throw(UException)
}
}
// --------------------------------------------------------------------------
long
UModbus
::
getWord
(
int
addr
,
int
mbreg
,
int
mbfunc
)
throw
(
UException
)
long
UModbus
::
getWord
(
int
addr
,
int
mbreg
,
int
mbfunc
)
{
return
mbread
(
addr
,
mbreg
,
mbfunc
,
"signed"
);
}
// --------------------------------------------------------------------------
long
UModbus
::
getByte
(
int
addr
,
int
mbreg
,
int
mbfunc
)
throw
(
UException
)
long
UModbus
::
getByte
(
int
addr
,
int
mbreg
,
int
mbfunc
)
{
return
mbread
(
addr
,
mbreg
,
mbfunc
,
"byte"
);
}
// --------------------------------------------------------------------------
bool
UModbus
::
getBit
(
int
addr
,
int
mbreg
,
int
mbfunc
)
throw
(
UException
)
bool
UModbus
::
getBit
(
int
addr
,
int
mbreg
,
int
mbfunc
)
{
return
mbread
(
addr
,
mbreg
,
mbfunc
,
"unsigned"
);
}
// --------------------------------------------------------------------------
long
UModbus
::
mbread
(
int
mbaddr
,
int
mbreg
,
int
mbfunc
,
const
char
*
s_vtype
,
int
nbit
,
const
char
*
new_ip
,
int
new_port
)
throw
(
UException
)
const
char
*
new_ip
,
int
new_port
)
{
using
namespace
VTypes
;
...
...
@@ -202,6 +169,13 @@ long UModbus::mbread( int mbaddr, int mbreg, int mbfunc, const char* s_vtype, in
}
catch
(
ModbusRTU
::
mbException
&
ex
)
{
// jclass eclass = JNIEnv.FindClass("java/lang/IOException");
// jclass eclass = env->FindClass("java/lang/IOException");
// if ( eclass ) {
// JNIEnv->ThrowNew( eclass, ex.what() );
// }
if
(
ex
.
err
!=
ModbusRTU
::
erTimeOut
)
throw
UTimeOut
();
...
...
@@ -209,6 +183,12 @@ long UModbus::mbread( int mbaddr, int mbreg, int mbfunc, const char* s_vtype, in
err
<<
ex
;
throw
UException
(
err
.
str
());
}
catch
(
const
std
::
exception
&
ex
)
{
std
::
ostringstream
err
;
err
<<
ex
.
what
();
throw
UException
(
err
.
str
());
}
catch
(...)
{
throw
UException
(
"(mbread): catch..."
);
...
...
@@ -279,8 +259,15 @@ long UModbus::data2value( VTypes::VType vtype, ModbusRTU::ModbusData* data )
return
0
;
}
//---------------------------------------------------------------------------
void
UModbus
::
mbwrite
(
int
mbaddr
,
int
mbreg
,
int
val
,
int
mbfunc
,
const
char
*
new_ip
,
int
new_port
)
throw
(
UException
)
bool
UModbus
::
setWord
(
int
addr
,
int
mbreg
,
int
val
,
int
mbfunc
)
{
return
mbwrite
(
addr
,
mbreg
,
val
,
mbfunc
,
0
,
0
);
}
//---------------------------------------------------------------------------
bool
UModbus
::
mbwrite
(
int
mbaddr
,
int
mbreg
,
int
val
,
int
mbfunc
,
const
char
*
new_ip
,
int
new_port
)
{
// ost::Thread::setException(ost::Thread::throwException);
const
char
*
n_ip
=
(
new_ip
!=
0
)
?
new_ip
:
ip
.
c_str
();
int
n_port
=
(
new_port
>
0
)
?
new_port
:
port
;
...
...
@@ -293,6 +280,7 @@ void UModbus::mbwrite( int mbaddr, int mbreg, int val, int mbfunc, const char* n
case
ModbusRTU
:
:
fnWriteOutputSingleRegister
:
{
ModbusRTU
::
WriteSingleOutputRetMessage
ret
=
mb
->
write06
(
mbaddr
,
mbreg
,
val
);
return
(
ret
.
start
==
mbreg
&&
ret
.
data
==
val
);
}
break
;
...
...
@@ -301,12 +289,14 @@ void UModbus::mbwrite( int mbaddr, int mbreg, int val, int mbfunc, const char* n
ModbusRTU
::
WriteOutputMessage
msg
(
mbaddr
,
mbreg
);
msg
.
addData
(
val
);
ModbusRTU
::
WriteOutputRetMessage
ret
=
mb
->
write10
(
msg
);
return
(
ret
.
start
==
mbreg
&&
ret
.
quant
==
1
);
}
break
;
case
ModbusRTU
:
:
fnForceSingleCoil
:
{
ModbusRTU
::
ForceSingleCoilRetMessage
ret
=
mb
->
write05
(
mbaddr
,
mbreg
,
val
);
return
(
ret
.
start
==
mbreg
&&
ret
.
data
==
val
);
}
break
;
...
...
@@ -315,6 +305,7 @@ void UModbus::mbwrite( int mbaddr, int mbreg, int val, int mbfunc, const char* n
ModbusRTU
::
ForceCoilsMessage
msg
(
mbaddr
,
mbreg
);
msg
.
addBit
(
(
val
?
true
:
false
)
);
ModbusRTU
::
ForceCoilsRetMessage
ret
=
mb
->
write0F
(
msg
);
return
(
ret
.
start
==
mbreg
&&
ret
.
quant
==
1
);
}
break
;
...
...
@@ -327,7 +318,7 @@ void UModbus::mbwrite( int mbaddr, int mbreg, int val, int mbfunc, const char* n
break
;
}
}
catch
(
ModbusRTU
::
mbException
&
ex
)
catch
(
const
ModbusRTU
::
mbException
&
ex
)
{
if
(
ex
.
err
!=
ModbusRTU
::
erTimeOut
)
throw
UTimeOut
();
...
...
@@ -336,9 +327,17 @@ void UModbus::mbwrite( int mbaddr, int mbreg, int val, int mbfunc, const char* n
err
<<
ex
;
throw
UException
(
err
.
str
());
}
catch
(
const
std
::
exception
&
ex
)
{
std
::
ostringstream
err
;
err
<<
ex
.
what
();
throw
UException
(
err
.
str
());
}
catch
(...)
{
throw
UException
(
"(mbwrite): catch..."
);
}
return
false
;
}
//---------------------------------------------------------------------------
wrappers/java/UModbus.h
View file @
4fc054de
...
...
@@ -13,8 +13,6 @@
class
UModbus
{
public
:
// UModbus( int argc, char** argv )throw(UException);
// UModbus( UTypes::Params* p )throw(UException);
UModbus
();
~
UModbus
();
...
...
@@ -23,9 +21,9 @@ class UModbus
inline
bool
isWriteFunction
(
int
mbfunc
){
return
ModbusRTU
::
isWriteFunction
((
ModbusRTU
::
SlaveFunctionCode
)
mbfunc
);
}
// выставление паметров связи, без установления соединения (!)
void
prepare
(
const
char
*
ip
,
int
port
)
throw
(
UException
)
;
void
prepare
(
const
char
*
ip
,
int
port
);
void
connect
(
const
char
*
ip
,
int
port
)
throw
(
UException
)
;
void
connect
(
const
char
*
ip
,
int
port
);
inline
int
conn_port
(){
return
port
;
}
inline
std
::
string
conn_ip
(){
return
ip
;
}
inline
bool
isConnection
(){
return
(
mb
&&
mb
->
isConnection
());
}
...
...
@@ -39,18 +37,21 @@ class UModbus
*/
long
mbread
(
int
addr
,
int
mbreg
,
int
mbfunc
,
const
char
*
vtype
,
int
nbit
=-
1
,
const
char
*
ip
=
0
,
int
port
=-
1
)
throw
(
UException
)
;
const
char
*
ip
=
0
,
int
port
=-
1
);
long
getWord
(
int
addr
,
int
mbreg
,
int
mbfunc
=
0x4
)
throw
(
UException
)
;
long
getByte
(
int
addr
,
int
mbreg
,
int
mbfunc
=
0x4
)
throw
(
UException
)
;
bool
getBit
(
int
addr
,
int
mbreg
,
int
mbfunc
=
0x2
)
throw
(
UException
)
;
long
getWord
(
int
addr
,
int
mbreg
,
int
mbfunc
=
0x4
);
long
getByte
(
int
addr
,
int
mbreg
,
int
mbfunc
=
0x4
);
bool
getBit
(
int
addr
,
int
mbreg
,
int
mbfunc
=
0x2
);
/*! Функция записи регистров 0x06 или 0x10 задаётся параметром \a mbfunc.
* Если не указывать ip и порт, будут использованы, те
* чтобы были заданы в UModbus::connect(). Если заданы другие ip и port,
* будет сделана переподключение..
* \return TRUE - если получен положительный ответ
*/
void
mbwrite
(
int
addr
,
int
mbreg
,
int
val
,
int
mbfunc
,
const
char
*
ip
=
0
,
int
port
=-
1
)
throw
(
UException
);
bool
mbwrite
(
int
addr
,
int
mbreg
,
int
val
,
int
mbfunc
=
0x6
,
const
char
*
ip
=
0
,
int
port
=-
1
);
bool
setWord
(
int
addr
,
int
mbreg
,
int
val
,
int
mbfunc
=
0x6
);
protected
:
long
data2value
(
VTypes
::
VType
vt
,
ModbusRTU
::
ModbusData
*
data
);
...
...
@@ -59,7 +60,7 @@ class UModbus
// DebugStream dlog;
ModbusTCPMaster
*
mb
;
int
port
;
string
ip
;
st
d
::
st
ring
ip
;
int
tout_msec
;
};
//---------------------------------------------------------------------------
...
...
wrappers/java/UModbus.i
View file @
4fc054de
...
...
@@ -7,7 +7,7 @@
%pragma(java) jniclasscode=%{
static {
try {
System.loadLibrary("
.libs/_jUModbus.so
");
System.loadLibrary("
mUModbus
");
} catch (UnsatisfiedLinkError e) {
System.err.println("Native code library failed to load. \n" + e);
System.exit(1);
...
...
@@ -16,6 +16,8 @@
%}
*/
%include "UModbus.h"
%include "UTypes.h"
%include "UExceptions.h"
%include UExceptions.i
%include "UModbus.h"
wrappers/java/UTypes.h
View file @
4fc054de
...
...
@@ -9,13 +9,13 @@ namespace UTypes
struct
Params
{
static
const
int
max
=
20
;
static
const
int
max
num
=
20
;
Params
()
:
argc
(
0
){
memset
(
argv
,
0
,
sizeof
(
argv
));
}
bool
add
(
char
*
s
)
{
if
(
argc
<
Params
::
max
)
if
(
argc
<
Params
::
max
num
)
{
argv
[
argc
++
]
=
s
;
return
true
;
...
...
@@ -24,7 +24,7 @@ namespace UTypes
}
int
argc
;
char
*
argv
[
max
];
char
*
argv
[
max
num
];
static
Params
inst
(){
return
Params
();
}
};
...
...
wrappers/java/mk.sh
0 → 100755
View file @
4fc054de
#!/bin/sh
javac runme_modbus.java
&&
java runme_modbus
\ No newline at end of file
wrappers/java/runme_modbus.java
0 → 100644
View file @
4fc054de
public
class
runme_modbus
{
public
static
void
main
(
String
argv
[])
{
System
.
load
(
"/home/pv/Projects/uniset-2.0/wrappers/java/.libs/_jUModbus.so"
);
System
.
load
(
"/home/pv/Projects/uniset-2.0/wrappers/java/.libs/_jUExceptions.so"
);
UModbus
u
=
new
UModbus
();
u
.
connect
(
"localhost"
,
2048
);
for
(
int
i
=
0
;
i
<
10
;
i
++
)
{
try
{
System
.
out
.
println
(
"read..32="
+
u
.
getWord
(
1
,
32
));
System
.
out
.
println
(
"write 40=4 "
+
(
u
.
setWord
(
1
,
40
,
4
)
?
"ok"
:
"failed"
)
);
}
catch
(
Exception
e
)
{
System
.
err
.
println
(
e
.
getMessage
());
}
}
}
}
\ No newline at end of file
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