Jump to content
OMRON Forums

Make a C# HMI run on Power PMAC and Communicate to PPmac


bradp

Recommended Posts

PPmac has the mono system installed so it can execute and even build .NET solutions. Once you have an exe run it by entering the keyword mono followed by a space and the executable's name. To make a C# program that executes on PPmac talk to PPmac you must import the needed functions from libppmac.so. The three basic functions are InitLibrary(), CloseLibrary(), and GetResponse(). The syntax is: [DllImport("/var/ftp/ppmaclibs/libppmac/libppmac.so")] internal static extern int InitLibrary(); [DllImport("/var/ftp/ppmaclibs/libppmac/libppmac.so")] internal static extern void CloseLibrary(); [DllImport("/var/ftp/ppmaclibs/libppmac/libppmac.so", EntryPoint = "GetResponse", CharSet = CharSet.Ansi)] static extern int GetResponse([In, MarshalAs(UnmanagedType.LPStr)] string q, [Out, MarshalAs(UnmanagedType.LPStr)] StringBuilder a, Int32 maxlen, Byte echomode); To see how to use these download the attached Visual Studio 2008 C# console solution. In the release folder you will find the .exe which can be placed on the PPmac ftp site and executed from a telnet session. After you copy it use chmode +x PPmacConsoleMonoTest01.exe Then execute it with mono PPmacConsoleMonoTest01.exe
Link to comment
Share on other sites

  • Replies 12
  • Created
  • Last Reply

Top Posters In This Topic

Is there a way to access the C API from C#? I'm thinking specifically that I would like to access the same functions as in C programs, such as the calls to get global vars and ptr vars. I realize that you can do this with GetResponse() but it is significantly slower. Is it simply a matter of finding the C api *.so file and doing the same as in this example?
Link to comment
Share on other sites

  • 1 year later...
I'm currently using the following class as a static C# API for the native PowerPMAC functions (i.e. when running HMI on the PPMAC itself with the video option). [code] class Pmac { public const string DllLocation = "/var/ftp/ppmaclibs/libppmac/libppmac.so"; [DllImport(DllLocation)] internal static extern int InitLibrary(); [DllImport(DllLocation)] internal static extern void CloseLibrary(); [DllImport(DllLocation, EntryPoint = "GetResponse", CharSet = CharSet.Ansi)] private static extern int GetResponse([In, MarshalAs(UnmanagedType.LPStr)] string q, [Out, MarshalAs(UnmanagedType.LPStr)] StringBuilder a, Int32 maxlen, Byte echomode); [DllImport(DllLocation, EntryPoint = "GetPmacVar", CharSet = CharSet.Ansi)] private static extern int GetPmacVar([In, MarshalAs(UnmanagedType.LPStr)] string VarName, ref double VarRetValue); [DllImport(DllLocation, EntryPoint = "SetPmacVar", CharSet = CharSet.Ansi)] private static extern int SetPmacVar([In, MarshalAs(UnmanagedType.LPStr)] string VarName, double VarValue); internal static double GetVar(string VarName) { Double val = 0; if (GetPmacVar(VarName, ref val) != 0) MessageBox.Show("The Following Variable Could not be retreived from the PMAC: " + VarName); return val; } internal static void SetVar(string VarName, double VarValue) { if (SetPmacVar(VarName, VarValue) != 0) MessageBox.Show("The Following Variable Could not be set in the PMAC: " + VarName); } } [/code] I don't know if these are 100% correct but I use all these calls daily on a machine that is running. BTW, I wrapped the SetPmacVar and GetPmacVar() functions so I can do: Pmac.SetVar() and Pmac.GetVar() which I find cleaner. but its a preference thing. KEJR
Link to comment
Share on other sites

Thanks for the tips KEJR. I am brand new to MONO, and a bit rusty on C# (I usually do VB.NET). So, pardon my ignorance, but where do MessageBox.Show statements go to in your PMAC class? Do you need to include a system DLL for this? Is it just System.Windows.Forms that I need? And, where does it display?
Link to comment
Share on other sites

