November 13, 2009, 10:27 pm
I got my first Arduino a few days ago, but it wasn’t until today that I managed to get down to the local electronics store to buy a few bits to connect to it. This simple project is the result.

It’s been a long time since a dozen lines of code has put a smile on my face like this did tonight.
October 20, 2009, 12:19 pm
I have just been looking at the Arduino kits you can buy on-line. They remind me of those 150 in 1 electronic kits you could get when I was a kid.
The question is, how do I get my wife to agree that they would make a good present for one of the kids? Her argument will be that I am one of the kids which is difficult to disagree with.
April 7, 2009, 2:53 pm
The WMI performance counters on Windows have a timestamp value in the field “Timestamp_Sys100NS”. To convert this to a more useable datetime use follow this example code:
epoch = datetime.datetime( 1601, 1, 1, 0, 0, 0 )
wmic = wmi.WMI( find_classes = False )
pd = wmic.Win32_PerfRawData_PerfOS_Processor( Name = "_Total" )[0]
ts = epoch + datetime.timedelta( microseconds = pd.Timestamp_Sys100NS / 10.0)
February 18, 2008, 2:49 pm
After cloning a virtual machine running Ubuntu Server 7.10 I found that it didn’t have any network available. Restarting networking gave:
sudo /etc/init.d/networking restart
* Reconfiguring network interfaces...
eth0: ERROR while getting interface flags: No such device
SIOCSIFADDR: No such device
eth0: ERROR while getting interface flags: No such device
SIOCSIFNETMASK: No such device
SIOCSIFBRDADDR: No such device
eth0: ERROR while getting interface flags: No such device
eth0: ERROR while getting interface flags: No such device
Failed to bring up eth0.
The problem lies in the fact that ethernet MAC addresses are cached. You need to remove a file to clear the cached value:
sudo rm /etc/udev/rules.d/70-persistent-net.rules
After a restart of your server you should have networking back again.
I also had to edit the following files to change the static ip addresses and hostname:
/etc/hosts – change ip address and hostnames
/etc/hostname – change hostname
/etc/network/interfaces – change ip address
January 28, 2008, 11:42 am
My previous post on CasPol is great for ordinary shares, but for DFS it doesn’t work. To solve this you need to add your share into the LocalIntranet zone by doing this:
caspol -machine -addgroup "LocalIntranet_Zone" -url "file:///<dfs share path>" FullTrust
January 25, 2008, 10:35 am
Blogs are great for jotting down the usage of commands that you use very rarely. This posting is one of these cases. (This is actually the second time I have made this note, but the first one got lost in wiki that was destroyed some time ago.)
The issue I had was that on a new machine I got the following error when running some .net code from a network share:
An unhandled exception of type 'System.Security.SecurityException' occurred in mscorlib.dll
After a little searching a remembered the answer. It was to use caspol like this:
caspol -machine -chggroup Internet_Zone FullTrust
November 21, 2007, 3:45 pm
Today I wanted to add, update and delete virtual directories on a number of IIS servers.
To connect to the IIS servers I use:
import win32com.client
locator = win32com.client.Dispatch( 'WbemScripting.SWbemLocator' )
server = locator.ConnectServer( server_name, 'root/MicrosoftIISv2' )
server.Security_.authenticationLevel = 6 # wbemAuthenticationLevelPkt
Then to add a virtual directory called ‘name’ that maps to directory called ‘directory’ you need:
vdir_class = server.Get( "IIsWebVirtualDirSetting" )
vdir_settings = vdir_class.SpawnInstance_()
vdir_settings.Name = 'W3SVC/1/ROOT/' + name
vdir_settings.Path = directory
vdir_settings.Put_()
To update a virtual directory you need:
vdir_settings = server.Get( "IIsWebVirtualDirSetting='%s'" % ( 'W3SVC/1/ROOT/' + name ) )
vdir_settings.Path = directory
vdir_settings.Put_()
Finally, to delete a virtual directory you need:
vdir = server.Get( "IIsWebVirtualDirSetting='%s'" % ( 'W3SVC/1/ROOT/' + name ) )
vdir.Delete_()
September 26, 2007, 2:07 pm
I have had a Dell 690 Workstation for a while now. It originally came with a pair of dual core Xeon processors, but some time ago Intel were kind enough to send me a pair of quad core Xeons, 2.66GHz X5350’s to be precise. I replaced the original processors with these new ones and everything worked fine until yesterday.
Yesterday I decided to upgrade the BIOS on the 690 from version A01 to A06. The Dell download worked fine and upgraded the BIOS but rebooting resulted, after the POST messages, in a message saying “Incompatible processor detected!” and a halted system! This was not good. I couldn’t even get into the BIOS setup with F2.
The trick to getting it working again was to remove the button cell battery on the motherboard for a minute or so and then replace it. When you power on the machine you will be asked to go into setup and set the date and time. After doing this my machine would boot with A06. The problem is that if you ever remove the power cable, or switch off at the wall, then your 690 won’t boot again and it will give the “Incompatible processor detected!” message again. I found this out the hard way. So while I had a working machine I downloaded the A01 version of the BIOS from ftp.us.dell.com and installed it. After this my machine is fully functional again. I don’t have the time at the moment to do a test of all BIOS versions between A01 and A06 to see where the problem starts.
August 13, 2007, 10:21 am
Using the SolidWorks API with Python is not as easy as it should be.
Generating modules from the type libraries is easy enough with makepy:
makepy.py sldworks.tlb
makepy.py swconst.tlb
As is using these to start up SolidWorks.
from win32com.client import gencache,Dispatch
from win32com.client import constants
sldworks = gencache.EnsureModule('{83A33D31-27C5-11CE-BFD4-00400513BB57}', 0, 15, 0) # sw2007
swconst = gencache.EnsureModule('{4687F359-55D0-4CD3-B6CF-2EB42C11F989}', 0, 15, 0) # sw2007
sw = sldworks.SldWorks( Dispatch( 'SldWorks.Application' ) )
But you soon hit problems when you want to open a model with OpenDoc6. This code:
model, errors, warnings = sw.OpenDoc6( 'cube.sldprt', constants.swDocPART, constants.swOpenDocOptions_Silent, '' )
triggers this exception:
pywintypes.com_error: (-2147352561, 'Parameter not optional.', None, None)
The problem turns out to be that the method generated with makepy has incorrect default values. In the definition below Errors and Warnings should have deafult values of pythoncom.Missing.
def OpenDoc6(self, FileName=defaultNamedNotOptArg, Type=defaultNamedNotOptArg, Options=defaultNamedNotOptArg, Configuration=defaultNamedNotOptArg, Errors=defaultNamedNotOptArg, Warnings=defaultNamedNotOptArg):
To fix this I have used the Python introspection methods to rewrite the default arguments.
import pythoncom
import new
method = getattr( sldworks.ISldWorks, 'OpenDoc6' )
arg_list = list( method.func_defaults )
arg_list[ -1 ] = pythoncom.Missing
arg_list[ -2 ] = pythoncom.Missing
new_function = new.function( method.func_code, method.func_globals, method.func_code.co_name, tuple( arg_list ) )
new_method = new.instancemethod( new_function, None, sldworks.ISldWorks )
setattr( sldworks.ISldWorks, 'OpenDoc6', new_method )
I have created a generic method that could be used to fix up more than just OpenDoc6. You can download it here: swfix.py It is used like this:
from win32com.client import gencache,Dispatch
from win32com.client import constants
from swfix import fix_swtlb
sldworks = gencache.EnsureModule('{83A33D31-27C5-11CE-BFD4-00400513BB57}', 0, 15, 0) # sw2007
swconst = gencache.EnsureModule('{4687F359-55D0-4CD3-B6CF-2EB42C11F989}', 0, 15, 0) # sw2007
fix_swtlb( sldworks )
sw = sldworks.SldWorks( Dispatch( 'SldWorks.Application' ) )
Currently it only fixes OpenDoc6, but I hope to include other methods over time. Of course help in doing this is most welcome.
August 11, 2007, 12:28 pm
I have my iPhoto library on a NFS mounted volume. In iPhoto ‘06 this worked fine. After upgrading to iLife ‘08, iPhoto would no longer open, giving me this error message:
The iPhoto Library is locked, on a locked disk, or you do not have permission to make changes to it.
It turned out that I did not have rpc.statd or rpc.lockd running on my FreeBSD NFS server. After I started these I was able to start iPhoto.