Wireless Communication Library Support Forum
Frameworks => Bluetooth Framework => Topic started by: dartecs on October 03, 2012, 06:15:45 PM
-
My C# application receives about 80 bytes per second from a bluetooth sensor. While receiving those bytes I occasionally get a System.AccessViolationException in wcl.dll.
My wclClient.OnData handler looks like this:
private void OnDataReceived(object sender, wcl.wclDataEventArgs e)
{
lock (mRxBytesLock)
{
mRxBytes.AddRange(e.Data);
}
}
While receiving data I frequently scan for new devices using a wclBluetoothDiscovery and send data every few seconds:
private void SendTgm(byte[] tgm)
{
try
{
lock (mSendLock)
{
if (IsConnected)
{
wcl.wclErrors.wclShowError(mClient.Write(tgm, (uint)tgm.Length));
if (TgmSent != null)
TgmSent(new List<byte>(tgm));
}
}
}
catch
{
Disconnect();
}
}
Any idea on what could cause the access violation inside wcl.dll?
-
Hello,
Empty tgm array or wrong Length?
-
Empty tgm is very unlikely. But I have now added a check before sending:
private void SendTgm(byte[] tgm)
{
try
{
lock (mSendLock)
{
if (IsConnected)
{
System.Diagnostics.Debug.Assert(tgm.Length > 0);
wcl.wclErrors.wclShowError(mClient.Write(tgm, (uint)tgm.Length));
if (TgmSent != null)
TgmSent(new List<byte>(tgm));
}
}
}
catch
{
Disconnect();
}
}
tgm.Length should always be correct as this is property of the .NET array type.
Now if the tgm should be empty for whatever reason the newly inserted assertion would fire. If the AccessViolationException should throw again without the assertion being fired before I will get back to you again.
-
OK, thanks. I am checking this too.
-
Maybe this problem could also be related to Toshiba stack? (see my other post http://forum.btframework.com/index.php/topic,1692.0.html)
I am now testing without Toshiba Stack and will see if this problem disappeared.
-
Yearly I faced AV with Toshiba but this problem has been fixed (at least I haven't been noticed about that since fixed).