com0com Fork

I've been using com0com a bit lately and it's proved to be very useful. However the source doesn't appear to have been touched in quite a long time, and it still uses make and other gross stuff from way back. I have forked com0com (including com2tcp and hu4com) and made nice shiny new Visual Studio 2013 projects for everything (including the kernel mode drivers) and put everything on GitHub for all to enjoy.  I have even gone to the trouble of purchasing an Authenticode Certificate and have published signed binaries.  Hopefully I'll get round to creating a nice WiX installer but I remember the last time I did battle with WiX I came out a shell of a human.

| Posted in Software | No Comments »

Virtual Serial Ports, com0com, RFC2217, and Radio

Tunneling com ports over tcp, and in particular over low bandwidth radio links can be a tricky business. Even more so if you are on windows and want to use free or preferably open source software. Recent work I've been involved in has required that many devices with different and proprietary protocols (all serial in nature) be tunneled over a udp radio connection from a Windows server to the client device.  The image below demonstrates the conecpt.

Read the rest of this entry »


Autolisp part II - convert drawing to grayscale skeleton

For my second Autolisp job, I was tasked to convert a drawing to a grayscale skeleton so that it could be used as a background for additional drawings.  This is typical of floor plans that are developed by one company, then another company overlays electrical, air conditioning or other building services over top of the floor plan.

Read the rest of this entry »

| Posted in Software | No Comments »

The case of the files that wouldn't upload to OneDrive

I've been uploading man photos to OneDrive lately, and I ran into a couple of files that just refused to upload, with OneDrive saying that there was already a file with that name, when there definitely wasn't.  A quick check with Uncle Google didn't reveal anyone else that seemed to be having quite the same problem.  So I tried a  couple of things:

  1. Rename the file. Nope.
  2. Edit the file in paint (in case of some hash based index thing).  Nope.
  3. Change the filename and edit the file in case of a caching issue. Nope.

At this point I concluded that there must be some particular part of the file, possibly metadata of some sort that OneDrive really didn't like.  So I removed all EXIF, XMP and other metadata from the file, and bingo! It uploaded no problem.  A closer look at the data revealed something interesting, there was a tag called 'fffffffffffffffff' and an XMP people tag ''.  Odd.  I opened up the file in Picasa, and indeed the tag is there, but I don't see the people tag.  However, in Photo Gallery the people tag shows up!  Deleting the rogue people tag in Photo Gallery allows the photo to be uploaded.

It turns out, that if you remove an automatically detected face in Picasa, then go and convert all the people tags to XMP using  avpicfacexmptagger it will also convert that previously hidden tag.  It is these tags that OneDrive has a problem with, so one must be vigilant when converting people tags to XMP that you delete these hidden faces!


| Posted in Software | No Comments »

A foray into AutoLISP

I was recently asked by a friend to write a couple of AutoLISP routines that would offset a polyline in both directions, and change a few styles along the way. The problem is easiest defined visually:


This was to be my second experience writing lisp (after my experience with GIMP scripts), so I knew the language concepts and syntax already.  Initially I tried to get away with command macros; unfortunately these have no ability to store objects (as far as I could tell) and if you can't do what you want by running a sequence of AutoCAD commands it seems you're pretty much out of luck.

The entire function is as follows:

