设为首页收藏本站|繁體中文 快速切换版块

 找回密码
 立即加入
搜索
查看: 1562|回复: 0

C#调用BPA

[复制链接]

该用户从未签到

尚未签到

发表于 2010-5-3 11:31:18 | 显示全部楼层 |阅读模式

马上加入,结交更多好友,共享更多资料,让你轻松玩转电力研学社区!

您需要 登录 才可以下载或查看,没有账号?立即加入

×
这是我写的一段小代码,就是调用BPA对指定的.dat文件计算一次潮流,代码如下
% o9 w- n! U# ]* qusing System;
) X3 f& z' M' K7 s2 susing System.Collections.Generic;
9 h/ e- T2 J0 @% [6 Zusing System.Text;
. |8 W* E. ]. f) a! D' v5 H* ?using System.Diagnostics;  G) k' t2 N) R  c) n& `

8 _# g; s' R0 J$ d' e" [2 S  c4 V  M
namespace 调用BPA$ A' C; d  \4 o& v
{. }- R+ R: C. p6 ^/ F
    class Program
9 N& {- g, Z) z% e  _    {) H" b# s8 Z  y- d$ j$ k( a1 ^( L
        public class powerflow; S9 k0 C& E6 s* Q3 x/ S
        {
$ [; s3 \+ H1 X: o            public void powerflow1(string BPApath, string BPAdatapath) //BPApath 为BPA程序的存放路径,BPAdatapath为.dat数据文件的路径
( ?, p9 `: Q# u$ I# \; `            {
/ V) ~3 k% R# C+ G  D) x9 W0 E. ]                Process dyBPA = new Process();
- o+ g6 I+ \9 O5 Z                dyBPA.StartInfo.FileName = BPApath + "pfnt.exe";
, z1 W9 Y" w* ]. M( l, C* E                dyBPA.StartInfo.Arguments = BPAdatapath;2 u* a' B6 z2 z* H5 M; N5 \
                dyBPA.StartInfo.UseShellExecute = false;! h6 C) X  f, E9 r
                dyBPA.StartInfo.RedirectStandardInput = true;
) S: y/ q; _' O- r$ k1 {" m                dyBPA.StartInfo.RedirectStandardOutput = true;# ~# s$ x; R  g) [
                dyBPA.StartInfo.CreateNoWindow = false;( l4 Z* Y' P6 j5 g/ m
                dyBPA.StartInfo.WorkingDirectory = BPApath.Substring(0,BPApath.Length-1);
4 [7 s4 \! W$ I, B4 V3 i5 R7 c& y                dyBPA.Start();
6 |: }5 n6 r% G) Y1 A                string output = dyBPA.StandardOutput.ReadToEnd();
% ]% V- R& e5 I, V" }                dyBPA.Close();
+ r1 E) G: }4 }0 z             ! l3 ~( {( O, }: I) w  N5 n
            ( p9 Q/ O; I3 w, `; F
            }
: l. \: N) \1 ?" r7 K+ _' o, E        }% H- p8 Y: I7 n1 j' T  G
        static void Main(string[] args)" H1 L1 v* U5 j/ i0 R0 r  C" d
        {
4 ^0 Q# g' i; ]9 w7 h8 M            powerflow calculate = new powerflow();- T# N) `: t, F2 Y
            calculate.powerflow1(@"C:\psap32\psaw", @"E:\广东电网充裕度评估系统\童—潮流计算程序\013bpa");
! F6 m. S6 T4 t; m  E        }
: w; F, p, l, l6 q! w+ _    }
* x# Z1 c; d# k. l. ~}+ a3 ]) i" m7 h# f8 J( j% `
由于本人是刚刚学习,可能上面代码有许多错误,还请高手赐教~~~小弟不胜感激
"真诚赞赏,手留余香"
还没有人打赏,支持一下
楼主热帖
帖文化:【文明发帖 和谐互动】 社区精神:【创新、交流、互助、共享】
您需要登录后才可以回帖 登录 | 立即加入

本版积分规则

招聘斑竹

小黑屋|手机版|APP下载(beta)|Archiver|电力研学网 ( 赣ICP备12000811号-1|赣公网安备36040302000210号 )|网站地图

GMT+8, 2026-10-23 10:00

Powered by Discuz! X3.5 Licensed

© 2001-2026 Discuz! Team.

快速回复 返回顶部 返回列表