<< 点击显示目录 >> 主页 PVI通信 > PVI帮助信息 > PVI Services > Communication classes > Module class > 将一个BR模块传输到控制器 |
BR模块通过 Download 方法传输到控制器 。
下载 (MemoryType内存类型, InstallMode安装模式,String文件名)
memoryType参数定义了模块的目标内存类型,installMode参数定义了安装类型。BR模块文件是用fileName参数(完整的路径和文件名)指定的。也可以使用 FileName 属性和下载功能提前设置文件名 ,而不必指定第三个参数。
"模块 "例子
下面的例子演示了上面描述的要点(连接一个对象,进行上传,删除一个BR模块,进行下载)。
// Definition of global communication objects
Service service;
Cpu cpu;
Module module;
/// <summary>
/// Generate and connect service object
/// </summary>
private void btConnectPvi_Click(object sender, System.EventArgs e)
{
if ( service == null )
{
service = new Service("service");
service.Connected+=new PviEventHandler(service_Connected);
}
service.Connect();
}
/// <summary>
/// Connect CPU object if service object connection successful
/// </summary>
private void service_Connected(object sender, PviEventArgs e)
{
if ( cpu == null )
{
// Create CPU object and add the event handler
cpu = new Cpu(service,"cpu");
cpu.Connected+=new PviEventHandler(cpu_Connected);
// Set the connection properties for a serial connection
cpu.Connection.DeviceType = DeviceType.Serial;
cpu.Connection.Serial.BaudRate = 57600;
cpu.Connection.Serial.Channel = 1;
}
// Cpu verbinden
cpu.Connect();
}
/// <summary>
/// Output appropriate message when CPU
/// connection established
/// </summary>
private void cpu_Connected(object sender, PviEventArgs e)
{
String strOut = String.Format("\"{0}\" connected. BootMode: {1}\r\n" ,
((Cpu)sender).Name,
((Cpu)sender).BootMode.ToString());
this.tbStatus.Text += strOut;
this.btDownloadModule.Enabled = true;
this.btConnectModule.Enabled = true;
}
/// <summary>
/// Create and connect module object
/// </summary>
private void btConnectModule_Click(object sender, System.EventArgs e)
{
if ( module == null )
{
// Create module object
CreateNewModuleObject();
}
module.Connect();
}
/// <summary>
/// Upload module
/// </summary>
private void btUploadModule_Click(object sender, System.EventArgs e)
{
module.Upload("C:\\ab_task.br");
this.btDeleteModule.Enabled = true;
this.lbProgressStatus.Text = "Upload ...";
}
/// <summary>
/// Status output when Connected event received
/// </summary>
private void mod_Connected(object sender, PviEventArgs e)
{
// Output successful connection and
// memory type where BR module located
this.tbStatus.Text += "Module "+ ((Module)sender).Name + " connected, MemoryType: "+ module.MemoryType.ToString() + "\r\n";
this.btUploadModule.Enabled = true;
this.btDeleteModule.Enabled = true;
}
/// <summary>
/// Receive Uploaded event
/// </summary>
private void module_Uploaded(object sender, PviEventArgs e)
{
this.tbStatus.Text += "Module " + ((Module)sender).Name + " uploaded\r\n";
this.lbProgressStatus.Text = "Upload finished";
}
/// <summary>
/// Update progress indicator
/// </summary>
private void module_Progress(object sender, ModuleEventArgs e)
{
this.pbProgress.Value = e.Percentage;
}
/// <summary>
/// Delete BR module on the controller
/// </summary>
private void btDeleteModule_Click(object sender, System.EventArgs e)
{
module.Delete();
}
/// <summary>
/// Receive Deleted event
/// </summary>
private void module_Deleted(object sender, PviEventArgs e)
{
this.tbStatus.Text += "Module "+ ((Module)sender).Name + " deleted\r\n";
this.btUploadModule.Enabled = false;
}
/// <summary>
/// Transfer BR module to the controller
/// </summary>
private void btDownloadModule_Click(object sender, System.EventArgs e)
{
if ( module == null )
{
// Create module object
CreateNewModuleObject();
module.Download(MemoryType.UserRam,InstallMode.Overload,"C:\\ab_task.br");
this.lbProgressStatus.Text = "Download ...";
}
}
/// <summary>
/// Output any error messages (receive an Error event)
/// </summary>
private void module_Error(object sender, PviEventArgs e)
{
String strTextOut;
strTextOut = String.Format("Module {0} error: {1}: {2}\r\n",((Module)sender).Name,e.ErrorCode.ToString(),e.ErrorText);
this.tbStatus.Text += strTextOut;
}
/// <summary>
/// BR module transferred successfully
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void module_Downloaded(object sender, PviEventArgs e)
{
this.tbStatus.Text += "Module "+ ((Module)sender).Name + " downloaded\r\n";
this.lbProgressStatus.Text = "Download finished";
this.btDeleteModule.Enabled = true;
}
/// <summary>
/// Create new module object and add all needed handlers
/// </summary>
private void CreateNewModuleObject()
{
module = new Module(this.cpu,"ab_task");
// Add all needed handlers
module.Connected += new PviEventHandler(mod_Connected);
module.Deleted += new PviEventHandler(module_Deleted);
module.Uploaded += new PviEventHandler(module_Uploaded);
module.Downloaded +=new PviEventHandler(module_Downloaded);
module.UploadProgress += new ModuleEventHandler(module_Progress);
module.DownloadProgress +=new ModuleEventHandler(module_Progress);
module.Error += new PviEventHandler(module_Error);
}