May 27, 2011

Getting sharper while falling in love with .Net Micro Framework

After many years of programming in AVR-GCC I decided to make the leap to .Net Micro Framework.

Why?

  1. I develop in C# everyday, I’m really really good at it.
  2. I’m tired of digging through data sheets setting registers!
  3. I want to use GOOD tools like Visual Studio!
  4. One word… BREAKPOINTS.image
  5. I’m tired of penny pinching RAM. Getting fast write time to FAT is really difficult on Arduino and kills half your RAM at least.
  6. Events rock.

Now, if someone wants something in C on AVR I am more than happy to oblige. I am developing a few things using LUFA as of late, but I’m going to start concentrating on learning .Net Microframework.

Projects I’m considering

  1. Porting all RockSat-X code to C#.
  2. ADB / ADK bridge for .Net Micro Framework.
  3. .Net MicroFramework Oscilloscope

Things I ‘m hoping to see fixed in future .Net MF.

  1. .Net support for analog ports. Everyone has their own implementation making writing emulators for analog REALLY HARD.
  2. Compiled mode and Interpreted mode. The JIT compilation engine is amazing. Understandably it wont fit on MF but why can’t my comp compile and spit down pure machine code rather than interpreting line by line.

A final note. I really think these could be a good option for education. Many schools teach programming and teach C#

May 18, 2011

Matlab,C# and DynamicObject a perfect marriage!

I am using an old version of matlab (7.5). I have been porting some code to C# but I wanted to make sure my plots were correct. After writing _m.Execute about 10 times I decided to write a wrapper for plot. I quickly started needing many commands and thought, there has to be an easier way. What if we can write code like this in C#?

static void Main(string[] args)
{
dynamic m = new Matlab();
m.cd(Environment.CurrentDirectory);
m.close();
m.clear();
m.figure(1);
m.plot(new double[] { 1, 2, 3 }, new double[] { 3, 1, 3 });
m.title("plot title");
var z=m.zeros(2,100);
var o = m.ones(2, 100);

}

Well in fact you can if we do some dancing! First, get familiar with the wonderful class that Microsoft built called DynamicObject. This class allows us to dynamically dispatch calls anywhere we want, in our case, MATLAB. We get the call to TryInvokeMember. From there we use the binder to tell us what we are doing and then we execute it. There is still along way for this project to go, but for now, I’ve got C# friendly code calling matlab!


using System.Text;
usingSystem.Dynamic;

namespaceMatlabExtensions
{
    public classMatlab : DynamicObject
  
{
        MLApp.MLApp _a;
        publicMatlab()
        {
            _a = newMLApp.MLApp();
        }

        public override bool TryInvokeMember(InvokeMemberBinder binder, object[] args, out objectresult)
        {
            StringBuilder command = newStringBuilder();
            command.Append(binder.Name);
            command.Append("(");
            int idx = 0;
            foreach (var arg inargs)
            {
                stringvar = string.Format("arg{0}", idx++);
                _a.PutWorkspaceData(var, "base", arg);
                command.Append(var);
                command.Append(",");
            }

            stringexec = command.ToString();
            exec = exec.TrimEnd(',') + ")";
            _a.Execute(exec);
            try
          
{
                result = _a.GetVariable("ans", "base");
            }
            catch{ result = null; }
           
            return true;
        }
    }
}

A small note, you will need to reference the matlab com library.


image

Nov 1, 2010

this.slTimeOfDeath=DateTime.Now;

this.slCauseOfDeath=Microsoft.Politics;

The internet has been a buzz this week over what has been interpreted as the end of Silverlight http://team.silverlight.net/announcement/pdc-and-silverlight/ .

While people may be reading into this more than it is, one thing seems apparent, Silverlight will not be coming to more platforms like Android, IOS, or a Microsoft supported Linux distribution.

So is Silverlight dead? In short NO, it will linger and maybe even excel on Microsoft platforms. Is the dream of Silverlight dead? YES.  In my eyes Silverlight was the ultimate expression of .Net goals, cross language, cross platform.  With the cross platform piece shrinking and dying my dream of what Silverlight could be and what it could do is gone.

What this really is, is the Windows and IE team taking care of business and banishing the most beautiful thing to supporting WP7.  If the Windows and IE team have that much power what else will they decide to take shots at?

