代码的功能:
调用com中的
Event RequestArrive(ByVal asker As Long, ByVal fromSession As Long, ByVal
toSession As Long, ByVal timestamp As Long, ByVal cmdId As Integer, cmdData
As String)
和
Event RequestAnswer(ByVal answer As Long, ByVal fromSession As Long, ByVal
toSession As Long, ByVal status As Integer, result As String)
两个事件,
处理RequestArrive中得到的cmdData,之后使用RequestAnswer返回处理后的数据。
事件的概念我一直不太明白,向各位大虾请教先在vs中添加了com组件,然后代码是这么写的,RequestAnswer应该是没有用对,各位大虾帮帮看看应该怎么写啊?!!using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Text;namespace CommZ
{
/// <summary>
/// Form1 的摘要说明。
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.TextBox textBox1;
private System.Windows.Forms.Button button1;
private CommZilla.CTGatewayCtrl comm1 = new CommZilla.CTGatewayCtrlClass();
private UnicodeEncoding ue = new UnicodeEncoding(); private void
c_RequestAnswer(int asker, int toSession, int fromSession, short status, ref
string cmdData)
{
}
private void c_RequestArrive(int asker, int fromSession, int toSession,
int timestamp, short cmdId, ref string cmdData)
{
//cmdData转换为本地字符
byte[] localData = ue.GetBytes(cmdData);
//判断cmdId,跳到相应操作
switch (cmdId)
{
//操作1
case 1 : {
cmdData = "0";
}
break;
//操作2
case 2 :
break;
default:
label1.Text = "没有此操作";
break;
} //cmdData转换为Unicode
byte[] ByteArray = ue.GetBytes(cmdData);
cmdData = ByteArray.ToString();
comm1.RequestAnswer += new
CommZilla._IGatewayEvents_RequestAnswerEventHandler(c_RequestAnswer);
c_RequestAnswer(asker, toSession, fromSession, 1, ref cmdData);
} /// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.Container components = null; public Form1()
{
//
// Windows 窗体设计器支持所必需的
//
InitializeComponent(); //
// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
//
} /// <summary>
/// 清理所有正在使用的资源。
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
} #region Windows 窗体设计器生成的代码
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.textBox1 = new System.Windows.Forms.TextBox();
this.button1 = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// textBox1
//
this.textBox1.Location = new System.Drawing.Point(16, 128);
this.textBox1.Multiline = true;
this.textBox1.Name = "textBox1";
this.textBox1.Size = new System.Drawing.Size(264, 104);
this.textBox1.TabIndex = 0;
this.textBox1.Text = "信息";
//
// button1
//
this.button1.Location = new System.Drawing.Point(32, 32);
this.button1.Name = "button1";
this.button1.TabIndex = 1;
this.button1.Text = "开始";
this.button1.Click += new System.EventHandler(this.button1_Click);
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(292, 273);
this.Controls.Add(this.button1);
this.Controls.Add(this.textBox1);
this.Name = "Form1";
this.Text = "Form1";
this.Load += new System.EventHandler(this.Form1_Load);
this.ResumeLayout(false); }
#endregion /// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Form1());
} private void button1_Click(object sender, System.EventArgs e)
{
try
{
comm1.Start();
}
catch
{
textBox1.Text = "启动失败,错误信息"+comm1.ErrorNumber;
}
if (comm1.ErrorNumber == 0)
{
textBox1.Text = "启动成功";
comm1.RequestArrive += new
CommZilla._IGatewayEvents_RequestArriveEventHandler(c_RequestArrive);
}
} private void Form1_Load(object sender, System.EventArgs e)
{
} }
}
调用com中的
Event RequestArrive(ByVal asker As Long, ByVal fromSession As Long, ByVal
toSession As Long, ByVal timestamp As Long, ByVal cmdId As Integer, cmdData
As String)
和
Event RequestAnswer(ByVal answer As Long, ByVal fromSession As Long, ByVal
toSession As Long, ByVal status As Integer, result As String)
两个事件,
处理RequestArrive中得到的cmdData,之后使用RequestAnswer返回处理后的数据。
事件的概念我一直不太明白,向各位大虾请教先在vs中添加了com组件,然后代码是这么写的,RequestAnswer应该是没有用对,各位大虾帮帮看看应该怎么写啊?!!using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Text;namespace CommZ
{
/// <summary>
/// Form1 的摘要说明。
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.TextBox textBox1;
private System.Windows.Forms.Button button1;
private CommZilla.CTGatewayCtrl comm1 = new CommZilla.CTGatewayCtrlClass();
private UnicodeEncoding ue = new UnicodeEncoding(); private void
c_RequestAnswer(int asker, int toSession, int fromSession, short status, ref
string cmdData)
{
}
private void c_RequestArrive(int asker, int fromSession, int toSession,
int timestamp, short cmdId, ref string cmdData)
{
//cmdData转换为本地字符
byte[] localData = ue.GetBytes(cmdData);
//判断cmdId,跳到相应操作
switch (cmdId)
{
//操作1
case 1 : {
cmdData = "0";
}
break;
//操作2
case 2 :
break;
default:
label1.Text = "没有此操作";
break;
} //cmdData转换为Unicode
byte[] ByteArray = ue.GetBytes(cmdData);
cmdData = ByteArray.ToString();
comm1.RequestAnswer += new
CommZilla._IGatewayEvents_RequestAnswerEventHandler(c_RequestAnswer);
c_RequestAnswer(asker, toSession, fromSession, 1, ref cmdData);
} /// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.Container components = null; public Form1()
{
//
// Windows 窗体设计器支持所必需的
//
InitializeComponent(); //
// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
//
} /// <summary>
/// 清理所有正在使用的资源。
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
} #region Windows 窗体设计器生成的代码
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.textBox1 = new System.Windows.Forms.TextBox();
this.button1 = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// textBox1
//
this.textBox1.Location = new System.Drawing.Point(16, 128);
this.textBox1.Multiline = true;
this.textBox1.Name = "textBox1";
this.textBox1.Size = new System.Drawing.Size(264, 104);
this.textBox1.TabIndex = 0;
this.textBox1.Text = "信息";
//
// button1
//
this.button1.Location = new System.Drawing.Point(32, 32);
this.button1.Name = "button1";
this.button1.TabIndex = 1;
this.button1.Text = "开始";
this.button1.Click += new System.EventHandler(this.button1_Click);
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(292, 273);
this.Controls.Add(this.button1);
this.Controls.Add(this.textBox1);
this.Name = "Form1";
this.Text = "Form1";
this.Load += new System.EventHandler(this.Form1_Load);
this.ResumeLayout(false); }
#endregion /// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Form1());
} private void button1_Click(object sender, System.EventArgs e)
{
try
{
comm1.Start();
}
catch
{
textBox1.Text = "启动失败,错误信息"+comm1.ErrorNumber;
}
if (comm1.ErrorNumber == 0)
{
textBox1.Text = "启动成功";
comm1.RequestArrive += new
CommZilla._IGatewayEvents_RequestArriveEventHandler(c_RequestArrive);
}
} private void Form1_Load(object sender, System.EventArgs e)
{
} }
}
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货