Getting matrix of data from LabVIEW into C# .NET - c#

I am running a simultaneous data acquisition and hardware control. The data acquisition is with an NI-DAQmx device. The hardware control is already written in C#.NET and we would like to synchronize our acquisition with the control, i.e. wait for control event -> collect data -> stop collection -> continue control. I know there is NI Measurement Studio that gives .NET controls for data acquisition but I don't think my boss wants to pay the $350+ for a license and the 45 day evaluation is not enough. So then I found that you can communicate to LabVIEW (which is already installed on our computers) via ActiveX controls and this seems like the route to take. I found an example on zone.ni that open a LabVIEW vi, takes an input from the Windows form, does a calculation in the vi and returns a value. First, I don't understand LabVIEW in the slightest and can't see where the input parameters actually go in to the vi on its block diagram and how it knows to send the output into the output parameter back to the Windows form. Beyond this, for our purposes we need to collect a matrix of data (3-4 large columns) from the LabVIEW vi that we can run acquisition on. Does anyone know if/ how I can do this with an output parameter or where I could find out how? Also, I'd appreciate it if someone could explain how LabVIEW handles the input reference parameters when the vi is called.
Thanks

I have no practical experience with .NET, but the VIs simply call functions from C DLLs. I assume it should be possible to call the same functions yourself from C# and avoid LV completely, which is probably better for you if you don't know it. If you have Labwindows/CVI, I assume you should already have examples for how to do this. If not, I think that the DAQmx installer allows you to install such examples.

Have you thought about serializing data and importing it into LabView? I know it can parse a few simple formats, including even CSV. If you need callbacks between your DAQ and LabView, this won't be sufficient, but in case of data import/export this approach works reasonably well. I'm not a LabView expert but I've done quite a bit of data acquisition and system integration.

Related

Windows: create a multi-mouse lib that dose not require an UI

I'm trying to create a windows application that can manage multiple mouses, with the feature of understanding which device is generating the input
(something like Microsoft's Multimouse, but without a UI).
The problem is that I don't want to use a UI because this will be a plug-in for Unity3D so I have many limitations imposed from this.
I also thought about a parallel service that can talk with Unity, but in that case I would like to not block all the system to take mouses inputs.
In this special case I have to manage 12 of these devices: AimTrak, that are recognized as a mouse input device.
So does anyone have some idea about that how can do this without hacking them and rewriting their driver?
Ok after 3 days of googleing things i have found a way to do this!!!!
We have need to make a windows's system hook on user32.dll in order to catch all mouse inputs.

How to intercept each trying to use API function in C#?

i need to block any screen capture software on the computer from taking screen shots. Since all of them are work on standard API-functions, i think i could monitor and block them.
I need to use C#.
All i have found is how to monitor and block them in a certain program (screen capture program). They are looking for a function in the program, then they change it address on mine function address.
But how can i do it, if i haven't any certain programs? I need to block anyone which tries to take a screenshot.
If your final goal is possible or not I don't know, but for the hooking the API portion I can help you out.
I have used the library EasyHook many times in the past, this will let you hook and intercept system function calls from C# code fairly easily. Just read through the PDF tutorial for setup instructions.
For actually finding the API's I recommend Rohitab's API Monitor, it's still in Alpha stages but it works really well and is free. You just hook it on to a processes and it tells you every external DLL call it makes (with the parameters it passed if you have the xml definition file for the DLL, the program comes with almost all of the windows API dll's pre-defined).
The combination of EasyHook and API Monitor is a great 1-2 punch for mucking with other program's calls.
It is not possible to prevent screenshots from being taken. The battle is already lost because of the DWM (Desktop Window Manager). It's lower level than Win32 and device contexts.
If you want to protect the text in your program, there are a lot easier ways to extract it than doing screenshots and OCR. TextOut and/or Direct2D hooking and accessibility APIs.
If there's a lot of IP in your program. Then don't make it all available onscreen. Make sure it's tedious to crawl the GUI for text, and hard to automate it. And don't load whole texts in memory of the program.
Possible solutions:
1. To prevent copying of text. Draw the text as an image.
2. To prevent accessibility technologies, like screen readers - override WndProc in your control, handle and ignore the window message WM_GETOBJECT.
3. To make it harder if they try to use OCR. Draw graphics behind the text. Human readable, but much harder for a machine to interpret it.
Neither of these methods are invasive for the user.
** A very invasive suggestion **:
If you are really serious about preventing anyone from "stealing" your content.
Implement mouse and keyboard hooks. Filter out typical copy shortcuts. Prevent the mouse from leaving the boundaries of your application.
Allow your application to only run when the OS runs well-known processes and services.
If any process starts which you don't recognize, black out the application and notify the user about it, and request the user to close it. And ofc make sure someone is not just spoofing a well-known process.
Monitor the clipboard as you suggested yourself.
You can ofc soften some of these suggestions based on the context of your application.
As Scott just posted it likely can be prevented with API hooks to see that paint events only go to desktop bound handles and not others, and refuse to paint otherwise. However, you need to consider the following scenarios and see if they're relevant threat to your approach or not:
Your software may be running in a virtual machine like VMWare. Such software has capapbilities to capture screen that does so at "virtual hardware" level, and your API hooks will not be able to discern it - and this would be the easiest way approach if I wanted to bypass your protections.
As a post suggests here, nothing also prevents someone to take monitor cable and plug it into another computer's capture card, and take screenshot that way. Again, your hooks will be helpless here.
Bottom line, you can make it somewhat harder to do, but bypassing such protection may be pretty trivial thing to do.
My 2c.