Sadly from a business perspective, I can’t say what Microsoft is doing is bad business. Sure its not good to tick off devs and drop a product, but why keep paying for a product that causes political tension inside and outside Microsoft. Why not go with the flow, repurpose your assets and commit to what the world is telling you they want, HTML5.

So where do we go from here? Well being a developer who got the rug pulled out from under me, I’m starting to think PHP and Jscript, or maybe Node.Js! 

If WP7 doesn’t take off, this is all a moot point anyway, I definitely won’t be buying stocks in Microsoft until their 3 screen strategy is achieved and profitable.

Jan 3, 2010

Silverlight 4 Communicating with Matlab

I have taken it on myself to try and expand and inspire people’s view of what a web application can do.  In this installment I’m leveraging Silverlight 4 and Matlab to build a simple Matlab console.

Again I am using COM automation to communicate with Silverlight.  Why would anyone want to do this? Well, I’m slowly porting some Matlab code to c# so it is nice to check my code by communicating with Matlab.  Matlab also has an insane amount of its own functions so if you wanted to build a neural network but use Silverlight to display and distribute your code then Silverlight 4 is for you!

using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Interop;

namespace SLMatlab
{
public partial class MainPage : UserControl
{
dynamic matlab;
public MainPage()
{
InitializeComponent();
input.IsEnabled = false;
output.IsEnabled = false;
Install.Visibility = Visibility.Collapsed;
if (Application.Current.InstallState != InstallState.Installed)
{
MessageBox.Show("To run this, this application must be installed, Please click install.");
Install.Visibility = Visibility.Visible;
Connect.IsEnabled = false;
}
else if (!Application.Current.IsRunningOutOfBrowser)
{
MessageBox.Show("This application is installed but is running inside the browser. Please launch this from the desktop!");
Connect.IsEnabled = false;
}
}

private void Connect_Click(object sender, RoutedEventArgs e)
{
try
{
matlab = ComAutomationFactory.CreateObject("Matlab.Application");
matlab.Visible = 0;
input.IsEnabled = true;
output.IsEnabled = true;
}
catch { }

}

private void input_KeyDown(object sender, KeyEventArgs e)
{
try
{
if (e.Key == Key.Enter)
{
dynamic result = matlab.Execute(input.Text);
input.Text = "";
output.Text = result.ToString() + Environment.NewLine + output.Text;
}
}
catch { }
}

private void Install_Click(object sender, RoutedEventArgs e)
{
App.Current.Install();
}
}
}



<UserControl x:Class="SLMatlab.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="400">

<
Grid x:Name="LayoutRoot" Background="White">
<
Grid.RowDefinitions>
<
RowDefinition Height="Auto"></RowDefinition>
<
RowDefinition Height="Auto"></RowDefinition>
<
RowDefinition Height="Auto"></RowDefinition>
<
RowDefinition Height="*"></RowDefinition>
</
Grid.RowDefinitions>
<
Button Name="Install" Content="Install" Grid.Row="0" Click="Install_Click"></Button>
<
Button Name="Connect" Content="Connect" Grid.Row="1" Click="Connect_Click"></Button>
<
TextBox Name="input" Grid.Row="2" KeyDown="input_KeyDown"></TextBox>
<
TextBox Name="output" Grid.Row="3"></TextBox>
</
Grid>
</
UserControl>


Dec 24, 2009

Twitter->SL4->Arduino Light Controller

This is a preliminary post about a new project I just finished (a variation of CoffeeTrack). I wanted to test the new capabilities of Silverlight 4 and push the boundaries of what people think of as a web application.  I made a point to not have a server portion of my application.  This application only requires SL4 and a COM library (trying to avoid).

I wanted to be able to control my lights from the internet.  This system takes twitter posts (now possible in SL4) and interprets them as commands and commands the Arduino via COM automation. Once a command is received the web cam snaps a photo and posts that to twitter to confirm the results.

The Arduino code is DEAD simple. The Arduino is linked to a wireless light controller found at Walmart for $10. I found one online that is similar.  I used relays to close the switches.

image

const int ledPin1 = 13; // the pin that the LED is attached to
const int ledPin2 = 12; // the pin that the LED is attached to

int incomingByte;      // a variable to read incoming serial data into

