Our full technical support staff does not monitor this forum. If you need assistance from a member of our staff, please submit your question from the Ask a Question page.


Log in or register to post/reply in the forum.

Reference Coralib and SimplePB - BMP5 SDK


ivi May 25, 2011 06:57 PM

Hi there,

I want to know how use coralib3d.dll and simplepb.dll with language C#, how add reference them. There examples only in another languages like VB6, Delphi6, C++. I would like the example SimplePB in C# language. Anyone do this??

Thanks

Iv


artmann May 26, 2011 07:50 PM

hi ivi

i have once tried to use C# with the BMP5-SDK, but did not get too far. One reason is that i have not the skills in C#.
The other is that (even when i tried it in C/C++) the function OpenIPPort always returns zero, indicating a successful connection even if i enter a invalid ip.
This was once mentioned in this forum.
Maybe a CS-Guru can shed a light on this?

Below is the snippet i have used, but be warned that it is full of errors as i think i did not have used the correct marshaling parameters.
Most of the time it throws exceptions, but if i execute it like 20 times at least on my PC one time it will be successful. I have no clue why this is so, but take it as a starting point...

If you have more luck than me, please let the forum know!

using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;
namespace PakBusTest
{
class Program
{
[DllImport("simplepb.dll", EntryPoint = "OpenIPPort", CharSet = CharSet.Auto, CallingConvention = CallingConvention.StdCall)]
public static extern int OpenIPPort([MarshalAs(UnmanagedType.LPStr)] String ip, int port);
[DllImport("simplepb.dll")]
public static extern int CloseIPPort();
[DllImport("simplepb.dll", EntryPoint = "GetClock", CharSet = CharSet.Auto, CallingConvention = CallingConvention.StdCall)]
public static extern int GetClock(int pakid, int type, [MarshalAs(UnmanagedType.LPStr)] out string data, [MarshalAs(UnmanagedType.I4)] out System.Int32 return_data_len);
static void Main(string[] args)
{
int result=0;
string data = "";
System.Int32 len = 0;
try
{
System.Console.WriteLine("\nCR1000 Test\n");
result = OpenIPPort("192.168.178.22", 6785);
System.Console.WriteLine(" Open : {0}", result);
if (result == 0)
{
// System.Threading.Thread.Sleep(1000);
System.Console.Write(" GetClock : ");
result = GetClock(1, 3, out data, out len);
System.Console.WriteLine("{0}", result);
System.Console.WriteLine(" -> Data : <{0}>", data);
System.Console.WriteLine(" -> Len : {0}", len);
result = CloseIPPort();
System.Console.WriteLine(" Close : {0}\n", result);
}
}catch(System.AccessViolationException){
System.Console.WriteLine(" Exception\n");
}
System.Console.WriteLine("\nBye");
}
}
}

* Last updated by: artmann on 5/26/2011 @ 1:54 PM *


ivi May 27, 2011 12:31 PM

Hi Artmann,

Thank's for answer my question. I don't have skills in C# too. I'm trying to use OpenPort function, and it always returns zero too. Thank's for your code, if i do it i'll post.

More answers??? Please.

Thanks.

Ivi

Log in or register to post/reply in the forum.