在好例子网,分享、交流、成长!
您当前所在位置:首页C# 开发实例C#语言基础 → C# 实现与翠欧控制器通信(附源码)

C# 实现与翠欧控制器通信(附源码)

C#语言基础

下载此实例
  • 开发语言:C#
  • 实例大小:0.29M
  • 下载次数:41
  • 浏览次数:906
  • 发布时间:2020-03-16
  • 实例类别:C#语言基础
  • 发 布 人:wangmiao2009
  • 文件格式:.zip
  • 所需积分:2
 相关标签: 控制 通信

实例介绍

【实例简介】实例    含源码   Visual Studio和翠欧控制器通信

【实例截图】

from clipboard

【核心代码】

using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;

namespace TrioPC_Test
{
	/// <summary>
	/// Summary description for Form1.
	/// </summary>
	public class frmMain : System.Windows.Forms.Form
	{
		private System.Windows.Forms.Button btnExit;
		private System.Windows.Forms.GroupBox groupBox1;
		private System.Windows.Forms.Button btnOpen;
		private System.Windows.Forms.Button btnClose;
		private System.Windows.Forms.Label label1;
		private System.Windows.Forms.ComboBox cbConnectionType;
		private System.Windows.Forms.Label label2;
		private System.Windows.Forms.TextBox tbHostAddress;
		private System.Windows.Forms.Label label3;
		private System.Windows.Forms.TextBox tbChannel;
		private AxTrioPCLib.AxTrioPC axTrioPC;
		private System.Windows.Forms.TabPage tabStatus;
		private System.Windows.Forms.TabPage tabAxisParameters;
		private System.Windows.Forms.TabPage tabIO;
		private System.Windows.Forms.TabPage tabTable;
		private System.Windows.Forms.TabPage tabVRs;
		private System.Windows.Forms.Label label4;
		private System.Windows.Forms.Label label5;
		private System.Windows.Forms.Label label6;
		private System.Windows.Forms.Label label7;
		private System.Windows.Forms.TextBox tbAnalogueIOs;
		private System.Windows.Forms.TextBox tbDigitalIOs;
		private System.Windows.Forms.TextBox tbSystemVersion;
		private System.Windows.Forms.TextBox tbControllerType;
		/// <summary>
		/// Required designer variable.
		/// </summary>
		private System.ComponentModel.Container components = null;
		private System.Windows.Forms.Button btnRefresh;
		private System.Windows.Forms.Button btnRefreshLamp;
		private System.Windows.Forms.TabControl shtControllerPages;
		private System.Windows.Forms.Label label8;
		private System.Windows.Forms.TextBox tbAxis;
		private System.Windows.Forms.ListView lstParameters1;
		private System.Windows.Forms.ColumnHeader clmDescription;
		private System.Windows.Forms.ColumnHeader clmValue;
		private System.Windows.Forms.ListView lstParameters2;
		private System.Windows.Forms.ColumnHeader columnHeader1;
		private System.Windows.Forms.ColumnHeader columnHeader2;
		private System.Windows.Forms.Label label9;
		private System.Windows.Forms.TextBox tbDigitalIOValue;
		private System.Windows.Forms.Label label10;
		private System.Windows.Forms.Label label11;
		private System.Windows.Forms.TextBox tbTableStart;
		private System.Windows.Forms.TextBox tbTableEntries;
		private System.Windows.Forms.ListView lstTableValues;
		private System.Windows.Forms.ColumnHeader clmEntry;
		private System.Windows.Forms.ColumnHeader clmTableValue;
		private System.Windows.Forms.ColumnHeader columnHeader3;
		private System.Windows.Forms.ColumnHeader columnHeader4;
		private System.Windows.Forms.ListView lstVRValues;
		private System.Windows.Forms.ColumnHeader columnHeader5;
		private System.Windows.Forms.ColumnHeader columnHeader6;
		private System.Windows.Forms.TextBox tbVREntries;
		private System.Windows.Forms.TextBox tbVRStart;
		private System.Windows.Forms.Label label12;
		private System.Windows.Forms.Label label13;
		private System.Windows.Forms.TabPage tabDir;
		private System.Windows.Forms.TextBox tbDirList;
		private System.Windows.Forms.Button btnSetVR;
		private System.Windows.Forms.TabPage tabMoves;
		private System.Windows.Forms.Label label14;
		private System.Windows.Forms.TextBox tbRunStatus;
		private System.Windows.Forms.Button btnRun;
		private System.Windows.Forms.Label label15;
		private System.Windows.Forms.TextBox tbWatchdogState;
		private System.Windows.Forms.ListView lstMoveParams;
		private System.Windows.Forms.ColumnHeader clmParameter;
		private System.Windows.Forms.ColumnHeader clmAxis0;
		private System.Windows.Forms.ColumnHeader clmAxis1;
		private System.Windows.Forms.Button btnWriteTableValues;

		protected short m_iPortID;
		protected int m_iSelectedTableItem;
		private System.Windows.Forms.TextBox tbTableEdit;
		protected int m_iPreSelectedTableItem;

		public frmMain()
		{
			//
			// Required for Windows Form Designer support
			//
			InitializeComponent();

			m_iPortID = 0;
			cbConnectionType.SelectedIndex = 0;
			m_iSelectedTableItem = -1;
			m_iPreSelectedTableItem = -1;
			InitParameterGrids();
			tbRunStatus.Text = "Stopped";
			tbRunStatus.Refresh();
		}
		/// <summary>
		/// Clean up any resources being used.
		/// </summary>
		protected override void Dispose( bool disposing )
		{
			if( disposing )
			{
				if (components != null) 
				{
					components.Dispose();
				}
			}
			base.Dispose( disposing );
		}

