Saturday, April 26, 2008

RXTX and the funky PortInUseException on Macosx

I am using the RXTX serial libs for getting data out of my gps. They always worked nice, but the first time I tried them on Macosx they didn't work, throwing this ugly:

gnu.io.PortInUseException: Unknown Application

Since the thing worked from commandline:
>>> cat /dev/tty.touchGPS-SSP-1
$GPGGA,172025.233,2500.0001,N,12159.9999,E,0,0,,80.9,M,16.1,M,,*7D
$GPGSA,A,1,,,,,,,,,,,,,,,*1E
$GPGSV,1,1,00*79
$GPRMC,172025.233,V,2500.0001,N,12159.9999,E,0.00,0.00,260408,,,N*77
$GPVTG,0.00,T,,M,0.00,N,0.00,K,N*32... etc etc

I was pretty helpless. Then I found in some mailinglist archive the solution. To cite the guy that solved my problem: "As I've discovered the PortInUseException rarely has anything to do the port being in use. For reasons I don't understand RXTX is not using /var/spool/uucp for lock files. It's using /var/lock. A directory that didn't exist on my system. Once I created this directory I started getting different errors for the RXTX code. This directory requires read/write permissions for the user. I just used the blanket chmod 777."


Nothing to add, tried it and it worked.






UPDATE as of Saturday 4th of April 2009:


As a nice anonymous user comments, these are the steps to go:
  1. Open 'Terminal' from Applications->Utilities
  2. Enter the commands:
sudo mkdir /var/lock   (hit enter end type your password)
sudo chmod 777 /var/lock (hit enter again)

19 comments:

Anonymous said...

Thanks a lot - this really saved us a lot of headache! Works like a charm. Now to figure out how the @*"$($ install4j will create this for our rxtx enabled application :(

Anonymous said...

Thanks! This helped a lot!

Anonymous said...

Man, you saved my life and my graduation.
Thank you.

Anonymous said...

Oh, I've just forgotten. I would like to make this post easier for who those aren't very familiar with unix commands.
1) Open 'Terminal' from Applications->Utilities
2) Enter the commands:
sudo mkdir /var/lock (hit enter end type your password)
sudo chmod 777 /var/lock (hit enter again)
3) It's done! Good luck.

moovida said...

:) Thanks anonymous (come guys leave your name), I will update the post directly with your lines.

Anonymous said...

Thanks a lot!

Unknown said...

Well done sir! Any idea why mac os x doesn't include this directory by default?

Anonymous said...

Man, i have the same problem but in windows. Could you give some help.

Unknown said...

Under Snow Leopard it seems not to work anymore. Processing throws exactly this PortInUseException when compiling code which adresses the serial port. What i don`t get is that Arduino IDE exactly does adressing the serial port but it works quiet well.
But why 2 hell it doesn't work with some other processing snippets. I created the lock folder and tried some "changepermission"-stuff by adding to group __uucp but it doesn't work :-(

some suggestions?
Help would be highly appreciated ;-)
Andi

Anonymous said...

Thank you a lot :-) . After 9 hours I found your Site and the solution of my problem.

BlackSheep said...

Thanks for the TIP, now my Serial COM driver works!

Riley Porter said...

Great! This fixed my "unknown application" error when trying to grab ahold of the port in code. This is a real pain. Any thoughts as to how to "distribute" this fix with my application to my users?

psuhas said...

Thanks for the great TIP, searched for 2 days and found this out!

Anonymous said...

thank u guys , it's worked for me after taste a couple of coffee ... :-)

Anonymous said...

many thanks!

Anonymous said...

Many thanks!!! Worked for me too!

Anonymous said...

Many thanks!!! Worked for me too!

Steven said...

This was very, very helpful, thanks!

Anonymous said...

You are saving projects for 4 years hahah... Tkx