void setup() {
  // initialize serial communication:
  Serial.begin(9600);
  // initialize the LED pin as an output:
  pinMode(ledPin1, OUTPUT);
  pinMode(ledPin2, OUTPUT);
}

void loop() {
  // see if there's incoming serial data:
  if (Serial.available() > 0)
  {
    // read the oldest byte in the serial buffer:
    incomingByte = Serial.read();
   Serial.println((char)incomingByte);
   if (incomingByte == '0') {
      digitalWrite(ledPin1, HIGH);
      delay(1000);
      digitalWrite(ledPin1, LOW);
      Serial.println("Lights are off");
    }
    else if (incomingByte == '1') {
      digitalWrite(ledPin2, HIGH);
      delay(1000);
      digitalWrite(ledPin2, LOW);
      Serial.println("Lights are on!");
    }
  }
}

 

The Silverlight 4 code is a combination of many, many different libraries. I was able to successfully talk to twitter as long as I ran as an out of browser application (dumb client access policy).  I used the FJCore library to encode images to Jpeg. Special thanks to VisiFire for some helpful code using FJCore. I spent about 3 days working with the code from this post (which works in a Console App).  Once I figured out how the encodings worked I was able to update a photo on twitter via Silverlight.  The rest of the code I stole from CoffeeTrack (stay tuned!).

using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.IO;
using System.Xml.Linq;
using System.Text;
using System.Threading;
using System.Windows.Threading;
using System.Net.Browser;
using System.Windows.Media.Imaging;
using FluxJpeg.Core.Encoder;
using FluxJpeg.Core;

