Vahid.Keykhaey
Member
Hi, My code is as below:
public void Init() { IntPtr hCTAPI = CTAPI.ctOpen(null, "u1", "1", 2); TestMe(hCTAPI); } [DllImport("ctapi.dll", CallingConvention = CallingConvention.StdCall, SetLastError = true)] public static extern IntPtr ctOpen(string sComputerName, string sUsername, string sPassword, UInt32 nMode); [DllImport("ctapi.dll", CallingConvention = CallingConvention.StdCall, SetLastError = true)] public static extern bool ctTagRead(IntPtr hCTAPI, [MarshalAs(UnmanagedType.LPStr)] string tag, [MarshalAs(UnmanagedType.LPStr)] System.Text.StringBuilder value, int length); public static void TestMe(IntPtr ip) { var tag = "tag1"; var tagPtr = Marshal.StringToHGlobalAnsi(tag); System.Text.StringBuilder vsl = new StringBuilder(20); bool b = ctTagRead(ip, tag, vsl, 20);//, tagValueItemsPtr); }
bool b is always false. I dont know what to do!
I used GetLastError Function and I found out there is a "No connection could be made because the target machine actively refused it" error. but I am trying to connect to citect on my own computer which has an installed and working citect on it, and in citect.ini [ctapi] remote is set to 1.
public void Init() { IntPtr hCTAPI = CTAPI.ctOpen(null, "u1", "1", 2); TestMe(hCTAPI); } [DllImport("ctapi.dll", CallingConvention = CallingConvention.StdCall, SetLastError = true)] public static extern IntPtr ctOpen(string sComputerName, string sUsername, string sPassword, UInt32 nMode); [DllImport("ctapi.dll", CallingConvention = CallingConvention.StdCall, SetLastError = true)] public static extern bool ctTagRead(IntPtr hCTAPI, [MarshalAs(UnmanagedType.LPStr)] string tag, [MarshalAs(UnmanagedType.LPStr)] System.Text.StringBuilder value, int length); public static void TestMe(IntPtr ip) { var tag = "tag1"; var tagPtr = Marshal.StringToHGlobalAnsi(tag); System.Text.StringBuilder vsl = new StringBuilder(20); bool b = ctTagRead(ip, tag, vsl, 20);//, tagValueItemsPtr); }
bool b is always false. I dont know what to do!
I used GetLastError Function and I found out there is a "No connection could be made because the target machine actively refused it" error. but I am trying to connect to citect on my own computer which has an installed and working citect on it, and in citect.ini [ctapi] remote is set to 1.