Skip to content

Commit

Permalink
Removed check for EoF in IsValidFrame(), fixed null reference excepti…
Browse files Browse the repository at this point in the history
…on on reader disconnect, changed URL launching to not cease if a scanning error or non-URI tag is detected.
  • Loading branch information
dshalaby committed Oct 23, 2017
1 parent 929668d commit e17a71b
Show file tree
Hide file tree
Showing 9 changed files with 55 additions and 44 deletions.
2 changes: 1 addition & 1 deletion Example/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
xmlns:gif="http://wpfanimatedgif.codeplex.com"
mc:Ignorable="d"
WindowStartupLocation="CenterScreen"
Title="Tappy Demo 2.4" Height="650" Width="800" Foreground="{x:Null}" Background="{StaticResource LightBackground}">
Title="Tappy Demo 2.5" Height="650" Width="800" Foreground="{x:Null}" Background="{StaticResource LightBackground}">
<Grid Background="{StaticResource LightBackground}">
<Grid.RowDefinitions>
<RowDefinition Height="50"/>
Expand Down
18 changes: 10 additions & 8 deletions Example/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,8 @@ private void AddUID(ResponseFrame frame, Exception e)

private void WriteURLButton_Click(object sender, RoutedEventArgs e)
{
string url = string.Copy(urlTextBox.Text);

string url = string.Copy(urlTextBox.Text);
Command cmd = new WriteUri((byte)timeout.Value, (bool)lockCheckBox.IsChecked, new NdefUri(url));
Callback repeatCommand = null;
bool repeat = (bool)repeatUrlWrite.IsChecked;
Expand Down Expand Up @@ -486,7 +487,7 @@ private void AutoDetectButton_Click(object sender, RoutedEventArgs e)

tappy.SwitchProtocol(window.Protocol);

ShowPendingStatus("Searching for a Tappy");
ShowPendingStatus("Searching for a Tappy");

Task.Run(() =>
{
Expand Down Expand Up @@ -654,7 +655,7 @@ private void launchUrlButton_Click(object sender, RoutedEventArgs e)

private void DetectandLaunch()
{
Command cmd = new DetectSingleNdef(0, DetectTagSetting.Type2Type4AandMifare);
Command cmd = new StreamNdef(0, DetectTagSetting.Type2Type4AandMifare);
tappy.SendCommand(cmd, LaunchCallback);
}

Expand Down Expand Up @@ -737,12 +738,13 @@ private void disconnectButton_Click(object sender, RoutedEventArgs e)
{
try
{
tappy.Disconnect();
tappy.DisconnectBlueGiga();
ShowSuccessStatus("Disconnect was successful");
tappy.Disconnect();
ShowSuccessStatus("Disconnect was successful");
}
catch
{
catch(Exception exc)

{
Console.Write(exc.ToString());
ShowFailStatus("Disconnect was unsuccessful");
}
}
Expand Down
8 changes: 4 additions & 4 deletions Example/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("Tappy Demo")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyDescription("Tappy Reader Demo for Windows")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyCompany("TapTrack (TM)")]
[assembly: AssemblyProduct("Tappy Demo")]
[assembly: AssemblyCopyright("Copyright © 2017")]
[assembly: AssemblyTrademark("")]
Expand Down Expand Up @@ -51,7 +51,7 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("2.4.0.0")]
[assembly: AssemblyFileVersion("2.4.0.0")]
[assembly: AssemblyVersion("2.5.0.0")]
[assembly: AssemblyFileVersion("2.5.0.0")]
[assembly: NeutralResourcesLanguage("en-CA")]

16 changes: 9 additions & 7 deletions Example/Tappy Tcmp Demo.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<OutputType>WinExe</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>TapTrack.Demo</RootNamespace>
<AssemblyName>Tappy Demo 2.4</AssemblyName>
<AssemblyName>Tappy Demo 2.5</AssemblyName>
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<ProjectTypeGuids>{60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
Expand Down Expand Up @@ -49,7 +49,7 @@
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<DocumentationFile>bin\Debug\Tappy Demo 2.4.xml</DocumentationFile>
<DocumentationFile>bin\Debug\Tappy Demo 2.5.xml</DocumentationFile>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
Expand All @@ -59,7 +59,7 @@
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<DocumentationFile>bin\Release\Tappy Demo 2.4.xml</DocumentationFile>
<DocumentationFile>bin\Release\Tappy Demo 2.5.xml</DocumentationFile>
</PropertyGroup>
<PropertyGroup>
<ManifestCertificateThumbprint>DA55EDA3D657C041EF308F9D8CDF1B5A4950F2E4</ManifestCertificateThumbprint>
Expand Down Expand Up @@ -102,9 +102,6 @@
<Reference Include="System.Xaml">
<RequiredTargetFramework>4.0</RequiredTargetFramework>
</Reference>
<Reference Include="TapTrack.Tcmp">
<HintPath>..\Tcmp-SDK\bin\Debug\TapTrack.Tcmp.dll</HintPath>
</Reference>
<Reference Include="WindowsBase" />
<Reference Include="PresentationCore" />
<Reference Include="PresentationFramework" />
Expand Down Expand Up @@ -659,7 +656,12 @@
<ItemGroup>
<Resource Include="Resources\keyboard_highlight.png" />
</ItemGroup>
<ItemGroup />
<ItemGroup>
<ProjectReference Include="..\Tcmp-SDK\TapTrack.Tcmp.csproj">
<Project>{cd277ef8-6666-4b0c-b482-9eafa662732e}</Project>
<Name>TapTrack.Tcmp</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
Expand Down
4 changes: 2 additions & 2 deletions Tcmp-SDK/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("0.5.1.0")]
[assembly: AssemblyFileVersion("0.5.1.0")]
[assembly: AssemblyVersion("0.5.2.0")]
[assembly: AssemblyFileVersion("0.5.2.0")]
5 changes: 4 additions & 1 deletion Tcmp-SDK/Tcmp/Communication/Bluetooth/BluetoothConnection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,10 @@ public override void DisconnectBlueGiga()
public override void Disconnect()
{
if (device?.ConnectionHandle != null && (port?.IsOpen) != null)
bluetooth.SendCommand(port, bluetooth.BLECommandConnectionDisconnect((byte)device.ConnectionHandle));
{
bluetooth.SendCommand(port, bluetooth.BLECommandConnectionDisconnect((byte)device.ConnectionHandle));
DisconnectBlueGiga();
}
}

public override string[] GetAvailableDevices()
Expand Down
21 changes: 10 additions & 11 deletions Tcmp-SDK/Tcmp/Communication/TappyReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ private void DataReceivedHandler(object sender, EventArgs e)

ResponseFrame resp;

buffer = TcmpFrame.RemoveEscapseCharacters(buffer.ToArray());
buffer = TcmpFrame.RemoveEscapeCharacters(buffer.ToArray());

for (int i = 0; i < buffer.Count; i++)
{
Expand Down Expand Up @@ -263,23 +263,22 @@ public void FlushBuffer()

public bool ConnectByName(string tappyName)
{
foreach (string name in conn.GetAvailableDevices())
{
if (name.ToUpper() == tappyName.ToUpper())
foreach (string name in conn.GetAvailableDevices())
{
return Connect(tappyName);
if (name.ToUpper() == tappyName.ToUpper())
{
return Connect(tappyName);
}
}
}
return false;

return false;
}


/// <summary>
/// Connect to a Tappy device by the device name (TAPPY123) when it is in kiosk/keyboard wedge mode
/// </summary>
/// <returns>True if connection to a Tappy device was successful, false otherwise</returns>

///
public bool ConnectKioskKeyboardWedgeByName(string tappyName)
{
foreach (string name in conn.GetAvailableDevices())
Expand All @@ -290,7 +289,6 @@ public bool ConnectKioskKeyboardWedgeByName(string tappyName)
}
}
return false;

}


Expand Down Expand Up @@ -327,6 +325,7 @@ public string[] FindNearbyTappyBLEs(int timeout)

}