namespace XmasLightController
{
public partial class MainPage : UserControl
{
DispatcherTimer t = new DispatcherTimer() { Interval = new TimeSpan(0, 1, 0) };
byte[] currentImage = null;
string value = "";
public MainPage()
{
InitializeComponent();
t.Tick += new EventHandler(t_Tick);
//t.Start();
MakeRequest();
//UpdateTwitterImage();

}

void t_Tick(object sender, EventArgs e)
{
MakeRequest();

}


private void MakeRequest()
{
HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(new Uri("http://twitter.com/statuses/user_timeline/uwstephens.atom?&count=1"));
request.BeginGetResponse(new AsyncCallback(ReadCallback), request);
WriteText("Contacting twitter");
}


int currentcommand = 0;


private void ReadCallback(IAsyncResult asynchronousResult)
{
this.Dispatcher.BeginInvoke(delegate()
{
t.Stop();

});
WriteText("Recieved response from twitter");
HttpWebRequest request = (HttpWebRequest)asynchronousResult.AsyncState;
HttpWebResponse response = (HttpWebResponse)request.EndGetResponse(asynchronousResult);
using (StreamReader streamReader1 = new StreamReader(response.GetResponseStream()))
{

string resultString = streamReader1.ReadToEnd();
XDocument doc = XDocument.Parse(resultString, LoadOptions.SetBaseUri | LoadOptions.SetLineInfo);
List<XElement> elems = doc.Elements("entry").ToList();
StringBuilder sb = new StringBuilder();
int oldcommand = currentcommand;
foreach (var a in doc.Descendants().ToList())
{
if (a.Name.LocalName == "entry")
{
if(value!=a.Value)
{
UpdateTwitterImage();
}
value=a.Value;
if (a.Value.ToLower().Contains("action"))
{
currentcommand = 1;
}
else if (a.Value.ToLower().Contains("cut"))
{
currentcommand = 2;
}
else if (a.Value.ToLower().Contains("snap"))
{
currentcommand = 3;
}
}
}

this.Dispatcher.BeginInvoke(delegate()
{
if (currentcommand == 1)
{
WriteText("Start command received");

input.Text = "1";
SendMessage();
UpdateTwitterImage();

}
else if (currentcommand == 2)
{
WriteText("Stop command received");
input.Text = "0";
SendMessage();
UpdateTwitterImage();

}

});

this.Dispatcher.BeginInvoke(delegate()
{
t.Start();
});

}

}

public void WriteText(string txt)
{
this.Dispatcher.BeginInvoke(delegate() { this.outputWindow.Text += Environment.NewLine + txt; });
}

public void UpdateTwitterImage()
{
WriteText("Updating image");
if (currentImage == null) { return; }
String avatarUrl = "http://twitter.com/account/update_profile_image.xml";
String file = "xmas";
string imageType = "png";
WebRequest.RegisterPrefix("http://", System.Net.Browser.WebRequestCreator.ClientHttp);
string contentBoundaryBase = DateTime.Now.Ticks.ToString("x");
string beginContentBoundary = string.Format("--{0}\r\n", contentBoundaryBase);
var contentDisposition = string.Format("Content-Disposition:form-data); name=\"image\"); filename=\"{0}\"\r\nContent-Type: image/{1}\r\n\r\n", file, imageType);
var endContentBoundary = string.Format("\r\n--{0}--\r\n", contentBoundaryBase);

byte[] fileBytes = null;
Encoding encoding = Encoding.UTF8;

MemoryStream test = new MemoryStream();
byte[] data = encoding.GetBytes(beginContentBoundary);
test.Write(data, 0, data.Length);
data = encoding.GetBytes(contentDisposition);
test.Write(data, 0, data.Length);
data = currentImage;
test.Write(data, 0, data.Length);
data = encoding.GetBytes(endContentBoundary);
test.Write(data, 0, data.Length);
fileBytes = test.GetBuffer();

var req = (HttpWebRequest)HttpWebRequest.Create(new Uri(avatarUrl, UriKind.Absolute));
req.ContentType = "multipart/form-data;boundary=" + contentBoundaryBase;
req.AllowReadStreamBuffering = true;
req.Method = "POST";

req.UseDefaultCredentials = false;
req.Credentials = new NetworkCredential("uwstephens", "-");
File.WriteAllBytes(@"C:\Users\michael\Documents\test.txt", fileBytes);
req.BeginGetRequestStream(delegate(IAsyncResult result)
{
Stream reqStream = req.EndGetRequestStream(result);
reqStream.Write(fileBytes, 0, fileBytes.Length);
//reqStream.wr(fileBytes, 0, fileBytes.Length);
reqStream.Close();
req.BeginGetResponse(delegate(IAsyncResult result1)
{
WriteText("Image updated");
if (req.HaveResponse)
{
try
{
WebResponse resp = req.EndGetResponse(result1);
WriteText(resp.Headers["status"]);
}
catch (Exception e) { WriteText(e.Message); }
}
}, req);

}, null);
}

VideoCaptureDevice webcam = null;
CaptureSource captureSource = null;
private void loadCamera_Click(object sender, RoutedEventArgs e)
{
webcam = CaptureDeviceConfiguration.GetDefaultVideoCaptureDevice();

if (CaptureDeviceConfiguration.RequestDeviceAccess())
{
captureSource = new CaptureSource();
captureSource.VideoCaptureDevice = webcam;
captureSource.Start();
captureSource.AsyncCaptureImage(snap);
}
}

public void snap(WriteableBitmap b)
{

currentImage = GetImageStream(b).GetBuffer();
webcamImg.Source = b;
File.WriteAllBytes(@"C:\Users\michael\Documents\test\test.png", currentImage);
captureSource.AsyncCaptureImage(snap);

}


/// <summary>
///
Reads raster information from WriteableBitmap
/// </summary>
/// <param name="bitmap">
WriteableBitmap</param>
/// <returns>
Array of bytes</returns>
public static byte[][,] ReadRasterInformation(WriteableBitmap bitmap)
{
int width = bitmap.PixelWidth;
int height = bitmap.PixelHeight;
int bands = 3;
byte[][,] raster = new byte[bands][,];

for (int i = 0; i < bands; i++)
{
raster[i] = new byte[width, height];
}

for (int row = 0; row < height; row++)
{
for (int column = 0; column < width; column++)
{
int pixel = bitmap.Pixels[width * row + column];
raster[0][column, row] = (byte)(pixel >> 16);
raster[1][column, row] = (byte)(pixel >> 8);
raster[2][column, row] = (byte)pixel;
}
}

return raster;
}

/// <summary>
///
Encode raster information to MemoryStream
/// </summary>
/// <param name="raster">
Raster information (Array of bytes)</param>
/// <param name="colorSpace">
ColorSpace used</param>
/// <returns>
MemoryStream</returns>
public static MemoryStream EncodeRasterInformationToStream(byte[][,] raster, ColorSpace colorSpace)
{
ColorModel model = new ColorModel { colorspace = ColorSpace.RGB };
FluxJpeg.Core.Image img = new FluxJpeg.Core.Image(model, raster);

//Encode the Image as a JPEG
MemoryStream stream = new MemoryStream();
FluxJpeg.Core.Encoder.JpegEncoder encoder = new FluxJpeg.Core.Encoder.JpegEncoder(img, 100, stream);
encoder.Encode();

// Back to the start
stream.Seek(0, SeekOrigin.Begin);

return stream;
}

/// <summary>
///
Get image MemoryStream from WriteableBitmap
/// </summary>
/// <param name="bitmap">
WriteableBitmap</param>
/// <returns>
MemoryStream</returns>
public static MemoryStream GetImageStream(WriteableBitmap bitmap)
{
byte[][,] raster = ReadRasterInformation(bitmap);
return EncodeRasterInformationToStream(raster, ColorSpace.RGB);
}

dynamic com;

private void serialConnect_Click(object sender, RoutedEventArgs e)
{
com = System.Windows.Interop.ComAutomationFactory.CreateObject("ActiveXperts.ComPort");
dynamic count = com.GetDeviceCount();
StringBuilder sb = new StringBuilder();

com.Device = "COM1";
com.Open();
MessageBox.Show(com.GetErrorDescription(com.LastError));
string buffer = "";
System.Threading.Thread t = new Thread(new ThreadStart(delegate()
{

while (1 == 1)
{
com.Sleep(200);
buffer = com.ReadString();
if (buffer == "") { continue; }
serialOutput.Dispatcher.BeginInvoke(delegate()
{
serialOutput.Text += "\r\n" + buffer;
});
}
}));
t.Start();
}



void SendMessage()
{
if (com != null)
{
foreach (char c in input.Text)
{
com.WriteByte((byte)c);
}
input.Text = "";
}
}

private void input_KeyUp(object sender, KeyEventArgs e)
{
if (e.Key == Key.Enter)
{
SendMessage();
}
}

}

}