Intercept and cancel key press events for DirectX game

I'm working on a small tool for a DirectX game and I want to prevent the user from pressing a certain key (F12 in this case) for a certain period.
I could find many options for simulating keypresses but what are the options when it comes to nulling out a keystroke before the game reads it?
The language doesn't really matter, although I would prefer a C# or C++ solution, or just a nudge in the right direction :)
Thanks in advance!
The good news is, I've done this before so I can say that it is possible and it does work.
The bad news is that it's not simple. It requires a lot of complicated code, and will likely take a long time to implement, but I'll explain how you can do it.
Applications like DirectX games usually register for raw input.
Since you want to stop a keyboard event from reaching the application, you need a way to insert your code between the raw input and the game so you can check the raw input and decide whether to allow it to be passed to the game:
So you want to change the flow from:
Raw Input --> Game
to
Raw Input --> Your Code --> Game
Without having access to the source code of the game, you have to find a way to insert your code.
When there is keyboard input available, the game will call the WinAPI function GetRawInputData, which will tell it about the keyboard event. Ideally, what we want is when the game calls this function, it actually calls our code instead of the WinAPI function. Then we can decide what to tell the game about the keyboard event, we could tell it anything we want (e.g. ignore F12). Sounds great right? Here's where it gets interesting...
We can take advantage of how windows loads executables into memory. Typically, a program uses (or 'imports') calls to functions in other DLLs (such as GetRawInputData, in User32.dll). When the program gets loaded into memory, Windows will fill in a table (the Import Address Table (IAT)) with pointers to the executable code in the appropriate DLLs. This means that when the program calls the function, it gets directed to the executable code in User32.dll in memory to run it.
Wouldn't it be great if we could write/patch the address of one of our functions into that table, so that when the game calls GetRawInputData, it actually gets directed to our function for us to process? Well we can! It's called Import Address Table Patching.
There's a pretty good article on it here with some working code in C++. You should first read it to understand in more detail how it works, then you can modify it to support your needs. It will work, but I know it's probably more work (much more work) than you would have been hoping for, but essentially you're hacking the application which is never easy to do.
It's worth doing, even just to gain a better understanding of Windows behind the scenes.
Good luck!
EDIT
As Simon said, Windows Hooks is a much simpler way to do it if the game isn't using raw input. DirectX Games tend to be a special case that don't really work too well with standard Hooks as they use special methods to get the input from the user. By all means give it a go though, it will be a lot easier if it works.

Register Application programmatically for Graphic card

I am trying to write a Setup for an application with Inno Setup, which is pretty neat by the way ;) , but now I am stuck with a problem regarding the graphiccard.
I am installing a 3D application and want to configure the program so that it uses a certain graphic card as default.
It sounded logical to me that somewhere in the registry must be a something to configure that.
I tried to change the default graphiccard manually und compare the changes in the registry but couldn't find any entrys relative to the changes
I know that programs like Adobe Photoshop are using the high performance graphiccards by default so there must be some kind of solution to my problem.
I am using inno script to write my setup but I can call external programs to do some tasks so I could write a C# program to execute this task.
This option is mostly relevant for Windows 7 and Windows 8 because I only saw it there.
Does anyone of you know how to change the default graphiccard of an application programmatically?
Your approach, sorry, sucks. This is not something you should do during setup. What if the card changes?
Check it during application start. Let the user choose if you do not find anything. Let him update. Not everyone has only one graphics card. People do update the graphics card. Why should I rerun setup just to get this done?
And it is quite easy to identify graphics cards, performance is another story. Which one is "high performance" in your eyes?

Digital Input device to c#

The Problem:
I'm writing an application that needs to receive electrical input from a machine every time the machine does something.
I have a Limit switch set up to the machine and it currently completes a circuit every time the machine does it's thing
I need it to input into a computer using usb as oppose to just complete a circuit.
I had a dataq 'dl-148u-sp' And i got the c# code to produce a graph using ActiveX controls but all i really need is the digital output from the circuit being completed (which for the life of me i couldn't figure out how to do)..
I ended up frying the device(i think) even the software it came with doesn't recognize it anymore...
I need a new device, and it turns out they discontinued the one i had, and the next one up after shipping is like 90$.
The Question:
Is there a Better/Cheaper/Easier way of doing this? Or can anyone suggest a Good device that's easy to get the output using c# code so i can incorporate it into a program i made?
It's not clear if you are asking for a hardware or software solution here. Are you asking what the best way to facilitate that data transfer from your machine to the PC? If so, this may not be the place to ask, but you might look at a USB to GPIO module.
http://numato.com/8-channel-usb-gpio-module is an example.
I'd recommend an Arduino:
http://www.arduino.cc/playground/Main/InterfacingWithHardware
They dev kits are cheap and there's a ton of open/free libraries that interface the Arduino to C#.
More expensive and complex board is IOFirebug with c# library and many functions. Input voltage range is from 5V to 30V.

Categories

Resources