Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

USB listening  RSS feed

 
ibrahim yener
Ranch Hand
Posts: 202
Android Java PHP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello to all.

I have a task which i have to achieve. I am trying to listen socket with a certain port with java as long as program runs.

PC is connected to a PIC card which controls various devices. So this PIC is connected to PC via USB and send sensor values to PC
every 3 minutes.

How can i listen USB port?

I have searched many internet sources and most of them is related with IP address listening.

I am trying to use javacomm library but there is a lot of negative comments about it such as portability
My pc (where program runs and listen USB) is Windows 7 64 bit.

Thanks for any help and advice.
 
Paul Clapham
Sheriff
Posts: 22185
38
Eclipse IDE Firefox Browser MySQL Database
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Normally when you connect a device to a USB port in a Windows machine, you need a device driver for the device. This driver allows Windows to understand the connected device in some way. And normally Windows will look around for a driver when you connect the device, even to the point of getting a driver from the web if it recognizes the device.

A USB port is not a TCP/IP port, so there is no way to connect to it via a socket. Neither is a USB port a serial port, so you can't use the Javacomm library to connect to it either.

Apparently various people have tried to write general Java code to work with USB ports (Google it: java usb) but from what I can see they all became basically dead several years ago. None of them really looked like production quality and you'd have a very difficult time doing anything useful with them, I think.

My guess is that you would be better off trying to interface with the device's driver, rather than directly with the USB port. But that could be difficult too -- I'd suggest talking to the manufacturer or distributor of the device to see what tools they have to offer.
 
ibrahim yener
Ranch Hand
Posts: 202
Android Java PHP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear Paul
Thanks for quick response.

PIC card is building by another team. I am going to ask them either write a driver or communicate over tcp/ip.
I guess TCP option is too difficult because PIC cards works stand alone and only communication with outside of world is through my java application.

I am going to search google as you suggested hope to find something useful.

I guess even serial port needs driver for communication right?
 
Paul Clapham
Sheriff
Posts: 22185
38
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ibrahim yener wrote:I guess even serial port needs driver for communication right?


Not exactly, people who wrote telephony applications for Windows would just connect directly to a serial port and transmit data. But Windows PCs haven't been manufactured with serial ports for several years now, ever since people stopped using dial-up modems to access the web.
 
ibrahim yener
Ranch Hand
Posts: 202
Android Java PHP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So, do you mean that i can communicate my java desktop application with PIC through serial port without installing a driver?
If yes, can i still use javacomm library?
If not, what do yo suggest?

Thanks for anwer.
 
Paul Clapham
Sheriff
Posts: 22185
38
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Not unless they design the PIC device to plug into a serial port. But I understood you to say that it was designed to connect vis USB.
 
ibrahim yener
Ranch Hand
Posts: 202
Android Java PHP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, they are design and develop item to plug into usb port.
I just have sent a request to PIC teams and waiting answer.
 
Tim Holloway
Bartender
Posts: 18531
61
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I've actually been looking as talking to PIC myself, but I don't have the requisite hardware yet. I already do something similar to that on the Arduino.

If I don't have it confused with one of the other hardware development IDEs I use, I think the Arduino designer is itself a Java application.

To program many of the stock Arduinos is trivial, since the stock circuit cards come with a USB connector on them that can be used with a generic USB cable with a mini-male terminator like my old cellphones used to use.

For some of the more specialized devices I have, there's no direct connection via USB, but I got myself a FTDI cable. It plugs into the USB port on the PC and has a 4-connector plug on the other end, I think it does some sort of voltage level shifting.

At any rate these devices register with the OS as stock serial comm devices. And there's definitely a PIC interface, because I've been shopping.
 
ibrahim yener
Ranch Hand
Posts: 202
Android Java PHP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have got the answer from PIC developer team and they said they are going to connect PIC to pc via USB/Serial converter.
In that case pc recognize USB port as Serial port.

With this information what you suggest to communicate with?
RTXT is the best solution?
does javacomm can be alternate?

Regards
 
Tim Holloway
Bartender
Posts: 18531
61
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Paul Clapham wrote:
ibrahim yener wrote:I guess even serial port needs driver for communication right?


Not exactly, people who wrote telephony applications for Windows would just connect directly to a serial port and transmit data. But Windows PCs haven't been manufactured with serial ports for several years now, ever since people stopped using dial-up modems to access the web.


Actually, that's not really true. My latest set of motherboards still has hardware serial ports on them. However, you have to buy your own cable to connect to it - the motherboards no longer have DB-9 connectors welded to them. In fact, I do have a machine where I have such a cable installed. It talks to an ancient (pre-USB) UPS device using questionably protocols so I don't trust a USB-to-serial converter to handle its quirks.

The primary difference between the old DOS pcs and something like Windows 10 when it comes to serial devices is that when Windows 95 and XP came out, the serial ports were virtualized. Because many programs did direct port-level I/O on the serial and parallel ports. But the higher-level device drivers remain the same and they're still there. In fact, the DOS-device drivers are still used for serial-over-USB, as far as I know.
 
Paul Clapham
Sheriff
Posts: 22185
38
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ibrahim yener wrote:With this information what you suggest to communicate with?
RTXT is the best solution?
does javacomm can be alternate?


I haven't used that sort of thing since about 2001. Why can't you just try both of them and see which of them works better, or which of them work?
 
ibrahim yener
Ranch Hand
Posts: 202
Android Java PHP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Paul Clapham wrote:
I haven't used that sort of thing since about 2001. Why can't you just try both of them and see which of them works better, or which of them work?

Thanks for reply. I will check both of them as you suggest and will let you guys know the result.
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!