Dec 12, 2009

Silverlight talking to Arduino

This is an initial rough post, but I have managed to get Silverlight 4 beta talking to an ActiveXperts COM+ interface that talks to an Arduino over a serial connection.

Here is my first attempt to do a video of it. Looks like I’m going to need to learn how to make a screencast.

 

 

image

 

The C# code.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Windows.Interop;
using System.Text;
using System.Threading;

namespace TestSerial
{
public partial class MainPage : UserControl
{
public MainPage()
{
InitializeComponent();
}

private void button1_Click(object sender, RoutedEventArgs e)
{
if (App.Current.InstallState == InstallState.NotInstalled)
{
App.Current.Install();
}
}
dynamic com;
private void button2_Click(object sender, RoutedEventArgs e)
{

com=ComAutomationFactory.CreateObject("ActiveXperts.ComPort");
dynamic count = com.GetDeviceCount();
StringBuilder sb = new StringBuilder();

List<dynamic> devices = new List<dynamic>();
for(int i=1;i<=9;i++)
{
devices.Add("COM" + i);
}

for (int i = 0; i < count; i++)
{
devices.Add(com.GetDevice(i));

}
devicelst.ItemsSource = devices;

}

private void button3_Click(object sender, RoutedEventArgs e)
{
//string device = devicelst.SelectedItem.ToString();
if (devicelst.SelectedItem == null) { MessageBox.Show("Please pick a port"); return; }
com.Device = devicelst.SelectedItem.ToString();
com.Open();
MessageBox.Show(com.GetErrorDescription(com.LastError));
string buffer = "";
System.Threading.Thread t = new Thread(new ThreadStart(delegate()
{

while (1 == 1)
{
com.Sleep(200);
buffer = com.ReadString();
if (buffer == "") { com.Close(); return; }
tb.Dispatcher.BeginInvoke(delegate()
{
tb.Text += "\r\n" + com.ReadString();
});
}
}));
t.Start();
}


}
}
 
The Xaml.
<UserControl x:Class="TestSerial.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="400">