;;double offset with offset line style change
(defun C:doffset(/ pickEnts pickEnt offset i n)
  (if (setq pickEnts (ssget '((0 . "LWPOLYLINE"))))       ;select polylines
    (setq offset(getreal "\n Offset: "))                  ;store offset
    (setq i 0 n (sslength pickEnts))
    (while (< i n)
     (setq  pickEnt (ssname pickEnts i))                  ;get the next polyline from the selection
     (setq i (1+ i))
     (setq pickObj (vlax-EName->vla-Object pickEnt))   ;convert entity to object
     (vla-Offset pickObj offset)                          ;offset in one direction
     (command "_change" "l" "" "p" "LT" "ZIGZAG" "")
     (vla-Offset pickObj (- offset))                      ;offset in the other direction
     (command "_change" "l" "" "p" "LT" "ZIGZAG" "")
     (command "_change" pickEnt "" "p" "LT" "ACAD_ISO07w100" "")
     (command "_pedit" pickEnt "w" (* offset 2) "")       ;change the pline width (twice the original offset)
   )                                                      ;progn
   (princ "No object selected!\n")                      
  )                                                       ;endif
  (princ)                                                 ;clean exit (supresses echo)

All in all this lisp business seems to be a quick and easy way to automate some of the more tedious AutoCAD jobs.

| Posted in Software | No Comments »

batch scripting with GIMP on windows

I recently had the need to create a script to resize a large number of images (overwriting the original files).  I thought this should be straight forward using GIMP.  It was and it wasn't...

My nightmare started with learning lisp.  Lisp seems to be pretty straightforward once you get the hang of it.  In the few hours it took me to get the hang of it, my feathers got rather ruffled at having to keep track of so many parentheses and caddrdacadrar's.  Lisp wasn't the only tricky bit.  The GIMP documentation on how to register functions, and if you need to register them, and so on is so fragmented and confusing that I'm surprised anyone manages to write one of these damn script things at all.

Anyway, I worked it out, and here it is:

(define (batch-image-resize-width pattern width)
  (let* ((filelist (cadr (file-glob pattern 1))))
    (while (not (null? filelist))
      (let* ((filename (car filelist))
          (image (car (gimp-file-load RUN-NONINTERACTIVE filename filename)))
          (drawable (car (gimp-image-get-active-layer image))))
        (gimp-image-scale-full image width (/ (car (gimp-image-height image)) (/ (car (gimp-image-width image)) width)) INTERPOLATION-CUBIC)
        (file-jpeg-save RUN-NONINTERACTIVE image drawable filename filename 0.8 0 1 1 "" 0 0 0 1)
        (gimp-image-delete image)
      (set! filelist (cdr filelist))

    SF-STRING "pattern" "pattern"
    SF-VALUE  "width" "width"

The batch file I use to run this bad boy is:

"c:\Program Files\GIMP 2\bin\gimp-console-2.8.exe" -i -b "(batch-image-resize-height \"*.jpg\" 300)" -b "(gimp-quit 0)"

I should note that I am obviously running Windows here (GIMP 2.8), and apparently that some of this stuff is slightly different on Linux.

| Posted in Software | No Comments »

Bypassing MiCOM S1 Studio password

MiCOM S1 Studio is a program for programming power system protection relays. This post outlines how the password protection feature can be bypassed, in the case that it mysteriously starts asking for a password that it never used to like it did for me...



I know that S1 Studio is largely written in .NET, so lets try reflection to see what gives:
Read the rest of this entry »

| Posted in Software | 8 Comments »

Autonumbering Title Blocks in AutoCAD

Several people seem to have had this problem (going by the number of posts on the internet about it), but I didn't really find a satisfying solution.  After spending half a day on the problem, I think I have come up with something useable.

First, lets outline the problem:  Normally, along the top of a title block we have a column numbers (for referencing purposes).  Say there are 20 columns per drawing.  In a multisheet drawing, we want the first sheet to go from 1 to 20, the second from 21 to 41 and so on.  You can do this easily by editing your block each time and changing the numbers, but this is tedious...

First we need to create a table for our column numbers.  My title block is 400 units wide, so I have a table 400 wide, with one row and 20 columns of 20 units each.  In the second column, enter the formula "=A1 + 1".  Drag this across all the columns so each one increments from the previous cell (so now you should have a blank first cell, then 1 to 19 in the others).autocad-autonum3
Read the rest of this entry »

| Posted in Software | No Comments »

Moving Outlook 2013 profiles to a new PC

This ought to be straightforward, however there is no export feature built in to Outlook 2013. The common advice out there is to copy all your data files (.pst extension) and recreate all your account profiles manually.  This seems like a fairly average solution - especially if you have many accounts.

You can can easily export your profile data from the registry - just export the key HKEY_CURRENT_USER\Software\Microsoft\Office\15.0\Outlook\Profiles.  The problem then comes when you try to match up the data files to the newly imported accounts.  Even if you change the folder using the change folder button (below) to the correct data file, Outlook will sometimes not associate the account with your data file, giving you the error "data file cannot be accessed" when you try to send/recieve.

outlook change folder

The trick is to create a new data file and associate your account with the inbox of the new data file.  Then change it back to your original pst, and everything should work - no recreating of account profiles necessary!


| Posted in Software | No Comments »

On video formats

On a trip recently my friends and I recorded video on a few different devices, all of which used several different video formats.  We ended up with the following flavours:

MTS, x264, 50fps (interlaced), 1440x1080 (Effective ratio 1920x1080)
MP4, x264, 25fps (progressive), 1440x1080 (Effective ratio 1920x1080)
MP4, x264, 30fps (progressive), 1920x1080

We wanted to join all the clips together in movie maker, but unfortunately Windows Movie Maker is not that good at making all these different flavours look the same when they are run together - some are smooth (ish), some are noticeably more jagged and so on.

I first decided on a common format that I would try to convert all the video to.  The obvious choice for codec is x264, and MP4 is also the container of choice these days.  Frame size would stay at 1920x1080, and the video would be progressive (as all screens these days are progressive in nature).  The only real decision was frame rate.  Naturally the 50fps video looked smoothest, and was noticeably staggered once resampled at 25fps.  In the end I decided to convert everything to 50fps.  For the MTS video, this was straightforward using Avidemux with  yadif and scaling filters:

adm = Avidemux()
adm.videoCodec("x264", <omitted>)
adm.addVideoFilter("yadif", "mode=1", "order=1")
adm.addVideoFilter("swscale", "width=1920", "height=1080", "algo=2", "sourceAR=1", "targetAR=1")
adm.addVideoFilter("resampleFps", "mode=0", "newFpsDen=1000", "newFpsNum=50000")
adm.audioCodec(0, "LavAAC");
adm.audioSetDrc(0, 0)
adm.audioSetShift(0, 0,0)
adm.setContainer("MP4V2", "optimize=0", "add_itunes_metadata=0")

Avidemux can be used for batch processing quite easily, just save the project file and remove the lines at the top of the project file that load the video and set the markers (else we end up cutting longer videos short!). Then we need a batch or powershell script to pass all the files we want to process, I used the following:

set avidemux="C:\Program Files\Avidemux 2.6\avidemux.exe"
for %%f in (*.MTS) do %avidemux% --force-alt-h264 --load "%%f" --run MTS2MP4.py --save "%%f.mp4" --quit

Next up I needed a way to convert the 25 and 30fps video to 50fps.  There seems to be two ways to do this - either fill the gaps with the existing frames, or predict the intermediate frames based on the frames either side.  Filling the gaps is not going to make the video any smoother, so I opted for the latter.  MeGui is the tool that gets the job done here - it uses AviSynth to do the heavy lifting (see http://mewiki.project357.com/wiki/Main_Page).  The Avisynth script I used:

PluginPath = "C:\Program Files (x86)\MeGUI\tools\avisynth_plugin\"
InterFrame(Cores=4, NewNum=50000, NewDen=1000)
LanczosResize(1920, 1080)

I was pleasantly surprised with the results from this - the video looked much smoother, and the process introduced few artefacts.  With all the video in the same format, we can now import  into WMM and get a nice consistent frame rate in the output.

| Posted in Software | No Comments »