This thread has been locked.
If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.
Tool/software: Code Composer Studio
I began by trying to add a complex package of Java API function provided by Peak to interface a can bus driver over USB. Realizing I had class path problems I followed the example in thread
by downloading the trivial example com.ti.test.zip and trying to successfully execute the example. So far, I cannot do even that. I went so far as to truncate the path to only my working directory, but I can't seem to get the importPackage() function to add the package, nor execute the example "Hi" function. I'm using the dss.bat to invoke the Rhino/js script shown here.
I'm an embedded C/C++ developer and am new to Java.
MOMScript.js
importPackage( Packages.java.lang );
importPackage( Packages.java.io );
importPackage( Packages.java.math );
print("_____________________________");
//MyClassPath = "C:\\_svn_repos\\_BRANCHES\\NGJ_MC_01_04_JS\\DSP\\SEU\\JVScript;" + System.getProperty("java.class.path") ;
MyClassPath = "C:\\_svn_repos\\_BRANCHES\\NGJ_MC_01_04_JS\\DSP\\SEU\\JVScript" ;
System.setProperty("java.class.path", MyClassPath)
System.setProperty("java.library.path", MyClassPath)
print("class.path="+System.getProperty("java.class.path"));
print("library.path="+System.getProperty("java.library.path"));
print("_____________________________");
importPackage(Packages.com.ti.test)
//print(new Echo().say("hi"));
packs = java.lang.Package.getPackages()
var sstr="xxxy";
for (p in packs)
{
sstr = String(packs[p]);
if ((sstr.indexOf("xyzzy.") != -1) ||
(sstr.indexOf("ti.") != -1) ||
0
)
{
print(packs[p]);
}
}
and the results
08/30/2019 13:45 749 xyzzy.jar
28 File(s) 419,478 bytes
19 Dir(s) 126,350,622,720 bytes free
C:\_svn_repos\_BRANCHES\NGJ_MC_01_04_JS\DSP\SEU\JVScript>dss MOMScript.js
_____________________________
class.path=C:\_svn_repos\_BRANCHES\NGJ_MC_01_04_JS\DSP\SEU\JVScript
library.path=C:\_svn_repos\_BRANCHES\NGJ_MC_01_04_JS\DSP\SEU\JVScript
_____________________________
package com.ti.ccstudio.rhino
package com.ti.ccstudio.rhino.internal
C:\_svn_repos\_BRANCHES\NGJ_MC_01_04_JS\DSP\SEU\JVScript>
Hi Luke,
Luke Reuter said:by downloading the trivial example com.ti.test.zip and trying to successfully execute the example. So far, I cannot do even that.
Did you copy the file to \ccs\eclipse\jre\lib\ext and rename the extension to jar?
That is all you should need to do. Once that is done, the below script can be run via DSS:
Thanks! I'd missed that suggestion in the older post. I got fixated on class.path and library.path they'd brought up at the end.
I added my jar file to the CCS7 directory as instructed (same as example program)
So, I've built a jar file from the manufacturer of the CAN bus USB adaptor, and I think I built it right.. I've tried it out in Java and done some basic I/O to prove it works. The Java main class looks like:
package peak.can.basic;
public class PCANBasic {
/**
* Initializes a PCAN Channel
*
* @param Channel The handle of a PCAN Channel
* @param Btr0Btr1 The speed for the communication (BTR0BTR1 code)
* @param HwType NON PLUG'n'PLAY: The type of hardware and operation mode
* @param IOPort NON PLUG'n'PLAY: The I/O address for the parallel port
* @param Interrupt NON PLUG'n'PLAY: Interrupt number of the parallel port
* @return a TPCANStatus error code
*/
public native TPCANStatus Initialize(
and I compiled it and created a jar file that has this content:
C:\Users\chreuter\Documents\AAAcan>jar -tf peak.can.basic.jar
META-INF/
META-INF/MANIFEST.MF
peak/can/basic/IRcvEventProcessor.class
peak/can/basic/PCANBasic.class
peak/can/basic/RcvEventDispatcher.class
peak/can/basic/TPCANBaudrate.class
peak/can/basic/TPCANBitrateFD.class
peak/can/basic/TPCANBitrateFDValue.class
peak/can/basic/TPCANDevice.class
peak/can/basic/TPCANHandle$1.class
peak/can/basic/TPCANHandle.class
peak/can/basic/TPCANMessageType.class
peak/can/basic/TPCANMode.class
peak/can/basic/TPCANMsg.class
peak/can/basic/TPCANMsgFD.class
peak/can/basic/TPCANParameter$1.class
peak/can/basic/TPCANParameter.class
peak/can/basic/TPCANParameterValue.class
peak/can/basic/TPCANStatus.class
peak/can/basic/TPCANTimestamp.class
peak/can/basic/TPCANTimestampFD.class
peak/can/basic/TPCANType.class
C:\Users\chreuter\Documents\AAAcan>
in the same script I tried your example program I added
importPackage(Packages.peak.can.basic);
var x = new PCANBasic();
but no joy.
PCANBasic is not defined. I may not have the constructor right, but wouldn't I get "wron constructor" errors instead of simply "not defined"
Can you attach the jar file to this thread? If you do not wish to share it publicly, please start a private conversation with me
Thanks
ki
I tried attaching, but "an error occurred". Chrome and explorer. Not sure if it's 1) size; 2) it's binary; or 3) my corporate firewall is in the way.
How do I start a private conversation? or maybe email?
It could also be the file extension. Try renaming it.
Luke Reuter said:How do I start a private conversation?
See the last FAQ in:
Hi Luke,
The jar file that you gave to Ki doesn't work for me either even with setting the java.library.path to the directory of the dll/lib.
What I ended up creating a new Java Project using Eclipse and copy the PCAN java source code that you gave to him to the new project and re-export the jar file using Eclipse. After dropping the jar file into the ccs/eclipse/jre/lib/ext folder and setting the -Djava.library.path=<path to the dll/lib folder> in ccstudio.ini. I was able to import the peak.can.basic package and call new PCANBasic() in the scripting console.
Let me know if you want me to attach the jar file to this thread. I can also send it to you through PM.
Regards,
Patrick
Good Morning Patrik,
Yes, could you please attach the jar file? The thread should be ok, since the source is published by the vendor. Could you tell me how you created the Java project in Eclipse? I don't use Eclipse, at least not from the GUI. I'm writing test scripts from the command line for software verification of our embedded code so I'm not a strong Eclipse user. I do need to document how the interface was built, for the test report.
Thanks to you and Ki for getting me off the ground!
Hi Luke,
Here is the file peak.can.basic.jar
I created the empty project using the standard New Java Project and add all the .java files from the CAN library.
I added
C:\ti\ccsv7\eclipse
to my Windows System path and started eclipse, but I don't see Java in the new project wizard.
The eclipse version that we shipped with CCS does not include Java development, you will need to download it from eclipse.org if you like to work with Java.
Here is the direct link:
https://www.eclipse.org/downloads/packages/release/2019-06/r/eclipse-ide-java-developers
I took you peak.can.basic.jar file and dropped it in C:\ti\ccsv7\eclipse\jre\lib\ext
and ran the script
C:\_svn_repos\_BRANCHES\NGJ_MC_01_04_JS\DSP\SEU\JVScript>dss PcanScript.js
hi
js: "PcanScript.js", line 11: uncaught JavaScript runtime exception: ReferenceError: "PCANBasic" is not defined.
C:\_svn_repos\_BRANCHES\NGJ_MC_01_04_JS\DSP\SEU\JVScript>
which contains the JavaScipt:
importPackage( Packages.java.lang );
importPackage( Packages.java.io );
importPackage( Packages.java.math );
importPackage(Packages.com.ti.test)
print(new Echo().say("hi"));
importPackage(Packages.peak.can.basic);
var x = new PCANBasic();
Ki had sent me the sample package com.ti.test.jar which I also included in the eclipse directory. Do I need to explicity update java.library.path, like you did scripting console?
We don't use the console for these scripts. we are writing a set of scripts that exercise our code from command line scripts we use to regression test our software.
Yes, you need to tell Java where to load the DLL. There are two important things you need to do, drop the .jar file into the jre that you use to execute the script For CCS, it is the eclipse/jre/lib/ext folder. You also need to pass the java.library.path property to the vmarg using the -Djava.library.path=<path> argument. For CCS, you can include this in ccstudio.ini.
I have the .jar file in the ..lib/ext folder.
I have the DLLs in folders that are included in th java.library.path
Isn't ReferenceError: "PCANBasic" is not defined.
an indicator that the Pcan packge isn't referenced? I thought the DLL didn't get searched for until the constructor runs.
Obviously, I'm learning Java/JavaScript as we go. I'm an embedded C/C++ programmer whose new task is to run scripts from the command line to validate our code.
CCS isn't even active when our scripts run.
Are you running the script with dss from the command prompt? i.e dss mytest.js?
If so, add -vmargs -Djava.library.path=<path to dll> to where eclipsec.exe is invoke in the \ccs\ccs_base\scripting\bin\dss.bat file.
Look for the LAUNCH_IDE_SCRIPT string in the dss.bat file.
For example:
!DEBUGSERVER!\..\..\eclipse\eclipsec.exe -nosplash -application com.ti.ccstudio.apps.runScript -product com.ti.ccstudio.branding.product -dss.debug -dss.rhinoArgs -data @user.home/workspace "%ArgsAfterFirst%" -vmargs -Djava.library.path=<path to dll>
I added, then enable batch command echo. Looks like the same result.
At the end I appended what the java.library path used to be. I really truncated it.
C:\_svn_repos\_BRANCHES\NGJ_MC_01_04_JS\DSP\SEU\JVScript>!DEBUGSERVER!\..\..\eclipse\eclipsec.exe -dev "C:\ti\ccsv7\ccs_base\DebugServer\packages\ti\dss\java\peak.can.basic.PCANBasic.jar" -nosplash -application com.ti.ccstudio.apps.runScript -product com.ti.ccstudio.branding.product -dss.rhinoArgs "PcanScript.js" -vmargs -Djava.library.path="C:\ti\ccsv7\eclipse"
library.path=C:\ti\ccsv7\eclipse
hi
js: "PcanScript.js", line 12: uncaught JavaScript runtime exception: ReferenceError: "PCANBasic" is not defined.
C:\_svn_repos\_BRANCHES\NGJ_MC_01_04_JS\DSP\SEU\JVScript>goto THEEND
library.path=C:\ti\ccsv7\eclipse;C:\WINDOWS\Sun\Java\bin;C:\WINDOWS\system32;C:\WINDOWS;C:/ti/ccsv7/ccs_base/scripting/bin/../../DebugServer/../../eclipse/jre/bin/client;C:/ti/ccsv7/ccs_base/scripting/bin/../../DebugServer/../../eclipse/jre/bin;C:/ti/ccsv7/ccs_base/scripting/bin/../../DebugServer/../../eclipse/jre/lib/i386;C:\ActiveTcl\bin;C:\Program Files\Java\jdk-11.0.2\bin;C:\Program Files (x86)\Common Files\Oracle\Java\javapath;C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\WINDOWS\system32\config\systemprofile\.dnx\bin;C:\Program Files\Microsoft DNX\Dnvm\;C:\Program Files\TortoiseSVN\bin;C:\Program Files\Microsoft SQL Server\130\Tools\Binn\;C:\Program Files (x86)\Windows Kits\10\Windows Performance Toolkit\;C:\Program Files (x86)\Windows Kits\8.1\Windows Performance Toolkit\;C:\Program Files\Microsoft SQL Server\Client SDK\ODBC\110\Tools\Binn\;C:\Program Files (x86)\Microsoft SQL Server\120\Tools\Binn\;C:\Program Files\Microsoft SQL Server\120\Tools\Binn\;C:\Program Files\Microsoft SQL Server\120\DTS\Binn\;C:\WINDOWS\System32\OpenSSH\;C:\ti\ccsv7\ccs_base\common\bin;C:\ti\ccsv7\ccs_base\scripting\bin;C:\ti\ccsv7\ccs_base\common\uscif;C:\Program Files\MATLAB\R2018b\bin;C:\Program Files (x86)\PuTTY\;C:\ti\ccsv7\eclipse;C:\Users\chreuter\AppData\Local\Programs\Python\Python37\Scripts\;C:\Users\chreuter\AppData\Local\Programs\Python\Python37\;C:\Users\chreuter\AppData\Local\Microsoft\WindowsApps;;C:\_svn_repos\_BRANCHES\NGJ_MC_01_04_JS\DSP\SEU\JVScript;;.
I just realized you are using CCSv7.x and I am using CCSv9.x to compile the jar file. Would you be able to use CCSv9 to run the scirpt?
CCSv7.x is using a 32bit JRE and CCSv9.x is using a 64bit JRE. Hence, I think it is causing a class load error when importing the package.
Unfortunately, we are in the tail end of a program that started out with CCSv7 and dare not switch over this late in the game. Can I rebuild my PCANbasic package using 32 bit JRE in Eclipse as you did and try to import THAT in?
Now that I look, I see I installed a 64 bit JDK:
jdk-12.0.2_windows-x64_bin.exe
is what I built my Java development environment from.
I have compiled the jar in 32bit java, however the DLL that you provided is a 64bit DLL. So, you either have to get a 32bit version of the dll or upgrade to CCS9.x.
I have attached the 32bit jar file here, incase you want to use a 32bit version of the dll.
Thanks! I substituted the attached jar file. Peak provides 32 bit libraries with their distribution. JavaScript now recognizes the package and lets me create a PCANBasic() object.