Failed to open a handle to the device when opening GPIO pin - c#

Everytime I open a GPIO pin I get this exception:
WinRT information: Failed to open a handle to the device.
A resource required for this operation is disabled.
I can't seem to find much information for this on the internet. Probably because UAP is still in a preview. And I don't think something is wrong with my code, it is almost the same one from the Blink example:
GpioController gpio = GpioController.GetDefault();
if (gpio != null)
{
var ledpin = gpio.OpenPin(11);
ledpin.Write(_light ? GpioPinValue.High : GpioPinValue.Low);
ledpin.SetDriveMode(GpioPinDriveMode.Output);
}

Only a subset of pins are available to usermode. Most pins are reserved by the system and cannot be accessed from usermode.
As far as I know pin 11 is not available. Try pin 12 or 13.
List of available Pins:
GPIO# Power-on Pull Header Pin
4 PullUp 7
5 PullUp 29
6 PullUp 31
12 PullDown 32
13 PullDown 33
16 PullDown 36
17 PullDown 11
18 PullDown 12
19 PullDown 35
20 PullDown 38
21 PullDown 40
22 PullDown 15
23 PullDown 16
24 PullDown 18
25 PullDown 22
26 PullDown 37
27 PullDown 13
35 PullUp Red Power LED
47 PullUp Green Activity LED
Edit: Added missing GPIOs

Related

Issue with providing load balancing information using AxMSTSCLib

I am trying to establish a remote desktop connection via a remote desktop session broker in my C# application using the 'AxInterop.MSTSCLib' where I encounter problems with the transfer of the load balancing information.
Basically, I create a new object and set the basic parameters. A connection directly to a single Remote Desktop (RD) server is already possible with this:
var rd = new AxMsRdpClient11NotSafeForScripting();
rd.Server = "target-server.domain.local";
rd.UserName = "user";
var secured = (MSTSCLib.IMsTscNonScriptable)rd.GetOcx();
secured.ClearTextPassword = "password";
The RD environment I want to connect to consists of multiple RD service collections, each managing one or more RD Servers. For new RD connections, RD clients connect to an RD broker server, which redirects the clients according to the individual load balancing information they provide.
To provide this load balancing info, using mstsc.exe and a .rdp file I provide the setting 'loadbalanceinfo:s:tsv://MS Terminal Services Plugin.1.99999' where '99999' is the name of the targeted RD Collection which works fine. To implement this in MSTSCLib, I have to set it with 'rd.AdvancedSettings9.LoadBalanceInfo'.
However, as this post on the Microsoft Technet forum also describes, the load balancing info string must first be re-encoded.
var lbinfo = "loadbalanceinfo:s:tsv://MS Terminal Services Plugin.1.99999";
if (lbinfo.Length % 2 == 1) lbinfo += " ";
lbinfo += "\r\n";
var b = Encoding.UTF8.GetBytes(lbinfo);
var final = Encoding.Unicode.GetString(b);
rd.AdvancedSettings9.LoadBalanceInfo = final;
According to the last comment in the Technet post, the number of bytes must be even, so a space (U+0020) is added if necessary.
With 'rd.Connect()' the connection is established and my client reaches the connection broker. In the first step, my connection request appears in the logs of the broker server:
[TerminalServices-SessionBroker (Operational)]
The Remote Desktop Connection Broker has received a connection request for user {user}.
Notes in the RDP file (TSV URL) = 'tsv://MS Terminal Services Plugin.1.99999 '
(note: there are two empty spaces at the end of the string)
Original application = NULL
The call comes from the redirection server = broker.domain.local
The redirector is configured as a virtual machine redirector.
Note the two spaces at the end of the TSV URL that gets added by the used code because the bytes count would be uneven otherwise. The only difference to mstsc.exe is that there is only one space (which is the new line break we also add I guess) displayed.
In the next step, the error occurs and our connection attempt fails. It says 'The farm specified for the connection does not exist.'
The OnDisconnected event is triggered and provides me the information: 'DiscReason: 3' and 'ExtendedDisconnectReason: 1040'.
My guess: Because of the space we add, the name of the RD collection can't be assigned correctly anymore. If we compare the passed information (loadbalanceinfo:s:tsv://MS Terminal Services Plugin.1.99999) on byte level, we also see that this added space is the only difference:
mstsc.exe
74 73 76 3a 2f 2f 4d 53 20 54 65 72 6d 69 6e 61 6c 20 53 65 72 76 69 63 65 73 20 50 6c 75 67 69 6e 2e 31 2e 39 39 39 39 39 0d 0a
AxMSTSCLib:
74 73 76 3a 2f 2f 4d 53 20 54 65 72 6d 69 6e 61 6c 20 53 65 72 76 69 63 65 73 20 50 6c 75 67 69 6e 2e 31 2e 39 39 39 39 39 20 0d 0a
Note the third last byte, the U+0020, which we added to achieve an even byte count.
If I do not add the space and the number of bytes (43) is thus not even, I see in WireShark that the TPKT packet is not even sent anymore. The broker server, according to its logs, also takes no notice of the connection attempt. The OnDisconnected event provides me the information:: 'DiscReason: 4' and 'ExtendedDisconnectReason: exDiscReasonNoInfo'. So it seems that the AxMSTSCLib already assumes that the byte number is even.
Unfortunately, I can't figure out how mstsc.exe manages to successfully transmit the same odd string. On the byte level, I work supposedly identically.
I have uploaded the entire byte contents of the TPKT packages here for better comparison: https://pastebin.com/tLtfWHiP
I am grateful for any ideas.
Thanks and regards
Lukas P.
I tried a lot before I came up with a solution: adding space, zero width space chars like \u200B, before the load balancing string, and behind it. But the rd broker didn't take it.
Solution:
In case of an odd number of bytes, if we put a dot (U+002E) in the right place, the rd session broker can extract the required identifier for the targeted rd collection and the connection will be established correctly.
private void RdpLogic()
{
AdvancedSettings9.LoadBalanceInfo = ToLoadBalanceString($"tsv://MS Terminal Services Plugin.1.lbinfo");
}
private string ToLoadBalanceString(string loadBalanceInfo)
{
var temp = loadBalanceInfo;
if (temp.Length % 2 == 1) temp = temp.Insert(temp.LastIndexOf('.'), ".");
var final = Encoding.Unicode.GetString(Encoding.UTF8.GetBytes(temp + "\r\n"));
return final;
}
Samples:
ToLoadBalanceString("tsv://MS Terminal Services Plugin.1.even")
Result: 'tsv://MS Terminal Services Plugin.1.even/r/n'
ToLoadBalanceString("tsv://MS Terminal Services Plugin.1.odd")
Results in 'tsv://MS Terminal Services Plugin.1..odd/r/n'

