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)
Wednesday, June 19, 2013
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.
Labels:
.NET,
.net compact,
Bluetooth,
c#,
MC75A,
mobile development
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;
}
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;
}
Labels:
.NET,
.net compact,
BeginRead,
BeginWrite,
Bluetooth,
c sharp,
c#,
EndRead,
EndWrite,
read,
serial communications,
stream,
write
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!
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!
Labels:
code,
config,
configuration files,
development,
Visual Studio
Saturday, February 16, 2013
Great day for snowshoeing the Blue Hills
SC and I went for a nice hike today. The conditions were great for snowshoeing. It was snowing and temps were still warm. It was quite a good workout the shoes would go a few inches into the heavy snow.
Glad we got out there to enjoy the hills and no rain, just fluffy snow. APRS track ends before our hike does because of antenna issues.
Glad we got out there to enjoy the hills and no rain, just fluffy snow. APRS track ends before our hike does because of antenna issues.
Labels:
Blue Hills,
Hiking Journal,
outdoors
Friday, February 8, 2013
metronome
I'm discovering that practicing with a metronome is relaxing. When your thoughts being to wonder, the next click syncs you back into the task at hand.
Within a practice session will bump it up 2 BPM so to keep expanding.
Within a practice session will bump it up 2 BPM so to keep expanding.
Subscribe to:
Posts (Atom)




