I have a processing program that is supposed to read the data from a serial port created by an arduino uno. I got the program to work perfectly in Processing but not in Eclipse. I added core.jar serial.jar and jssc.jar to my java project's build path, but am still getting an error calling the port with Serial.list()[0].
I have seen similar questions on here, but none have helpful answers. I don't know if I'm missing something or need to import a different jar file to my build path.
import processing.core.PApplet;
import processing.serial.*;
public class Processing extends PApplet {
public Processing() {
// TODO Auto-generated constructor stub
}
public static void main(String[] args) {
PApplet.main("Processing");
}
Serial myPort;
String val;
public void setup() {
myPort = new Serial(this, Serial.list()[0], 9600);
}
public void draw() {
if ( myPort.available() > 0) {
val = myPort.readString();
}
if (val != null) {
println(val);
}
delay(250);
}
}
Error Message:
java.lang.UnsatisfiedLinkError: jssc.SerialNativeInterface.getSerialPortNames()[Ljava/lang/String;
at jssc.SerialNativeInterface.getSerialPortNames(Native Method)
at jssc.SerialPortList.getWindowsPortNames(SerialPortList.java:309)
at jssc.SerialPortList.getPortNames(SerialPortList.java:298)
at jssc.SerialPortList.getPortNames(SerialPortList.java:182)
at processing.serial.Serial.list(Unknown Source)
at Performance.Processing.setup(Processing.java:44)
at processing.core.PApplet.handleDraw(PApplet.java:2425)
at processing.awt.PSurfaceAWT$12.callDraw(PSurfaceAWT.java:1547)
at processing.core.PSurfaceNone$AnimationThread.run(PSurfaceNone.java:313)
You have added jssc.jar to the Java Build Path which is great, however jssc uses a native c++ library which you need to also reference:
From the Java Build Path > Libraries section
use the arrow to expand jssc.jar and select Native library location
click Edit... on the right hand side and select the folder containing the native c++ library for your OS (in my case that's macosx right now)
Once you apply the changes, the link error will be satisfied.
Related
Good Morning
I'm currently doing a plugIn for ImageJ in JAVA that needs to call the function "Maximum Intensity Z-projection", which I know that is already in ImageJ if you go for "Image/Stacks/Z Project...". Documentation here: http://imagej.net/Z-functions#Maximum_Intensity_Z-projection
I know how to call plugins from another plugins, but doing the same thing in this case I get all the time my "Error" message.
public class Maximum_Intensity implements PlugIn{
ImagePlus img = WindowManager.getCurrentImage();
#Override
public void run(String arg0) {
// TODO Auto-generated method stub
Object ZProjector = null;
ZProjector = IJ.runPlugIn(img, "ZProjector", arg0);
if(ZProjector==null){
String arg = "Error";
IJ.showMessage(arg);
}
}
}
How can I do it? Thank you so much.
You can easily use the macro recorder for help to record all commands in ImageJ, see:
https://imagej.nih.gov/ij/docs/guide/146-31.html#sub:Record...
Enable Java for the recorder and then use the "Create" action to create an ImageJ plugin from the recorded interface actions.
In the following example (created with the Recorder) I applied the Max. Intensity function on a stack.
import ij.*;
import ij.process.*;
import ij.gui.*;
import java.awt.*;
import ij.plugin.*;
public class My_Plugin implements PlugIn {
public void run(String arg) {
ImagePlus imp = IJ.openImage("http://imagej.nih.gov/ij/images/mri-stack.zip");
IJ.run(imp, "Z Project...", "projection=[Max Intensity]");
imp.show();
}
}
The ZProjector class description can be found here (for instantiation):
https://imagej.nih.gov/ij/developer/api/ij/plugin/ZProjector.html
In my eclipse plugin, I created an utility class that does some work when I create my files, with my wizard.
I´d like to show to user some text, warning him about what´s happening, in the progress bar.
How could I do this?
Thanks a lot.
UPDATE: my wizard calls my utility class, that unzips 2 ZIP files and import 2 projects into workspace. So, I´d like to show a message after each operation, like:
Unzipping file1...
Unzipping file2...
Importing project1...
Importing project2...
In your Wizard class enable the progress monitor by calling
setNeedsProgressMonitor(true);
in the constructor.
You can then run your IRunnableWithProgress class with:
IRunnableWithProgress runnable = new MyRunnable();
getContainer().run(true, true, runnable);
This can be in the Wizard or in a WizardPage.
The IRunnableWithProgress class might look like:
private class MyRunnable implements IRunnableWithProgress
{
#Override
public void run(final IProgressMonitor monitor)
throws InvocationTargetException, InterruptedException
{
monitor.beginTask("title", progress count);
try
{
... your work
}
finally
{
monitor.done();
}
}
}
I've been trying to implement DirectInput into unity using SharpDX.DirectInput dlls, but when i create a joystick, it gives me an error:
SharpDXException: HRESULT: [0x80070057], Module: [General], ApiCode: [E_INVALIDARG/Invalid Arguments], Message: The parameter is incorrect.
and here is my code:
using System;
using UnityEngine;
using SharpDX.DirectInput;
namespace KurdifyEngine.Input
{
static class Direct
{
public static DirectInput directInput;
public static Guid directGuid;
public static Joystick directGamepad ;
internal static void Initialize()
{
// Initialize DirectInput
directInput = new DirectInput();
directGuid = Guid.Empty;
DirectUpdate();
}
internal static void DirectUpdate()
{
// search for Gamepad
foreach (var deviceInstance in directInput.GetDevices(SharpDX.DirectInput.DeviceType.Gamepad, DeviceEnumerationFlags.AttachedOnly))
directGuid = deviceInstance.InstanceGuid;
}
if (directGuid != Guid.Empty)
{
directGamepad = new Joystick(directInput, directGuid);
}
}
}
}
the error happens when i create a joystick:
directGamepad = new Joystick(directInput, directGuid);
We have been developing exotic controller support for a Unity product and encountered the same problem (SharpDXException: HRESULT: [0x80070057]) on the exact same line.
We tried recompiling the SharpDX by fixing it like it is explained in this github post: https://github.com/sharpdx/SharpDX/issues/406 but encountered other problems with the DirectX (June 2010) SDK.
We just found a way to compile our Unity project using the libraries included in this project (which is an add-on for exotic controllers support in Kerbal Space Program): https://github.com/pbatard/AltInput just pick up the .dll under Libraries/, replace your old .dll by these and you're good to go !
Thanks in advance for your assistance. I have the following exported part:
[Export (typeof(INewComponent))] // orignally tried just [Export} here and importing NewComponent below
public class NewComponent : INewComponent
{
// does stuff including an import
}
The Console test program imports the above:
public class Program
{
[Import] // have tried variations on importing "NewComponent NewComponent" etc
public INewComponent NewComponent
{
get;
set;
}
public static void Main(string[] args)
{
var p = new Program();
var catalog = new AssemblyCatalog(typeof(Program).Assembly);
var container = new CompositionContainer(catalog);
container.ComposeParts(p);
}
The Composition fails with these CompositionExceptions (I removed the namespace to protect the guilty :)):
1) No valid exports were found that match the constraint
'((exportDefinition.ContractName == "INewComponent") AndAlso
(exportDefinition.Metadata.ContainsKey("ExportTypeIdentity") AndAlso
"INewComponent".Equals(exportDefinition.Metadata.get_Item("ExportTypeIdentity"))))',
invalid exports may have been rejected.
The Composition works successfully if I do the composition in the main program like this:
public class Program
{
public static void Main(string[] args)
{
INewComponent newComponent = new NewComponent();
var catalog = new AssemblyCatalog(typeof(Program).Assembly);
var container = new CompositionContainer(catalog);
container.ComposeParts(newComponent);
}
}
Thank You
Is your Exported part contained in the same Assembly as Program? If it is in a separate DLL, you need to include that Assembly in your catalog as well, like this:
var aggregateCatalog = new AggregateCatalog();
aggregateCatalog.Catalogs.Add(new AssemblyCatalog(typeof(Program).Assembly));
aggregateCatalog.Catalogs.Add(new AssemblyCatalog(typeof(NewComponent).Assembly));
var container = new CompositionContainer(aggregateCatalog);
// etc...
If that's doesn't work, then there is a nice open source tool called Visual MEFx that can help you analyze your catalog. Here is a short article about setting it up:
Getting Started With Visual MEFx
In your NewComponent class you wrote this:
// does stuff including an import
If there is a problem with that unshown import, then MEF will complain about the Program.NewComponent import instead of the actual deeper cause. This is called "stable composition". Stable composition can be useful, but it also complicates the debugging of a failed composition.
You can follow the instructions in the MEF documentation about Diagnosing Composition Errors to home in on the actual cause.
In a small program, you can also try to call container.GetExportedValue<ISomeExport>() for a few exports until you find the one that is causing problems.
this is the code from TIJ4#
The java code can compile and run in cmd window , but can not compile and run in eclipse .
//: io/MemoryInput.java
import java.io.*;
public class MemoryInput {
public static void main(String[] args)
throws IOException {
StringReader in = new StringReader(
BufferedInputFile.read("MemoryInput.java"));
int c;
while((c = in.read()) != -1){
System.out.print((char)c);
}
}
the wrong information about the code in eclipse is :
BufferedInputFile cannot be resolved
BufferedInputFile is not part of the package java.io. If you have that class in a library or in a certain folder you have to include it in Eclipse.
BufferedInputFile is not part of any default lib of java. So you have to add that class to your class path.