PDK开发初步(C#)(一)
PDK是PMAC运动控制器的上位机开发包,通过该开发包可以定制化开发客户的上位机程序。
以C#为例,开始编程时,需要注意如下工作:
1,安装&使用基于Visual Studio2015的C#编程环境。
2,新建C#项目,在项目属性中设置“目标框架”为.NET Framework4.6.1,“输出类型”为Windows应用程序。
3,增加三条using:
using ODT.PowerPmacComLib; using ODT.Common.Services; using ODT.Common.Core;
4,在namespace命名空间内,增加:
delegate bool ComErrorInvokeDelegate(); delegate void AppendTextDelegate(String message);
5,在类class from1下,增加5行:
ISyncGpasciiCommunicationInterface communication = null; deviceProperties currentDeviceProp = new deviceProperties(); deviceProperties currentDevProp = new deviceProperties(); String commands = String.Empty; // If you already added this, don’t add this again
String response = String.Empty; // For storing the response from PPMAC
6,在InitializeComponent()下增加7行:
this.currentDevProp.IPAddress = Settings1.Default.defaultIPAddress; this.currentDevProp.Password = Settings1.Default.defaultPassword; this.currentDevProp.PortNumber = Convert.ToInt16(Settings1.Default.defaultPort); this.currentDevProp.User = Settings1.Default.defaultUser; this.currentDevProp.Protocol = CommunicationGlobals.ConnectionTypes.SSH; this.communication = Connect.CreateSyncGpascii(currentDevProp.Protocol, this.communication);
var bSuccess = this.communication.ConnectGpAscii(currentDevProp.IPAddress, currentDevProp.PortNumber, currentDevProp.User, currentDevProp.Password);
7,“引用”右键,添加引用。分别添加:ODT.PowerPmacComLib.dll,和ODT.Common.dll两个库文件。
8,右键工程-添加-新建项-设置文件,修改配置文件内容,添加如下条目:
9,添加Textbox控件和一个Button按钮,在按钮的Click事件中,写如下Code:
String response; var communicationStatus = this.communication.GetResponse(CMD_TXT.Text, out response); Display_TXT.Text = response;
CMD_TXT.Text = "";
在textbox控件中可以输入相关指令来控制PMAC运动,至此可以完成与PMAC控制器的基本通讯。