[quote='BoneSkier' pid='2589' dateline='1318885948'] Thanks for the tips KEJR. I am brand new to MONO, and a bit rusty on C# (I usually do VB.NET). So, pardon my ignorance, but where do MessageBox.Show statements go to in your PMAC class? Do you need to include a system DLL for this? Is it just System.Windows.Forms that I need? And, where does it display? [/quote] BoneSkier, To use the MessageBox you need to put a using statement for System.Windows.Forms in your application ("using System.Windows.Forms;"). No need to deploy this dll however, because it exists in the Mono framework (it is already installed on the Power PMAC). The MessageBox will displayed as a popup box (e.g. if you plug an HDMI cable into the Power PMAC display port and launch your program, it will be displayed on the screen like a normal program. If it is a console app, it will be displayed in the terminal).
Link to comment
Share on other sites

  • 2 months later...
This is a great thread for those of us with limited knowledge of MONO. I've tried your examples ...thanks works great! I am interested in accessing the P-Variables across the Mono interface. Seems straight forward to import the GetSharedMemPtr() function. Also to include the 'rtpmacapi.h' into the C# solution. Can't seem to make it work though... any suggestions?...you seem to have a bit more depth with this mono stuff. however, the typedef for "pshm" is SHM
Link to comment
Share on other sites

[quote='HRS' pid='2989' dateline='1326402492'] This is a great thread for those of us with limited knowledge of MONO. I've tried your examples ...thanks works great! I am interested in accessing the P-Variables across the Mono interface. Seems straight forward to import the GetSharedMemPtr() function. Also to include the 'rtpmacapi.h' into the C# solution. Can't seem to make it work though... any suggestions?...you seem to have a bit more depth with this mono stuff. however, the typedef for "pshm" is SHM [/quote]
Link to comment
Share on other sites

I would not try to access shared memory in mono directly. It may be able to be done and someone can correct me, but dealing with pointers in c# doesn't exist (by design) so I don't know where you would go with this. Personally, I do everything from P vars as they are really just double floating point arrays in shared memory. All environments can get at them on the PPMAC. Since a Double is the largest data type on the system you can use them for passing everything except strings (I suppose you could, but really??). I use sockets to pass strings back and forth to my C applications, its kind of a pain at first but it works well once you get the hang of it. May I ask why you need to read shared memory *directly* in the HMI? I haven't done this, but I'm pretty sure the "GetResponse" command lets you get at all the servo data structures it can parse, so this handles alot of functionality. KEJR
Link to comment
Share on other sites

  • 3 months later...
I am using a MONO program, and I just compiled with .NET 4.0. Apparently, the mono.posix.dll that I am using doesn't support this. I get this error: The runtime version supported by this application is unavailable. Using default runtime: v1.1.4322 I poked around on the net and it looks like there may be newer versions available, but not sure which to get. http://www.go-mono.com/mono-downloads/download.html I was currently using version 2.0.0.0 of mono.posix.dll. Thanks for your help with this.
Link to comment
Share on other sites

[quote='BoneSkier' pid='3394' dateline='1335287938'] I am using a MONO program, and I just compiled with .NET 4.0. [/quote] Do a version on the MONO system, I'm pretty sure the mono that shipped with PPMAC only supports .NET 2.0 which is what I did for my project that targeted mono on the PPMAC. .NET 2.0 includes windows forms so unless you are doing something complex it should be OK for a machine HMI. You should be able to change your Visual Studio settings to compile for .NET 2.0 runtime. In the end we ended up doing a connection to a panel PC over TCP/IP and the GPASCII program (Its quite fast for our needs). KEJR
Link to comment
Share on other sites

  • 2 years later...
[quote='KEJR' pid='3395' dateline='1335289106'] Do a version on the MONO system, I'm pretty sure the mono that shipped with PPMAC only supports .NET 2.0 which is what I did for my project that targeted mono on the PPMAC. .NET 2.0 includes windows forms so unless you are doing something complex it should be OK for a machine HMI. You should be able to change your Visual Studio settings to compile for .NET 2.0 runtime. [/quote] [b]uname -a[/b] [color=#696969]Linux powerpmac 2.6.30.3 #34 Tue Dec 17 09:52:34 PST 2013 ppc GNU/Linux[/color] [b]mono -V[/b] [color=#696969]Mono JIT compiler version 2.6.1 (tarball Tue Feb 2 09:56:27 PST 2010) Copyright (C) 2002-2008 Novell, Inc and Contributors. www.mono-project.co TLS: __thread GC: Included Boehm (with typed GC and Parallel Mark) SIGSEGV: altstack Notifications: epoll Architecture: ppc Disabled: none[/color] [b]Mono 2.6.1[/b] should compile and run projects that target [b].NET 3.5[/b] and lower.
Link to comment
Share on other sites

Guest
This topic is now closed to further replies.

×
×
  • Create New...