January 5, 2012

Red Friday

I never knew there's such a thing as Red Friday as opposed to Black Friday. But here it is.


Most things are roughly 10% off, equivalent to the Black Friday sale in countries that celebrate Thanksgiving.

January 4, 2012

Fixing lock up on SerialPort.Close()


Earlier this year I bought several Arduino boards to do some hardware interfacing and programming. It all worked out pretty well excep the part where the application locks up completely.

The Arduino connects to the computer using USB, but it emulates a serial port, it's really easy to communicate with the Arduino using the standard SerialPort Class in Visual Basic 2008, but the application sometimes locks up when I'm done using the serial port and attempt to close it. A Google search reveals hundreds of other people facing the same issue, and apparently no easy solution. So after some head banging, I found that the trick was to put the SerialPort.Close() method into a thread, and also handle the I/O exception that sometimes happens. See below for code.

Instead of just closing the port, I created a thread:
Dim t As New Thread(AddressOf ClosePort)
t.Start()
And put the actual Close() method into a subroutine:

Public Sub ClosePort ()    SerialPort1.Close()End Sub

In the subroutine that handles DataReceived events, I added an exception handler:
Private Sub SerialPort1_DataReceived(ByVal sender As System.Object, ByVal e As System.IO.Ports.SerialDataReceivedEventArgs)
    On Error Resume Next
    Me.Invoke(New myDelegate(AddressOf updateTextBox), New Object() {})
End Sub
In this example, the subroutine invokes the updateTextBox subroutine, which does a ReadLine on the serial port and sends the captured data to a textbox.

It's obvious by now that because SerialPort.Close() sometimes waits on DataReceived and the UI, so just closing the port when that occurs hangs the application. By putting SerialPort.Close() into a new thread, instead of the application hanging, the DataReceived event started giving exceptions due to the port being closed, so handling the exception fixed that issue. At first I tried removing the event handler, but that only reduced the frequency of the exceptions, but did not completely get rid of it. Using an exception handler was probably best, but also see disclaimer below.

Disclaimer: I'm not a programmer, and this may not be the best way or even the right way to solve the serial port lock up issue, but it works for me.

December 26, 2011

WRT54GL vs. H2O


This is the PCB of a good old Linksys WRT54GL that was completely submerged for approximately one month during the Great Thailand Flood of 2011. Oh, the router was actually placed on a desk, the water level was much much higher than that.

My domain and database servers were all safe since they were on the second floor, but I had to evacuate them (by boat) to another site, which I'll write in detail the next time. Computers that were on the ground floor were all dead, either directly by water or rusted by the humidity. Some I could actually salvage the hard drives or CPU's since the water level was lower, others were completely underwater.

October 24, 2011

Server evacuation

I'm stuck in the middle of the Great Thailand Flood of 2011. My entire factory was flooded, and I had to evacuate my server backups to a safe and dry place.

A few years ago, when I was writing policies for SOX compliance, there was a section about risk assessment and business continuity planning, and one of the issues was how to resume operations in case of fire or flood or other acts of God. Who would've thunk that after less than four years, everything I wrote has to be put into actual usage?

So, we were evacuated out to a nearby hotel with free Wi-Fi, and all the managers are connected to the free Wi-Fi, and then they need printing. So I went back to the flooded factory and took out (by boat) a trusty Linksys WRT160NL and a Canon inkjet printer. Previously I talked about using the WRT160NL to share USB printers, but this is slightly different since I don't actually have a LAN any more.

It turned out to be quite easy, I just joined the WRT160NL to the hotel's free Wi-Fi by using client bridge, then used Angry IP Scanner to find a free IP address outside of what I think is the normal DHCP range, and then I just pointed everyone's printer to the new IP address of the WRT160NL, and then we got printing.


While setting things up, I suddenly lost Wi-Fi connectivity, and I called the hotel's front desk to ask them to reset the Wi-Fi, and they told me the only Wi-Fi they have is down at the lobby, and it was working perfectly. I ended up having to find a maid on my floor to ask her if she has ever seen a little box with blinking lights, and she pointed me to a Linksys WAP54G. I simply power cycled the access point and all was fine again.

October 6, 2011

RIP Steve


When I was growing up, the first computer I ever used was the Apple ][. (And yes, I have to write II like that.) Even though when I finally saved enough money to buy my own Apple ][, somehow I ended up with a Commodore 64, but the Apple ][ always had a special place in my heart, and I totally admired Apple's founders.

Of course, being the young geek and future engineer that I was, Steve Jobs was always "the other Steve" to me. Fast forward thirty years, I guess few people these days even know of Woz except for us engineer types and students of computer history. It's all about Steve Jobs and his Apple Empire. But I still totally admire the two Steves and what they have done.

Rest in peace.

September 15, 2011

Virtual Windows 8

I installed Windows 8 Developer Preview in VirtualBox. I normally use VMware, but for some reason it didn't work with VMware, so I tried installing it in VirtualBox and it worked, er, out of the box.

The setup is simple and somewhat faster than Windows 7.



I'm installing Windows 8 the minute it's released. The reason? The up arrow returns!