Is it possible to send HTTP GET Requests from a Simulink Block? - matlab

basically the title says it all. I'm working on a model that needs (there is no way around it) to load data from a website, parse it and pass it onto another block. I thought I could use an S-Function written in C++, which didn't properly work, then I tried to use webread()
which also didn't work in Simulink because I can't use extrinsic functions on the device this will run on.
I thought I could work around it by downloading the file externally and then reading it through fscanfbut it turned out that Matlab CODER doesn't support that as well.
After putting 2 1/2 days into this now, I'm asking myself whether it is even possible to do something like an HTTP Request through a Simulink block. That's why I went here to ask that question. Thanks for every answer!

I figured out a way to do it with a C++ S-Function by now.
I also created a GitHub Repo for it. If you're stuck with the same problem as I was, try to take a look at this. I'm pretty sure it will help you.

Related

Confusing error from libasound function snd_pcm_hw_params

My question has to do with the libasound function named "snd_pcm_hw_params" in connection with code to play a sound file. I am new to ALSA programming. Using a coding example I found on the internet, I wrote a small program to play a 7 second .wav file to the default sound card. When I run this code several times in a row, occasionally (but not always) the requisite call to snd_pcm_hw_params to write the previously filled in snd_hw_params_t struct to the driver, I get back an error code of -2 (ENOENT). I have no idea what this means, nor how to handle nor prevent it. My code just emits an error message and bails. Usually, if I run it again, the code runs fine. Its fine for my use, but eventually, this code is supposed to be given to a non-programmer to use, and I'd like to either prevent the error, or resolve it internally without involving said non-programming user. I note hear that the user is supposed to be able to cause an early abort of the program by clicking a button, and when this happens, my code calls snd_pcm_drop, followed by snd_pcm_close. If the program runs to completion, and plays all 7 seconds of the wav file, then it finishes up by calling snd_pcm_drain, followed by snd_pcm_close. Any help or suggestions would be greatly appreciated. :)

Problems getting OSVR to initialise the HMD Display with Oculus DK2

I am using a Oculus DK2 (v0.8) and OSVR SDK. I'm having a problem getting the HMD to run/display anything.
The Oculus samples and the OSVR samples do work however, so the osvr_server seems to run fine.
My application itself renders a test scene just fine when not using a HMD.
I tried two approaches:
First, just creating a osvr context and creating a DisplayConfig object. This seems to work, but DisplayConfig::checkStartup() fails (I do this in a loop, calling update on the context when the checkStartup call is failing). I used the OpenGLSample.cpp as a guide for this
Second, I tried using a RenderManager, but the call to createRenderManager results in a crash within the RenderManager.dll. I get the same crash wether I create the graphics lib object myself or if I let the library create it.
I am quite stuck now, since the demos and examples do work, I have no idea where to look for the error on my side. Creating the context works, querying interfaces as well, but the crash with createRenderManager is beyond me.
Does anyone have any hints or ideas what the problem could possibly be?
Regards and thanks in advance
pettersson
RenderManager should not crash during open. There have been a couple of bug fixes recently to avoid that happening, and the latest RenderManager binaries, libraries and header files are available with the SDK download from http://osvr.github.io/using/ along with updated copies of the example programs.
When something goes wrong in RenderManager, it usually reports that to standard error. We're moving that to a logging interface, but for now it should show up on the console. Posting an output of that as an issue at https://github.com/sensics/OSVR-RenderManager/issues is a good way to let the developers know that there is a problem. Of course, providing the same sort of information you provided here will be helpful as well.

Using string without CRT library? Any workarounds?

Here's a little code I'm working on: http://pastebin.com/92Nzc6pG
I basically inject code into a running process, but the problem is, that CRT library is no longer valid, so I can't use strings for example. Is there any workarounds for that? Rest of my program requires creating/modifying strings as well, so I really need to get this sorted out.
I managed to get it working with passing a char pointer, like this: http://pastebin.com/T1qdjfRK
However using strings is still kind of a "must" for me, so any workarounds, ideas and whatsoever are welcome.
An easier way to do this would be to inject minimal code that just loads a DLL with proper imports and relocations. All of your imports are going to be satisfied by the loader once the DLL is loaded.
If you really must inject code and not a DLL for some reason, you'd have to make sure your code is compiled against the same CRT the process was compiled against. If it doesn't use CRT at all, you can use static CRT, or not use CRT at all. Windows has built-in string functions like lstrlen() and friends.
By far the simplest method is injecting an entire DLL and not just code. It will be a bit more complicated because it's two steps, but once you're fully loaded, you can do pretty much everything the same way you would have done it in your own process.

How to find out if Unity plugin hangs (from unityscript)

Unity player on my page hangs sometimes. Is it possible to detect it from unityscript (polling method is acceptable) and react to that- for example reload page?
a colleague ran into this issue, I believe that after an extend research with no good results he came up with this solution:
In the web page declare a global variable stillAlive for example.
Use setInterval to check for that variable every n second, something like this:
if (stillAlive){
stillAlive = false;
}else{
//do things
}
Make an Application.ExternalEval call in your application every n/2 seconds, something like this
Application.ExternalEval ("stillAlive=true;");
I don't know the exact details, but he did something to sync those. I'm sure you can figure something out along this idea.
Note: For some reason I couldn't format the code in this answer, so if someone can fix it, please do.
Update: I've just asked him, he said he "synced" them by initiating the setInterval() with Application.ExternalEval().

Gtkwebkit, save html to pdf

Last days I search for best and shortest way to convert html files to pdf. Since I create my html files with C program and see them through gtkwebkit which uses cairo it should be some efficient and direct way to convert content of showed page to html with C (I think).
But can't find any example or direction to go on the net.
Until now, among different virtual printers, I find only commandline tools which are maded in perl or which depends on qt what is not wanted.
Please for any suggestion, example or advice to get this functionality from gtkwebkit and if not, maybe something with some tiny C library.
As far as I can tell from reading the documentation (haven't tried it out myself):
Get the main frame with webkit_web_view_get_main_frame().
Create a GtkPrintOperation with gtk_print_operation_new().
Set the export-file property on your print operation to be the name of the PDF you want to export to.
Print the frame with webkit_web_frame_print_full(). Make sure to pass GTK_PRINT_OPERATION_ACTION_EXPORT as the 'action' parameter.
I once wrote some code, to accomplish that without opening a window. But then I ran into a problem with using that code from multiple threads (in a webserver e.g.). I made some research and I figured out that gtk itself is single threaded. So I made my code thread safe, by queuing the print operations to the main thread. Anyway, if it helps, check it out... https://github.com/gnudles/wkgtkprinter