C# Renci SshNet The server response contains a null character at position 0x0000002A

i have multiple Raspberries running with SSH server:
(OpenSSH_7.4p1 Raspbian-10+deb9u7, OpenSSL 1.0.2u 20 Dec 2019).
And if i try to connect via Renci SshNet, i get the following error message:
Renci.SshNet.Common.SshConnectionException: "The server response
contains a null character at position 0x0000002A:
00000000 53 53 48 2D 32 2E 30 2D 4F 70 65 6E 53 53 48 5F
SSH-2.0-OpenSSH_ 00000010 37 2E 34 70 31 20 52 61 73 70 62 69 61 6E
2D 31 7.4p1 Raspbian-1 00000020 30 2B 64 65 62 39 75 37 0A 00
0+deb9u7..
A server must not send a null character before the Protocol Version
Exchange is complete.
More information is available here:
https://www.rfc-editor.org/rfc/rfc4253#section-4.2"
SshClient scClient = new SshClient("123.123.123.123", "pi", "raspberry");
scClient.Connect();
is it possible to change the behavior of the ssh server,
or even better; can i tell renci ssh to ignore these protocol errors?
I think it's a problem of the latest SSH.NET NuGet Package. Currently the newest is 2020.0.0. And the one prior to that is 2020.0.0-beta1.
2020.0.0 gives me this problem, 2020.0.0-beta1 does not.
I will report this issue on https://github.com/sshnet/SSH.NET/issues
EDIT:
2020.0.1 just got published. That doesn't seem to have this problem. I recommend you to try that version.

Calling WAMS from Windows Forms application, freezes