/// <summary>
/// Switch between USB or Bluetooth modes
/// </summary>
Expand Down Expand Up @@ -422,7 +421,7 @@ public string[] GetAvailableDevices()
public string DeviceName
{
get;
set;
private set;
}

/// <summary>
Expand Down
16 changes: 10 additions & 6 deletions Tcmp-SDK/Tcmp/Communication/TcmpFrame.cs
Original file line number Diff line number Diff line change
Expand Up @@ -236,8 +236,12 @@ protected byte[] AddEscapeChars(params byte[] data)

return temp.ToArray();
}
public static List<byte> RemoveEscapseCharacters(byte[] data) //legacy incorrect spelling in case someone ever called this explicitly
{
return RemoveEscapeCharacters(data);
}

public static List<byte> RemoveEscapseCharacters(byte[] data)
public static List<byte> RemoveEscapeCharacters(byte[] data)
{
List<byte> temp = new List<byte>(data);

Expand Down Expand Up @@ -285,14 +289,14 @@ public static bool IsValidFrame(TcmpFrame frame)
{
if (frame == null)
return false;

byte[] contents = frame.ToArray();

byte[] contents = frame.ToArray();

if (contents.Length < 10)
if (contents.Length < 10)
return false;

if (contents[0] != 0x7E || contents[contents.Length - 1] != 0x7E)
return false;
if (contents[0] != 0x7E)
return false;

if (HasLcsError(frame.Len1, frame.Len0, frame.Lcs))
return false;
Expand Down
9 changes: 5 additions & 4 deletions Tcmp-SDK/Tcmp/Communication/UsbConnection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,14 @@ public override bool Connect(string portName)
try
{
Disconnect();
port.PortName = portName;
port.Open();
return true;
port.PortName = portName;
port.Open();
return true;
}
catch
{
return false;
port.PortName = null;
return false;
}
}

Expand Down

0 comments on commit e17a71b

Please sign in to comment.