Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 16 of 16

Thread: Programming USB Relay Board

  1. #1
    Junior Member
    Join Date
    Jun 2011
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Programming USB Relay Board

    So I've bought a USB 4 port Relay Module that has been shipped and is on its way.
    Here is the link to the product: Denkovi Assembly Electronics ltd: USB Four Channel Relay Board for Automation

    Meanwhile I'm waiting for it I thought I'd maybe prepare a simple application in Java for it however I've encountered some trouble.

    I asked the supplier for a java source code example and got this:

    Firstly, please donwload the library I have attached. It is documented here - http://bleyer.org/jd2xx/
    Secondly, please use the following code I am sending to you.

    //Create a JD2XX object
    usb4Relay = new JD2XX();
     
    //Use some open method
    usb4Relay.open(0);
     
    //Adjust the bit-bang mode
    usb4Relay.setBitMode(255, 1);
     
    //Set the relays
    String RelayState="1111" //prepare the state for the relays
    String State="";                
    for (int i=RelayState.length; i>0; i--)        
     if (RelayState[i-1]==0)
       State=State+"00";
     else
       State=State+"10";         
    // Now we have State=10101010. We are using bits 1,3,5,7 bits from FT245 for controlling the relays.
    usb4Relay.write(Integer.parseInt(State, 2));
     
     
    //Finally, close it
    usb4Relay.close();
    I have attached the library (jd2xx.jar inside the jd2xx.zip) he provided me with that email.

    I found some mistakes in his code and made some minor changes to it:
    import java.io.IOException;
     
    import jd2xx.JD2XX;
     
     
    class Main {
    	public static void main(String[] args) throws IOException {
     
    		// Create a JD2XX object
    		JD2XX usb4Relay = new JD2XX();
     
    		// Use some open method
    		usb4Relay.open(0);
     
    		// Adjust the bit-bang mode
    		usb4Relay.setBitMode(255, 1);
     
    		// Set the relays
    		String RelayState = "1111"; // prepare the state for the relays
    		char[] chars = RelayState.toCharArray();
     
    		String state = "";
    		for (int i = RelayState.length(); i > 0; i--)
    			if (chars[i - 1] == 0)
    				state = state + "00";
    			else
    				state = state + "10";
     
    		// Now we have State=10101010. We are using bits 1,3,5,7 bits from FT245
    		// for controlling the relays.
    		usb4Relay.write(Integer.parseInt(state, 2));
     
    		// Finally, close it
    		usb4Relay.close();
    	}
     
    }

    While running the application in Eclipse I receive the following errors:
    Exception in thread "main" java.lang.UnsatisfiedLinkError: no jd2xx in java.library.path
    at java.lang.ClassLoader.loadLibrary(Unknown Source)
    at java.lang.Runtime.loadLibrary0(Unknown Source)
    at java.lang.System.loadLibrary(Unknown Source)
    at jd2xx.JD2XX.<clinit>(JD2XX.java:587)
    at Main.main(Main.java:10)
    Code for JD2XX.java:587 says:
    586: static {
    587: System.loadLibrary("jd2xx");
    588: }
    So what am I doing wrong here?
    Attached Files Attached Files


  2. #2
    mmm.. coffee JavaPF's Avatar
    Join Date
    May 2008
    Location
    United Kingdom
    Posts
    3,336
    My Mood
    Mellow
    Thanks
    258
    Thanked 294 Times in 227 Posts
    Blog Entries
    4

    Default Re: Programming USB Relay Board

    I have just looked at the link and the USB Relay Board looks cool. What are you planning to do with it?

    For some reason there is an error loading jd2xx. What IDE are you using?
    Please use [highlight=Java] code [/highlight] tags when posting your code.
    Forum Tip: Add to peoples reputation by clicking the button on their useful posts.

  3. #3
    Junior Member
    Join Date
    Jun 2011
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Programming USB Relay Board

    Thanks for your reply.

    For the moment I am planning to build a simple automatic plant waterer, have a water pump on it's way as well.
    As stated above I am using Eclipse. It doesn't actually complain on any of the source code until I run the application.

    I right-clicked on the library in the menu to the left -> Build Paths -> Configure Build Path... -> Libraries -> Add External JARs... -> Selected file jd2xx.jar

    I suppose this is how it should be done? Or have I missed anything?

  4. #4
    mmm.. coffee JavaPF's Avatar
    Join Date
    May 2008
    Location
    United Kingdom
    Posts
    3,336
    My Mood
    Mellow
    Thanks
    258
    Thanked 294 Times in 227 Posts
    Blog Entries
    4

    Default Re: Programming USB Relay Board

    Ah sorry I missed the fact you were using Eclipse.

    An automatic plant waterer is a good idea. I wanted to do something similar myself. My Dad grows chillies in an indoor environment and I wanted to create a system to automate tasks like watering and heating management. I would be interested to track your progress.

    Yes this is how it is done. I am going to set this project up myself and see if I run into any problems.
    Please use [highlight=Java] code [/highlight] tags when posting your code.
    Forum Tip: Add to peoples reputation by clicking the button on their useful posts.

  5. #5
    Junior Member
    Join Date
    Jun 2011
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Programming USB Relay Board

    Thanks once again for your quick reply,

    I am very glad to hear that you enjoy the idea and I will make sure to update my progress on this project.
    For now I am looking a way to solve this minor issue with the imported library.

    Best Regards

  6. #6
    mmm.. coffee JavaPF's Avatar
    Join Date
    May 2008
    Location
    United Kingdom
    Posts
    3,336
    My Mood
    Mellow
    Thanks
    258
    Thanked 294 Times in 227 Posts
    Blog Entries
    4

    Default Re: Programming USB Relay Board

    OK I've setup this project exactly and imported jd2xx.jar. I can see that this has imported correctly...

    When I attempt to run the program I too get the error:

    Exception in thread "main" java.lang.UnsatisfiedLinkError: no jd2xx in java.library.path
    at java.lang.ClassLoader.loadLibrary(Unknown Source)
    at java.lang.Runtime.loadLibrary0(Unknown Source)
    at java.lang.System.loadLibrary(Unknown Source)
    at jd2xx.JD2XX.<clinit>(JD2XX.java:587)
    at Main.main(Main.java:10)


    What exactly is this code ment to do?
    Will this function without the hardware or any additional software installed?

    May be worth going back to the supplier to get clarification.
    Please use [highlight=Java] code [/highlight] tags when posting your code.
    Forum Tip: Add to peoples reputation by clicking the button on their useful posts.

  7. #7
    Junior Member
    Join Date
    Jun 2011
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Programming USB Relay Board

    Yep, I just sent him an email so I am hoping that he will have enough time to reply soon.

    I found similar project that also runs JD2XX:
    Super4 Windows Software

    I tried to run the project file from there and it basically gives the same error.
    So my thoughts are that it has to do with some kind of drivers, but I am not sure however.

    Best Regards

  8. #8
    mmm.. coffee JavaPF's Avatar
    Join Date
    May 2008
    Location
    United Kingdom
    Posts
    3,336
    My Mood
    Mellow
    Thanks
    258
    Thanked 294 Times in 227 Posts
    Blog Entries
    4

    Default Re: Programming USB Relay Board

    Quote Originally Posted by Infinity8 View Post
    So my thoughts are that it has to do with some kind of drivers, but I am not sure however.
    Looking at the documentation, maybe you need the FTDI drivers?

    jd2xx is a Java native interface port of Future Technology Devices International (FTDI) D2XX direct USB driver. FTDI chips are used in a variety of USB products such as serial converters and dongles.
    D2XX Direct Drivers
    Please use [highlight=Java] code [/highlight] tags when posting your code.
    Forum Tip: Add to peoples reputation by clicking the button on their useful posts.

  9. #9
    Junior Member
    Join Date
    Jun 2011
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Programming USB Relay Board

    Yep, Had a look at that as well. I've already tried including these files to my System32 folder and directing my Native Library Location to these drivers but still get the same error.
    I have actually no great experience combining java with hardware so I'll have a further look at the documentation meanwhile I am waiting for his reply.

  10. #10
    mmm.. coffee JavaPF's Avatar
    Join Date
    May 2008
    Location
    United Kingdom
    Posts
    3,336
    My Mood
    Mellow
    Thanks
    258
    Thanked 294 Times in 227 Posts
    Blog Entries
    4

    Default Re: Programming USB Relay Board

    OK no problem. Hopefully his reply will help you move forward.

    Please keep us updated.
    Please use [highlight=Java] code [/highlight] tags when posting your code.
    Forum Tip: Add to peoples reputation by clicking the button on their useful posts.

  11. #11
    Junior Member
    Join Date
    Jun 2011
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Programming USB Relay Board

    So I got this reply.
    this is because you have to put these two lib files in your classpath.
    I've tried a little but with no great success. But am still trying to figure it out.

    I've got the usb relay board and my water pump and have to say that it's running as expected (using the finished software).

    Best Regards
    Attached Files Attached Files

  12. #12
    Junior Member
    Join Date
    Jun 2011
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Programming USB Relay Board

    Ok, good news. Got it fully working with the relay board.
    This is how I did:
    I collected all three files that is attached to this thread (jd2xx.jar, ftd2xx.dll, JDXX.dll).
    On main class Build Path -> Configure build path.. -> Libraries -> Add external JARs... -> Select jd2xx.jar
    And then switch to the Source folder
    Native library location -> Edit -> External Folder... -> And select the folder with the three files

    That's it.

    I am going to play around with this for now, will keep you updated.

  13. #13
    Junior Member
    Join Date
    Jun 2011
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Programming USB Relay Board

    And here's a clip of it running after I've played around a little:

  14. #14
    Junior Member
    Join Date
    Apr 2012
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Programming USB Relay Board

    Hey there,
    I've got the same problem to build the paths in eclipse with the jd2xx, and ftd2xx-files.
    Thanks for your solution, it fixed up the Error: "java.lang.UnsatisfiedLinkError:: no jd2xx in java.library.path".

    But now i've got the second problem:
    "java.lang.UnsatisfiedLinkError: C:\directorys.....\JD2XX.dll: Can't find dependent libraries"

    Did you got the same error?
    I dont know how to solve it.. :/

    Thanks

  15. #15
    Junior Member
    Join Date
    Jan 2013
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Programming USB Relay Board

    I tried like the JD2XX downloaded from this site - see right - Attached Files
    JD2XX.zip (232.6 KB, 27 views)

    and it worked perfectly. I'm using a USB/I2C interface from Robot Electronics. With VB.NET I only needed to use the Import System.IO.Ports
    to address this module, with Java it's a touch more tricky and the JDXXX was the only way I could get Java to send bytes to the module.

  16. #16
    Junior Member
    Join Date
    Dec 2013
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Programming USB Relay Board

    hey guys,
    I am actually working on this just wanted to know whether you were able to solve the "java.lang.UnsatisfiedLinkError: C:\directorys.....\JD2XX.dll: Can't find dependent libraries" issue and can you tell me how you did it???

Similar Threads

  1. Hi everybody, im new to programming.
    By Sauliux in forum Member Introductions
    Replies: 1
    Last Post: March 5th, 2011, 12:06 PM
  2. Relay data from remote port to local port
    By chegers in forum Java Networking
    Replies: 0
    Last Post: November 7th, 2010, 12:46 PM
  3. Help with score board!
    By vlan in forum Java Applets
    Replies: 0
    Last Post: June 2nd, 2010, 04:34 AM
  4. DOS board game
    By SageNTitled in forum Java Theory & Questions
    Replies: 5
    Last Post: March 4th, 2010, 03:53 PM
  5. Replies: 0
    Last Post: February 3rd, 2009, 01:15 AM