4

HI! I want to interface PIC18F4550 with Java program and make it cross-platform initially. There are only one way I now Java has is javacomm. But i want it to be USB because not every laptop has RS232 port nowadays. Waht are the ways of interfacing PIC with Java you can suggest to make it really cross-platform and avoid writing driver for every new OS?

starblue
  • 55,348
  • 14
  • 97
  • 151
Dmytro Leonenko
  • 1,443
  • 5
  • 19
  • 30
  • If you know, let me know because I have faced similar problems in the past too. I've resorted the MPLab ICD2 (i think). – Buhake Sindi Feb 26 '10 at 08:03

4 Answers4

2

First the disclaimer: I have not done this with a PIC and Java, only with an AVR32B with VB on the pc.

If you implement a USB CDC class device on the microcontroller USB interface and connect it to your pc USB HOST it will enumerate and appear as a new COM: port. This is then treated by the application as a normal serial port. I used the standard windows driver USBSER.SYS.

I presume that microchip provide example source code for their USB peripheral to allow it to operate in different device classes. (I know that Atmel do for the AVR32 families)

uɐɪ
  • 2,540
  • 1
  • 20
  • 23
  • +1 good answer - you should always look to interface as high up the software stack as you can, rather than trying to explicitly work at the USB level. – Paul R Feb 26 '10 at 08:58
2

Why did you accept the answer above? I agree with @Ian's comment there.

The PIC18F4550 and its friends have onboard USB. It is easy and there are plenty of examples out there to put a virtual serial port in the PIC firmware. Another other is an HID device, again plenty of PIC firmware examples.

Don't add more hardware to the pudding.

kenny
  • 21,522
  • 8
  • 49
  • 87
1

Arduino's approach should be adaptable to your needs: a microcontroller with hardware UART coupled with a FTDI USB-to-TTL chip, then use rxtx to access the resulting serial port on "100+" platforms.

This approach seem to work well: communicating and programming the arduino is very easy under Linux, Windows, and OS X.

freespace
  • 16,529
  • 4
  • 36
  • 58
  • 1
    This would be a bit of a waste of money/board real estate as the PIC used here has its own built-in USB 2.0 controller. – uɐɪ Feb 26 '10 at 09:20
  • Very-very interesting project! Never heard about it! – Dmytro Leonenko Feb 26 '10 at 09:46
  • @Ian: agreed. Though I feel I should point out I described arduino's approach as an example of such a setup, not as a formulae for @melco-man to follow. A combination of your answer with mine would yield an optimal answer. – freespace Feb 26 '10 at 10:32
  • I agree with @Ian and @freespace, this is *not* the way to do it, this time with that processor. – kenny Feb 28 '10 at 13:27
1

You need to use JNI to make calls to the WIN32API directly. I was using JNA (JNI wrapper) library to make the implementation easy and made a DLL to export easier and direct methods in Visual C++ 2010. You can also create other libraries (DLL/SO) using the same interface to other systems like OSX and Linux.