Main siteMain site  ForumForum  ForumSearch  Private messageEmail contact  RegisterRegister  Log inLog in 
Topic: Custom Element
Reply to topic
Author Message
EMebane



Joined: Apr 15, 2019
Posts: 86

PostPosted: May 2, 2020 9:32 PM    Post subject: Custom Element

I'm trying to write a custom element. I'm working with the sample from the manual.

I realized that the sample only implements the Scalar type. Is that correct?

The docs say, "Note 2: To compile you need to use the same java version BioEra uses. BioEra version 3.xxx uses java 1.6.". I don't know what version of Java is appropriate.
I am using javac 1.8.0_212-release

BioEra 4.132

I modified the Test class as described in the manual with a few changes to the logging so that I can verify that I'm seeing my class not the default ExternalElement.

I also made a few other changes in preparation for testing the float input type.

I closed BioEra, recompiled the Java file, and ran BioEra with the -console flag.

The custom element is removed from my design and I see this console error:

D:\Software\BioEra\BioEraPro>bioera.exe -console
***************** BioEra 4.132 is started *****************
Loading design: D:\Software\BioEra\Designs\EM\HRV\Test2.bpd on Windows
Element 'Custom element' (class bE) initElement() error: java.lang.UnsupportedClassVersionError: Test : Unsupported major.minor version 52.0
Error drawing icon image of element Custom element(41)
java.lang.ArrayIndexOutOfBoundsException: 0
at d.s(src:358)
at lP.j(src:114)
at dD.h(src:310)
at cH.a(src:313)
at cH.b(src:302)
at RR.a(src:707)
at DY.e(src:617)
at m.b(src:1165)
at m.S(src:880)
at m.U(src:1385)
at m.a(src:591)
at m.a(src:715)
at com.proatech.bioera.BioEraApp.main(src:95)
Error drawing icon image of element Custom element(41)
java.lang.ArrayIndexOutOfBoundsException: 0
at d.s(src:358)
at lP.j(src:114)
at dD.h(src:310)
at bd.c(src:151)
at cH.b(src:232)
at QQ.b(src:691)
at QQ.o(src:796)
at m.G(src:1258)
at m.a(src:628)
at m.a(src:715)
at com.proatech.bioera.BioEraApp.main(src:95)
jarek



Joined: Oct 22, 2007
Posts: 789

PostPosted: May 3, 2020 9:02 AM    Post subject:

CustomElement does support float (and double) data, but only for single values, not vectors.

The error 'UnsupportedClassVersionError' means you need to compile with the same java version (as you suspected). So either download jdk1.6 and compile with it, or start BioEra with -jre8 command line option: http://proatech.com/be/architecture.html

It may also be possible to use ExpressionEvaluator instead of CustomElement. And access external (or yours) libraries put under 'ext' folder in this file: extlibs.jar
EMebane



Joined: Apr 15, 2019
Posts: 86

PostPosted: May 3, 2020 4:23 PM    Post subject:

Launching with -jre8 works. The test component I compiled with my version of Java runs. I also noticed the startup.cfg instructions in the architecture docs and I've edited it to include -jre8 and -console. This could be a workflow that would work for me.

Would you clarify what you mean by this, "And access external (or yours) libraries put under 'ext' folder in this file: extlibs.jar"? Do you just mean putting my .jar files in the \ext folder, or is there a requirement to use the extlibs.jar filename?

Also, are you suggesting that a .jar file containing Java 1.8 compiled classes would work with BioEra running Java 1.6?

I tried compiling the Custom Element with Java 1.6 using the -target flag and got the following error:
D:\Software\BioEra\BioEraPro\impl>javac -target 1.6 *.java
javac: target release 1.6 conflicts with default source release 1.8

Should that work, or do I need to actually have the JDK for 1.6 installed? I figured the -target flag allows the newer compiler to compile backwards-compatible versions. Maybe not -- maybe you still need the old JDK for the -target flag to work.

I initially was exploring the ExpressionEvaluator and having some success, but I'd like to be able to make actual elements.

With ExpressionEvaluator, can you use public members and set them with a PropertySetter?

Is there a way of making new un-attached input nubs appear on a Custom Element the way an extra nub is added to some native Elements like Polygraph so that a variable number of inputs may be attached?

How do I make make a custom Element take float inputs? Is it determined by the pipe type I select when creating a new instance of the Custom Element? I notice the processInputData and processOutputData overloaded methods accept int/float/double arrays (and return ints). Does the class use whichever overloaded method aligns with the pipe type that was selected?

Regarding vector inputs, does this mean that when I'm working with custom elements I can't send around collections? Only int/float/doubles? Is there a recommended workflow regarding this? Perhaps I'll have to use nested designs if I want to send arrays/vectors.
jarek



Joined: Oct 22, 2007
Posts: 789

PostPosted: May 3, 2020 4:49 PM    Post subject:

CustomElement has only single value data types. Targeted for fast access from a device, which usually only sends data like that. Collections could be built later from those streams. Or perhaps better - use ExpressionEvaluators, that is probably what I would do.

Yes, only one file extlibs.jar is visible to ExpressionEvaluator. Not all in that folder.

If you use -jre8 that will probably not work with 1.6 compiled sources, not sure about that though. And yes, that applies also to all libraries in jar files, to execute with default setting (java 1.6), you need libraries also compiled like that.

Yes, different processInputData is executed for each CustomElement type.

PropertySetter will only work with fields on any element, so it could be used to set text on ExpressionEvaluator, but not for your own variables or structures. For that, use inputs/outputs. With ObjectExpressionEvaluator anything can be exchanged that way.
EMebane



Joined: Apr 15, 2019
Posts: 86

PostPosted: May 4, 2020 11:53 PM    Post subject:

When logging the received values in processInputData of a CustomElement I notice that the method is called many times with no values, and then when it receives values it receives a bundle of 2 to 4 values. I presume this is because the BM1000 sends at a slower rate than BioEra updates and probably includes several recorded values in each burst. By the time processOutputData has been called the destinationBuffer has been populated with the adjusted values. What happens with the values in destinationBuffer after that? Is each value passed out of the element one at a time? Are they sent one per BioEra tick?

How would this data flow be different in ExpressionEvaluator?

What happens in the write method? There's a comment in processOutputData about it:
// Just copy the data which has been already preprocessed in write() method
jarek



Joined: Oct 22, 2007
Posts: 789

PostPosted: May 5, 2020 3:50 PM    Post subject:

Yes, processInputData may be called with no data, the 'count' value is for detecting that.

The destinationBuffer is where you write your data. You should assume it stays there only for the time the processOuputData is being executed.

For most elements there is no "one at a time" processing, that includes CustomeElement. Most BioEra elements process data in chunks, all that is available in input buffer may be processes at one time.

The ExpressionEvaluator does process input values one at a time.
Reply to topic