I have a simple Windows Azure Mobile Service. I can get data from it by IOS, now I want to do it from Windows Forms application. My problem, it is not working. It is very strange, because when I call the same code from unit test from the same solution, it works, but when from a Windows Forms app, it freezes. Project targets .net 4.5 and references WAMS client lib by nuget.
Here is my code:
var testTable = WAMSService.MobileService.GetTable<HBCDataLib.WAMS.Test>();
var testResult = testTable.Take(1000).ToListAsync().Result;
By investigating it by Fiddler, i can see this:
CONNECT xy.azure-mobile.net:443 HTTP/1.1
Host: xy.azure-mobile.net
Connection: Keep-Alive
A SSLv3-compatible ClientHello handshake was found. Fiddler extracted the parameters below.
Version: 3.1 (TLS/1.0)
Random: 52 A0 0F 12 01 B1 9A 53 9A 2C 43 13 BD AD 44 6E 9D FB 2E A1 92 FC 5A C0 15 EB 72 30 B9 29 C4 B6
SessionID: empty
Extensions:
renegotiation_info 00
server_name xy.azure-mobile.net
elliptic_curves 00 05 00 18 00 20
ec_point_formats 01 00
SessionTicket TLS empty
Ciphers:
[002F] TLS_RSA_AES_128_SHA
[0035] TLS_RSA_AES_256_SHA
[0005] SSL_RSA_WITH_RC4_128_SHA
[000A] SSL_RSA_WITH_3DES_EDE_SHA
[C013] TLS1_CK_ECDHE_RSA_WITH_AES_128_CBC_SHA
[C014] TLS1_CK_ECDHE_RSA_WITH_AES_256_CBC_SHA
[C009] TLS1_CK_ECDHE_ECDSA_WITH_AES_128_CBC_SHA
[C00A] TLS1_CK_ECDHE_ECDSA_WITH_AES_256_CBC_SHA
[0032] TLS_DHE_DSS_WITH_AES_128_SHA
[0038] TLS_DHE_DSS_WITH_AES_256_SHA
[0013] SSL_DHE_DSS_WITH_3DES_EDE_SHA
[0004] SSL_RSA_WITH_RC4_128_MD5
Compression:
[00] NO_COMPRESSION
It is trivial, and works from unit test from the same solution. So, is it restricted (?!) to call WAMS from Windows forms app? Or what could be the problem?
Thanks in advance!

Can somebody make sense of that crash in Monotouch 5.2.6 happening with SGen on?

Randomly I'm getting the crash below in the iOS5 Simulator with Monotouch 5.2.6 and SGen being enabled. This is a debug build.
It is happening after clicking a button. That click spins off a new thread that shows a little progress indicator. When it is done thinking, it will exchange two views with animation (running all this on the UI thread).
I would like to know where to start because I don't get a managed stack trace. Am I right that it is trying to layout a UITableViewCell that no longer exists?
Native stacktrace:
0 MobileApp 0x00094fbc mono_handle_native_sigsegv + 284
1 MobileApp 0x0000be72 mono_sigsegv_signal_handler + 178
2 libsystem_c.dylib 0x9c5ee59b _sigtramp + 43
3 ??? 0xffffffff 0x0 + 4294967295
4 QuartzCore 0x04176891 -[CALayer actionForKey:] + 89
5 QuartzCore 0x0417982d _ZL12actionForKeyP7CALayerPN2CA11TransactionEP8NSString + 82
6 QuartzCore 0x0417c9c3 _ZN2CA5Layer12begin_changeEPNS_11TransactionEjRP11objc_object + 131
7 QuartzCore 0x04181f82 _ZN2CA5Layer12set_positionERKNS_4Vec2IdEEb + 388
8 QuartzCore 0x04178205 -[CALayer setPosition:] + 68
9 QuartzCore 0x04177cba -[CALayer setFrame:] + 675
10 UIKit 0x021d8590 -[UIView(Geometry) setFrame:] + 198
11 UIKit 0x022e1731 -[UILabel setFrame:] + 233
12 UIKit 0x02439731 -[UITableViewCellLayoutManager layoutSubviewsOfCell:] + 4511
13 UIKit 0x02390e34 -[UITableViewCell layoutSubviews] + 2650
14 UIKit 0x021e3322 -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 178
15 CoreFoundation 0x011d6e72 -[NSObject performSelector:withObject:] + 66
16 QuartzCore 0x0417392d -[CALayer layoutSublayers] + 266
17 QuartzCore 0x0417d827 _ZN2CA5Layer16layout_if_neededEPNS_11TransactionE + 231
18 QuartzCore 0x04103fa7 _ZN2CA7Context18commit_transactionEPNS_11TransactionE + 377
19 QuartzCore 0x04105ea6 _ZN2CA11Transaction6commitEv + 374
20 QuartzCore 0x041059d3 _ZN2CA11Transaction14release_threadEPv + 65
21 libsystem_c.dylib 0x9c5dfe0c _pthread_tsd_cleanup + 85
22 libsystem_c.dylib 0x9c59864c _pthread_exit + 146
23 libsystem_c.dylib 0x9c5989a0 pthread_exit + 33
24 MobileApp 0x0020434e thread_exit + 30
25 MobileApp 0x00203d03 thread_start_routine + 163
26 MobileApp 0x001aeb20 gc_start_thread + 80
27 libsystem_c.dylib 0x9c596ed9 _pthread_start + 335
28 libsystem_c.dylib 0x9c59a6de thread_start + 34
Native code is trying to access something that has been freed.
This is the key line:
4 QuartzCore 0x04176891 -[CALayer actionForKey:] + 89
you need to figure out what [CALayer actionForKey:] is trying to do (and on which object) - have in mind that this can be a number of things (calling a delegate / event, calling a virtual method, fetching a property). It's however difficult to be specific without seeing your actual code.

Debugging WP7 Crash

my first forray into Stack traces for WP7.
This is causing me particular trouble and is popping up from several users of my app. I need a bit of help deciphering this.
This is the stack track:
Frame Image Function Offset
0 coredll.dll xxx_RaiseException 32
1 mscoree3_7.dll WatsonUnhandledManagedException 300
2 mscoree3_7.dll Dbg_NotifyManagedException 136
3 mscoree3_7.dll FirstPassException 1044
4 TransitionStub 0
5 System.ThrowHelper.ThrowArgumentException 52
6 System.Collections.Generic.Dictionary`2.Insert 344
7 System.IO.IsolatedStorage.IsolatedStorageSettings.Add 92
8 traffic_and_travel_uk.Services.push_settings.button4_Click 92
9 System.Windows.Controls.Primitives.ButtonBase.OnClick 132
10 System.Windows.Controls.Button.OnClick 120
11 System.Windows.Controls.Primitives.ButtonBase.OnMouseLeftButtonUp 228
12 System.Windows.Controls.Control.OnMouseLeftButtonUp 100
13 MS.Internal.JoltHelper.FireEvent 800
14 mscoree3_7.dll IL_CallManaged 860
15 mscoree3_7.dll IL_CallDelegateInternal 176
16 mscoree3_7.dll makeComPlusCall 984
17 mscoree3_7.dll makeComPlusCallReturnInt 40
18 0
19 agcore.dll CCoreServices::CLR_FireEvent 400
20 npctrl.dll CommonBrowserHost::CLR_FireEvent 36
21 npctrl.dll CControlBase::ScriptCallback 536
22 npctrl.dll CXcpDispatcher::OnScriptCallback 300
23 npctrl.dll CXcpDispatcher::OnReentrancyProtectedWindowMessage 712
24 npctrl.dll CXcpDispatcher::WindowProc 408
25 coredll.dll SendMessageW 96
26 npctrl.dll CXcpBrowserHost::SyncScriptCallbackRequest 196
27 agcore.dll CEventManager::RaiseControlEvents 208
28 agcore.dll CEventManager::Raise 320
29 agcore.dll CEventManager::RaiseInterleavedRoutedEvents 360
30 agcore.dll CInputManager::InterleaveMouseAndGesture 320
31 agcore.dll CInputManager::ProcessMouseInput 1768
32 agcore.dll CInputManager::SimulateMouse 248
33 agcore.dll CInputManager::ProcessGestureInput 4492
34 agcore.dll CInputManager::ProcessInput 440
35 agcore.dll CCoreServices::ProcessInput 68
36 npctrl.dll CXcpBrowserHost::HandleInputMessage 920
37 npctrl.dll CXcpControl::OnGestureEvent 460
38 npctrl.dll CXcpControl::ProcessWindowMessage 1868
39 npctrl.dll ATL::CWindowImplBaseT_ATL::CWindow,ATL::CWinTraits_1442840576,0_ _::WindowProc 140
40 coredll.dll DispatchMessageW
41 TaskHost.exe CHostActiveXModule::RunMessageLoop 424
42 TaskHost.exe ATL::CAtlExeModuleT_CHostActiveXModule_::Run 40
43 TaskHost.exe WinMain 1420
44 TaskHost.exe WinMainCRTStartupHelper 60
45 coredll.dll MainThreadBaseFunc 428
So I can see its getting stuck on button4_Click function and adding the Iso storage setting, but what else is going on here? I cant understand what is causing the crash for some people.
This is the code in question:
private void button4_Click(object sender, RoutedEventArgs e)
{
var settings = IsolatedStorageSettings.ApplicationSettings;
settings.Add("FirstPush", "true");
var hide = Visibility.Collapsed;
grid4.Visibility = hide;
SE_service_btn_Click1();
}
Thanks. Any guidance appreciated.
Look at the documentation for IsolatedStorageSettings.Add():
ArgumentException key already exists in the dictionary.
Use IsolatedStorageSettings["FirstPush"] = "true" instead. That will either create or update the key if it already exists without throwing an exception.

Categories

Resources