Tuesday, August 20, 2013

92 F

Had to take the day off.  When the tough chore was completed, I road the local compressed woodlands of the city.  Total of Two main loops and 4 inner loops around sailors.  92 degrees.  I have not rode in that type of heat in a while.  I started off slow, but still sprinted up some of the hills and kept pedaling hard.

Tuesday, August 6, 2013

Conditional Breakpoint Exaple in Visual Studio 2010

I was looking for a few bad HL7 messages by control ID in this processor that we're coding.  Here's one way to get the debugger to stop on a break point on condition.  In this case I set up a bool that is set to True when any of the control IDs come into the main loop.  Add a breakpoint.  Right click on this breakpoint and select Condition.  Type in the name of the bool that you have set up and select Is True radio option.




Wednesday, June 19, 2013

Cleaner code with SQL Coalesce

ver 1.

if @runDate != null
  set @rd = CONVERT(VARCHAR(10),@runDate,101)
else
  set @rd = CONVERT(VARCHAR(10),getdate(),101)

set @rd = replace(@rd,'/','')



ver 2.

set @rd = replace(CONVERT(VARCHAR(10),COALESCE(@runDate,getdate()),101),'/','')


Coalesce takes in a list of values,  it will return the first non null value.

I also wrapped the replace call around the results of the convert statement.


More on MSDN: COALESCE (Transact-SQL)

Thursday, June 6, 2013

Sorting by last modified date of files







 private static void GetFileDates()
        {
            DirectoryInfo di = new DirectoryInfo(_path);
            FileSystemInfo[] files = di.GetFileSystemInfos();
            var orderedFiles = files.OrderBy(f => f.LastWriteTime);
            FileSystemInfo first = (FileSystemInfo)orderedFiles.First();
            FileSystemInfo last = (FileSystemInfo)orderedFiles.Last();

            _startDate = first.LastWriteTime.ToString();
            _stopDate = last.LastWriteTime.ToString();

           
        }

Friday, May 31, 2013

Bluetooth Chat Screens

For learning I put together a Bluetooth chat client.  I used sample code from the InTheHand examples to get this to work.  

I decided to store devices in a config file instead of trying to discover clients.  The discovery takes too much time on these devices.  Another advantage of storing Bluetooth addresses in a config file is these devices can remain in non discovery mode. 

I can send the source code to anyone interested.  

thanks.





Friday, May 17, 2013

Asynchronous write and read using InTheHand 32Feet Bluetooth serial communications

With the connection all ready opened:


public class MyAsyncInfo
        {
            public Byte[] ByteArray { get; set; }
            public Stream MyStream { get; set; }

            public MyAsyncInfo(Byte[] array, Stream stream)
            {
                ByteArray = array;
                MyStream = stream;
            }
        }

        private void CASMonitor_SendData()
        {
            byte[] data = new byte[4];
            data[0] = 0x58;
            data[1] = 0x30;
            data[2] = 0x39;
            data[3] = 0x0D;


            try
            {
                stream.BeginWrite(data, 0, data.Length, WriteComplete, null);
            }
            catch (Exception ee)
            {
                MessageBox.Show("Error: Sending, Verify Bluetooth Connection");
            }
        }

        private void WriteComplete(IAsyncResult ar)
        {
            try
            {
                stream.EndWrite(ar);

                byte[] DeviceBuffer = new byte[100];
                DeviceBuffer.Initialize();

                Stream DeviceStream = null;
                DeviceStream = btClient.GetStream();
                DeviceStream.Flush();

                DeviceStream.BeginRead(DeviceBuffer, 0, DeviceBuffer.Length, DeviceReadComplete, new MyAsyncInfo(DeviceBuffer, DeviceStream));

            }
            catch (Exception ex)
            {
                MessageBox.Show("write error");
            }
        }

        private void DeviceReadComplete(IAsyncResult r)
        {
            int numbytes = 0;
            MyAsyncInfo info = r.AsyncState as MyAsyncInfo;

            try
            {
                numbytes = info.MyStream.EndRead(r);
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error: Readcomplete ex " + ex.Message);

                return;
            }

            string msg = System.Text.Encoding.Default.GetString(info.ByteArray, 0, numbytes);

            if ((info.ByteArray[0] == 'X') && (info.ByteArray[1] == '0') && (info.ByteArray[2] == '9') && (numbytes == 24))
            {
                ProcessDataProc(msg, numbytes);
            }
            else
            {
                if (_retryCnt < 3)
                {
                    CASMonitor_SendData();
                    return;
                }
            }

            return;
        }

Wednesday, March 13, 2013

“These are not the quotes you are looking for”

I wasted a few hours trying to get WSE 3.0 enabled for VS 2010 / VS 2012.

I followed the steps to a blog post on how to enable the above. Lots of frustration as the steps were exactly followed but VS would crash upon start up.

Lucky my co-worker helped out.  I explain now. The last step to get WSE enabled is to add a few lines to a config file. I pasted these lines right from the blog.

My coworker noticed on a print out of these config lines looked off.

The quotes in a config file have to be the ones that go straight up and down like this "

The quotes that I had pasted from the blog were word processor type, they were slanted like this:
  “ ”

These slanted quotes are a completely different character than the normal quote. This is enough to choke your config file!

So next time everything looks right but stuff is still not working, and you had cut n paste something into a config file, double check for the correct quotes!