Friday, 29 January 2010

Editing PDFs - insert images etc

This is a bit of a dirty trick but you can use Foxit's PDF editor in evaluation mode to edit a PDF doc (i.e. add images) and then save it and use PDFedit to remove the evaluation messages - however I can't condone this trick...

Thursday, 28 January 2010

Mingw and Visual Studio

Mingw is a great environment for building stuff on Windows especially for apps that came from UNIX environments. It provides a gcc compiler for Windows that links directly against the Windows libraries (as opposed to Cygwin that uses an intermediate library to achieve compatibility).

If you're working on projects that combine Mingw and Microsoft's Visual Studio environment (VS2008 etc) then here are a few things that are useful to know:
  • How to get Mingw/Msys to pick up or import VS environment (e.g. for include paths etc):
    • Add the line below (change version of VS if necessary) to C:\MinGW\msys.bat
      • Call "C:/Program Files/Microsoft Visual Studio 9.0/Common7/Tools/vsvars32.bat"
  • How to add other tools to the path for Mingw/Msys (e.g. Collabnet's svn):
    • Add the line below to /etc/profile (within msys) or C:\MinGW\etc\profile:
      • export PATH="/c/Program Files/CollabNet/Subversion Client:$PATH"

Thursday, 21 January 2010

Messing with WxPython

I've been playing with Wx Python on OSX and it's not bad for knocking things up. Trying to find out how to do certain things has taken a while - when you just can't find the right search term! Here's a couple of things that I'd been trying to do:
  • Mini sliders/widgets - On OSX Cocoa/Carbon there's some neat small sliders

    • You can enable them on OSX (only) by using this method (there is also a MINI size):
  • Multiple display/screen or multi-monitor info - like how many displays and what resolution/size are they?

    • Find out info using the wxDisplay() class - e.g. wx.Display.GetCount() tells you how many displays are connected - as seen here.
  • WxPython on Snow Leopard - you need to enable 32-bit python - do it in either of these two ways:

    • defaults write Prefer-32-Bit -bool yes

Tuesday, 12 January 2010

Using Python for SD84 Servo/Robot controller

I've been playing with an SD84 board which uses 4 x PIC18F2520 chips to provide control for up to 84 servos (and/or analogue/digital input/output). I wanted to use Python on OSX but there are others out there who have used C (see the sd84lib). I've updated this article enough that I thought I repost it with a newer date.

The SD84 also uses a chip from FTDI which provides for the USB-serial interface. FTDI are a company based in Scotland that make a range of chips  e.g. FT232R used in Robot Electronic's SD84, and the Arduino.

Firstly you need to get the FTDI VCP drivers for OSX 10.5 (there are also drivers for Windows and Linux) - I found that the FTDIUSBSerialDriver_v2_2_9.dmg worked better than the latest 2.2.10 version (though there are now newer ones which may well work ok). Initially I installed the 2.2.10 version but firstly the kernel module didn't load when I plugged in the SD84, nor would it load manually (complaining of "can't add kernel extension /System/Library/Extensions/FTDIUSBSerialDriver.kext (not a bundle)") - I tried some suggestions here to no avail. I fixed it by uninstalling that version and cleaning up according to here - also removing my old pl2303 drivers, as mentioned here:
sudo rm -rf /System/Library/Extensions/FTDIUSBSerialDriver.kext \
/System/Library/Extensions.kextcache \
/System/Library/Caches/* \
/Library/Receipts/FTDIUSBSerialDriver.* /Library/Receipts/osx-pl2303-10.4.* \
I then did a clean install of the 2.2.9 package and rebooted then the drivers just loaded when I plugged in the SD84 - you should see a message about FTDI drivers loading in dmesg, and you should also see the driver instantiate the appropriate device nodes - e.g. /dev/tty.usbserial-XXXX.

There are also FTDI's D2XX drivers which are apparently supported by the Python pyusb module (not sure diff with this one) but I haven't tried them yet - though they potentially provide for better performance. It seems that these can also be used for JTAG based debugging.

I then used Python pyserial module (installed on OSX from ports using sudo port install py-serial, or you can download pyserial package and then run: sudo python install in the unpacked directory) to control an SD84 - the basics are (which will work on Linux as well, and windows if you replace'/dev/tty.usbserial-A2001mJE' with 'COM3') :
import serial
# Open Serial port to FTDI usb serial tty
ser = serial.Serial('/dev/tty.usbserial-A2001mJE', baudrate=115200, byte
size=8, parity='N', stopbits=2,timeout=1)
# Send GET_VERSION command
# Read the returned version and print
print "VERSION:"+ver
# set SERVO mode
#Read return code (should be \x00 if all is well)

There's also other places with useful info here on OSX and serial setup.
[written on 15/9/9 updated 23oct09, 12jan09]

Friday, 8 January 2010

Accessing OSX install DVD from Linux/Ubuntu

Have you ever tried sticking your Mac [Snow] Leopard/Tiger OSX installation DVD/CD disks into a Linux box and just found a measly little windows partition there with the BootCamp stuff on it, and wondered where all the Mac stuff was hiding? Yeah so have I.

This is how to copy the disk using the dd command (you can do virtually the same thing on OSX - here's an article with some more info):
dd if=/dev/sr0 of=/DVDcopy.iso
For older versions of *NIX (which used to use '-if/-of'):
dd -if=/dev/sr0 -of=/DVDcopy.iso 

However whilst Ubuntu doesn't understand - it is all there just hiding... This handy site explained a way to get to it - directly on DVD. You can use your DVDcopy.iso in the same way. You'll probably need to install the tool (e.g. aptitude install kpartx). On your Linux box you do:
#sudo kpartx -av /DVDcopy.iso
add map loop0p1 (252:0): 0 60 linear /dev/loop0 4
add map loop0p2 (252:1): 0 2020420 linear /dev/loop0 64
add map loop0p3 (252:2): 0 13158216 linear /dev/loop0 2020488
add map loop0p4 (252:3): 0 12 linear /dev/loop0 15178704

Then use file to find out which partition contains the Mac stuff - run file on each one till you find one that says it's an Macintosh HFS e.g:
sudo file -s /dev/mapper/loop0p3
/dev/mapper/loop0p3: Macintosh HFS Extended version 4 data last....

The mount it and you're away:
sudo mount /dev/mapper/loop0p3 /my_mount

You should now be able to see the contents of the Mac (HFS+) partition in the directory /my_mount

Tuesday, 5 January 2010

Handy iPhone apps

Happy New Year to all! Well I thought I'd list a few apps I've found to be handy on the iPhone - all free apart from two:
  • Fring - Gives you a consolidated VoIP solution (SIP, Skype, and others) with offline notifications (some might say it's too consolidated - maybe Fring are run by the Spooks?!)
  • MobileRSS - The best free Google Reader with good offline and un/subscribing support
  • Twitterific - A nice Twitter app for keeping an eye on all that chattering with support for un/subscribing and stuff
  • OffMaps ($) - A very handy (and very reasonably priced) maps app that uses OpenStreetmap/cloudmade data with good offline support
  • Discover - Useful app for storing random stuff on the iPhone (works over wifi and acts as web server)
  • Touchterm ($) - A useful and cheapish ssh client
  • RjDj - A cool app that generates 'music' using 'patches' - based upon Pure-Data
  • MrMr - An OSC app for whacky control applications