level 1
albertlee
楼主
1. 添加 SwiPlCs.dll 的引用
注意区分 32, 64 位版本,对于 SwiPlCs64.dll 在64位机器上运行时要改名成 SwiPlCs.dll
2. C# 代码:
using System;
using System.Collections.Generic;
using System.Text;
using SbsSW.SwiPlCs;
namespace TestPl
{
class Program
{
static void Main(string[] args)
{
Environment.SetEnvironmentVariable("SWI_HOME_DIR", @"C:\Program Files\pl\boot32.prc");
if (!PlEngine.IsInitialized)
{
String[] param = { "-q" }; // suppressing informational and banner messages
PlEngine.Initialize(param);
PlQuery.PlCall("consult(['cat.pl'])");
PlQuery.PlCall("assert(cat(tom))");
PlQuery.PlCall("assert(mouse(jerry))");
PlQuery.PlCall("assert(mouse(micky))");
using (PlQuery q = new PlQuery("can_eat(X, Y)"))
{
foreach (PlQueryVariables v in q.SolutionVariables)
{
Console.WriteLine("{0} can eat {1}", v["X"].ToString(),v["Y"].ToString());
}
}
PlEngine.PlCleanup();
Console.WriteLine("finshed!");
}
Console.ReadKey();
}
}
}
3. cat.pl 内容:
can_eat(X, Y) :- cat(X), mouse(Y).
4. 执行结果
tom can eat jerry
tom can eat micky
finshed!
2009年11月30日 08点11分
1
注意区分 32, 64 位版本,对于 SwiPlCs64.dll 在64位机器上运行时要改名成 SwiPlCs.dll
2. C# 代码:
using System;
using System.Collections.Generic;
using System.Text;
using SbsSW.SwiPlCs;
namespace TestPl
{
class Program
{
static void Main(string[] args)
{
Environment.SetEnvironmentVariable("SWI_HOME_DIR", @"C:\Program Files\pl\boot32.prc");
if (!PlEngine.IsInitialized)
{
String[] param = { "-q" }; // suppressing informational and banner messages
PlEngine.Initialize(param);
PlQuery.PlCall("consult(['cat.pl'])");
PlQuery.PlCall("assert(cat(tom))");
PlQuery.PlCall("assert(mouse(jerry))");
PlQuery.PlCall("assert(mouse(micky))");
using (PlQuery q = new PlQuery("can_eat(X, Y)"))
{
foreach (PlQueryVariables v in q.SolutionVariables)
{
Console.WriteLine("{0} can eat {1}", v["X"].ToString(),v["Y"].ToString());
}
}
PlEngine.PlCleanup();
Console.WriteLine("finshed!");
}
Console.ReadKey();
}
}
}
3. cat.pl 内容:
can_eat(X, Y) :- cat(X), mouse(Y).
4. 执行结果
tom can eat jerry
tom can eat micky
finshed!