<
Grid x:Name="LayoutRoot" Background="White">
<
Grid.ColumnDefinitions>
<
ColumnDefinition></ColumnDefinition>
<
ColumnDefinition></ColumnDefinition>
<
ColumnDefinition></ColumnDefinition>
</
Grid.ColumnDefinitions>
<
Grid.RowDefinitions>
<
RowDefinition Height="Auto"></RowDefinition>
<
RowDefinition Height="Auto"></RowDefinition>
<
RowDefinition></RowDefinition>
</
Grid.RowDefinitions>
<
Button Content="Install" Height="23" HorizontalAlignment="Left" Name="button1" VerticalAlignment="Top" Width="75" Click="button1_Click" Grid.Row="0"/>
<
Button Content="Get Devices" Height="23" HorizontalAlignment="Left" Name="button2" VerticalAlignment="Top" Width="75" Grid.Row="1" Click="button2_Click"/>
<
ComboBox Name="devicelst" Grid.Row="1" Margin="1,0,0,0" Grid.Column="1"></ComboBox>
<
Button Content="Connect" Grid.Column="3" Grid.Row="1" Height="23" HorizontalAlignment="Left" Name="button3" VerticalAlignment="Top" Click="button3_Click"/>
<
TextBox Name="tb" Grid.ColumnSpan="3" Grid.Row="2" VerticalScrollBarVisibility="Visible"></TextBox>
</
Grid>
</
UserControl>



/*
  ASCII table
Prints out byte values in all possible formats: 
* as raw binary values
* as ASCII-encoded decimal, hex, octal, and binary values
For more on ASCII, see http://www.asciitable.com and http://en.wikipedia.org/wiki/ASCII
The circuit:  No external hardware needed.
created 2006
by Nicholas Zambetti
modified 18 Jan 2009
by Tom Igoe
<http://www.zambetti.com>
*/
void setup()
{
  Serial.begin(9600);

  // prints title with ending line break
  Serial.println("ASCII Table ~ Character Map");
}

// first visible ASCIIcharacter '!' is number 33:
int thisByte = 33;
// you can also write ASCII characters in single quotes.
// for example. '!' is the same as 33, so you could also use this:
//int thisByte = '!'; 

void loop()
{
  // prints value unaltered, i.e. the raw binary version of the
  // byte. The serial monitor interprets all bytes as
  // ASCII, so 33, the first number,  will show up as '!'
  Serial.print(thisByte, BYTE);   

  Serial.print(", dec: ");
  // prints value as string as an ASCII-encoded decimal (base 10).
  // Decimal is the  default format for Serial.print() and Serial.println(),
  // so no modifier is needed:
  Serial.print(thisByte);     
  // But you can declare the modifier for decimal if you want to.
  //this also works if you uncomment it:

  // Serial.print(thisByte, DEC); 

  Serial.print(", hex: ");
  // prints value as string in hexadecimal (base 16):
  Serial.print(thisByte, HEX);    

  Serial.print(", oct: ");
  // prints value as string in octal (base 8);
  Serial.print(thisByte, OCT);    

  Serial.print(", bin: ");
  // prints value as string in binary (base 2)
  // also prints ending line break:
  Serial.println(thisByte, BIN);  

  // if printed last visible character '~' or 126, stop:
  if(thisByte == 126) {     // you could also use if (thisByte == '~') {
    // This loop loops forever and does nothing
    while(true) {
      continue;
    }
  }
  // go on to the next character
  thisByte++; 
}

Jul 9, 2009

Entity framework Eager Loading error

If you you get this

"The execution of this query requires the APPLY operator, which is not supported in versions of SQL Server earlier than SQL Server 2005."

We ran into this because we generated it via a 2000 database and threw an error.

Load the edmx file in notepad.

<?xml version="1.0" encoding="utf-8"?>
<edmx:Edmx Version="1.0" xmlns:edmx="http://schemas.microsoft.com/ado/2007/06/edmx">
  <!-- EF Runtime content -->
  <edmx:Runtime>
    <!-- SSDL content -->
    <edmx:StorageModels>
      <Schema Namespace="TableModels.Store" Alias="Self" Provider="System.Data.SqlClient" ProviderManifestToken="2000" xmlns:store="http://schemas.microsoft.com/ado/2007/12/edm/EntityStoreSchemaGenerator" xmlns="http://schemas.microsoft.com/ado/2006/04/edm/ssdl">
       

Now all we need to do is change the 2000 to 2005!

Followers