		#region Windows Form Designer generated code
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{
            this.btnExit = new System.Windows.Forms.Button();
            this.btnOpen = new System.Windows.Forms.Button();
            this.btnClose = new System.Windows.Forms.Button();
            this.groupBox1 = new System.Windows.Forms.GroupBox();
            this.tbChannel = new System.Windows.Forms.TextBox();
            this.label3 = new System.Windows.Forms.Label();
            this.tbHostAddress = new System.Windows.Forms.TextBox();
            this.label2 = new System.Windows.Forms.Label();
            this.cbConnectionType = new System.Windows.Forms.ComboBox();
            this.label1 = new System.Windows.Forms.Label();
            this.shtControllerPages = new System.Windows.Forms.TabControl();
            this.tabStatus = new System.Windows.Forms.TabPage();
            this.tbAnalogueIOs = new System.Windows.Forms.TextBox();
            this.tbDigitalIOs = new System.Windows.Forms.TextBox();
            this.tbSystemVersion = new System.Windows.Forms.TextBox();
            this.tbControllerType = new System.Windows.Forms.TextBox();
            this.label7 = new System.Windows.Forms.Label();
            this.label6 = new System.Windows.Forms.Label();
            this.label5 = new System.Windows.Forms.Label();
            this.label4 = new System.Windows.Forms.Label();
            this.tabAxisParameters = new System.Windows.Forms.TabPage();
            this.lstParameters2 = new System.Windows.Forms.ListView();
            this.columnHeader1 = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
            this.columnHeader2 = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
            this.lstParameters1 = new System.Windows.Forms.ListView();
            this.clmDescription = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
            this.clmValue = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
            this.tbAxis = new System.Windows.Forms.TextBox();
            this.label8 = new System.Windows.Forms.Label();
            this.tabIO = new System.Windows.Forms.TabPage();
            this.tbDigitalIOValue = new System.Windows.Forms.TextBox();
            this.label9 = new System.Windows.Forms.Label();
            this.tabTable = new System.Windows.Forms.TabPage();
            this.tbTableEdit = new System.Windows.Forms.TextBox();
            this.btnWriteTableValues = new System.Windows.Forms.Button();
            this.lstTableValues = new System.Windows.Forms.ListView();
            this.clmEntry = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
            this.clmTableValue = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
            this.tbTableEntries = new System.Windows.Forms.TextBox();
            this.tbTableStart = new System.Windows.Forms.TextBox();
            this.label11 = new System.Windows.Forms.Label();
            this.label10 = new System.Windows.Forms.Label();
            this.tabVRs = new System.Windows.Forms.TabPage();
            this.btnSetVR = new System.Windows.Forms.Button();
            this.lstVRValues = new System.Windows.Forms.ListView();
            this.columnHeader5 = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
            this.columnHeader6 = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
            this.tbVREntries = new System.Windows.Forms.TextBox();
            this.tbVRStart = new System.Windows.Forms.TextBox();
            this.label12 = new System.Windows.Forms.Label();
            this.label13 = new System.Windows.Forms.Label();
            this.tabDir = new System.Windows.Forms.TabPage();
            this.tbDirList = new System.Windows.Forms.TextBox();
            this.tabMoves = new System.Windows.Forms.TabPage();
            this.tbWatchdogState = new System.Windows.Forms.TextBox();
            this.label15 = new System.Windows.Forms.Label();
            this.btnRun = new System.Windows.Forms.Button();
            this.tbRunStatus = new System.Windows.Forms.TextBox();
            this.label14 = new System.Windows.Forms.Label();
            this.lstMoveParams = new System.Windows.Forms.ListView();
            this.clmParameter = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
            this.clmAxis0 = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
            this.clmAxis1 = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
            this.btnRefresh = new System.Windows.Forms.Button();
            this.btnRefreshLamp = new System.Windows.Forms.Button();
            this.columnHeader3 = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
            this.columnHeader4 = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
            this.groupBox1.SuspendLayout();
            this.shtControllerPages.SuspendLayout();
            this.tabStatus.SuspendLayout();
            this.tabAxisParameters.SuspendLayout();
            this.tabIO.SuspendLayout();
            this.tabTable.SuspendLayout();
            this.tabVRs.SuspendLayout();
            this.tabDir.SuspendLayout();
            this.tabMoves.SuspendLayout();
            this.SuspendLayout();
            // 
            // btnExit
            // 
            this.btnExit.Location = new System.Drawing.Point(595, 353);
            this.btnExit.Name = "btnExit";
            this.btnExit.Size = new System.Drawing.Size(87, 26);
            this.btnExit.TabIndex = 0;
            this.btnExit.Text = "Exit";
            this.btnExit.Click  = new System.EventHandler(this.btnExit_Click);
            // 
            // btnOpen
            // 
            this.btnOpen.Location = new System.Drawing.Point(48, 172);
            this.btnOpen.Name = "btnOpen";
            this.btnOpen.Size = new System.Drawing.Size(86, 26);
            this.btnOpen.TabIndex = 1;
            this.btnOpen.Text = "Open";
            this.btnOpen.Click  = new System.EventHandler(this.btnOpen_Click);
            // 
            // btnClose
            // 
            this.btnClose.Enabled = false;
            this.btnClose.Location = new System.Drawing.Point(48, 215);
            this.btnClose.Name = "btnClose";
            this.btnClose.Size = new System.Drawing.Size(86, 26);
            this.btnClose.TabIndex = 2;
            this.btnClose.Text = "Close";
            this.btnClose.Click  = new System.EventHandler(this.btnClose_Click);
            // 
            // groupBox1
            // 
            this.groupBox1.Controls.Add(this.tbChannel);
            this.groupBox1.Controls.Add(this.label3);
            this.groupBox1.Controls.Add(this.tbHostAddress);
            this.groupBox1.Controls.Add(this.label2);
            this.groupBox1.Controls.Add(this.cbConnectionType);
            this.groupBox1.Controls.Add(this.label1);
            this.groupBox1.Controls.Add(this.btnOpen);
            this.groupBox1.Controls.Add(this.btnClose);
            this.groupBox1.Location = new System.Drawing.Point(547, 9);
            this.groupBox1.Name = "groupBox1";
            this.groupBox1.Size = new System.Drawing.Size(173, 258);
            this.groupBox1.TabIndex = 3;
            this.groupBox1.TabStop = false;
            this.groupBox1.Text = "Connection";
            // 
            // tbChannel
            // 
            this.tbChannel.Location = new System.Drawing.Point(86, 121);
            this.tbChannel.Name = "tbChannel";
            this.tbChannel.Size = new System.Drawing.Size(77, 21);
            this.tbChannel.TabIndex = 8;
            this.tbChannel.Text = "0";
            // 
            // label3
            // 
            this.label3.Location = new System.Drawing.Point(19, 121);
            this.label3.Name = "label3";
            this.label3.Size = new System.Drawing.Size(58, 17);
            this.label3.TabIndex = 7;
            this.label3.Text = "Channel";
            // 
            // tbHostAddress
            // 
            this.tbHostAddress.Location = new System.Drawing.Point(48, 86);
            this.tbHostAddress.Name = "tbHostAddress";
            this.tbHostAddress.Size = new System.Drawing.Size(115, 22);
            this.tbHostAddress.TabIndex = 6;
            this.tbHostAddress.Text = "192.168.0.111";
            // 
            // label2
            // 
            this.label2.Location = new System.Drawing.Point(19, 60);
            this.label2.Name = "label2";
            this.label2.Size = new System.Drawing.Size(96, 18);
            this.label2.TabIndex = 5;
            this.label2.Text = "Host address";
            // 
            // cbConnectionType
            // 
            this.cbConnectionType.Items.AddRange(new object[] {
            "USB",
            "Ethernet",
            "PCI"});
            this.cbConnectionType.Location = new System.Drawing.Point(86, 26);
            this.cbConnectionType.Name = "cbConnectionType";
            this.cbConnectionType.Size = new System.Drawing.Size(77, 20);
            this.cbConnectionType.TabIndex = 4;
            this.cbConnectionType.Text = "???";
            this.cbConnectionType.SelectedIndexChanged  = new System.EventHandler(this.cbConnectionType_SelectedIndexChanged);
            // 
            // label1
            // 
            this.label1.Location = new System.Drawing.Point(19, 26);
            this.label1.Name = "label1";
            this.label1.Size = new System.Drawing.Size(48, 17);
            this.label1.TabIndex = 3;
            this.label1.Text = "Type";
            // 
            // shtControllerPages
            // 
            this.shtControllerPages.Controls.Add(this.tabStatus);
            this.shtControllerPages.Controls.Add(this.tabAxisParameters);
            this.shtControllerPages.Controls.Add(this.tabIO);
            this.shtControllerPages.Controls.Add(this.tabTable);
            this.shtControllerPages.Controls.Add(this.tabVRs);
            this.shtControllerPages.Controls.Add(this.tabDir);
            this.shtControllerPages.Controls.Add(this.tabMoves);
            this.shtControllerPages.Location = new System.Drawing.Point(10, 9);
            this.shtControllerPages.Name = "shtControllerPages";
            this.shtControllerPages.SelectedIndex = 0;
            this.shtControllerPages.Size = new System.Drawing.Size(528, 379);
            this.shtControllerPages.TabIndex = 4;
            this.shtControllerPages.SelectedIndexChanged  = new System.EventHandler(this.shtControllerPages_SelectedIndexChanged);
            // 
            // tabStatus
            // 
            this.tabStatus.Controls.Add(this.tbAnalogueIOs);
            this.tabStatus.Controls.Add(this.tbDigitalIOs);
            this.tabStatus.Controls.Add(this.tbSystemVersion);
            this.tabStatus.Controls.Add(this.tbControllerType);
            this.tabStatus.Controls.Add(this.label7);
            this.tabStatus.Controls.Add(this.label6);
            this.tabStatus.Controls.Add(this.label5);
            this.tabStatus.Controls.Add(this.label4);
            this.tabStatus.Location = new System.Drawing.Point(4, 22);
            this.tabStatus.Name = "tabStatus";
            this.tabStatus.Size = new System.Drawing.Size(520, 353);
            this.tabStatus.TabIndex = 0;
            this.tabStatus.Text = "Status";
            // 
            // tbAnalogueIOs
            // 
            this.tbAnalogueIOs.Location = new System.Drawing.Point(154, 112);
            this.tbAnalogueIOs.Name = "tbAnalogueIOs";
            this.tbAnalogueIOs.ReadOnly = true;
            this.tbAnalogueIOs.Size = new System.Drawing.Size(124, 21);
            this.tbAnalogueIOs.TabIndex = 7;
            this.tbAnalogueIOs.Text = "0";
            // 
            // tbDigitalIOs
            // 
            this.tbDigitalIOs.Location = new System.Drawing.Point(154, 78);
            this.tbDigitalIOs.Name = "tbDigitalIOs";
            this.tbDigitalIOs.ReadOnly = true;
            this.tbDigitalIOs.Size = new System.Drawing.Size(124, 21);
            this.tbDigitalIOs.TabIndex = 6;
            this.tbDigitalIOs.Text = "0";
            // 
            // tbSystemVersion
            // 
            this.tbSystemVersion.Location = new System.Drawing.Point(154, 43);
            this.tbSystemVersion.Name = "tbSystemVersion";
            this.tbSystemVersion.ReadOnly = true;
            this.tbSystemVersion.Size = new System.Drawing.Size(124, 21);
            this.tbSystemVersion.TabIndex = 5;
            this.tbSystemVersion.Text = "0.0";
            // 
            // tbControllerType
            // 
            this.tbControllerType.Location = new System.Drawing.Point(154, 9);
            this.tbControllerType.Name = "tbControllerType";
            this.tbControllerType.ReadOnly = true;
            this.tbControllerType.Size = new System.Drawing.Size(124, 21);
            this.tbControllerType.TabIndex = 4;
            this.tbControllerType.Text = "Unknown";
            // 
            // label7
            // 
            this.label7.Location = new System.Drawing.Point(19, 112);
            this.label7.Name = "label7";
            this.label7.Size = new System.Drawing.Size(115, 26);
            this.label7.TabIndex = 3;
            this.label7.Text = "Analogue I/Os";
            this.label7.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
            // 
            // label6
            // 
            this.label6.Location = new System.Drawing.Point(19, 78);
            this.label6.Name = "label6";
            this.label6.Size = new System.Drawing.Size(115, 25);
            this.label6.TabIndex = 2;
            this.label6.Text = "Digitao I/Os";
            this.label6.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
            // 
            // label5
            // 
            this.label5.Location = new System.Drawing.Point(19, 43);
            this.label5.Name = "label5";
            this.label5.Size = new System.Drawing.Size(115, 26);
            this.label5.TabIndex = 1;
            this.label5.Text = "System version:";
            this.label5.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
            // 
            // label4
            // 
            this.label4.Location = new System.Drawing.Point(19, 9);
            this.label4.Name = "label4";
            this.label4.Size = new System.Drawing.Size(115, 25);
            this.label4.TabIndex = 0;
            this.label4.Text = "Controller type:";
            this.label4.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
            // 
            // tabAxisParameters
            // 
            this.tabAxisParameters.Controls.Add(this.lstParameters2);
            this.tabAxisParameters.Controls.Add(this.lstParameters1);
            this.tabAxisParameters.Controls.Add(this.tbAxis);
            this.tabAxisParameters.Controls.Add(this.label8);
            this.tabAxisParameters.Location = new System.Drawing.Point(4, 22);
            this.tabAxisParameters.Name = "tabAxisParameters";
            this.tabAxisParameters.Size = new System.Drawing.Size(520, 353);
            this.tabAxisParameters.TabIndex = 1;
            this.tabAxisParameters.Text = "Axis Parameters";
            // 
            // lstParameters2
            // 
            this.lstParameters2.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] {
            this.columnHeader1,
            this.columnHeader2});
            this.lstParameters2.GridLines = true;
            this.lstParameters2.HideSelection = false;
            this.lstParameters2.Location = new System.Drawing.Point(163, 215);
            this.lstParameters2.Name = "lstParameters2";
            this.lstParameters2.Size = new System.Drawing.Size(240, 121);
            this.lstParameters2.TabIndex = 4;
            this.lstParameters2.UseCompatibleStateImageBehavior = false;
            this.lstParameters2.View = System.Windows.Forms.View.Details;
            // 
            // columnHeader1
            // 
            this.columnHeader1.Text = "Parameter";
            this.columnHeader1.Width = 80;
            // 
            // columnHeader2
            // 
            this.columnHeader2.Text = "Value";
            this.columnHeader2.Width = 100;
            // 
            // lstParameters1
            // 
            this.lstParameters1.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] {
            this.clmDescription,
            this.clmValue});
            this.lstParameters1.GridLines = true;
            this.lstParameters1.HideSelection = false;
            this.lstParameters1.Location = new System.Drawing.Point(163, 9);
            this.lstParameters1.Name = "lstParameters1";
            this.lstParameters1.Size = new System.Drawing.Size(240, 206);
            this.lstParameters1.TabIndex = 3;
            this.lstParameters1.UseCompatibleStateImageBehavior = false;
            this.lstParameters1.View = System.Windows.Forms.View.Details;
            // 
            // clmDescription
            // 
            this.clmDescription.Text = "Parameter";
            this.clmDescription.Width = 80;
            // 
            // clmValue
            // 
            this.clmValue.Text = "Value";
            this.clmValue.Width = 100;
            // 
            // tbAxis
            // 
            this.tbAxis.Location = new System.Drawing.Point(67, 17);
            this.tbAxis.Name = "tbAxis";
            this.tbAxis.Size = new System.Drawing.Size(48, 21);
            this.tbAxis.TabIndex = 2;
            this.tbAxis.Text = "0";
            this.tbAxis.TextChanged  = new System.EventHandler(this.tbAxis_TextChanged);
            // 
            // label8
            // 
            this.label8.Location = new System.Drawing.Point(19, 17);
            this.label8.Name = "label8";
            this.label8.Size = new System.Drawing.Size(39, 17);
            this.label8.TabIndex = 1;
            this.label8.Text = "Axis:";
            // 
            // tabIO
            // 
            this.tabIO.Controls.Add(this.tbDigitalIOValue);
            this.tabIO.Controls.Add(this.label9);
            this.tabIO.Location = new System.Drawing.Point(4, 22);
            this.tabIO.Name = "tabIO";
            this.tabIO.Size = new System.Drawing.Size(520, 353);
            this.tabIO.TabIndex = 2;
            this.tabIO.Text = "I/O";
            // 
            // tbDigitalIOValue
            // 
            this.tbDigitalIOValue.Location = new System.Drawing.Point(106, 17);
            this.tbDigitalIOValue.Name = "tbDigitalIOValue";
            this.tbDigitalIOValue.Size = new System.Drawing.Size(211, 21);
            this.tbDigitalIOValue.TabIndex = 1;
            // 
            // label9
            // 
            this.label9.Location = new System.Drawing.Point(19, 17);
            this.label9.Name = "label9";
            this.label9.Size = new System.Drawing.Size(77, 26);
            this.label9.TabIndex = 0;
            this.label9.Text = "Digital I/O:";
            this.label9.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
            // 
            // tabTable
            // 
            this.tabTable.Controls.Add(this.tbTableEdit);
            this.tabTable.Controls.Add(this.btnWriteTableValues);
            this.tabTable.Controls.Add(this.lstTableValues);
            this.tabTable.Controls.Add(this.tbTableEntries);
            this.tabTable.Controls.Add(this.tbTableStart);
            this.tabTable.Controls.Add(this.label11);
            this.tabTable.Controls.Add(this.label10);
            this.tabTable.Location = new System.Drawing.Point(4, 22);
            this.tabTable.Name = "tabTable";
            this.tabTable.Size = new System.Drawing.Size(520, 353);
            this.tabTable.TabIndex = 3;
            this.tabTable.Text = "Table";
            // 
            // tbTableEdit
            // 
            this.tbTableEdit.Location = new System.Drawing.Point(432, 164);
            this.tbTableEdit.Name = "tbTableEdit";
            this.tbTableEdit.Size = new System.Drawing.Size(58, 21);
            this.tbTableEdit.TabIndex = 6;
            this.tbTableEdit.Visible = false;
            this.tbTableEdit.Leave  = new System.EventHandler(this.tbTableEdit_Leave);
            // 
            // btnWriteTableValues
            // 
            this.btnWriteTableValues.Location = new System.Drawing.Point(96, 310);
            this.btnWriteTableValues.Name = "btnWriteTableValues";
            this.btnWriteTableValues.Size = new System.Drawing.Size(58, 26);
            this.btnWriteTableValues.TabIndex = 5;
            this.btnWriteTableValues.Text = "Write";
            this.btnWriteTableValues.Click  = new System.EventHandler(this.btnWriteTableValues_Click);
            // 
            // lstTableValues
            // 
            this.lstTableValues.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] {
            this.clmEntry,
            this.clmTableValue});
            this.lstTableValues.GridLines = true;
            this.lstTableValues.HideSelection = false;
            this.lstTableValues.Location = new System.Drawing.Point(173, 9);
            this.lstTableValues.Name = "lstTableValues";
            this.lstTableValues.Size = new System.Drawing.Size(230, 327);
            this.lstTableValues.TabIndex = 4;
            this.lstTableValues.UseCompatibleStateImageBehavior = false;
            this.lstTableValues.View = System.Windows.Forms.View.Details;
            this.lstTableValues.MouseDown  = new System.Windows.Forms.MouseEventHandler(this.lstTableValues_MouseDown);
            this.lstTableValues.MouseUp  = new System.Windows.Forms.MouseEventHandler(this.lstTableValues_MouseUp);
            // 
            // clmEntry
            // 
            this.clmEntry.Text = "Entry";
            this.clmEntry.Width = 70;
            // 
            // clmTableValue
            // 
            this.clmTableValue.Text = "Value";
            this.clmTableValue.Width = 100;
            // 
            // tbTableEntries
            // 
            this.tbTableEntries.Location = new System.Drawing.Point(86, 52);
            this.tbTableEntries.Name = "tbTableEntries";
            this.tbTableEntries.Size = new System.Drawing.Size(68, 21);
            this.tbTableEntries.TabIndex = 3;
            this.tbTableEntries.Text = "10";
            // 
            // tbTableStart
            // 
            this.tbTableStart.Location = new System.Drawing.Point(86, 17);
            this.tbTableStart.Name = "tbTableStart";
            this.tbTableStart.Size = new System.Drawing.Size(68, 21);
            this.tbTableStart.TabIndex = 2;
            this.tbTableStart.Text = "0";
            // 
            // label11
            // 
            this.label11.Location = new System.Drawing.Point(19, 52);
            this.label11.Name = "label11";
            this.label11.Size = new System.Drawing.Size(58, 17);
            this.label11.TabIndex = 1;
            this.label11.Text = "Entries";
            this.label11.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
            // 
            // label10
            // 
            this.label10.Location = new System.Drawing.Point(19, 17);
            this.label10.Name = "label10";
            this.label10.Size = new System.Drawing.Size(58, 17);
            this.label10.TabIndex = 0;
            this.label10.Text = "Start";
            this.label10.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
            // 
            // tabVRs
            // 
            this.tabVRs.Controls.Add(this.btnSetVR);
            this.tabVRs.Controls.Add(this.lstVRValues);
            this.tabVRs.Controls.Add(this.tbVREntries);
            this.tabVRs.Controls.Add(this.tbVRStart);
            this.tabVRs.Controls.Add(this.label12);
            this.tabVRs.Controls.Add(this.label13);
            this.tabVRs.Location = new System.Drawing.Point(4, 22);
            this.tabVRs.Name = "tabVRs";
            this.tabVRs.Size = new System.Drawing.Size(520, 353);
            this.tabVRs.TabIndex = 4;
            this.tabVRs.Text = "VRs";
            // 
            // btnSetVR
            // 
            this.btnSetVR.Location = new System.Drawing.Point(77, 302);
            this.btnSetVR.Name = "btnSetVR";
            this.btnSetVR.Size = new System.Drawing.Size(86, 25);
            this.btnSetVR.TabIndex = 10;
            this.btnSetVR.Text = "Set VR";
            this.btnSetVR.Click  = new System.EventHandler(this.btnSetVR_Click);
            // 
            // lstVRValues
            // 
            this.lstVRValues.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] {
            this.columnHeader5,
            this.columnHeader6});
            this.lstVRValues.GridLines = true;
            this.lstVRValues.HideSelection = false;
            this.lstVRValues.Location = new System.Drawing.Point(182, 12);
            this.lstVRValues.Name = "lstVRValues";
            this.lstVRValues.Size = new System.Drawing.Size(231, 327);
            this.lstVRValues.TabIndex = 9;
            this.lstVRValues.UseCompatibleStateImageBehavior = false;
            this.lstVRValues.View = System.Windows.Forms.View.Details;
            // 
            // columnHeader5
            // 
            this.columnHeader5.Text = "Entry";
            this.columnHeader5.Width = 70;
            // 
            // columnHeader6
            // 
            this.columnHeader6.Text = "Value";
            this.columnHeader6.Width = 100;
            // 
            // tbVREntries
            // 
            this.tbVREntries.Location = new System.Drawing.Point(96, 55);
            this.tbVREntries.Name = "tbVREntries";
            this.tbVREntries.Size = new System.Drawing.Size(67, 21);
            this.tbVREntries.TabIndex = 8;
            this.tbVREntries.Text = "10";
            // 
            // tbVRStart
            // 
            this.tbVRStart.Location = new System.Drawing.Point(96, 20);
            this.tbVRStart.Name = "tbVRStart";
            this.tbVRStart.Size = new System.Drawing.Size(67, 21);
            this.tbVRStart.TabIndex = 7;
            this.tbVRStart.Text = "0";
            // 
            // label12
            // 
            this.label12.Location = new System.Drawing.Point(29, 55);
            this.label12.Name = "label12";
            this.label12.Size = new System.Drawing.Size(57, 17);
            this.label12.TabIndex = 6;
            this.label12.Text = "Entries";
            this.label12.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
            // 
            // label13
            // 
            this.label13.Location = new System.Drawing.Point(29, 20);
            this.label13.Name = "label13";
            this.label13.Size = new System.Drawing.Size(57, 18);
            this.label13.TabIndex = 5;
            this.label13.Text = "Start";
            this.label13.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
            // 
            // tabDir
            // 
            this.tabDir.Controls.Add(this.tbDirList);
            this.tabDir.Location = new System.Drawing.Point(4, 22);
            this.tabDir.Name = "tabDir";
            this.tabDir.Size = new System.Drawing.Size(520, 353);
            this.tabDir.TabIndex = 5;
            this.tabDir.Text = "Directory";
            // 
            // tbDirList
            // 
            this.tbDirList.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.tbDirList.Location = new System.Drawing.Point(10, 9);
            this.tbDirList.Multiline = true;
            this.tbDirList.Name = "tbDirList";
            this.tbDirList.ReadOnly = true;
            this.tbDirList.ScrollBars = System.Windows.Forms.ScrollBars.Both;
            this.tbDirList.Size = new System.Drawing.Size(499, 336);
            this.tbDirList.TabIndex = 0;
            this.tbDirList.WordWrap = false;
            // 
            // tabMoves
            // 
            this.tabMoves.Controls.Add(this.tbWatchdogState);
            this.tabMoves.Controls.Add(this.label15);
            this.tabMoves.Controls.Add(this.btnRun);
            this.tabMoves.Controls.Add(this.tbRunStatus);
            this.tabMoves.Controls.Add(this.label14);
            this.tabMoves.Controls.Add(this.lstMoveParams);
            this.tabMoves.Location = new System.Drawing.Point(4, 22);
            this.tabMoves.Name = "tabMoves";
            this.tabMoves.Size = new System.Drawing.Size(520, 353);
            this.tabMoves.TabIndex = 6;
            this.tabMoves.Text = "Moves";
            // 
            // tbWatchdogState
            // 
            this.tbWatchdogState.Location = new System.Drawing.Point(115, 250);
            this.tbWatchdogState.Name = "tbWatchdogState";
            this.tbWatchdogState.Size = new System.Drawing.Size(39, 21);
            this.tbWatchdogState.TabIndex = 5;
            // 
            // label15
            // 
            this.label15.Location = new System.Drawing.Point(10, 250);
            this.label15.Name = "label15";
            this.label15.Size = new System.Drawing.Size(67, 17);
            this.label15.TabIndex = 4;
            this.label15.Text = "Watchdog";
            // 
            // btnRun
            // 
            this.btnRun.Location = new System.Drawing.Point(202, 215);
            this.btnRun.Name = "btnRun";
            this.btnRun.Size = new System.Drawing.Size(57, 26);
            this.btnRun.TabIndex = 3;
            this.btnRun.Text = "Run";
            this.btnRun.Click  = new System.EventHandler(this.btnRun_Click);
            // 
            // tbRunStatus
            // 
            this.tbRunStatus.Location = new System.Drawing.Point(86, 215);
            this.tbRunStatus.Name = "tbRunStatus";
            this.tbRunStatus.Size = new System.Drawing.Size(68, 21);
            this.tbRunStatus.TabIndex = 2;
            // 
            // label14
            // 
            this.label14.Location = new System.Drawing.Point(10, 224);
            this.label14.Name = "label14";
            this.label14.Size = new System.Drawing.Size(67, 17);
            this.label14.TabIndex = 1;
            this.label14.Text = "Status";
            // 
            // lstMoveParams
            // 
            this.lstMoveParams.AutoArrange = false;
            this.lstMoveParams.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] {
            this.clmParameter,
            this.clmAxis0,
            this.clmAxis1});
            this.lstMoveParams.GridLines = true;
            this.lstMoveParams.HideSelection = false;
            this.lstMoveParams.LabelEdit = true;
            this.lstMoveParams.LabelWrap = false;
            this.lstMoveParams.Location = new System.Drawing.Point(10, 9);
            this.lstMoveParams.Name = "lstMoveParams";
            this.lstMoveParams.Size = new System.Drawing.Size(393, 198);
            this.lstMoveParams.TabIndex = 0;
            this.lstMoveParams.UseCompatibleStateImageBehavior = false;
            this.lstMoveParams.View = System.Windows.Forms.View.Details;
            // 
            // clmParameter
            // 
            this.clmParameter.Text = "Parameter";
            this.clmParameter.Width = 80;
            // 
            // clmAxis0
            // 
            this.clmAxis0.Text = "Axis 0";
            this.clmAxis0.Width = 120;
            // 
            // clmAxis1
            // 
            this.clmAxis1.Text = "Axis 1";
            this.clmAxis1.Width = 120;
            // 
            // btnRefresh
            // 
            this.btnRefresh.Enabled = false;
            this.btnRefresh.Location = new System.Drawing.Point(595, 293);
            this.btnRefresh.Name = "btnRefresh";
            this.btnRefresh.Size = new System.Drawing.Size(106, 26);
            this.btnRefresh.TabIndex = 5;
            this.btnRefresh.Text = "Refresh";
            this.btnRefresh.Click  = new System.EventHandler(this.btnRefresh_Click);
            // 
            // btnRefreshLamp
            // 
            this.btnRefreshLamp.Location = new System.Drawing.Point(566, 293);
            this.btnRefreshLamp.Name = "btnRefreshLamp";
            this.btnRefreshLamp.Size = new System.Drawing.Size(29, 26);
            this.btnRefreshLamp.TabIndex = 6;
            // 
            // columnHeader3
            // 
            this.columnHeader3.Text = "Entry";
            this.columnHeader3.Width = 70;
            // 
            // columnHeader4
            // 
            this.columnHeader4.Text = "Value";
            this.columnHeader4.Width = 100;
            // 
            // frmMain
            // 
            this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
            this.ClientSize = new System.Drawing.Size(762, 425);
            this.Controls.Add(this.btnRefreshLamp);
            this.Controls.Add(this.btnRefresh);
            this.Controls.Add(this.shtControllerPages);
            this.Controls.Add(this.groupBox1);
            this.Controls.Add(this.btnExit);
            this.Name = "frmMain";
            this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
            this.Text = "TrioPC Test (VCS)";
            this.groupBox1.ResumeLayout(false);
            this.shtControllerPages.ResumeLayout(false);
            this.tabStatus.ResumeLayout(false);
            this.tabStatus.PerformLayout();
            this.tabAxisParameters.ResumeLayout(false);
            this.tabAxisParameters.PerformLayout();
            this.tabIO.ResumeLayout(false);
            this.tabIO.PerformLayout();
            this.tabTable.ResumeLayout(false);
            this.tabTable.PerformLayout();
            this.tabVRs.ResumeLayout(false);
            this.tabVRs.PerformLayout();
            this.tabDir.ResumeLayout(false);
            this.tabDir.PerformLayout();
            this.tabMoves.ResumeLayout(false);
            this.tabMoves.PerformLayout();
            this.ResumeLayout(false);

		}
		#endregion

		/// <summary>
		/// The main entry point for the application.
		/// </summary>
		[STAThread]
		static void Main() 
		{
			Application.Run(new frmMain());
		}

		private void btnExit_Click(object sender, System.EventArgs e)
		{
			if ( axTrioPC.IsOpen( 0 ) )
				axTrioPC.Close( 0 );
			Close();
		}

		private void btnClose_Click(object sender, System.EventArgs e)
		{
			if ( axTrioPC.IsOpen( 0 ) )
			{
				btnClose.Enabled = false;
				axTrioPC.Close( 0 );
				btnOpen.Enabled = true;
				btnRefresh.Enabled = false;
				axTrioPC.Refresh();
			}
		}

		private void btnOpen_Click(object sender, System.EventArgs e)
		{
			short	iPortID = -1,
				iPortType = -1;

			btnOpen.Enabled = false;
			btnRefresh.Enabled = false;
			switch ( cbConnectionType.Text )
			{
				case "USB":
					iPortType = 0;
					iPortID = 0;
					break;
				case "Ethernet":
					axTrioPC.HostAddress = tbHostAddress.Text;
					iPortType = 2;
					iPortID = 3240;
					break;
				case "PCI":
					axTrioPC.Board = Convert.ToInt32( tbChannel.Text );
					iPortType = 3;
					iPortID = 0;
					break;
			}

			if ( (iPortType != -1) && (iPortID != -1) )
				axTrioPC.Open( iPortType, iPortID );

			if ( axTrioPC.IsOpen( iPortID ) )
			{
				btnClose.Enabled = true;
				btnRefresh.Enabled = true;
				m_iPortID = iPortID;
				axTrioPC.Refresh();
				RefreshVisibleTab();
			}
			else
			{
				btnOpen.Enabled = true;
				m_iPortID = 0;
			}
		}

		private void cbConnectionType_SelectedIndexChanged(object sender, System.EventArgs e)
		{
			switch ( cbConnectionType.Text )
			{
				case "USB":
					tbHostAddress.Enabled = false;
					tbChannel.Enabled = false;
					break;
				case "Ethernet":
					tbHostAddress.Enabled = true;
					tbChannel.Enabled = false;
					break;
				case "PCI":
					tbHostAddress.Enabled = false;
					tbChannel.Enabled = true;
					break;
				default:
					tbHostAddress.Enabled = false;
					tbChannel.Enabled = false;
					break;
			}
		}

		private void btnRefresh_Click(object sender, System.EventArgs e)
		{
			RefreshVisibleTab();
			btnRefresh.Focus();
		}

		private void RefreshVisibleTab()
		{
			btnRefresh.Enabled = false;
			btnRefreshLamp.BackColor = System.Drawing.Color.Red;
			btnRefreshLamp.Refresh();

			switch ( shtControllerPages.SelectedIndex )
			{
				case 0:
					RefreshStatus();
					break;
				case 1:
					RefreshAxisParameters();
					break;
				case 2:
					RefreshIO();
					break;
				case 3:
					RefreshTable();
					break;
				case 4:
					RefreshVRs();
					break;
				case 5:
					RefreshDirectory();
					break;
			}
			
			btnRefreshLamp.BackColor = System.Drawing.SystemColors.Control;
			btnRefreshLamp.Refresh();
			btnRefresh.Enabled = true;
		}

		private void RefreshStatus()
		{
			if ( axTrioPC.IsOpen ( m_iPortID ) )
			{
				double	dReadVal;

				if ( axTrioPC.GetVariable( "CONTROL", out dReadVal ))
					tbControllerType.Text = dReadVal.ToString();

				if ( axTrioPC.GetVariable( "VERSION", out dReadVal ))
					tbSystemVersion.Text = Math.Round( dReadVal, 4 ).ToString();

				if ( axTrioPC.GetVariable( "NIO", out dReadVal ))
					tbDigitalIOs.Text = dReadVal.ToString();

				if ( axTrioPC.GetVariable( "NAIO", out dReadVal ))
					tbAnalogueIOs.Text = dReadVal.ToString();
			}
		}

		private void RefreshAxisParameters()
		{
			if ( axTrioPC.IsOpen( m_iPortID ))
			{
				double	dReadVar;
				short	iBase = Convert.ToInt16( tbAxis.Text );
				int		nItem = 0;

				if ( axTrioPC.Base( 1, iBase ))
				{
					if ( axTrioPC.GetVariable( "ATYPE", out dReadVar ))
						lstParameters1.Items[ nItem   ].SubItems[ 1 ].Text = dReadVar.ToString();
						
					if ( axTrioPC.GetVariable( "P_GAIN", out dReadVar ))
						lstParameters1.Items[ nItem   ].SubItems[ 1 ].Text = dReadVar.ToString();

					if ( axTrioPC.GetVariable( "I_GAIN", out dReadVar ))
						lstParameters1.Items[ nItem   ].SubItems[ 1 ].Text = dReadVar.ToString();

					if ( axTrioPC.GetVariable( "D_GAIN", out dReadVar ))
						lstParameters1.Items[ nItem   ].SubItems[ 1 ].Text = dReadVar.ToString();

					if ( axTrioPC.GetVariable( "OV_GAIN", out dReadVar ))
						lstParameters1.Items[ nItem   ].SubItems[ 1 ].Text = dReadVar.ToString();

					if ( axTrioPC.GetVariable( "VFF_GAIN", out dReadVar ))
						lstParameters1.Items[ nItem   ].SubItems[ 1 ].Text = dReadVar.ToString();

					if ( axTrioPC.GetVariable( "UNITS", out dReadVar ))
						lstParameters1.Items[ nItem   ].SubItems[ 1 ].Text = dReadVar.ToString();

					if ( axTrioPC.GetVariable( "SPEED", out dReadVar ))
						lstParameters1.Items[ nItem   ].SubItems[ 1 ].Text = dReadVar.ToString();

					if ( axTrioPC.GetVariable( "ACCEL", out dReadVar ))
						lstParameters1.Items[ nItem   ].SubItems[ 1 ].Text = dReadVar.ToString();

					if ( axTrioPC.GetVariable( "DECEL", out dReadVar ))
						lstParameters1.Items[ nItem   ].SubItems[ 1 ].Text = dReadVar.ToString();

					if ( axTrioPC.GetVariable( "CREEP", out dReadVar ))
						lstParameters1.Items[ nItem   ].SubItems[ 1 ].Text = dReadVar.ToString();

					if ( axTrioPC.GetVariable( "JOGSPEED", out dReadVar ))
						lstParameters1.Items[ nItem   ].SubItems[ 1 ].Text = dReadVar.ToString();

					if ( axTrioPC.GetVariable( "FE_LIMIT", out dReadVar ))
						lstParameters1.Items[ nItem   ].SubItems[ 1 ].Text = dReadVar.ToString();

					if ( axTrioPC.GetVariable( "DAC", out dReadVar ))
						lstParameters1.Items[ nItem   ].SubItems[ 1 ].Text = dReadVar.ToString();

					if ( axTrioPC.GetVariable( "SERVO", out dReadVar ))
						lstParameters1.Items[ nItem   ].SubItems[ 1 ].Text = dReadVar.ToString();

					if ( axTrioPC.GetVariable( "REP_DIST", out dReadVar ))
						lstParameters1.Items[ nItem   ].SubItems[ 1 ].Text = dReadVar.ToString();

					if ( axTrioPC.GetVariable( "FWD_IN", out dReadVar ))
						lstParameters1.Items[ nItem   ].SubItems[ 1 ].Text = dReadVar.ToString();

					if ( axTrioPC.GetVariable( "REV_IN", out dReadVar ))
						lstParameters1.Items[ nItem   ].SubItems[ 1 ].Text = dReadVar.ToString();

					if ( axTrioPC.GetVariable( "DATUM_IN", out dReadVar ))
						lstParameters1.Items[ nItem   ].SubItems[ 1 ].Text = dReadVar.ToString();

					if ( axTrioPC.GetVariable( "FH_IN", out dReadVar ))
						lstParameters1.Items[ nItem   ].SubItems[ 1 ].Text = dReadVar.ToString();

					if ( axTrioPC.GetVariable( "FS_LIMIT", out dReadVar ))
						lstParameters1.Items[ nItem   ].SubItems[ 1 ].Text = dReadVar.ToString();

					if ( axTrioPC.GetVariable( "RS_LIMIT", out dReadVar ))
						lstParameters1.Items[ nItem   ].SubItems[ 1 ].Text = dReadVar.ToString();

					nItem = 0;

					if ( axTrioPC.GetVariable( "MTYPE", out dReadVar ))
						lstParameters2.Items[ nItem   ].SubItems[ 1 ].Text = dReadVar.ToString();

					if ( axTrioPC.GetVariable( "NTYPE", out dReadVar ))
						lstParameters2.Items[ nItem   ].SubItems[ 1 ].Text = dReadVar.ToString();

					if ( axTrioPC.GetVariable( "MPOS", out dReadVar ))
						lstParameters2.Items[ nItem   ].SubItems[ 1 ].Text = dReadVar.ToString();

					if ( axTrioPC.GetVariable( "DPOS", out dReadVar ))
						lstParameters2.Items[ nItem   ].SubItems[ 1 ].Text = dReadVar.ToString();

					if ( axTrioPC.GetVariable( "FE", out dReadVar ))
						lstParameters2.Items[ nItem   ].SubItems[ 1 ].Text = dReadVar.ToString();

					if ( axTrioPC.GetVariable( "AXISSTATUS", out dReadVar ))
						lstParameters2.Items[ nItem   ].SubItems[ 1 ].Text = dReadVar.ToString();

					if ( axTrioPC.GetVariable( "VPSPEED", out dReadVar ))
						lstParameters2.Items[ nItem   ].SubItems[ 1 ].Text = dReadVar.ToString();
				} // if ( axTrioPC.Base( 1, iBase ))
			} // if ( axTrioPC.IsOpen( iPortID ))
		}

		private void RefreshIO()
		{
			if ( axTrioPC.IsOpen( m_iPortID ))
			{
				double	dReadVar;

				if ( axTrioPC.GetVariable( "NIO", out dReadVar ))
				{
					const int kiIOBlockSize = 16;
					int		iLastToGet = (int)dReadVar - 1;
					short	iFrom = 0,
						iTo = -1;
					int		iReadVar;
					bool	bOK = true;
					string	strIn = "";
					int		nBit;

					while ( iFrom <= iLastToGet && bOK)
					{
						iTo = (short)(iFrom   kiIOBlockSize - 1);
						if ( iTo > iLastToGet )
							iTo = (short)iLastToGet;

						if ( axTrioPC.In( iFrom, iTo, out iReadVar ))
						{
							for ( nBit = 0; nBit < iTo - iFrom   1; nBit   )
							{
								if ( ( iReadVar & 1 ) == 1 )
									strIn = "1"   strIn;
								else
									strIn = "0"   strIn;
								iReadVar >>= 1;
							}
							iFrom = (short)(iTo   1);
						}
						else
							bOK = false;
					}
					if ( bOK )
						tbDigitalIOValue.Text = strIn;
					else
						tbDigitalIOValue.Text = "";
				} // if ( axTrioPC.GetVariable( "NIO", out dReadVar ))
			} // if ( axTrioPC.IsOpen( m_iPortID ))
		}

		private void RefreshTable()
		{
			if ( axTrioPC.IsOpen( m_iPortID ) )
			{
				int		iStart = Convert.ToInt32( tbTableStart.Text ),
					iEntries = Convert.ToInt32( tbTableEntries.Text );

				lstTableValues.Items.Clear();

				if ( iStart >= 0 && iEntries > 0 )
				{
					int		iFrom = iStart,
						iTo,
						iEntry;

					double [] dValues = new double[] { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,
														 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,
														 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,
														 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 };
					object	oValues = dValues;
					bool	bOK = true;
					ListViewItem	Item;

					while ( iFrom < ( iStart   iEntries ) && bOK )
					{
						iTo = iFrom   dValues.GetLength( 0 ) - 1;
						if ( iTo >= (iStart   iEntries))
							iTo = iStart   iEntries - 1;
						if ( axTrioPC.GetTable(iFrom, iTo - iFrom   1, ref oValues))
						{
							dValues = (double[])oValues;
							for ( iEntry = 0; iEntry < iTo - iFrom   1; iEntry   )
							{
								Item = lstTableValues.Items.Add((iFrom   iEntry).ToString());
								Item.SubItems.Add(dValues[iEntry].ToString());
							}
							iFrom = iTo   1;
						}
						else
							bOK = false;
					}
				}
			} // if ( axTrioPC.IsOpen( m_iPortID ) )
		}

		private void RefreshVRs()
		{
			if ( axTrioPC.IsOpen( m_iPortID ) )
			{
				short	iStart = Convert.ToInt16( tbVRStart.Text ),
					iEntries = Convert.ToInt16( tbVREntries.Text );

				if ( iStart >= 0 && iEntries > 0 )
				{
					short	iEntry;
					double	dReadVar;
					bool	bOK = true;
					ListViewItem	Item;

					lstVRValues.Items.Clear();
					for ( iEntry = 0; iEntry < iEntries && bOK; iEntry   )
					{
						if ( axTrioPC.GetVr( (short)(iEntry   iStart), out dReadVar ))
						{
							Item = lstVRValues.Items.Add( (iEntry   iStart).ToString() );
							Item.SubItems.Add( dReadVar.ToString() );
						}
						else
							bOK = false;
					}
				} // if ( iStart >= 0 && iEntries > 0 )
			} // if ( axTrioPC.IsOpen( m_iPortID ) )
		}

		private void InitParameterGrids()
		{
			int		nItem;

			lstParameters1.Items.Add( "ATYPE" );
			lstParameters1.Items.Add( "P_GAIN" );
			lstParameters1.Items.Add( "I_GAIN" );
			lstParameters1.Items.Add( "D_GAIN" );
			lstParameters1.Items.Add( "OV_GAIN" );
			lstParameters1.Items.Add( "VFF_GAIN" );
			lstParameters1.Items.Add( "UNITS" );
			lstParameters1.Items.Add( "SPEED" );
			lstParameters1.Items.Add( "ACCEL" );
			lstParameters1.Items.Add( "DECEL" );
			lstParameters1.Items.Add( "CREEP" );
			lstParameters1.Items.Add( "JOGSPEED" );
			lstParameters1.Items.Add( "FE_LIMIT" );
			lstParameters1.Items.Add( "DAC" );
			lstParameters1.Items.Add( "SERVO" );
			lstParameters1.Items.Add( "REP_DIST" );
			lstParameters1.Items.Add( "FWD_IN" );
			lstParameters1.Items.Add( "REV_IN" );
			lstParameters1.Items.Add( "DATUM_IN" );
			lstParameters1.Items.Add( "FH_IN" );
			lstParameters1.Items.Add( "FS_LIMIT" );
			lstParameters1.Items.Add( "RS_LIMIT" );

			for ( nItem = 0; nItem  < lstParameters1.Items.Count; nItem  )
				lstParameters1.Items[ nItem ].SubItems.Add( "0 ");
			
			lstParameters2.Items.Add( "MTYPE" );
			lstParameters2.Items.Add( "NTYPE" );
			lstParameters2.Items.Add( "MPOS" );
			lstParameters2.Items.Add( "DPOS" );
			lstParameters2.Items.Add( "FE" );
			lstParameters2.Items.Add( "AXISSTATUS" );
			lstParameters2.Items.Add( "VPSPEED" );

			for ( nItem = 0; nItem <lstParameters2.Items.Count; nItem  )
				lstParameters2.Items[ nItem ].SubItems.Add( "0 ");

			lstMoveParams.Items.Add("MTYPE");
			lstMoveParams.Items.Add("NTYPE");
			lstMoveParams.Items.Add("MPOS");
			lstMoveParams.Items.Add("DPOS");
			lstMoveParams.Items.Add("FE");
			lstMoveParams.Items.Add("SERVO");
			lstMoveParams.Items.Add("REMAIN");

			for ( nItem = 0; nItem < lstMoveParams.Items.Count; nItem  )
			{
				lstMoveParams.Items[ nItem ].SubItems.Add( "0 ");
				lstMoveParams.Items[ nItem ].SubItems.Add( "0 ");
			}

		} // private void InitParameterGrids()

		private void tbAxis_TextChanged(object sender, System.EventArgs e)
		{
			ClearParameterGrids();
		}

		private void ClearParameterGrids()
		{
			int		nItem;

			for ( nItem = 0; nItem  < lstParameters1.Items.Count; nItem  )
				lstParameters1.Items[ nItem ].SubItems[ 1 ].Text = "0";

			for ( nItem = 0; nItem  < lstParameters2.Items.Count; nItem  )
				lstParameters2.Items[ nItem ].SubItems[ 1 ].Text = "0";
		}

		private void shtControllerPages_SelectedIndexChanged(object sender, System.EventArgs e)
		{
			RefreshVisibleTab();
		}

		private void RefreshDirectory()
		{
			if ( axTrioPC.IsOpen( m_iPortID ))
			{
				string	strDir = "";
				var oDir = strDir;

				if ( axTrioPC.Dir( out oDir ))
				{
					strDir = (string)oDir;
					tbDirList.Text = strDir;
				}
			}
		}

		private void btnSetVR_Click(object sender, System.EventArgs e)
		{
			frmSetVR	SVForm = new frmSetVR();
		
			if (SVForm.ShowDialog(this) == DialogResult.OK)
			{
				short	nVR = Convert.ToInt16(SVForm.VR);

				if (nVR >= 0)
				{
					short	nStart = Convert.ToInt16(tbVRStart.Text);

					axTrioPC.SetVr(nVR, SVForm.Value);
					if (nVR >= nStart && nVR < nStart   Convert.ToInt16(tbVREntries.Text))
					{
						RefreshVRs();
					}
				}
			}
		}

		private void btnRun_Click(object sender, System.EventArgs e)
		{
			btnRun.Enabled = false;
			RunCommandSequence();
			btnRun.Enabled = true;
		}

		private void RunCommandSequence()
		{
			int		nAxis;
			object	oBases;
			object	oValues;
			int	[]	nBases = new int[2];
			double [] dValues = new double[2];
			const double kdBaseLength = 50;

			tbRunStatus.Text = "Running";
			tbRunStatus.Refresh();

			for (nAxis = 0; nAxis <= 1; nAxis  )
			{
				axTrioPC.Base(1, nAxis);
				axTrioPC.SetVariable("UNITS", 1000);
				axTrioPC.SetVariable("SPEED", 25);
				axTrioPC.SetVariable("ACCEL", 50);
				axTrioPC.SetVariable("DECEL", 25);
				axTrioPC.SetVariable("FE_LIMIT", 2);
			}

			axTrioPC.SetVariable("WDOG", 1);

			for (nAxis = 0; nAxis <= 1; nAxis  )
			{
				axTrioPC.Base(1, nAxis);
				axTrioPC.SetVariable("SERVO", 1);
			}

			nBases[0] = 0;
			nBases[1] = 1;
			oBases = nBases;

			axTrioPC.Base(2, oBases);
			dValues[0] = 0.0;
			dValues[1] = 0.0;
			oValues = dValues;
			axTrioPC.MoveAbs(2, dValues, oBases);
			WaitNextFree();

			axTrioPC.Base(2, oBases);
			dValues[0] = kdBaseLength;
			dValues[1] = 0.0;
			oValues = dValues;
			axTrioPC.MoveRel(2, dValues, oBases);
			WaitNextFree();

			axTrioPC.Base(2, oBases);
			dValues[0] = -kdBaseLength;
			dValues[1] = -kdBaseLength;
			oValues = dValues;
			axTrioPC.MoveRel(2, dValues, oBases);
			WaitNextFree();

			axTrioPC.Base(2, oBases);
			dValues[0] = -kdBaseLength;
			dValues[1] = kdBaseLength;
			oValues = dValues;
			axTrioPC.MoveRel(2, oValues, oBases);
			WaitNextFree();

			axTrioPC.Base(2, oBases);
			dValues[0] = kdBaseLength;
			dValues[1] = kdBaseLength;
			oValues = dValues;
			axTrioPC.MoveRel(2, oValues, oBases);
			WaitNextFree();

			axTrioPC.Base(2, oBases);
			dValues[0] = kdBaseLength;
			dValues[1] = -kdBaseLength;
			oValues = dValues;
			axTrioPC.MoveRel(2, oValues, oBases);
			WaitNextFree();

			axTrioPC.Base(2, oBases);
			dValues[0] = 0.0;
			dValues[1] = 0.0;
			oValues = dValues;
			axTrioPC.MoveAbs(2, oValues, oBases);
			WaitForEndOfMove();

			for (nAxis = 0; nAxis <= 1; nAxis  )
			{
				axTrioPC.Base(1, nAxis);
				axTrioPC.SetVariable("SERVO", 0);
			}
			axTrioPC.SetVariable("WDOG", 0);

			GetMoveData();

			tbRunStatus.Text = "Stopped";
			tbRunStatus.Refresh();

		} // private void RunCommandSequence()


		private void WaitForEndOfMove()
		{
			double [] dRemain = new double[2];
			int		nAxis;
			bool	bWaiting;

			bWaiting = true;
			while (bWaiting)
			{
				for (nAxis = 0; nAxis <= 1; nAxis  )
				{
					if (axTrioPC.Base(1, nAxis))
						axTrioPC.GetVariable("REMAIN", out dRemain[nAxis]);
					bWaiting = (Math.Abs(dRemain[0]) > 1.0) || (Math.Abs(dRemain[1]) > 1.0);
				}
				GetMoveData();
			}
		} // private void WaitForEndOfMove()

		private void WaitNextFree()
		{
			double [] dNType = new double[2];
			int		nAxis;
			bool	bWaiting;
		
			bWaiting = true;
			while (bWaiting)
			{
				for (nAxis = 0; nAxis <= 1; nAxis  )
				{
					if (axTrioPC.Base(1, nAxis))
						axTrioPC.GetVariable("NTYPE", out dNType[nAxis]);
				}
				bWaiting = (Math.Abs(dNType[0]) > 0.5) || (Math.Abs(dNType[1]) > 0.5);
				GetMoveData();
			}
		} // private void TfrmMain.WaitNextFree()

		private void GetMoveData()
		{
			int		nAxis;
			int		nItem;
			double	dReadVar;

			SetRefreshActive(true);
			if (axTrioPC.GetVariable("WDOG", out dReadVar))
			{
				if (dReadVar > 0.5)
				{
					tbWatchdogState.Text = "On";
					tbWatchdogState.BackColor = System.Drawing.Color.Red;
				}
				else
				{
					tbWatchdogState.Text = "Off";
					tbWatchdogState.BackColor = System.Drawing.SystemColors.Control;
				}
			}
			tbWatchdogState.Refresh();

			for (nAxis = 0; nAxis <= 1; nAxis  )
			{
				nItem = 0;

				if (axTrioPC.Base(1, nAxis))
				{
					if (axTrioPC.GetVariable("MTYPE", out dReadVar))
					{
						lstMoveParams.Items[nItem  ].SubItems[nAxis   1].Text = dReadVar.ToString();
						if (axTrioPC.GetVariable("NTYPE", out dReadVar))
						{
							lstMoveParams.Items[nItem  ].SubItems[nAxis   1].Text = dReadVar.ToString();
							if (axTrioPC.GetVariable("MPOS", out dReadVar))
							{
								lstMoveParams.Items[nItem  ].SubItems[nAxis   1].Text = dReadVar.ToString();
								if (axTrioPC.GetVariable("DPOS", out dReadVar))
								{
									lstMoveParams.Items[nItem  ].SubItems[nAxis   1].Text = dReadVar.ToString();
									if (axTrioPC.GetVariable("FE", out dReadVar))
									{
										lstMoveParams.Items[nItem  ].SubItems[nAxis   1].Text = dReadVar.ToString();
										if (axTrioPC.GetVariable("SERVO", out dReadVar))
										{
											lstMoveParams.Items[nItem  ].SubItems[nAxis   1].Text = dReadVar.ToString();
											if (axTrioPC.GetVariable("REMAIN", out dReadVar))
												lstMoveParams.Items[nItem  ].SubItems[nAxis   1].Text = dReadVar.ToString();
										}
									}
								}
							}
						}
					}
				} // if (axTrioPC.Base(1, nAxis))
			} // for (nAxis = 0; nAxis <= 1; nAxis  )
			lstMoveParams.Refresh();

			SetRefreshActive(false);
		} // private void GetMoveData()

		private void SetRefreshActive(bool bActive)
		{
			if (bActive)
			{
				Cursor = Cursors.WaitCursor;
				btnRefresh.Enabled = false;
				btnRefreshLamp.BackColor = System.Drawing.Color.Red;
			}
			else
			{
				Cursor = Cursors.Default;
				btnRefreshLamp.BackColor = System.Drawing.SystemColors.Control;
				btnRefresh.Enabled = true;
			}

			btnRefreshLamp.Refresh();
		} // private void SetRefreshActive(bool bActive)

		private void btnWriteTableValues_Click(object sender, System.EventArgs e)
		{
			WriteTableValues();
		} // private void SetRefreshActive(bool bActive)

		private void WriteTableValues()
		{
			const int c_nMaxAtOnce = 8;
			const double c_dMaxValue = 1e12;
			const double c_dMinValue = -1e12;

			int		nStart;
			int		nEntries;
			int		nEntry;
			int		nToSend;
			int		nStartIndex;
			int		nVarIndex;
			double	dValue;
			object	oValues;
			bool	bOK = true;
			double [] dValues = new double[c_nMaxAtOnce];
			string	strValue;

			SetRefreshActive(true);
			nStart = Convert.ToInt32(tbTableStart.Text);
			if (nStart < 0)
				nStart = 0;
			nEntries = Convert.ToInt32(tbTableEntries.Text);
			if (nEntries < 0)
				nEntries = 0;

			nToSend = nEntries;
			nEntry = 0;

			nStartIndex = Convert.ToInt32(lstTableValues.Items[0].SubItems[0].Text);
			while (nToSend > 0 && bOK)
			{
				// Gather group of values to send
				nVarIndex = 0;
				while ((nToSend > 0) && (nVarIndex < c_nMaxAtOnce) && bOK)
				{
					strValue = lstTableValues.Items[nEntry].SubItems[1].Text;
					dValue = Convert.ToDouble(strValue);
					if (dValue > c_dMaxValue) 
						dValue = c_dMaxValue;
					else if (dValue < c_dMinValue)
						dValue = c_dMinValue;

					dValues[nVarIndex] = dValue;
					  nVarIndex;
					  nEntry;
					--nToSend;
				}
				if (nVarIndex > 0)
				{
					oValues = dValues;
					axTrioPC.SetTable(nStartIndex, nVarIndex, oValues);
					nStartIndex = nStartIndex   nVarIndex;
				}
			} // while (nToSend > 0 && bOK)
			SetRefreshActive(false);
		}

		private int LocateTableEntry(int iX, int iY)
		{
			int		nItem = -1;
			bool	bFound = false;
			Rectangle	rectItem;

			if (iX >= 0 && iY >= 0)
			{
				// Locate Item
				nItem = 0;
				while (nItem < lstTableValues.Items.Count && !bFound)
				{
					rectItem = lstTableValues.Items[nItem].GetBounds(ItemBoundsPortion.Label);
					if (iY >= rectItem.Top && iY <= rectItem.Bottom)
						bFound = true;
					else
						nItem  ;
				}

				if (bFound)
				{
					int nLeft = lstTableValues.Columns[0].Width;
					int nRight = nLeft   lstTableValues.Columns[1].Width;
					// Item only valid if column = 1
					if (iX < nLeft || iX >= nRight)
						nItem = -1;
				}
			} // if (iX >= 0 && iY >= 0)

			return nItem;
		}

		private void lstTableValues_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
		{
			m_iPreSelectedTableItem = LocateTableEntry(e.X, e.Y);		
		}

		private void lstTableValues_MouseUp(object sender, System.Windows.Forms.MouseEventArgs e)
		{
			if (m_iPreSelectedTableItem >= 0)
			{
				m_iSelectedTableItem = LocateTableEntry(e.X, e.Y);
				if (m_iPreSelectedTableItem == m_iSelectedTableItem)
				{
					Rectangle	rectValue;
					Rectangle	rectTable;

					rectValue = lstTableValues.GetItemRect(m_iSelectedTableItem, ItemBoundsPortion.Entire);
					rectValue.X = lstTableValues.Columns[0].Width;
					rectValue.Width = lstTableValues.Columns[1].Width;
					rectValue.Height -= 4;

					rectTable = lstTableValues.Bounds;

					rectValue.Offset(rectTable.Left   2, rectTable.Top);
					tbTableEdit.Bounds = rectValue;
					tbTableEdit.Text = lstTableValues.Items[m_iSelectedTableItem].SubItems[1].Text;
					tbTableEdit.Show();
					tbTableEdit.Focus();
					tbTableEdit.SelectAll();
				}
			}
		}

		private void tbTableEdit_Leave(object sender, System.EventArgs e)
		{
			lstTableValues.Items[m_iSelectedTableItem].SubItems[1].Text = tbTableEdit.Text;
			tbTableEdit.Hide();
		}

	} // public class frmMain : System.Windows.Forms.Form
}

