How to Add the Missing Byte Shifter Operators to a VB.NET Netduino Project





0/5 (0 vote)
How to add the missing byte shifter operators to a VB.NET Netduino Project
Introduction
This tip will show you how to add the missing byte shifter operators to a VB.NET Netduino project. The steps are as given below:
- Start a new Netduino C# project.
- Locate the projects properties page and select the target framework your VB.NET project will be using. Mine was 4.2. Next, change the “Output Type” to “Class Library”.
- Locate the main menu item “Build” and find the “Configuration manager. Then change the configuration from debug to release. This will allow you to build a DLL you can use in all your projects. In debug mode, you would need many more files.
- Add a code file to the project and remove the program.cs file.
Add this code to it:
using System; namespace ByteShifter { public class ByteShifter { public byte ShiftRight(byte bytetoshift, int placestoshift) { byte ShiftedByte = (byte)(bytetoshift >> placestoshift); return ShiftedByte; } public byte ShiftLeft(byte bytetoshift, int placestoshift) { byte ShiftedByte = (byte)(bytetoshift << placestoshift); return ShiftedByte; } } }
- Build the solution and locate the release directory under solution directory. The new DLL should be there.
- Start of VB.NET project and add a reference to the DLL just created (I like to copy the DLL to the VB.NET debug directory and then add a reference to the VB.NET project).
- Below is an example of how to use the new byte shifting functions in the DLL you created.
Imports Microsoft.SPOT Imports Microsoft.SPOT.Hardware Imports SecretLabs.NETMF.Hardware Imports SecretLabs.NETMF.Hardware.Netduino Imports ByteShifter 'new byte shifter functions Module Module1 Sub Main() 'Create an object Dim obj As New ByteShifter.ByteShifter 'Dim b As Byte = 8 >> 2 Dim b As Byte = obj.ShiftRight(8, 2) 'output should be 2 Debug.Print("The 8 >> 2 answer is: " & b.ToString) Dim b1 As Byte = 155 ' Dim b2 As Byte = b1 >> 1 Dim b2 As Byte = obj.ShiftRight(b1, 1) 'output should be 77 Debug.Print("The answer for b2 is: " & b2.ToString) Dim b3 As Byte = 154 'Dim b2 As Byte = b1 << 1 Dim b4 As Byte = obj.ShiftedLeft(b3, 1) 'output should be 52 Debug.Print("Left Shifted b4 is:" & b4.ToString) End Sub End Module