tags:

views:

53

answers:

3

I work for a medium sized business integrating a moderate number of systems into one web application written in Ruby on Rails and running on Redhat. One of the functions of the application is to communicate with remote equipment. Some of the equipment I can communicate with directly, some I have to rely on the equipment reporting in to a database.

I was recently offered a "private API" from one of our equipment manufacturers to communicate with some of our remote gear that I do not currently have communication with. Of course I was interested in this possibility. The catch is that it is provided as a .NET 2.0 dll. That is the extent of the information I have about the interface.

Assuming that I can load the dll from mono (which I currently know nothing about) is it even possible to call into mono from ruby? Am I in for a world of hurt if I can and do?

(Getting this to work would save so much pain in other areas that I am willing to consider making system calls if I have to, assuming the performance wasn't atrocious)

+3  A: 

I don't think you can call into anything that's not a plain self-contained library that exposes a C calling convention interface.

That said, what I would consider doing in your situation (assuming that the .NET dll works with mono) is to write a small .NET/mono executable that interacts with the DLL and that allows you to drive the DLL, say, via command line parameters and read the results back via stdin (or write it to a file, for example). That way you've got a clear separation between 'worlds' and given that spawning a process is fairly easy in ruby, this shouldn't be overly hard to implement.

Timo Geusch
I think this will probably be the solution in the end. Assuming that there is no other way to interface with the equipment (via a standard TCP protocol). I like the separation of worlds that it provides while still being simple to do.
salt.racer
+2  A: 

Without using something like IronRuby you would probably be unable to access .NET-code from native code (which Ruby is). You would have to write a form of wrapper (written in some .NET technology) that gives you a form of RPC interface, probably using some form of IPC mechanism.

There is also more information here, if you find a way to run COM objects on Mono: http://stackoverflow.com/questions/265879/can-ruby-import-a-net-dll

Daniel Bruce
A: 

In addition to Timo's suggestion which I really like, I would first check what exactly "DLL as API" means in this case. What does that DLL do? If it communicates with the remote equipment using some well-documented and simple TCP protocol (not very likely, I know, but possible), you might ditch the DLL altogether and write the same thing in Ruby.

Mladen Jablanović
Yeah, figuring out what the dll is actually doing is going to be the first order of business. (Actually, figuring out if it runs under mono is. :) ) Then finding out how willing the company is (it's a small company) to provide bindings in ruby. Then implementing Timo's suggestion.
salt.racer