标签: 控制 通信

实例下载地址

C# 实现与翠欧控制器通信(附源码)

不能下载?内容有错? 点击这里报错 + 投诉 + 提问

好例子网口号:伸出你的我的手 — 分享

网友评论

发表评论

(您的评论需要经过审核才能显示)

查看所有0条评论>>

小贴士

感谢您为本站写下的评论,您的评论对其它用户来说具有重要的参考价值,所以请认真填写。

  • 类似“顶”、“沙发”之类没有营养的文字,对勤劳贡献的楼主来说是令人沮丧的反馈信息。
  • 相信您也不想看到一排文字/表情墙,所以请不要反馈意义不大的重复字符,也请尽量不要纯表情的回复。
  • 提问之前请再仔细看一遍楼主的说明,或许是您遗漏了。
  • 请勿到处挖坑绊人、招贴广告。既占空间让人厌烦,又没人会搭理,于人于己都无利。

关于好例子网

本站旨在为广大IT学习爱好者提供一个非营利性互相学习交流分享平台。本站所有资源都可以被免费获取学习研究。本站资源来自网友分享,对搜索内容的合法性不具有预见性、识别性、控制性,仅供学习研究,请务必在下载后24小时内给予删除,不得用于其他任何用途,否则后果自负。基于互联网的特殊性,平台无法对用户传输的作品、信息、内容的权属或合法性、安全性、合规性、真实性、科学性、完整权、有效性等进行实质审查;无论平台是否已进行审查,用户均应自行承担因其传输的作品、信息、内容而可能或已经产生的侵权或权属纠纷等法律责任。本站所有资源不代表本站的观点或立场,基于网友分享,根据中国法律《信息网络传播权保护条例》第二十二与二十三条之规定,若资源存在侵权或相关问题请联系本站客服人员,点此联系我们。关于更多版权及免责申明参见 版权及免责申明

;
报警