Passing a Byte into a Java method

I’m having issues passing a Byte into a Java library and I honestly can’t
find a single place on Google where anyone has done it or even talked about
doing it. I’m not sure if this means I’m missing something very simple and
obvious or just the first person to try :slight_smile:

Here is the java method I’m trying to call:
https://github.com/Pi4J/pi4j/blob/master/pi4j-core/src/main/java/com/pi4j/wiringpi/Shift.java#L115

The method signature is quite simple:
public static native void shiftOut(*byte *dPin, *byte *cPin, *byte *order, *byte
*val);

Using the CommandBox 2.0.0 REPL (Running Lucee 4.5.1.008):

CFSCRIPT-REPL: shift = createObject( ‘java’, ‘com.pi4j.wiringpi.Shift’)
[Object java.lang.Class]
CFSCRIPT-REPL: shift.shiftIn( 27, 28, shift.MSBFIRST, ‘00000000’ )
ERROR
No matching Method for shiftIn(numeric, numeric, numeric, string)
found for com.pi4j.wiringpi.Shift

Ok, fair enough-- I didn’t cast anything. Lucee saw a numeric, numeric,
numeric and a string, but we need all four of the parameters to be bytes.
Let’s try casting the first parameter and see what happens.

CFSCRIPT-REPL: shift.shiftIn( javaCast( ‘byte’, 27 ), 28, shift.MSBFIRST,
‘00000000’ )
ERROR
No matching Method for shiftIn(numeric, numeric, numeric, string) found
for com.pi4j.wiringpi.Shift

Nope, the first param was still seem as a numeric even though I cast it.
Let’s try manually creating an instance of java.lang.Byte.

CFSCRIPT-REPL: byte = createObject( ‘java’, ‘java.lang.Byte’)
[Object java.lang.Class]
CFSCRIPT-REPL: shift.shiftIn( byte.init( 27 ), 28, shift.MSBFIRST,
‘00000000’ )
ERROR
No matching Method for shiftIn(numeric, numeric, numeric, string) found
for com.pi4j.wiringpi.Shift

No dice. Lucee is still convinced I’m trying to pass a “numeric” into my
Java function.

I won’t show the code, but even trying to javaCast() my Byte object results
in Lucee seeing a “numeric”. Also, I’m aware the “java.lang.Byte” is not
the same as a native “byte” data type, but calling byte.init(27).byteValue()
doesn’t make any difference. It’s still always a numeric.

Any ideas?

Thanks!

~Brad

Sigh, I stared at this all morning and even thought I double checked the
method name, but it wasn’t until about 2 minutes after hitting send that I
realized I had been calling the wrong method. Notice, my examples have
“shiftIn” not “shiftOut”!

Lol, working great now so I think this can be entirely disregarded.

Thanks!

~Brad

ColdBox Platform Evangelist
*Ortus Solutions, Corp *

E-mail: brad@coldbox.org
ColdBox Platform: http://www.coldbox.org
Blog: http://www.codersrevolution.comOn Mon, Apr 27, 2015 at 12:54 PM, Brad Wood <@Brad_Wood> wrote:

I’m having issues passing a Byte into a Java library and I honestly can’t
find a single place on Google where anyone has done it or even talked about
doing it. I’m not sure if this means I’m missing something very simple and
obvious or just the first person to try :slight_smile:

Here is the java method I’m trying to call:

https://github.com/Pi4J/pi4j/blob/master/pi4j-core/src/main/java/com/pi4j/wiringpi/Shift.java#L115

The method signature is quite simple:
public static native void shiftOut(*byte *dPin, *byte *cPin, *byte *order,
*byte *val);

Using the CommandBox 2.0.0 REPL (Running Lucee 4.5.1.008):

CFSCRIPT-REPL: shift = createObject( ‘java’, ‘com.pi4j.wiringpi.Shift’)
[Object java.lang.Class]
CFSCRIPT-REPL: shift.shiftIn( 27, 28, shift.MSBFIRST, ‘00000000’ )
ERROR
No matching Method for shiftIn(numeric, numeric, numeric, string)
found for com.pi4j.wiringpi.Shift

Ok, fair enough-- I didn’t cast anything. Lucee saw a numeric, numeric,
numeric and a string, but we need all four of the parameters to be bytes.
Let’s try casting the first parameter and see what happens.

CFSCRIPT-REPL: shift.shiftIn( javaCast( ‘byte’, 27 ), 28, shift.MSBFIRST,
‘00000000’ )
ERROR
No matching Method for shiftIn(numeric, numeric, numeric, string) found
for com.pi4j.wiringpi.Shift

Nope, the first param was still seem as a numeric even though I cast it.
Let’s try manually creating an instance of java.lang.Byte.

CFSCRIPT-REPL: byte = createObject( ‘java’, ‘java.lang.Byte’)
[Object java.lang.Class]
CFSCRIPT-REPL: shift.shiftIn( byte.init( 27 ), 28, shift.MSBFIRST,
‘00000000’ )
ERROR
No matching Method for shiftIn(numeric, numeric, numeric, string) found
for com.pi4j.wiringpi.Shift

No dice. Lucee is still convinced I’m trying to pass a “numeric” into my
Java function.

I won’t show the code, but even trying to javaCast() my Byte object
results in Lucee seeing a “numeric”. Also, I’m aware the “java.lang.Byte”
is not the same as a native “byte” data type, but calling
byte.init(27).byteValue() doesn’t make any difference. It’s still always
a numeric.

Any ideas?

Thanks!

~Brad


You received this message because you are subscribed to a topic in the
Google Groups “Lucee” group.
To unsubscribe from this topic, visit
https://groups.google.com/d/topic/lucee/4wQTYdmE6DQ/unsubscribe.
To unsubscribe from this group and all its topics, send an email to
lucee+unsubscribe@googlegroups.com.
To post to this group, send email to lucee@googlegroups.com.
To view this discussion on the web visit
https://groups.google.com/d/msgid/lucee/7713fd26-ba04-43c6-b85b-3e35a2df8ae2%40googlegroups.com
https://groups.google.com/d/msgid/lucee/7713fd26-ba04-43c6-b85b-3e35a2df8ae2%40googlegroups.com?utm_medium=email&utm_source=footer
.
For more options, visit https://groups.google.com/d/optout.