# Tuesday, March 29, 2005

You're probably aware that using dumpbin.exe is very useful if you need to P/InvokedumpbinGUI.exe is a tool that I've been using for years that you might be interested in.  It adds a simply context menu to the Windows shell, so you can right click any DLL or LIB and view it's exports (among other things).

The install leaves a bit to be desired.  You have to have a dev tool installed, and you must modify your path to allow dumpbinGUI to find a couple files.  If you have Studio 2003 installed in the default location, add these to your system path:

C:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\bin
C:\Program Files\Microsoft Visual Studio .NET 2003\Common7\IDE

Tuesday, March 29, 2005 5:47:42 AM (Central Standard Time, UTC-06:00)  #     | 
# Friday, March 25, 2005

For those of you who may ever need to interface to a DS1307 I2C real time clock (it would wourk for the 1306 SPI RTC as well) here's a useful class.

private class RTCTime
{
 private byte[] m_bytes = new byte[7];
 
 public RTCTime()
 {
 }
 public RTCTime(byte[] data)
 {
  m_bytes = data;
 }
 public RTCTime(DateTime dateTime)
 {
  this.Second = dateTime.Second;
  this.Minute = dateTime.Minute;
  this.Hour = dateTime.Hour;
  this.Day = dateTime.Day;
  this.Month = dateTime.Month;
  this.Year = dateTime.Year;
 }
 public static implicit operator byte[](RTCTime rtc)
 {
  return rtc.m_bytes;
 }
 public static implicit operator RTCTime(byte[] bytes)
 {
  return new RTCTime(bytes);
 }
 public static explicit operator DateTime(RTCTime rtc)
 {
  return new DateTime(rtc.Year, rtc.Month, rtc.Day, rtc.Hour, rtc.Minute, rtc.Second, 0);
 }
 public int Second
 {
  get { return BCD_TO_WORD(m_bytes[0]); }
  set { m_bytes[0] = WORD_TO_BCD(value); }
 }
 public int Minute
 {
  get { return BCD_TO_WORD(m_bytes[1]); }
  set { m_bytes[1] = WORD_TO_BCD(value); }
 }
 public int Hour
 {
  get { return BCD_TO_WORD(m_bytes[2]); }
  set { m_bytes[2] = WORD_TO_BCD(value); }
 }
 public int DayOfWeek
 {
  get { return BCD_TO_WORD(m_bytes[3]); }
  set { m_bytes[3] = WORD_TO_BCD(value); }
 }
 public int Day
 {
  get { return BCD_TO_WORD(m_bytes[4]); }
  set { m_bytes[4] = WORD_TO_BCD(value); }
 }
 public int Month
 {
  get { return BCD_TO_WORD(m_bytes[5]); }
  set { m_bytes[5] = WORD_TO_BCD(value); }
 }
 public int Year
 {
  get { return BCD_TO_WORD(m_bytes[6]); }
  set { m_bytes[6] = WORD_TO_BCD(value); }
 }
 public int Length
 {
  get { return m_bytes.Length; }
 }
 private int BCD_TO_WORD(byte x)
 {
  return (x & 0x0f) + ((x >> 4) * 10);
 }
 private byte WORD_TO_BCD(int x)
 {
  return (byte)((x % 10) + ((x / 10) * 0x10));
 }
}
Friday, March 25, 2005 10:36:30 AM (Central Standard Time, UTC-06:00)  #     | 
# Saturday, March 12, 2005

Pocket PC magazine has published an article by Mick Badran of Breeze Training that uses the SDF (though they called it the Smart Device Extensions - remember back when the CF was called that?).  An online version is available here.

Saturday, March 12, 2005 3:53:55 PM (Central Standard Time, UTC-06:00)  #     | 
# Thursday, March 10, 2005

A transmission rate of 10 Mbps implies that each bit is sent in 0.1 microseconds. For a coaxial cable, the speed at which the signal travels along the cable is approximately 0.77 times the speed of light (3.0E8 m/s). A bit therefore occupies 23 meters of cable. That means the smallest frame would be 13.3 km long.

For those who no longer use 10-baseT and gave up coax for twisted pair years ago, propagation speed in twisted pair is much slower - roughly 0.59 times the speed of light.  I'll let you do the math for a frame.

Thursday, March 10, 2005 9:48:07 PM (Central Standard Time, UTC-06:00)  #     | 

So I'm in the process of writing a couple classes that wrap a stream interface driver.  Specifically I'm writing a class for a PCA9555 I2C chip, which inherits from a generic I2C class that inherits from the StreamInterfaceDriver class.  I come the the Read function and I realize that as the data parameter I have to pass a byte array, but the actual driver I'm talking to wants this to be a structure.  To make it more fun the structure contains a pointer to a byte array, so the struct is 16 bytes, 4 of which are a pointer to an array of unmanaged data.

To make a long story short, I ended up writing a new Read function in the I2C class that hides the base version so I can manage the unmanaged data.  Well I then needed to call the FileEx.ReadFile function, which needs a port handle.  The handle is a private member of StreamInterfaceDriver - oops, guess I didn't consider this in my original base class design.  Fortunately the SDF is shared source, so time from bug detection to when the publicly available code was fixed (making it protected) was about 2 minutes. 

If you've got customers concerned about using 3rd-party libraries I'd think examples like this would help ease their fears.

Thursday, March 10, 2005 3:58:11 PM (Central Standard Time, UTC-06:00)  #     |