CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 14 of 14
  1. #1
    Join Date
    Mar 2002
    Location
    Holland
    Posts
    279

    Smile usb to serial question

    Hi,

    for a project I need to communicate with a usb to serial convertor.
    the device is used on the mac and pc(windows)


    what is the best way to communicate?
    usb or serial?
    does anybody have a suggestion/examples?

    Thx,

    Jewe

    p.s. in the beginning I was sure that java was the solution to my problem. but at the moment I'm not sure. I have to have some good arguments to use java instead of C of C++. or else my project leader will make my life a living ****. (he hates java more then VB)
    Last edited by Jewe; November 2nd, 2004 at 09:57 AM.
    A VB programmer trying to stay alive in a Real C World

    If the hardware is so great.. why use software to correct it..?? It will only slow it down..
    Al is de hardware nog zo snel de software achterhaalt het wel

  2. #2
    Join Date
    Mar 2002
    Location
    Holland
    Posts
    279

    Re: usb to serial question

    anybody.??

    I still can not find it.
    looks like java is not the language I thought it would be.
    A VB programmer trying to stay alive in a Real C World

    If the hardware is so great.. why use software to correct it..?? It will only slow it down..
    Al is de hardware nog zo snel de software achterhaalt het wel

  3. #3
    Join Date
    Oct 2003
    Location
    .NET2.0 / VS2005 Developer
    Posts
    7,104

    Re: usb to serial question

    talking to hardware is a native application of a programming task, and is hence out of java's scope. the USB device is supposed to masquerade as a normal serial port, and java can then use it (in its major strains; windows/linux/solaris at least).. if youre writing a java program, then you really should let something else do the talking to the hardware
    "it's a fax from your dog, Mr Dansworth. It looks like your cat" - Gary Larson...DW1: Data Walkthroughs 1.1...DW2: Data Walkthroughs 2.0...DDS: The DataSet Designer Surface...ANO: ADO.NET2 Orientation...DAN: Deeper ADO.NET...DNU...PQ

  4. #4
    Join Date
    Mar 2002
    Location
    Holland
    Posts
    279

    Re: usb to serial question

    thx for the reply.

    I got that part.

    but what I am wondering about is should approace the device lke usb or like a serial port.

    I found some information about a usb package and about serial ports.
    Because the device is used in both apple and windows enviorment I am wondering what the best way is.
    both are not supported by the native java codes.

    So I am looking for the best way and the best examples. I am not a java guru. I had some experience during school.
    A VB programmer trying to stay alive in a Real C World

    If the hardware is so great.. why use software to correct it..?? It will only slow it down..
    Al is de hardware nog zo snel de software achterhaalt het wel

  5. #5
    Join Date
    Mar 2002
    Location
    Holland
    Posts
    279

    Re: usb to serial question

    Does anybody have any experience with this?

    I'm still trying to sort the problem out.
    but the longer I think about is, the more confused I get.
    from a general point of view I would say use the usb interface.
    but I guess the quikest way (the one my boss likes) is to connect to it like a serial device.

    please give me you advise or opinion..

    thx,

    jewe
    A VB programmer trying to stay alive in a Real C World

    If the hardware is so great.. why use software to correct it..?? It will only slow it down..
    Al is de hardware nog zo snel de software achterhaalt het wel

  6. #6
    dlorde is offline Elite Member Power Poster
    Join Date
    Aug 1999
    Location
    UK
    Posts
    10,163

    Re: usb to serial question

    Quote Originally Posted by Jewe
    p.s. in the beginning I was sure that java was the solution to my problem. but at the moment I'm not sure. I have to have some good arguments to use java instead of C of C++. or else my project leader will make my life a living ****. (he hates java more then VB)
    Then your project leader is an idiot (and a bad manager)... A programming language is just a tool. A competent programmer or project leader should select the language most appropriate to the task at hand. Obviously, the skills of the developers are relevant to the choice, but a professional should have a logical rather than an emotional reason for preferring one language over another.

    It's no mystery why there's so much rubbish software out there...
    Please use [CODE]...your code here...[/CODE] tags when posting code. If you get an error, please post the full error message and stack trace, if present.

  7. #7
    Join Date
    Oct 2003
    Location
    .NET2.0 / VS2005 Developer
    Posts
    7,104

    Re: usb to serial question

    i've reviewed the java usb interface (jUSB on sourceforge) but aside from looking like an api capable of querying a usb network layout, it doesnt look like it does much else (apart from consistently spell Buses incorrectly)

    if your USB device masquerades as a serial port, then you should use it in this mode, as sun provide a core component for serial communication, with the java api (javax.comm)
    http://java.sun.com/products/javacomm/index.jsp

    so aside from my reservations that jUSB cant actually be used to interact with a device in the way you expect, i'd be tempted to go for something that is officially supported; the popularity, public domain knowledge and availability of example source code is much higher

    but also, at the end of the day; youre talking about using a usb serial port.. its just a communication port! it does nothing interesting! (the device you plug into the comms port is what is actually interesting)
    if the device you plug into it expects commands in an rs232 style, then messing around with a usb API isnt going to advance the project any.
    to give a gross example of what i mean.. its like being given a brief to write a web browser, and wondering whether you should write a PCI or an ISA modem driver first; you should do neither, as it is entirely unrelated to the transports and commands necessary to get a web browser to work
    "it's a fax from your dog, Mr Dansworth. It looks like your cat" - Gary Larson...DW1: Data Walkthroughs 1.1...DW2: Data Walkthroughs 2.0...DDS: The DataSet Designer Surface...ANO: ADO.NET2 Orientation...DAN: Deeper ADO.NET...DNU...PQ

  8. #8
    Join Date
    Mar 2002
    Location
    Holland
    Posts
    279

    Re: usb to serial question

    Quote Originally Posted by cjard
    if your USB device masquerades as a serial port, then you should use it in this mode, as sun provide a core component for serial communication, with the java api (javax.comm)
    http://java.sun.com/products/javacomm/index.jsp
    I think you are right.
    But I still have a problem with detecting the com ports.
    I used the black box example and on 2 computers
    ( xp pro and win2k) the example reported that it was unable to find any comports.
    both pc's have got at least 1 unused serial port.

    Does anybody have the same problem?

    I figured out the both the mac and the PC are capable of communicating with rs-232 so this partly solves my problem.. now all I have to do is have the example running and I'm good to go...

    in case I forgot to mention it, thx for everybody that replied.

    Jewe
    Last edited by Jewe; November 10th, 2004 at 07:15 AM.
    A VB programmer trying to stay alive in a Real C World

    If the hardware is so great.. why use software to correct it..?? It will only slow it down..
    Al is de hardware nog zo snel de software achterhaalt het wel

  9. #9
    Join Date
    Oct 2003
    Location
    .NET2.0 / VS2005 Developer
    Posts
    7,104

    Re: usb to serial question

    i would expect that the usb device will operate in a similar fashion to a modem; you install a specific driver for the hardware, and then talk to it using a com port

    when you install a modem, it uses probably com3 or com4. this doesnt mean that you have to have a serial port on the PC for com3 or com4.. the ports have memory spaces assigned to them, and dma numbers. the memory address space is a small chunk of memory that serves as a communications gateway to the hardware. anything written to this area of memory is picked up by the hardware device. anything the hardware device has to say is also written to this area and picked up by the computer

    so, if com4 defines the region 0x378 to 0x37F, that's 8 bytes of memory that is used for com4. if your device is assigned to com4, and you write to com4, then the operating system will manage the shunting of your data so that it is written to that area of memory.

    the device does, hence, need a driver to operate
    "it's a fax from your dog, Mr Dansworth. It looks like your cat" - Gary Larson...DW1: Data Walkthroughs 1.1...DW2: Data Walkthroughs 2.0...DDS: The DataSet Designer Surface...ANO: ADO.NET2 Orientation...DAN: Deeper ADO.NET...DNU...PQ

  10. #10
    Join Date
    Mar 2002
    Location
    Holland
    Posts
    279

    Re: usb to serial question

    thank you cjard, but that was not what I meant.
    but you are right, for the device you need an additional driver.

    I have 1 serial port(rs 232) of 2 ports on the mobo of the pc.
    for some reason the black box example does not find any com port while windows tells me that they are there.

    I did not give any parameter.

    Can anybody help?

    Jewe
    A VB programmer trying to stay alive in a Real C World

    If the hardware is so great.. why use software to correct it..?? It will only slow it down..
    Al is de hardware nog zo snel de software achterhaalt het wel

  11. #11
    Join Date
    May 2004
    Posts
    94

    Re: usb to serial question

    I have 1 serial port(rs 232) of 2 ports on the mobo of the pc.
    for some reason the black box example does not find any com port while windows tells me that they are there.
    this same thing happened to me, I know I have 1 available port but note of the samples can detect them.

  12. #12
    Join Date
    Oct 2003
    Location
    .NET2.0 / VS2005 Developer
    Posts
    7,104

    Re: usb to serial question

    and would you believe i currently have the same problem with my pc; the modem on com3 works fine, anything attached to com1 doesnt appear to exist, and com4 is listed as in use, but no device is assigned to it. nothing but issues ever since i upgraded this pc.. i tell you
    "it's a fax from your dog, Mr Dansworth. It looks like your cat" - Gary Larson...DW1: Data Walkthroughs 1.1...DW2: Data Walkthroughs 2.0...DDS: The DataSet Designer Surface...ANO: ADO.NET2 Orientation...DAN: Deeper ADO.NET...DNU...PQ

  13. #13
    Join Date
    Oct 2003
    Location
    .NET2.0 / VS2005 Developer
    Posts
    7,104

    Re: usb to serial question

    Quote Originally Posted by rycerz
    this same thing happened to me, I know I have 1 available port but note of the samples can detect them.
    javax.comm is installed correctly, yes? note that sun's install instructions are wrong.. see the instructions i wrote to mikeBarr81 on here for proper installation guide
    "it's a fax from your dog, Mr Dansworth. It looks like your cat" - Gary Larson...DW1: Data Walkthroughs 1.1...DW2: Data Walkthroughs 2.0...DDS: The DataSet Designer Surface...ANO: ADO.NET2 Orientation...DAN: Deeper ADO.NET...DNU...PQ

  14. #14
    Join Date
    Nov 2004
    Posts
    1

    Re: usb to serial question

    Hey guys. I'm new to your forum, but have done some things with serial port comm in java, and in about 15 minutes am going to start a USB-Serial project.

    For Java straight to Serial, I used the javax.comm classes, which seem to work great. My program talks directly to a satellite demodulator that sends rs-232 data that my program constantly listens to.

    For my USB-Serial program, I'll be listening to weather data coming directly from our weather station (like a davis weather station with all of the wind instruments, temps, etc.) via serial port to my USB adapter.

    Some things to look at: http://java.sun.com/products/javacom...ers_guide.html
    http://developer.java.sun.com/develo...impleRead.java

    Any serial/comm communication is difficult in Java... it seems to be abandoned except for those who really need to use it. It's even fairly difficult to Print in Java. These are just areas that aren't as popular so they don't seem to be as advanced as a lot of other areas.

    The SimpleRead.java example is probably your best source for just seeing how they did it. It took a massive amount of modification, as you would probably expect, to get it to play with the rest of my program, though.

    Watch your threading too... I had big problems at first because I had a massive amount of data to organize, decode, unzip, put into databases, etc. Those processes ended up hanging up and stopping my serial data reading process...

    Good Luck!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured