I'm having trouble getting some basic C# code running with MQTTnet 4.1 examples.
Using this test code at https://blog.behroozbc.ir/mqtt-client-with-mqttnet-4-and-c , and also referencing the samples at https://github.com/dotnet/MQTTnet/blob/9cbd5dd778dec7308c079dd61652d9ab573bf186/Samples/Client/Client_Subscribe_Samples.cs ,
I am struggling to make a clean connection to the broker, and thereby publish/subscribe to a topic.
I'm working with VS2019, and installed NuGet package MQTTnet.4.1.4.563
Here's my Program.cs with a ConnectAndSendMessage method. My test EMQX Broker (the desktop client is called MQTTX) is running on my local box - and my Angular web client sends/receives message without issue.
using System;
using System.Threading.Tasks;
using System.Threading;
using MQTTnet.Client;
using MQTTnet.Extensions.ManagedClient;
using MQTTnet;
using System.Text.Json;
namespace mqtt_dotnet_sample1
{
class Program
{
static void Main(string[] args)
{
Task task = ConnectAndSendMessage();
}
public static async Task ConnectAndSendMessage()
{
IManagedMqttClient _mqttClient = new MqttFactory().CreateManagedMqttClient();
MqttClientOptionsBuilder builder = new MqttClientOptionsBuilder()
.WithClientId("MY_CLIENT_ID") // here is the same conn str as my TypeScript client in Angular 14
.WithWebSocketServer("broker.emqx.io");
ManagedMqttClientOptions options = new ManagedMqttClientOptionsBuilder()
.WithAutoReconnectDelay(TimeSpan.FromSeconds(60))
.WithClientOptions(builder.Build())
.Build();
// Set up handlers
_mqttClient.ConnectedAsync += _mqttClient_ConnectedAsync;
_mqttClient.DisconnectedAsync += _mqttClient_DisconnectedAsync;
_mqttClient.ConnectingFailedAsync += _mqttClient_ConnectingFailedAsync;
// Connect to the broker
Console.WriteLine("Attempting to connect to broker...");
await _mqttClient.StartAsync(options);
// Send a new message to the broker every second
while (true)
{
string json = JsonSerializer.Serialize(new { message = "Hi from MqttNet", sent = DateTime.UtcNow });
await _mqttClient.EnqueueAsync("bob-top", json);
await Task.Delay(TimeSpan.FromSeconds(10)); // ** IT BAILS OUT HERE **
}
Task _mqttClient_ConnectedAsync(MqttClientConnectedEventArgs arg)
{
Console.WriteLine("Connected");
return Task.CompletedTask;
};
Task _mqttClient_DisconnectedAsync(MqttClientDisconnectedEventArgs arg)
{
Console.WriteLine("Disconnected");
return Task.CompletedTask;
};
Task _mqttClient_ConnectingFailedAsync(ConnectingFailedEventArgs arg)
{
Console.WriteLine("Connection failed check network or broker!");
return Task.CompletedTask;
}
}
}
}
It just exists at this line: await Task.Delay(TimeSpan.FromSeconds(10)); and shows the following messages in the VS Output window - the final message being The program '[787944] mqtt-dotnet-sample1.exe' has exited with code 0 (0x0).
'mqtt-dotnet-sample1.exe' (CLR v4.0.30319: DefaultDomain): Loaded 'C:\WINDOWS\Microsoft.Net\assembly\GAC_32\mscorlib\v4.0_4.0.0.0__b77a5c561934e089\mscorlib.dll'.
'mqtt-dotnet-sample1.exe' (CLR v4.0.30319: DefaultDomain): Loaded 'c:\bob\dev\mqtt-dotnet-sample1\mqtt-dotnet-sample1\bin\Debug\mqtt-dotnet-sample1.exe'. Symbols loaded.
'mqtt-dotnet-sample1.exe' (CLR v4.0.30319: mqtt-dotnet-sample1.exe): Loaded 'c:\bob\dev\mqtt-dotnet-sample1\mqtt-dotnet-sample1\bin\Debug\MQTTnet.dll'.
'mqtt-dotnet-sample1.exe' (CLR v4.0.30319: mqtt-dotnet-sample1.exe): Loaded 'c:\bob\dev\mqtt-dotnet-sample1\mqtt-dotnet-sample1\bin\Debug\MQTTnet.Extensions.ManagedClient.dll'.
'mqtt-dotnet-sample1.exe' (CLR v4.0.30319: mqtt-dotnet-sample1.exe): Loaded 'c:\bob\dev\mqtt-dotnet-sample1\mqtt-dotnet-sample1\bin\Debug\System.Text.Json.dll'.
'mqtt-dotnet-sample1.exe' (CLR v4.0.30319: mqtt-dotnet-sample1.exe): Loaded 'C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\netstandard\v4.0_2.0.0.0__cc7b13ffcd2ddd51\netstandard.dll'.
'mqtt-dotnet-sample1.exe' (CLR v4.0.30319: mqtt-dotnet-sample1.exe): Loaded 'C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System.Core\v4.0_4.0.0.0__b77a5c561934e089\System.Core.dll'.
'mqtt-dotnet-sample1.exe' (CLR v4.0.30319: mqtt-dotnet-sample1.exe): Loaded 'C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System\v4.0_4.0.0.0__b77a5c561934e089\System.dll'.
'mqtt-dotnet-sample1.exe' (CLR v4.0.30319: mqtt-dotnet-sample1.exe): Loaded 'c:\bob\dev\mqtt-dotnet-sample1\mqtt-dotnet-sample1\bin\Debug\Microsoft.Bcl.AsyncInterfaces.dll'.
'mqtt-dotnet-sample1.exe' (CLR v4.0.30319: mqtt-dotnet-sample1.exe): Loaded 'C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System.Configuration\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Configuration.dll'.
'mqtt-dotnet-sample1.exe' (CLR v4.0.30319: mqtt-dotnet-sample1.exe): Loaded 'c:\bob\dev\mqtt-dotnet-sample1\mqtt-dotnet-sample1\bin\Debug\System.Memory.dll'.
'mqtt-dotnet-sample1.exe' (CLR v4.0.30319: mqtt-dotnet-sample1.exe): Loaded 'C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System.Xml\v4.0_4.0.0.0__b77a5c561934e089\System.Xml.dll'.
'mqtt-dotnet-sample1.exe' (CLR v4.0.30319: mqtt-dotnet-sample1.exe): Loaded 'c:\bob\dev\mqtt-dotnet-sample1\mqtt-dotnet-sample1\bin\Debug\System.ValueTuple.dll'.
'mqtt-dotnet-sample1.exe' (CLR v4.0.30319: mqtt-dotnet-sample1.exe): Loaded 'c:\bob\dev\mqtt-dotnet-sample1\mqtt-dotnet-sample1\bin\Debug\System.Text.Encodings.Web.dll'.
'mqtt-dotnet-sample1.exe' (CLR v4.0.30319: mqtt-dotnet-sample1.exe): Loaded 'c:\bob\dev\mqtt-dotnet-sample1\mqtt-dotnet-sample1\bin\Debug\System.Runtime.CompilerServices.Unsafe.dll'.
'mqtt-dotnet-sample1.exe' (CLR v4.0.30319: mqtt-dotnet-sample1.exe): Loaded 'c:\bob\dev\mqtt-dotnet-sample1\mqtt-dotnet-sample1\bin\Debug\System.Threading.Tasks.Extensions.dll'.
'mqtt-dotnet-sample1.exe' (CLR v4.0.30319: mqtt-dotnet-sample1.exe): Loaded 'c:\bob\dev\mqtt-dotnet-sample1\mqtt-dotnet-sample1\bin\Debug\System.Buffers.dll'.
The program '[787944] mqtt-dotnet-sample1.exe' has exited with code 0 (0x0).
Any advice or help is appreciated.
Your MQTT Code looks fine (at least on first glance). The problem is, that ConnectAndSendMessage returns a Task. This has to be awaited in the main method. Otherwise, the Task is created, assigned to the variable task and then the end of the main method is reached -> the program exits.
To await the Task, you can change your main method one of the following ways:
async static void Main(string[] args)
{
await ConnectAndSendMessage();
}
static void Main(string[] args)
{
Task task = ConnectAndSendMessage();
task.GetAwaiter().GetResult();
}
Related
I am new to C++ coding and in Visual studio environment. My simple code to find a sqrt of a number is being compiled and even run but the console disappears after taking number as input and I am left with the debugging messages and final message of Program terminated with exit code 0. Basically no output is shown.
#include <cmath>
#include <iostream>
int main()
{
double x{ 0.0 };
std::cout << "Enter x-";
std::cin >> x;
if (x >= 0)
std::cout << "\nSqrt(" << x << ") = " << std::sqrt(x) << std::endl;
else
std::cout << "\nWrong Value - cannot compute sqrt\n";
}
The code seems okay, it runs on online compilers. I have tried checking 'console' option from Linker->System->Sub-system->Console (/SUBSYSTEM:CONSOLE). But nothing works.
There are also certain debugging messages that seem to be generated some of them I am showing below -
......
'Project2.exe' (Win32): Loaded 'C:\Program Files (x86)\Citrix\System32\CtxGraphicsHelper.dll'. Cannot find or open the PDB file.
'Project2.exe' (Win32): Loaded 'C:\Windows\SysWOW64\setupapi.dll'. Symbols loaded.
'Project2.exe' (Win32): Loaded 'C:\Program Files (x86)\Citrix\System32\mmhook.dll'. Cannot find or open the PDB file.
'Project2.exe' (Win32): Loaded 'C:\Program Files (x86)\Citrix\System32\Sfrhook.dll'. Cannot find or open the PDB file.
'Project2.exe' (Win32): Loaded 'C:\Windows\SysWOW64\wtsapi32.dll'. Symbols loaded.
The thread 0x498 has exited with code 0 (0x0).
The thread 0x2500 has exited with code 0 (0x0).
The thread 0x30f0 has exited with code 0 (0x0).
'Project2.exe' (Win32): Loaded 'C:\Program Files (x86)\Citrix\System32\ShellHook.dll'. Cannot find or open the PDB file.
'Project2.exe' (Win32): Loaded 'C:\Windows\SysWOW64\shell32.dll'. Symbols loaded.
'Project2.exe' (Win32): Loaded 'C:\Windows\SysWOW64\windows.storage.dll'. Symbols loaded.
'Project2.exe' (Win32): Loaded 'C:\Windows\SysWOW64\shlwapi.dll'. Symbols loaded.
'Project2.exe' (Win32): Loaded 'C:\Windows\SysWOW64\SHCore.dll'. Symbols loaded.
'Project2.exe' (Win32): Loaded 'C:\Windows\SysWOW64\profapi.dll'. Symbols loaded.
'Project2.exe' (Win32): Loaded 'C:\Program Files (x86)\Citrix\System32\scardhook.dll'. Cannot find or open the PDB file.
'Project2.exe' (Win32): Loaded 'C:\Program Files (x86)\Citrix\System32\twnhook.dll'. Cannot find or open the PDB file.
'Project2.exe' (Win32): Loaded 'C:\Program Files (x86)\Citrix\System32\cxinjime.dll'. Cannot find or open the PDB file.
The program '[10912] Project2.exe' has exited with code 0 (0x0).
I tried checking the Tools->debugging->symbols->Microsoft Symbol Servers. Some PDF files were found and some were not. I want to get to the root of this issue and basically get my program to behave the way as its coded with output console taking input and showing the result.
You can temporarily add a simple line at the end of code:
system("pause");
Don't forget to include: #include <cstdlib>
I use some NVIDIA Management Library features to produce metrics in my application.
Every 1 second I call nvmlDeviceGetMemoryInfo() in a thread, and after a few minutes, in the output of Visual Studio, I can read hundreds of :
'MyApp.exe' (Win32): Loaded 'C:\Windows\System32\nvapi64.dll'.
'MyApp.exe' (Win32): Unloaded 'C:\Windows\System32\nvapi64.dll'
...
'MyApp.exe' (Win32): Loaded 'C:\Windows\System32\nvapi64.dll'.
'MyApp.exe' (Win32): Unloaded 'C:\Windows\System32\nvapi64.dll'
'MyApp.exe' (Win32): Loaded 'C:\Windows\System32\nvapi64.dll'.
'MyApp.exe' (Win32): Unloaded 'C:\Windows\System32\nvapi64.dll'
...
Other functions from NVML like nvmlDeviceGetCount(), nvmlDeviceGetHandleByIndex(), nvmlDeviceGetClockInfo() or nvmlDeviceGetUtilizationRates() don't produce this ponctual loading/unloading of the nvapi64.dll.
Is it possible to avoid unloading this dll, to keep it available for my next call to nvmlDeviceGetMemoryInfo() ?
EDIT :
I call this function to retreive gpu memory statistics like that :
nvmlMemory_t memInfo;
if (nvmlDeviceGetMemoryInfo(device, &memInfo) == NVML_SUCCESS) {
this->gpuMemUsed = memInfo.used;
this->gpuMemTotal = memInfo.total;
}
I see these output line in Debug and Release, each time I call nvmlDeviceGetMemoryInfo() there is on couple of Loaded nvapi64.dll / Unloaded nvapi64.dll
NVML comes with Cuda V10.2 .
you can simply call LoadLibraryW(L"nvapi64.dll"); after this dll already will be not unloaded (RbMm)
This did the trick
Language version: Microsoft Visual C++ 2013 Redistributable (x85) – 12.0.30501
Platform version: 4.0
Operating system: Microsoft Windows 8.1 6.3.9600 Build 9600
Any other relevant software:
Visual Studio 2013 Community with update 4
Halo Configuration Control Panel
Halo Hub
What I am trying to do
I am trying to communicate with a peripheral device that is using the OSDP protocol.
What is actually happening
I get the following from the output panel in visual studio.
Received valid packet of 326 bytes
Received authentication response from OSDP Hub
Session Key > E856417D8B0364313A4B8F0D89524273F0F70AB1DFF8E950FE96905FECAC9F2F
Received packet after 3 ms
Received valid packet of 4 bytes
Received authentication denial from OSDP Hub
Received packet after 0 ms
Performing a search on 0 devices
Rough Copy
'osdp_client_mswud_vc11.exe' (Win32): Loaded 'C:\Work\velox\admins-velox-project\proprietary\rtos\apps\chibios\utilities\osdp_client\Debug_msvc\osdp_client_mswud_vc11.exe'. Symbols loaded.
'osdp_client_mswud_vc11.exe' (Win32): Loaded 'C:\Windows\SysWOW64\ntdll.dll'. Symbols loaded.
'osdp_client_mswud_vc11.exe' (Win32): Loaded
'C:\Windows\SysWOW64\kernel32.dll'. Symbols loaded.
'osdp_client_mswud_vc11.exe' (Win32): Loaded
'C:\Windows\SysWOW64\KernelBase.dll'. Symbols loaded.
'osdp_client_mswud_vc11.exe' (Win32): Loaded 'C:\Windows\SysWOW64\user32.dll'. Symbols loaded.
'osdp_client_mswud_vc11.exe' (Win32): Loaded 'C:\Windows\SysWOW64\gdi32.dll'. Symbols loaded.
'osdp_client_mswud_vc11.exe' (Win32): Loaded 'C:\Windows\SysWOW64\comdlg32.dll'. Symbols loaded.
'osdp_client_mswud_vc11.exe' (Win32): Loaded 'C:\Windows\SysWOW64\winspool.drv'. Symbols loaded.
'osdp_client_mswud_vc11.exe' (Win32): Loaded 'C:\Windows\SysWOW64\winmm.dll'. Symbols loaded.
'osdp_client_mswud_vc11.exe' (Win32): Loaded 'C:\Windows\SysWOW64\shell32.dll'. Cannot find or open the PDB file.
'osdp_client_mswud_vc11.exe' (Win32): Loaded 'C:\Windows\WinSxS\x86_microsoft.windows.common-controls_6595b64144ccf1df_6.0.9600.18006_none_a9ec6aab013aafee\comctl32.dll'. Symbols loaded.
'osdp_client_mswud_vc11.exe' (Win32): Loaded 'C:\Windows\SysWOW64\ole32.dll'. Symbols loaded.
'osdp_client_mswud_vc11.exe' (Win32): Loaded 'C:\Windows\SysWOW64\oleaut32.dll'. Symbols loaded.
'osdp_client_mswud_vc11.exe' (Win32): Loaded 'C:\Windows\SysWOW64\rpcrt4.dll'. Cannot find or open the PDB file.
'osdp_client_mswud_vc11.exe' (Win32): Loaded 'C:\Windows\SysWOW64\advapi32.dll'. Symbols loaded.
'osdp_client_mswud_vc11.exe' (Win32): Loaded 'C:\Windows\SysWOW64\wsock32.dll'. Symbols loaded.
'osdp_client_mswud_vc11.exe' (Win32): Loaded 'C:\Windows\SysWOW64\ws2_32.dll'. Cannot find or open the PDB file.
'osdp_client_mswud_vc11.exe' (Win32): Loaded 'C:\Windows\SysWOW64\msvcp120d.dll'. Symbols loaded.
'osdp_client_mswud_vc11.exe' (Win32): Loaded 'C:\Windows\SysWOW64\msvcr120d.dll'. Symbols loaded.
'osdp_client_mswud_vc11.exe' (Win32): Loaded 'C:\Windows\SysWOW64\msvcrt.dll'. Symbols loaded.
'osdp_client_mswud_vc11.exe' (Win32): Loaded 'C:\Windows\SysWOW64\shlwapi.dll'. Symbols loaded.
'osdp_client_mswud_vc11.exe' (Win32): Loaded 'C:\Windows\SysWOW64\winmmbase.dll'. Symbols loaded.
'osdp_client_mswud_vc11.exe' (Win32): Loaded 'C:\Windows\SysWOW64\combase.dll'. Cannot find or open the PDB file.
'osdp_client_mswud_vc11.exe' (Win32): Loaded 'C:\Windows\SysWOW64\sechost.dll'. Symbols loaded.
'osdp_client_mswud_vc11.exe' (Win32): Loaded 'C:\Windows\SysWOW64\sspicli.dll'. Symbols loaded.
'osdp_client_mswud_vc11.exe' (Win32): Loaded 'C:\Windows\SysWOW64\nsi.dll'. Symbols loaded.
'osdp_client_mswud_vc11.exe' (Win32): Loaded 'C:\Windows\SysWOW64\cfgmgr32.dll'. Symbols loaded.
'osdp_client_mswud_vc11.exe' (Win32): Loaded 'C:\Windows\SysWOW64\devobj.dll'. Symbols loaded.
'osdp_client_mswud_vc11.exe' (Win32): Loaded 'C:\Windows\SysWOW64\cryptbase.dll'. Symbols loaded.
'osdp_client_mswud_vc11.exe' (Win32): Loaded 'C:\Windows\SysWOW64\SHCore.dll'. Cannot find or open the PDB file.
'osdp_client_mswud_vc11.exe' (Win32): Loaded 'C:\Windows\SysWOW64\bcryptprimitives.dll'. Symbols loaded.
'osdp_client_mswud_vc11.exe' (Win32): Loaded 'C:\Windows\SysWOW64\imm32.dll'. Symbols loaded.
'osdp_client_mswud_vc11.exe' (Win32): Loaded 'C:\Windows\SysWOW64\msctf.dll'. Symbols loaded.
'osdp_client_mswud_vc11.exe' (Win32): Loaded 'C:\Windows\SysWOW64\kernel.appcore.dll'. Symbols loaded.
'osdp_client_mswud_vc11.exe' (Win32): Loaded 'C:\Windows\SysWOW64\uxtheme.dll'. Symbols loaded.
'osdp_client_mswud_vc11.exe' (Win32): Loaded 'C:\ProgramData\Internet Helper Anti-phishing\internetHelper_antiphishing.dll'. Module was built without symbols.
'osdp_client_mswud_vc11.exe' (Win32): Loaded 'C:\Windows\SysWOW64\version.dll'. Symbols loaded.
'osdp_client_mswud_vc11.exe' (Win32): Loaded 'C:\Windows\SysWOW64\dwmapi.dll'. Symbols loaded.
'osdp_client_mswud_vc11.exe' (Win32): Loaded 'C:\Windows\SysWOW64\IconCodecService.dll'. Symbols loaded.
'osdp_client_mswud_vc11.exe' (Win32): Loaded 'C:\Windows\SysWOW64\WindowsCodecs.dll'. Symbols loaded.
'osdp_client_mswud_vc11.exe' (Win32): Loaded 'C:\Windows\WinSxS\x86_microsoft.windows.gdiplus_6595b64144ccf1df_1.1.9600.18696_none_dae05f525bc50fb1\GdiPlus.dll'. Cannot find or open the PDB file.
Password = 1234
Private key = 03ac674216f3e15c761ee1a5e255f067
Added 0 items
'osdp_client_mswud_vc11.exe' (Win32): Loaded 'C:\Windows\SysWOW64\mswsock.dll'. Cannot find or open the PDB file.
'osdp_client_mswud_vc11.exe' (Win32): Loaded 'C:\Windows\SysWOW64\dnsapi.dll'. Symbols loaded.
'osdp_client_mswud_vc11.exe' (Win32): Loaded 'C:\Windows\SysWOW64\FWPUCLNT.DLL'. Cannot find or open the PDB file.
'osdp_client_mswud_vc11.exe' (Win32): Loaded 'C:\Windows\SysWOW64\rasadhlp.dll'. Symbols loaded.
'osdp_client_mswud_vc11.exe' (Win32): Loaded 'C:\Windows\SysWOW64\cryptsp.dll'. Symbols loaded.
'osdp_client_mswud_vc11.exe' (Win32): Loaded 'C:\Windows\SysWOW64\rsaenh.dll'. Cannot find or open the PDB file.
'osdp_client_mswud_vc11.exe' (Win32): Loaded 'C:\Windows\SysWOW64\bcrypt.dll'. Symbols loaded.
..\..\src\common\strvararg.cpp(658): assert "n <= parser.nargs" failed in `anonymous-namespace'::DoGetArgumentType(): more arguments than format string specifiers? [in thread cb4]
First-chance exception at 0x76165608 (KernelBase.dll) in osdp_client_mswud_vc11.exe: 0x00001976.
'osdp_client_mswud_vc11.exe' (Win32): Loaded 'C:\Windows\SysWOW64\dbghelp.dll'. Symbols loaded.
DBGHELP: Symbol Search Path: .
DBGHELP: .\wkernelbase.pdb - file not found
DBGHELP: .\dll\wkernelbase.pdb - file not found
DBGHELP: .\symbols\dll\wkernelbase.pdb - file not found
DBGHELP: wkernelbase.pdb - file not found
DBGHELP: KERNELBASE - export symbols
DBGHELP: .\osdp_client_mswud_vc11.pdb - file not found
DBGHELP: .\exe\osdp_client_mswud_vc11.pdb - file not found
DBGHELP: .\symbols\exe\osdp_client_mswud_vc11.pdb - file not found
Received valid packet of 326 bytes
Received authentication response from OSDP Hub
Session Key > 63B2D0C583090EFD994B5AFE12A417A07F406CEE1F64DCB1613703B45428E32E
Received packet after 3 ms
Received valid packet of 4 bytes
Received authentication denial from OSDP Hub
Received packet after 2 ms
DBGHELP: osdp_client_mswud_vc11 - private symbols & lines
C:\Work\velox\admins-velox-project\proprietary\rtos\apps\chibios\utilities\osdp_client\Debug_msvc\osdp_client_mswud_vc11.pdb
DBGHELP: .\msvcr120d.i386.pdb - file not found
DBGHELP: .\dll\msvcr120d.i386.pdb - file not found
DBGHELP: .\symbols\dll\msvcr120d.i386.pdb - file not found
DBGHELP: msvcr120d.i386.pdb - file not found
DBGHELP: MSVCR120D - export symbols
DBGHELP: .\wntdll.pdb - file not found
DBGHELP: .\dll\wntdll.pdb - file not found
DBGHELP: .\symbols\dll\wntdll.pdb - file not found
DBGHELP: wntdll.pdb - file not found
DBGHELP: ntdll - export symbols
DBGHELP: .\wkernel32.pdb - file not found
DBGHELP: .\DLL\wkernel32.pdb - file not found
DBGHELP: .\symbols\DLL\wkernel32.pdb - file not found
DBGHELP: wkernel32.pdb - file not found
DBGHELP: KERNEL32 - export symbols
Here is the actual code;
case OSDP_HUB:
{
bool ipv4;
uint8_t ip_addr[16];
osdp_hub_messages* hub = (osdp_hub_messages*)m_packets.get_data( OSDP_HUB );
// goes from here to decode method ondown
hub->decode( (uint8_t*)buffer, m_packets.get_header()->m_data.length );
if ( hub->get_msg_type() == OSDP_HUB_TCP_IND )
{
hub->get_ip_addr( &ipv4, ip_addr );
if ( hub->get_enable() )
{
// Device has connected...
wxLogDebug( wxT("Device connected on IP address %d.%d.%d.%d : %u"),
ip_addr[0], ip_addr[1], ip_addr[2], ip_addr[3], hub->get_tcp_port() );
m_tcp_device_connected = true;
// Assign an address
/// #todo Create an address generation function
std::vector<uint8_t> ip_addr_vec;
ip_addr_vec.resize( ipv4? 4 : 16 );
memcpy( &ip_addr_vec[0], ip_addr, ipv4? 4 : 16 );
m_tcp_map[0] = ip_addr_vec;
MyCustomEvent customEvent( MyCustomCommandEvent, ID_EVENT_TCP_ADD );
customEvent.SetText( _T( "SocketThread::Entry() ID_EVENT_TCP_ADD" ) );
wxPostEvent( m_parent, customEvent );
}
else
{
// Device has disconnected...
wxLogDebug( wxT("Device disconnected on IP address %d.%d.%d.%d"),
ip_addr[0], ip_addr[1], ip_addr[2], ip_addr[3] );
// Change the UI to display the nearest device on the list
MyCustomEvent customEvent( MyCustomCommandEvent, ID_EVENT_TCP_REMOVE );
customEvent.SetText( _T( "SocketThread::Entry() ID_EVENT_TCP_REMOVE" ) );
wxPostEvent( m_parent, customEvent );
}
}
else if ( hub->get_msg_type() == OSDP_HUB_AUTH_1 )
{
wxLogDebug( wxT("Received authentication response from OSDP Hub") );
m_auth1_received = true;
std::string salt = hub->get_salt();
std::string key = hub->get_publickey();
m_srp_auth->gen_client_session_key( salt, key );
wxLogDebug( wxT("Session Key > %s"), m_srp_auth->get_session_key() );
m_srp_auth->gen_client_cryptogram();
}
else if ( hub->get_msg_type() == OSDP_HUB_AUTH_3 ) // skips here
{
wxLogDebug( wxT("Received authentication accept from OSDP Hub") );
m_auth3_received = true;
}
else if ( hub->get_msg_type() == OSDP_HUB_AUTH_4 ) // enters in here
{
wxLogDebug( wxT("Received authentication denial from OSDP Hub") );
m_auth4_received = true;
}
else if ( hub->get_msg_type() == OSDP_HUB_PONG )
{
wxLogDebug( wxT("Received PONG from OSDP Hub") );
m_pong_received = true;
int32_t length;
hub->encode( (uint8_t*)msg, &length );
m_clientSocket->Write( (char*)msg, length );
}
} break;
//comes in here
int32_t osdp_hub_messages::decode( uint8_t* buffer, int32_t len )
{
return osdp_hub_messages_decode( &m_osdp_hub_messages, buffer, len );
} // decode()
// then comes in here
int32_t osdp_hub_messages_decode( osdp_hub_messages_t* data, uint8_t* buffer, int32_t len )
{
//goes from OSDP_HUB_AUTH_2 t0 OSDP_HUB_AUTH_4
//never hits OSDP_HUB_START or OSDP_HUB_TCP_IND
data->hub_msg = (osdp_hub_e)buffer[0];
switch ( data->hub_msg )
{
case OSDP_HUB_START: return decode_start( data, buffer+1, len ); break;
case OSDP_HUB_TCP_IND: return decode_tcp_ind( data, buffer+1, len ); break;
case OSDP_HUB_AUTH_0: return decode_auth_0( data, buffer+1, len ); break;
case OSDP_HUB_AUTH_1: return decode_auth_1( data, buffer+1, len ); break;
case OSDP_HUB_AUTH_2: return decode_auth_2( data, buffer+1, len ); break;
case OSDP_HUB_AUTH_3: return decode_auth_2( data, buffer+1, len ); break;
case OSDP_HUB_AUTH_4: return decode_auth_4( data, buffer+1, len ); break;
case OSDP_HUB_PING: return decode_ping( data, buffer+1, len ); break;
case OSDP_HUB_PONG: return decode_pong( data, buffer+1, len ); break;
case OSDP_HUB_GET_AUTH_1: return decode_get_auth_1( data, buffer+1, len ); break;
case OSDP_HUB_GET_AUTH_3: return decode_get_auth_3( data, buffer+1, len ); break;
default:
{
return 0;
} break;
}
} // osdp_hub_messages_decode()
//additional code
/// #file osdp_halo_alarm_base.h
/// #brief A C implementation of the proprietary Halo alarm packet.
///
/// #author neil
#pragma once
#include "osdp_header.h"
#ifdef _cplusplus
extern "C" {
#endif
/// The ID used to define a HALO HUB packet
#define OSDP_HUB 0x00
typedef enum
{
OSDP_HUB_START = 0,
OSDP_HUB_TCP_IND,
OSDP_HUB_AUTH_0,
OSDP_HUB_AUTH_1,
OSDP_HUB_AUTH_2,
OSDP_HUB_AUTH_3,
OSDP_HUB_AUTH_4,
OSDP_HUB_PING,
OSDP_HUB_PONG,
OSDP_HUB_GET_AUTH_1,
OSDP_HUB_GET_AUTH_3,
} osdp_hub_e;
struct _osdp_hub_messages_t
{
osdp_hub_e hub_msg;
bool enable;
uint8_t max_tcp;
uint8_t ip_addr[16];
bool ipv4;
uint32_t port;
bool success;
uint8_t username[17];
uint8_t publickey[321];
uint8_t salt[65];
uint8_t cryptogram[65];
osdp_header_t* header;
};
typedef struct _osdp_hub_messages_t osdp_hub_messages_t;
/// #brief Translate the data structure to a packet for transmission
/// #param buffer An input data buffer used to store the packet
/// #param len The length of the output packet
void osdp_hub_messages_encode( osdp_hub_messages_t* data, uint8_t* buffer, int32_t* len );
/// #brief Translate a received packet into a data structure
/// #param data A struct containing the decoded output parameters
/// #param buffer An input data buffer used to store the packet
/// #param len The length of the input packet
/// #return The number of decoded bytes
int32_t osdp_hub_messages_decode( osdp_hub_messages_t* data, uint8_t* buffer, int32_t len );
#ifdef _cplusplus
}
#endif
//
// end of file
//
Anymore information required and i will surely add it. Thanks for your help!
The code you posted does not look like SIA OSDP. (According to Sensurity's web site that is the OSDP they are referring to.) Perhaps this is some other part of the mechanism? The current SIA OSDP working group activity regarding OSDP over an IP network is around OSDP over TCP (using the existing "secure channel" mechanism) or OSDP over TLS.
I am just learning Azure data lake analytics and U-SQL. I have a simple script that runs and produces the expected output. However when I set a breakpoint in the code behind helper method it is never hit because no symbols have been loaded. I have looked at all the available Microsoft tutorials and none suggest that I must do anything to enable debugging, it should just work when I run.
I am running on Local.
I am using F5 to run in debug mode.
Script completes successfully.
Output confirms that helper method is executed
U-SQL
#searchlog =
EXTRACT UserId int,
Start DateTime,
Region string,
Query string,
Duration int,
Urls string,
ClickedUrls string
FROM "/SearchLog.tsv"
USING Extractors.Tsv();
#searchlog = SELECT
UserId,
DataLake.Helper.Test() AS Test,
Start,
Region,
Query,
Duration,
Urls,
ClickedUrls
FROM #searchlog;
OUTPUT #searchlog
TO "/SearchLog_output.tsv"
USING Outputters.Tsv();
Code Behind
namespace DataLake
{
public class Helper
{
public static string Test()
{
Console.WriteLine("Stop");
return "Test";
}
}
}
Output Window
'DebugHost.exe' (CLR v4.0.30319: DefaultDomain): Loaded.
'C:\Windows\Microsoft.Net\assembly\GAC_64\mscorlib\v4.0_4.0.0.0__b77a5c561
934e089\mscorlib.dll'. Symbols loaded.
'DebugHost.exe' (CLR v4.0.30319: DefaultDomain): Loaded
'C:\Users\ksmith\Documents\Visual Studio
2017\Projects\USQLApplication1\DataLake\bin\LocalDebug\DebugHost.exe'.
Symbols loaded.
'DebugHost.exe' (CLR v4.0.30319: DebugHost.exe): Loaded
'C:\Users\ksmith\Documents\Visual Studio
2017\Projects\USQLApplication1\DataLake\bin\LocalDebug\Microsoft.Cosmos
.ScopeStudio.BusinessObjects.Debugger.dll'. Cannot find or open the PDB
file.
'DebugHost.exe' (CLR v4.0.30319: DebugHost.exe): Loaded
'C:\Users\ksmith\Documents\Visual Studio
2017\Projects\USQLApplication1\DataLake\bin\LocalDebug\Microsoft.Cosmos
.ScopeStudio.BusinessObjects.Common.dll'. Cannot find or open the PDB file.
'DebugHost.exe' (CLR v4.0.30319: DebugHost.exe): Loaded
'C:\Users\ksmith\Documents\Visual Studio
2017\Projects\USQLApplication1\DataLake\bin\LocalDebug\Microsoft.Analytics
.LocalRun.dll'. Cannot find or open the PDB file.
'DebugHost.exe' (CLR v4.0.30319: DebugHost.exe): Loaded
'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System\v4.0_4.0.0.0__b77a5c56
1934e089\System.dll'. Symbols loaded.
'DebugHost.exe' (CLR v4.0.30319: DebugHost.exe): Loaded
'C:\Users\ksmith\Documents\Visual Studio
2017\Projects\USQLApplication1\DataLake\bin\LocalDebug\Microsoft.Cosmos.
ClientTools.Shared.dll'. Cannot find or open the PDB file.
'DebugHost.exe' (CLR v4.0.30319: DebugHost.exe): Loaded
'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Core\v4.0_4.0.0.0__
b77a5c561934e089\System.Core.dll'. Symbols loaded.
'DebugHost.exe' (CLR v4.0.30319: DebugHost.exe): Loaded
'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Xml\v4.0_4.0.0.0__b
77a5c561934e089\System.Xml.dll'. Symbols loaded.
'DebugHost.exe' (CLR v4.0.30319: DebugHost.exe): Loaded
'C:\Users\ksmith\Documents\Visual Studio
2017\Projects\USQLApplication1\DataLake\bin\LocalDebug\ScopeRuntime.exe'.
Cannot find or open the PDB file.
The program '[28036] DebugHost.exe' has exited with code 0 (0x0).
Can anyone shed some light on why the breakpoints are not hit?
Adding Debugger.Launch(); caused the Choose Just-In-Time Debugger window to appear. If I select one of the options I then get an instance of visual studio were the code behind break points are hit. The VS instance is called LocalVertexHost
JIT Debugger
Thanks
It is some issue that the extension of DataLake Analytics has for visual studio. I have had, and still having, this issue. Follow these steps and it can be ok for some runs, then repeat it again:
Clean all the projects you have: ADLA and ADLA Class library;
Make sure that the debug folders are empty on both projects;
Rebuild and Register to your local ADLA the Class Library with the code behind;
Rebuild the script you are trying to debug;
Make the ADLA project your startup project;
Submit the script to your local ADLA (makes sure that you have all the needed files in debug and that the script is assigned as the startup script);
After the submit is successful, put the brak point into the code behind;
Start debugging;
If the breakpoint is not hit yet, then try to delete everything from the local U-SQL temporary folder and repeat again all the steps.
This happenes in my environment me when I click the Submit button in Visual Studio instead of hitting F5 or clicking on start (with debugging). Thought I should share even though you mention already running with f5 because this was the only mention of this issue I could find. Maybe this will be helpful to others.
I think clicking submit runs the usql script in a separate process without the debugger attached.
Go to the Debug options in Visual Studio and ensure the following:
Uncheck "Enable Just My Code"
Check "Suppress JIT optimization on module load"
After installing Visual Studio 2013 Express on my Windows 7 64-bit PC, I tested the following simple Hello World C++ program:
1 #include <iostream>
2 using namespace std;
3
4 int main() {
5 cout << "Hello World" << endl;
6 return 0;
7 }
When I run this code in normal execution (using ctr+F5), the programs runs fine. However, when I run it with the debugger (using F5 only), I get the following message box that appears :
"First-chance exception at 0x778412C7 in ConsoleApplication1.exe: 0xC0000008: An invalid handle was specified.
If there is a handler for this exception, the program may be safely continued."
I press continue and then another message box appear saying :
Unhandled exception at 0x778412C7 in ConsoleApplication1.exe: 0xC0000008: An invalid handle was specified.
If there is a handler for this exception, the program may be safely continued.
I press continue again and the console output is the following :
'ConsoleApplication1.exe' (Win32): Loaded 'C:\Users\212426625\Desktop\ConsoleApplication1\Debug\ConsoleApplication1.exe'. Symbols loaded.
'ConsoleApplication1.exe' (Win32): Loaded 'C:\Windows\SysWOW64\ntdll.dll'. Symbols loaded.
'ConsoleApplication1.exe' (Win32): Loaded 'C:\Windows\SysWOW64\kernel32.dll'. Symbols loaded.
'ConsoleApplication1.exe' (Win32): Loaded 'C:\Windows\SysWOW64\KernelBase.dll'. Symbols loaded.
'ConsoleApplication1.exe' (Win32): Loaded 'C:\Windows\SysWOW64\DgApi.dll'. Cannot find or open the PDB file.
'ConsoleApplication1.exe' (Win32): Loaded 'C:\Windows\SysWOW64\psapi.dll'. Symbols loaded.
'ConsoleApplication1.exe' (Win32): Loaded 'C:\Windows\SysWOW64\ws2_32.dll'. Symbols loaded.
'ConsoleApplication1.exe' (Win32): Loaded 'C:\Windows\SysWOW64\msvcrt.dll'. Symbols loaded.
'ConsoleApplication1.exe' (Win32): Loaded 'C:\Windows\SysWOW64\rpcrt4.dll'. Symbols loaded.
'ConsoleApplication1.exe' (Win32): Loaded 'C:\Windows\SysWOW64\sspicli.dll'. Symbols loaded.
'ConsoleApplication1.exe' (Win32): Loaded 'C:\Windows\SysWOW64\cryptbase.dll'. Symbols loaded.
'ConsoleApplication1.exe' (Win32): Loaded 'C:\Windows\SysWOW64\sechost.dll'. Symbols loaded.
'ConsoleApplication1.exe' (Win32): Loaded 'C:\Windows\SysWOW64\nsi.dll'. Symbols loaded.
'ConsoleApplication1.exe' (Win32): Loaded 'C:\Windows\SysWOW64\mpr.dll'. Symbols loaded.
'ConsoleApplication1.exe' (Win32): Loaded 'C:\Windows\SysWOW64\version.dll'. Symbols loaded.
'ConsoleApplication1.exe' (Win32): Loaded 'C:\Windows\SysWOW64\user32.dll'. Symbols loaded.
'ConsoleApplication1.exe' (Win32): Loaded 'C:\Windows\SysWOW64\gdi32.dll'. Symbols loaded.
'ConsoleApplication1.exe' (Win32): Loaded 'C:\Windows\SysWOW64\lpk.dll'. Symbols loaded.
'ConsoleApplication1.exe' (Win32): Loaded 'C:\Windows\SysWOW64\usp10.dll'. Symbols loaded.
'ConsoleApplication1.exe' (Win32): Loaded 'C:\Windows\SysWOW64\advapi32.dll'. Symbols loaded.
'ConsoleApplication1.exe' (Win32): Loaded 'C:\Windows\SysWOW64\shell32.dll'. Symbols loaded.
'ConsoleApplication1.exe' (Win32): Loaded 'C:\Windows\SysWOW64\shlwapi.dll'. Symbols loaded.
'ConsoleApplication1.exe' (Win32): Loaded 'C:\Windows\SysWOW64\ole32.dll'. Symbols loaded.
'ConsoleApplication1.exe' (Win32): Loaded 'C:\Windows\SysWOW64\oleaut32.dll'. Symbols loaded.
'ConsoleApplication1.exe' (Win32): Loaded 'C:\Windows\SysWOW64\userenv.dll'. Symbols loaded.
'ConsoleApplication1.exe' (Win32): Loaded 'C:\Windows\SysWOW64\profapi.dll'. Symbols loaded.
'ConsoleApplication1.exe' (Win32): Loaded 'C:\Windows\SysWOW64\msvcp120d.dll'. Symbols loaded.
'ConsoleApplication1.exe' (Win32): Loaded 'C:\Windows\SysWOW64\msvcr120d.dll'. Symbols loaded.
'ConsoleApplication1.exe' (Win32): Loaded 'C:\Windows\SysWOW64\imm32.dll'. Symbols loaded.
'ConsoleApplication1.exe' (Win32): Loaded 'C:\Windows\SysWOW64\msctf.dll'. Symbols loaded.
'ConsoleApplication1.exe' (Win32): Loaded 'C:\Program Files\DGAgent\plugins\09D849B6-32D3-4A40-85EE-6B84BA29E35B\AE_MailSensor_Plugin.dll'. Cannot find or open the PDB file.
'ConsoleApplication1.exe' (Win32): Loaded 'C:\Program Files\DGAgent\plugins\09D849B6-32D3-4A40-85EE-6B84BA29E35B\AME_OutlookSensor.dll'. Cannot find or open the PDB file.
'ConsoleApplication1.exe' (Win32): Loaded 'C:\Program Files\DGAgent\plugins\09D849B6-32D3-4A40-85EE-6B84BA29E35B\AME_SmtpSensor.dll'. Cannot find or open the PDB file.
'ConsoleApplication1.exe' (Win32): Loaded 'C:\Program Files\DGAgent\plugins\8E4EA70A-6128-4B57-BD3F-8E9E0F0DA6BB\OS_Plugin.dll'. Cannot find or open the PDB file.
'ConsoleApplication1.exe' (Win32): Loaded 'C:\Program Files\DGAgent\plugins\8E4EA70A-6128-4B57-BD3F-8E9E0F0DA6BB\COM_Sensor.dll'. Cannot find or open the PDB file.
The thread 0x1f34 has exited with code 0 (0x0).
First-chance exception at 0x778412C7 in ConsoleApplication1.exe: 0xC0000008: An invalid handle was specified.
Unhandled exception at 0x778412C7 in ConsoleApplication1.exe: 0xC0000008: An invalid handle was specified.
The program '[1836] ConsoleApplication1.exe' has exited with code 0 (0x0).
So I tried to figure out what's going on by putting a break point at line #5 and stepping with F10. I can step passed the closing bracket of the main() and then enter in a file called "crtexe.c" (see code block below). I continue stepping through this file until the exception pops up at line #649:
645 #else /* !defined (_WINMAIN_) && defined (_CRT_APP) */
646 if ( !managedapp )
647 {
648 #ifndef _CRT_APP
649 exit(mainret);
650 #else
What is the explanation for this behavior and how can I get it to work as expected?
Edit:
The stack trace is as follow (Since I can't post pictures, I wrote it down):
Call Stack
Name Language
ntdll.dll!ZwClose#4() Unknown
KernelBase.dll!_CloseHandle#4() Unknown
kernel32.dll!_CloseHandleImplementation#4() Unknown
AME_OutlookSensor.dll!732cc94d() Unknown
[Frames below may be incorrect and/or missing, no symbols loaded for AME_OutlookSensor.dll]
AME_OutlookSensor.dll!732b91bc() Unknown
AME_OutlookSensor.dll!732b928f() Unknown
AME_OutlookSensor.dll!732b44c4() Unknown
AME_OutlookSensor.dll!732b461f() Unknown
AME_OutlookSensor.dll!732b468a() Unknown
[External Code]