You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1636 lines
62 KiB
C#

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Runtime.Remoting;
using System.Runtime.Remoting.Channels;
using System.Runtime.Remoting.Channels.Tcp;
using System.Globalization;
using System.Collections;
using System.IO;
using System.Runtime.Serialization.Formatters.Binary;
using System.Timers;
using RemoteObjects;
using CommService;
namespace ClientTest
{
/*
*struIPPort
*
*2010-10-30
*ip port
*/
[Serializable]
struct struIPPort
{
public string sIP;
public int nPort;
};
/*
*FrmMain
*
*2010-10-30
*
*/
public partial class FrmMain : Form
{
private ReqHandler remoteobj = null;
private Hashtable htTerminalIPPort = new Hashtable();
private Hashtable htRemotingIPPort = new Hashtable();
private string sFileTerminalIPPort;
private string sFileRemotingIPPort;
private Hashtable htTerminals;
private Hashtable htTerminalParams = null;
private string sSelectedTID;
private string sSelectedMID;
private ImageList myImageList = null;
private System.Timers.Timer aTimer = null;
private Hashtable htOldTerminals = null;
delegate void UpdateTreeViewCallback(object userData);
private bool bStartTimer = false;
/*
*FrmMain
*
*2010-10-30
*void
*void
*
*/
public FrmMain()
{
InitializeComponent();
//remoting通道注册
ChannelServices.RegisterChannel(new TcpClientChannel(), false);
sFileTerminalIPPort = System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase + "TerminalIPPort.dat";
sFileRemotingIPPort = System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase + "RemotingIPPort.dat";
LoadTerminalIPPort();
myImageList = new ImageList();
myImageList.Images.Add(Image.FromFile(System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase + "集中器1.bmp"));
myImageList.Images.Add(Image.FromFile(System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase + "电表.bmp"));
myImageList.Images.Add(Image.FromFile(System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase + "电表-selected.bmp"));
myImageList.Images.Add(Image.FromFile(System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase + "变压器.bmp"));
myImageList.Images.Add(Image.FromFile(System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase + "Home.ico"));
myImageList.Images.Add(Image.FromFile(System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase + "集中器1_gray.bmp"));
myImageList.Images.Add(Image.FromFile(System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase + "电表_gray.bmp"));
Common.frmMain = this;
Common.btRefresh = btnRefresh;
}
/*
*UpdTreeViewInfo
*
*2010-10-30
*object userData
*void
*
*/
public static void UpdTreeViewInfo(object userData)
{
Button bt = (Button)userData;
if (bt.InvokeRequired)
{
UpdateTreeViewCallback d = new UpdateTreeViewCallback(UpdTreeViewInfo);
Common.frmMain.Invoke(d, new object[] { userData});
}
else
{
bt.PerformClick();
}
}
/*
*LoadTerminalIPPort
*
*2010-10-30
*void
*void
*IP
*/
private void LoadTerminalIPPort()
{
Common.configReader.Load(System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase + "\\config.xml");
if (File.Exists(sFileTerminalIPPort))
{
htTerminalIPPort.Clear();
FileStream fs = new FileStream(sFileTerminalIPPort, FileMode.OpenOrCreate);
BinaryFormatter bf = new BinaryFormatter();
htTerminalIPPort = (Hashtable)bf.Deserialize(fs);
fs.Close();
}
if (File.Exists(sFileRemotingIPPort))
{
htRemotingIPPort.Clear();
FileStream fs = new FileStream(sFileRemotingIPPort, FileMode.OpenOrCreate);
BinaryFormatter bf = new BinaryFormatter();
htRemotingIPPort = (Hashtable)bf.Deserialize(fs);
textBox1.Text = (string)htRemotingIPPort["RemotingIP"];
textBox2.Text = (string)htRemotingIPPort["RemotingPort"];
fs.Close();
}
}
/*
*SaveTerminalIPPort
*
*2010-10-30
*void
*void
*IP
*/
private void SaveTerminalIPPort()
{
FileStream fs = new FileStream(sFileTerminalIPPort, FileMode.Create);
BinaryFormatter bf = new BinaryFormatter();
bf.Serialize(fs, htRemotingIPPort);
fs.Close();
}
/*
*SaveRemotingIPPort
*
*2010-10-30
*void
*void
*remotingIP
*/
private void SaveRemotingIPPort() //
{
htTerminalIPPort["RemotingIP"] = textBox1.Text.Trim();
htTerminalIPPort["RemotingPort"] = textBox2.Text.Trim();
FileStream fs = new FileStream(sFileRemotingIPPort, FileMode.Create);
BinaryFormatter bf = new BinaryFormatter();
bf.Serialize(fs, htTerminalIPPort);
fs.Close();
}
/*
*ExitToolStripMenuItem_Click
*
*2010-10-30
*object sender , EventArgs e
*void
*退
*/
private void ExitToolStripMenuItem_Click(object sender, EventArgs e)
{
this.Close();
}
/*
*WriteTextBoxInfo
*
*2010-10-30
*string text
*void
*
*/
private void WriteTextBoxInfo(string text)
{
DateTime dtNow = DateTime.Now;
string log = dtNow.ToString("yyyy-MM-dd HH:mm:ss ", CultureInfo.InvariantCulture);
log += text + "\r\n";
richTBInfo.Text += log;
richTBInfo.Refresh();
}
/*
*ReadTTimeToolStripMenuItem_Click
*
*2010-10-30
*object sender , EventArgs e
*void
*
*/
private void ReadTTimeToolStripMenuItem_Click(object sender, EventArgs e)
{
if (tbCurrentTerminal.Text == "")
{
MessageBox.Show("请选择终端编号");
return;
}
string strTerminalTime = "";
WriteTextBoxInfo(tbCurrentTerminal.Text + " 开始读时间...");
try
{
bool res = remoteobj.GetTime(sSelectedTID, ref strTerminalTime);
WriteTextBoxInfo(tbCurrentTerminal.Text + " 读时间 结果返回:" + res.ToString() + (res == true ? ",时间为:" + strTerminalTime : strTerminalTime));
}
catch (Exception e1)
{
Console.WriteLine("exeption: " + e1.ToString());
}
}
/*
*TimingToolStripMenuItem_Click
*
*2010-10-30
*object sender , EventArgs e
*void
*
*/
private void TimingToolStripMenuItem_Click(object sender, EventArgs e)
{
if (tbCurrentTerminal.Text == "")
{
MessageBox.Show("请选择终端编号");
return;
}
WriteTextBoxInfo(tbCurrentTerminal.Text + " 开始校时...");
try
{
WriteTextBoxInfo(tbCurrentTerminal.Text + " 校时 结果返回:" + remoteobj.SetTime(sSelectedTID).ToString());
}
catch (Exception e1)
{
Console.WriteLine("exeption: " + e1.ToString());
}
}
/*
*ReadSteamDataToolStripMenuItem_Click
*
*2010-10-30
*object sender , EventArgs e
*void
*
*/
private void ReadSteamDataToolStripMenuItem_Click(object sender, EventArgs e)
{
if (tbCurrentTerminal.Text == "" || sSelectedMID =="")
{
MessageBox.Show("请选择当前仪表");
return;
}
List<uint> lstParams;
Hashtable hsTable = null;
S_CallDataForm inputDialog = new S_CallDataForm();
inputDialog.sMID = sSelectedMID;
// Show testDialog as a modal dialog and determine if DialogResult = OK.
if (inputDialog.ShowDialog(this) == DialogResult.OK)
{
//string sMID = sSelectedMID;
// Read the contents of testDialog's TextBox.
//this.txtResult.Text = testDialog.TextBox1.Text;
lstParams = inputDialog.lstOBJID;
WriteTextBoxInfo(tbCurrentTerminal.Text + " 开始招唤数据...");
string sComment = "";
try
{
bool res = remoteobj.GetData(sSelectedTID, sSelectedMID, lstParams, ref hsTable);
sComment += sSelectedTID + " " + sSelectedMID + " 招唤数据 结果返回:" + res + "\r\n";
if (res == true)
{
//int key = 0;
//foreach (DictionaryEntry de in hsTable)
{
//key = (int)de.Key;
if (hsTable.ContainsKey((uint)0x8030))
{
sComment += "\t\t\t\t终端时间" + hsTable[(uint)0x8030] + "\r\n";
}
if (hsTable.ContainsKey((uint)0x9B07))
{
sComment += "\t\t\t\t蒸汽仪表累积热量" + hsTable[(uint)0x9B07] + "\r\n";
}
if (hsTable.ContainsKey((uint)0x9B06))
{
sComment += "\t\t\t\t蒸汽仪表瞬时热量" + hsTable[(uint)0x9B06] + "\r\n";
}
if (hsTable.ContainsKey((uint)0x9B05))
{
sComment += "\t\t\t\t蒸汽仪表累积流量值" + hsTable[(uint)0x9B05] + "\r\n";
}
if (hsTable.ContainsKey((uint)0x9B03))
{
sComment += "\t\t\t\t蒸汽仪表瞬时流量值" + hsTable[(uint)0x9B03] + "\r\n";
}
if (hsTable.ContainsKey((uint)0x9B01))
{
sComment += "\t\t\t\t蒸汽仪表温度值" + hsTable[(uint)0x9B01] + "\r\n";
}
//温度为负值情况
if (hsTable.ContainsKey((uint)0x9B11))
{
sComment += "\t\t\t\t蒸汽仪表温度值" + hsTable[(uint)0x9B11] + "\r\n";
}
if (hsTable.ContainsKey((uint)0x9B1F))
{
sComment += "\t\t\t\t蒸汽仪表压力值" + hsTable[(uint)0x9B1F] + "\r\n";
}
if (hsTable.ContainsKey((uint)0x9B00))
{
sComment += "\t\t\t\t蒸汽仪表压力值" + hsTable[(uint)0x9B00] + "\r\n";
}
if (hsTable.ContainsKey((uint)0x9B02))
{
sComment += "\t\t\t\t蒸汽仪表频率" + hsTable[(uint)0x9B02] + "\r\n";
}
if (hsTable.ContainsKey((uint)0x9B0E))
{
sComment += "\t\t\t\t蒸汽仪表密度" + hsTable[(uint)0x9B0E] + "\r\n";
}
if (hsTable.ContainsKey((uint)0x9B0F))
{
sComment += "\t\t\t\t蒸汽仪表差压" + hsTable[(uint)0x9B0F] + "\r\n";
}
}
}
WriteTextBoxInfo(sComment);
}
catch (Exception e1)
{
Console.WriteLine("exeption: " + e1.ToString());
}
}
}
/*
*btnRefresh_Click
*
*2010-10-30
*object sender , EventArgs e
*void
*
*/
private void btnRefresh_Click(object sender, EventArgs e)
{
int nTHDeviceCount = 0;
int nElecDeviceCount = 0;
int nSteamDeviceCount = 0;
//List<string> lstTerminal = new List<string>();
Hashtable htTerminals = new Hashtable();
bool res = false;
try
{
res = remoteobj.GetTerminalList(ref htTerminals);
}
catch (Exception e1)
{
WriteTextBoxInfo("不能取终端列表,未注册 或 服务可能未启动");
}
if (res == true)
{
TerminalParamParsing(htTerminals);
tvTerminalList.ImageList = myImageList;
tvTerminalList.Nodes.Clear();
//int nSeq = 0;
tvTerminalList.BeginUpdate();
tvTerminalList.Nodes.Add("NormalROOT", "采集终端与仪表", 4, 4);//struNodeOfTree
tvTerminalList.Nodes.Add("TestROOT", "测试", 4, 4);//struNodeOfTree
int nTestSeq = 0;
foreach (DictionaryEntry de in htTerminalParams)
{
//测试
if (de.Key.ToString().StartsWith("测试"))
{
//添加集中器
tvTerminalList.Nodes[1].Nodes.Add(de.Key.ToString(), de.Key.ToString(), 0);
struTerminal Terminal = (struTerminal)de.Value;
//nElecDeviceCount++;
//添加仪表
foreach (DictionaryEntry de2 in Terminal.htMeters)
{
tvTerminalList.Nodes[1].Nodes[nTestSeq].Nodes.Add(de2.Key.ToString(), de2.Key.ToString(), 1, 2);
}
nTestSeq++;
}
else
{
struTerminal Terminal = (struTerminal)de.Value;
if (Terminal.bOn == true)
{
//treeView1.Nodes[0].Nodes.Add(de.Key.ToString(), de.Key.ToString(), 0);
//int index=de.Key.ToString().IndexOf("-");
//string id = de.Key.ToString().Substring(index+1);
//if (id.StartsWith("S"))
//{
TreeNode tn = tvTerminalList.Nodes[0].Nodes.Insert(0, de.Key.ToString(), de.Key.ToString(), 0);
//添加仪表
foreach (DictionaryEntry de2 in Terminal.htMeters)
{
//treeView1.Nodes[0].Nodes[nSeq].Nodes.Add(de2.Key.ToString(), de2.Key.ToString(), 1, 2);
tn.Nodes.Add(de2.Key.ToString(), de2.Key.ToString(), 1, 2);
}
if (Terminal.sTID.StartsWith("E"))
{
nElecDeviceCount++;
}
else if (Terminal.sTID.StartsWith("T"))
{
nTHDeviceCount++;
}
if (Terminal.sTID.StartsWith("S"))
{
nSteamDeviceCount++;
}
//}
}
else
{
TreeNode tn = tvTerminalList.Nodes[0].Nodes.Add(de.Key.ToString(), de.Key.ToString(), 5, 5);
//添加仪表
foreach (DictionaryEntry de2 in Terminal.htMeters)
{
tn.Nodes.Add(de2.Key.ToString(), de2.Key.ToString(), 6, 6);
}
}
}
}
tvTerminalList.Nodes[0].Expand();
tvTerminalList.Nodes[1].Expand();
tvTerminalList.EndUpdate();
}
lblStreamDeviceCount.Text = "" + nSteamDeviceCount;
lblTHDeviceCount.Text = "" + nTHDeviceCount;
lblElectronicDeviceCount.Text = "" + nElecDeviceCount;
return;
}
/*
*TerminalParamParsing
*
*2010-10-30
*Hashtable htTerminals
*void
*
*/
private void TerminalParamParsing(Hashtable htTerminals)
{
htTerminalParams = new Hashtable();
string sTName, sTID, sMName, sMID;
foreach (DictionaryEntry de in htTerminals)
{
sTName = "";
sTID = "";
sMName = "";
sMID = "";
string s = de.Key.ToString();
ParamParsing(ref s, ref sMID, ref sMName);
s = de.Value.ToString();
ParamParsing(ref s, ref sTID, ref sTName);// OnLine OffLine
struTerminal Terminal;
bool bTerminalOn = sTName.EndsWith("1");//0 1
sTName = sTName.Remove(sTName.Length-2,2);//
if (htTerminalParams[sTName + "-" + sTID] == null)
{
Terminal = new struTerminal();
Terminal.sTID = sTID;
Terminal.htMeters = new Hashtable();
Terminal.bOn = bTerminalOn;
htTerminalParams[sTName + "-" + sTID] = Terminal;
}
else
{
Terminal = (struTerminal)htTerminalParams[sTName + "-" + sTID];
}
Terminal.htMeters.Add(sMName +"-" +sMID, sMID);
}
return;
}
/*
*ParamParsing
*
*2010-10-30
*ref string sOri , ref string s1 1, ref string s2 2
*void
*
*/
private void ParamParsing(ref string sOri, ref string s1, ref string s2)
{
int nIndex = sOri.IndexOf('\n');
if (nIndex != -1)
{
s1 = sOri.Substring(0, nIndex);
s2 = sOri.Substring(nIndex + 1, sOri.Length - nIndex - 1);
}
}
/*
*richTBInfo_TextChanged
*
*2010-10-30
*object sender , EventArgs e
*void
*
*/
private void richTBInfo_TextChanged(object sender, EventArgs e)
{
//若内容长度过大,清空
if (richTBInfo.TextLength >= 65536)
{
richTBInfo.Clear();
return;
}
richTBInfo.SelectionStart = richTBInfo.TextLength;
richTBInfo.ScrollToCaret();
}
/*
*SetTerminalIPToolStripMenuItem_Click
*
*2010-10-30
*object sender , EventArgs e
*void
*IP Port
*/
private void SetTerminalIPToolStripMenuItem_Click(object sender, EventArgs e)
{
bool res = false;
if (tbCurrentTerminal.Text == "")
{
MessageBox.Show("请选择终端编号");
return;
}
IPPortInputForm inputDialog = new IPPortInputForm();
struIPPort struSavedIPPort;
if (htTerminalIPPort.ContainsKey(tbCurrentTerminal.Text))
{
struSavedIPPort = (struIPPort)htTerminalIPPort[tbCurrentTerminal.Text];
inputDialog.LoadIPPort(struSavedIPPort.sIP, struSavedIPPort.nPort);
}
else
{
struSavedIPPort = new struIPPort();
}
// Show testDialog as a modal dialog and determine if DialogResult = OK.
if (inputDialog.ShowDialog(this) == DialogResult.OK)
{
struSavedIPPort.sIP = inputDialog.sIP;
struSavedIPPort.nPort = inputDialog.nPort;
WriteTextBoxInfo(tbCurrentTerminal.Text + " 开始写IP和Port...");
try
{
res = remoteobj.SetIPPort(sSelectedTID, struSavedIPPort.sIP, struSavedIPPort.nPort);
WriteTextBoxInfo(tbCurrentTerminal.Text+ " 写IP和Port 结果返回:" + res.ToString());
if (res == true)
{
htTerminalIPPort[sSelectedTID] = struSavedIPPort;
SaveTerminalIPPort();
}
}
catch (Exception e1)
{
Console.WriteLine("exeption: " + e1.ToString());
}
}
inputDialog.Dispose();
}
/*
*MainForm_Load
*
*2010-10-30
*object sender , EventArgs e
*void
*
*/
private void MainForm_Load(object sender, EventArgs e)
{
btnRefresh.Enabled = false;
}
/*
*SetHeartBeatIntervalToolStripMenuItem_Click
*
*2010-10-30
*object sender , EventArgs e
*void
*
*/
private void SetHeartBeatIntervalToolStripMenuItem_Click(object sender, EventArgs e)
{
if (tbCurrentTerminal.Text == "")
{
MessageBox.Show("请选择终端编号");
return;
}
int nInterval;
HeartBeatIntervalForm inputDialog = new HeartBeatIntervalForm();
// Show testDialog as a modal dialog and determine if DialogResult = OK.
if (inputDialog.ShowDialog(this) == DialogResult.OK)
{
// Read the contents of testDialog's TextBox.
//this.txtResult.Text = testDialog.TextBox1.Text;
nInterval = inputDialog.nInterval*Common.MULTIPLE;
WriteTextBoxInfo(tbCurrentTerminal.Text + " 开始写心跳间隔...");
try
{
WriteTextBoxInfo(tbCurrentTerminal.Text + " 写心跳间隔 结果返回:" + remoteobj.SetHeartBeatInterval(sSelectedTID, nInterval).ToString());
}
catch (Exception e1)
{
Console.WriteLine("写心跳间隔 exeption: " + e1.ToString());
}
}
inputDialog.Dispose();
}
/*
*SetAutoSendIntervalToolStripMenuItem_Click
*
*2010-10-30
*object sender , EventArgs e
*void
*
*/
private void SetAutoSendIntervalToolStripMenuItem_Click(object sender, EventArgs e)
{
if (tbCurrentTerminal.Text == "")
{
MessageBox.Show("请选择终端编号");
return;
}
int nInterval;
AutoSendIntervalForm inputDialog = new AutoSendIntervalForm();
// Show testDialog as a modal dialog and determine if DialogResult = OK.
if (inputDialog.ShowDialog(this) == DialogResult.OK)
{
// Read the contents of testDialog's TextBox.
//this.txtResult.Text = testDialog.TextBox1.Text;
nInterval = inputDialog.nInterval*Common.MULTIPLE;
WriteTextBoxInfo(tbCurrentTerminal.Text + " 开始写主动上传间隔...");
try
{
WriteTextBoxInfo(tbCurrentTerminal.Text + " 写主动上传间隔 结果返回:" + remoteobj.SetAutoSendInterval(sSelectedTID, nInterval).ToString());
}
catch (Exception e1)
{
Console.WriteLine("写主动上传间隔 exeption: " + e1.ToString());
}
}
inputDialog.Dispose();
}
/*
*GetHeartIntervalToolStripMenuItem_Click
*
*2010-10-30
*object sender , EventArgs e
*void
*
*/
private void GetHeartIntervalToolStripMenuItem_Click(object sender, EventArgs e)
{
if (tbCurrentTerminal.Text == "")
{
MessageBox.Show("请选择终端编号");
return;
}
string sInterval = "";
WriteTextBoxInfo(tbCurrentTerminal.Text + " 开始读心跳间隔...");
try
{
bool res = remoteobj.GetHeartBeatInterval(sSelectedTID, ref sInterval);
WriteTextBoxInfo(tbCurrentTerminal.Text + " 读心跳间隔 结果返回:" + res.ToString() + (res == true ? ",心跳间隔为:" + (Convert.ToInt32(sInterval)/Common.MULTIPLE) : ""));
}
catch (Exception e1)
{
// Console.WriteLine("exeption: " + e1.ToString());
}
}
/*
*GetAutoSendIntervalToolStripMenuItem_Click
*
*2010-10-30
*object sender , EventArgs e
*void
*
*/
private void GetAutoSendIntervalToolStripMenuItem_Click(object sender, EventArgs e)
{
if (tbCurrentTerminal.Text == "")
{
MessageBox.Show("请选择终端编号");
return;
}
string sInterval = "";
WriteTextBoxInfo(tbCurrentTerminal.Text + " 开始读主动上传间隔...");
try
{
bool res = remoteobj.GetAutoSendInterval(sSelectedTID, ref sInterval);
WriteTextBoxInfo(tbCurrentTerminal.Text + " 读主动上传间隔 结果返回:" + res.ToString() + (res == true ? ",主动上传间隔为:" + Convert.ToInt32(sInterval)/Common.MULTIPLE : ""));
}
catch (Exception e1)
{
// Console.WriteLine("exeption: " + e1.ToString());
}
}
/*
*SetTerminalIDToolStripMenuItem_Click
*
*2010-10-30
*object sender , EventArgs e
*void
*
*/
private void SetTerminalIDToolStripMenuItem_Click(object sender, EventArgs e)
{
if (tbCurrentTerminal.Text == "")
{
MessageBox.Show("请选择终端编号");
return;
}
string sNewName;
NewTerminalNameForm inputDialog = new NewTerminalNameForm();
inputDialog.SetTerminalName(sSelectedTID);
// Show testDialog as a modal dialog and determine if DialogResult = OK.
if (inputDialog.ShowDialog(this) == DialogResult.OK)
{
// Read the contents of testDialog's TextBox.
//this.txtResult.Text = testDialog.TextBox1.Text;
sNewName = inputDialog.sNewName;
WriteTextBoxInfo(tbCurrentTerminal.Text + " 开始设置采集终端编号...");
try
{
WriteTextBoxInfo(tbCurrentTerminal.Text + " 设置采集终端编号:"
+ remoteobj.SetTerminalName(sSelectedTID, sNewName).ToString());
}
catch (Exception e1)
{
Console.WriteLine("exeption: " + e1.ToString());
}
}
inputDialog.Dispose();
}
/*
*SetMeterIDAndEnableToolStripMenuItem_Click
*
*2010-10-30
*object sender , EventArgs e
*void
*
*/
private void SetMeterIDAndEnableToolStripMenuItem_Click(object sender, EventArgs e)
{
if (tbCurrentTerminal.Text == "")
{
MessageBox.Show("请选择终端编号");
return;
}
//string sNewName;
MeterAddrForm inputDialog = new MeterAddrForm();
WriteTextBoxInfo(tbCurrentTerminal.Text + " 开始读取仪表地址...");
byte[] arr = null;
bool res = remoteobj.GetMeterAddr(sSelectedTID, ref arr);
WriteTextBoxInfo(tbCurrentTerminal.Text + " 读取仪表地址 结果:" + res);
if (res == false || arr.Length != 16)
{
return;
}
for (int i = 0; i < 16; i++)
{
inputDialog.arrTextBox[i].Text = arr[i].ToString("X2");
//inputDialog.arrTextBox[i].Text = arr[i].ToString("D2");
}
res = remoteobj.GetMeterAble(sSelectedTID, ref arr);
WriteTextBoxInfo(tbCurrentTerminal.Text + " 读取仪表置位 结果:" + res);
if (res == false || arr.Length != 16)
{
return;
}
for (int i = 0; i < 16; i++)
{
if (arr[i] > 0)
{
inputDialog.checkedListBox.SetItemChecked(i, true);// arrTextBox[0].Text = arr[i].ToString("D3");
}
else
{
inputDialog.checkedListBox.SetItemChecked(i, false);// arrTextBox[0].Text = arr[i].ToString("D3");
}
}
// Show testDialog as a modal dialog and determine if DialogResult = OK.
if (inputDialog.ShowDialog(this) == DialogResult.OK)
{
Console.WriteLine("inputDialog.ShowDialog(this) == DialogResult.OK");
res = false;
byte[] arrAddr = null;
WriteTextBoxInfo(tbCurrentTerminal.Text + " 开始设置仪表地址...");
try
{
arrAddr = new byte[16];
for (int i = 0; i < 16; i++)
{
arrAddr[i] = Convert.ToByte(inputDialog.arrTextBox[i].Text, 16);
//arrAddr[i] = Convert.ToByte(inputDialog.arrTextBox[i].Text);
}
res = remoteobj.SetMeterAddr(sSelectedTID, ref arrAddr);
WriteTextBoxInfo(tbCurrentTerminal.Text + " 设置仪表地址:" + res);
}
catch (Exception e1)
{
Console.WriteLine("exeption: " + e1.ToString());
}
if (res == false)
{
return;
}
WriteTextBoxInfo(tbCurrentTerminal.Text + " 开始设置仪表置位...");
try
{
for (int i = 0; i < 16; i++)
{
arrAddr[i] = Convert.ToByte(inputDialog.checkedListBox.GetItemChecked(i) == true ? 1 : 0);
}
res = remoteobj.SetMeterAble(sSelectedTID, ref arrAddr);
WriteTextBoxInfo(tbCurrentTerminal.Text + " 设置设置仪表置位:" + res);
}
catch (Exception e1)
{
Console.WriteLine("exeption: " + e1.ToString());
}
}
inputDialog.Dispose();
}
/*
*btnRegister_Click
*
*2010-10-30
*object sender , EventArgs e
*void
*remoting
*/
private void btnRegister_Click(object sender, EventArgs e)
{
SaveRemotingIPPort();
try
{
remoteobj = (ReqHandler)Activator.GetObject(typeof(ReqHandler),
"tcp://" + textBox1.Text.Trim() + ":" + textBox2.Text.Trim() + "/RemoteObject");
btnRefresh.Enabled = true;
StartTimer();
}
catch (Exception e1)
{
MessageBox.Show("注册失败");
}
}
/*
*S_AlarmSettingToolStripMenuItem_Click
*
*2010-10-30
*object sender , EventArgs e
*void
*
*/
private void S_AlarmSettingToolStripMenuItem_Click(object sender, EventArgs e)
{
if (tbCurrentTerminal.Text == "" || sSelectedMID == "")
{
MessageBox.Show("请选择当前仪表");
return;
}
//string sNewName;
AlarmSettingForm inputDialog = new AlarmSettingForm();
inputDialog.sMID = sSelectedMID;
bool res = false;
string[] arr = null;
WriteTextBoxInfo(tbCurrentTerminal.Text + " 开始读取蒸汽仪表上下限...");
res = remoteobj.GetStreamThreshold(sSelectedTID, sSelectedMID, ref arr);
WriteTextBoxInfo(tbCurrentTerminal.Text + " 读取蒸汽仪表上下限 结果:" + res);
if (res == false || arr.Length != 16)
{
return;
}
for (int i = 0; i < 16; i++)
{
inputDialog.arrTextBox[i].Text = arr[i];
}
// Show testDialog as a modal dialog and determine if DialogResult = OK.
inputDialog.Height = 419;
if (inputDialog.ShowDialog(this) == DialogResult.OK)
{
res = false;
string[] arrThreshold = null;
WriteTextBoxInfo(tbCurrentTerminal.Text + " 开始设置蒸汽仪表上下限...");
try
{
arrThreshold = new string[16];
for (int i = 0; i < 16; i++)
{
arrThreshold[i] = inputDialog.arrTextBox[i].Text;
}
res = remoteobj.SetStreamThreshold(sSelectedTID, sSelectedMID, ref arrThreshold);
WriteTextBoxInfo(tbCurrentTerminal.Text + " 蒸汽仪表上下限:" + res);
}
catch (Exception e1)
{
Console.WriteLine("exeption: " + e1.ToString());
}
}
inputDialog.Dispose();
}
/*
*tvTerminalList_AfterSelect
*
*2010-10-30
*object sender , EventArgs e
*void
*IDID
*/
private void tvTerminalList_AfterSelect(object sender, TreeViewEventArgs e)
{
if (e.Action == TreeViewAction.ByKeyboard || e.Action == TreeViewAction.ByMouse)
{
struTerminal termianl;
if (e.Node.Level == 1)
{
termianl = (struTerminal)htTerminalParams[e.Node.Text];
if (termianl.bOn)
{
tbCurrentTerminal.Text = e.Node.Text;
sSelectedTID = termianl.sTID;
sSelectedMID = "";
}
else
{
tbCurrentTerminal.Text = "";
sSelectedTID = "";
sSelectedMID = "";
}
}
else if (e.Node.Level == 2)
{
termianl = (struTerminal)htTerminalParams[e.Node.Parent.Text];
if (termianl.bOn)
{
tbCurrentTerminal.Text = e.Node.Parent.Text;
sSelectedTID = termianl.sTID;
sSelectedMID = (string)termianl.htMeters[e.Node.Text];
}
else
{
tbCurrentTerminal.Text = "";
sSelectedTID = "";
sSelectedMID = "";
}
}
}
}
/*
*E_AlarmSettingToolStripMenuItem_Click
*
*2010-10-30
*object sender , EventArgs e
*void
*
*/
private void E_AlarmSettingToolStripMenuItem_Click(object sender, EventArgs e)
{
if (tbCurrentTerminal.Text == "" || sSelectedMID == "")
{
MessageBox.Show("请选择当前仪表");
return;
}
E_AlarmSettingForm inputDialog = new E_AlarmSettingForm();
bool res = false;
string[] arr = null;
WriteTextBoxInfo(tbCurrentTerminal.Text + " " + sSelectedMID + " 开始读取电表上下限...");
res = remoteobj.GetElectricThreshold(sSelectedTID, sSelectedMID, ref arr);
WriteTextBoxInfo(tbCurrentTerminal.Text + " " + sSelectedMID + " 读取电表上下限 结果:" + res);
if (res == false || arr.Length != 8)
{
return;
}
for (int i = 0; i < 8; i++)
{
inputDialog.arrTextBox[i].Text = arr[i];
}
// Show testDialog as a modal dialog and determine if DialogResult = OK.
inputDialog.sMID = sSelectedMID;
if (inputDialog.ShowDialog(this) == DialogResult.OK)
{
res = false;
string[] arrThreshold = null;
WriteTextBoxInfo(tbCurrentTerminal.Text + " " + sSelectedMID + " 开始设置电表上下限...");
try
{
arrThreshold = new string[8];
for (int i = 0; i < 8; i++)
{
arrThreshold[i] = inputDialog.arrTextBox[i].Text;
}
res = remoteobj.SetElectricThreshold(sSelectedTID, sSelectedMID, ref arrThreshold);
WriteTextBoxInfo(tbCurrentTerminal.Text + " " + sSelectedMID + " 电表上下限:" + res);
}
catch (Exception e1)
{
Console.WriteLine("exeption: " + e1.ToString());
}
}
inputDialog.Dispose();
}
/*
*E_CallDataToolStripMenuItem_Click
*
*2010-10-30
*object sender , EventArgs e
*void
*
*/
private void E_CallDataToolStripMenuItem_Click(object sender, EventArgs e)
{
if (tbCurrentTerminal.Text == "" || sSelectedMID == "")
{
MessageBox.Show("请选择当前仪表");
return;
}
List<uint> lstParams;
Hashtable hsTable = null;
E_CallDataForm inputDialog = new E_CallDataForm();
inputDialog.sMID = sSelectedMID;
// Show testDialog as a modal dialog and determine if DialogResult = OK.
if (inputDialog.ShowDialog(this) == DialogResult.OK)
{
//string sMID = sSelectedMID;
// Read the contents of testDialog's TextBox.
//this.txtResult.Text = testDialog.TextBox1.Text;
lstParams = inputDialog.lstOBJID;
WriteTextBoxInfo(tbCurrentTerminal.Text + " 开始招唤数据...");
string sComment = "";
try
{
bool res = remoteobj.GetData(sSelectedTID, sSelectedMID, lstParams, ref hsTable);
sComment += sSelectedTID + " " + sSelectedMID + " 招唤数据 结果返回:" + res + "\r\n";
if (res == true)
{
//int key = 0;
//foreach (DictionaryEntry de in hsTable)
{
//key = (int)de.Key;
if (hsTable.ContainsKey(EMS_COMM_PARAMS.AU))
{
sComment += "\t\t\t\ta相电压" + hsTable[EMS_COMM_PARAMS.AU] + "\r\n";
}
if (hsTable.ContainsKey(EMS_COMM_PARAMS.BU))
{
sComment += "\t\t\t\tb相电压" + hsTable[EMS_COMM_PARAMS.BU] + "\r\n";
}
if (hsTable.ContainsKey(EMS_COMM_PARAMS.CU))
{
sComment += "\t\t\t\tc相电压" + hsTable[EMS_COMM_PARAMS.CU] + "\r\n";
}
if (hsTable.ContainsKey(EMS_COMM_PARAMS.AI))
{
sComment += "\t\t\t\ta相电流" + hsTable[EMS_COMM_PARAMS.AI] + "\r\n";
}
if (hsTable.ContainsKey(EMS_COMM_PARAMS.BI))
{
sComment += "\t\t\t\tb相电流" + hsTable[EMS_COMM_PARAMS.BI] + "\r\n";
}
if (hsTable.ContainsKey(EMS_COMM_PARAMS.CI))
{
sComment += "\t\t\t\tc相电流" + hsTable[EMS_COMM_PARAMS.CI] + "\r\n";
}
if (hsTable.ContainsKey(EMS_COMM_PARAMS.GLYS))
{
sComment += "\t\t\t\t总功率因数" + hsTable[EMS_COMM_PARAMS.GLYS] + "\r\n";
}
if (hsTable.ContainsKey(EMS_COMM_PARAMS.ZXYGZ))
{
sComment += "\t\t\t\t正向有功总电能" + hsTable[EMS_COMM_PARAMS.ZXYGZ] + "\r\n";
}
}
}
WriteTextBoxInfo(sComment);
}
catch (Exception e1)
{
Console.WriteLine("exeption: " + e1.ToString());
}
}
}
/*
*GetTerminalInfoToolStripMenuItem_Click
*
*2010-10-30
*object sender , EventArgs e
*void
*
*/
private void GetTerminalInfoToolStripMenuItem_Click(object sender, EventArgs e)
{
bool res = false;
string sInfo = "";
if (tbCurrentTerminal.Text == "")
{
MessageBox.Show("请选择终端编号");
return;
}
WriteTextBoxInfo(tbCurrentTerminal.Text + " 开始获取终端基本信息...");
res = remoteobj.GetInfo(sSelectedTID, ref sInfo);
WriteTextBoxInfo(tbCurrentTerminal.Text + " 获取终端基本信息 结果:" + res + (res == true ? sInfo : ""));
}
/*
*GetAllTerminalInfoToolStripMenuItem_Click
*
*2010-10-30
*object sender , EventArgs e
*void
*
*/
private void GetAllTerminalInfoToolStripMenuItem_Click(object sender, EventArgs e)
{
if (tvTerminalList.Nodes.Count == 0)
{
return;
}
else if (tvTerminalList.Nodes[0].Nodes.Count == 0)
{
return;
}
TreeNodeCollection myNodeCollection = tvTerminalList.Nodes[0].Nodes;
int myCount = myNodeCollection.Count;
// Create an Object array.
Object[] myArray = new Object[myCount];
// Copy the collection into an array.
myNodeCollection.CopyTo(myArray,0);
for(int i=0; i<myArray.Length; i++)
{
struTerminal termianl;
termianl = (struTerminal)htTerminalParams[((TreeNode)myArray[i]).Text];
bool res = false;
string sInfo = "";
WriteTextBoxInfo(((TreeNode)myArray[i]).Text + " 开始获取终端基本信息...");
res = remoteobj.GetInfo(termianl.sTID, ref sInfo);
WriteTextBoxInfo(((TreeNode)myArray[i]).Text + " 获取终端基本信息 结果:" + res + (res == true ? sInfo : ""));
}
}
/*
*OnTimedEvent
*
*2010-10-30
*object source , ElapsedEventArgs e
*void
*
*/
private static void OnTimedEvent(object source, ElapsedEventArgs e)
{
FrmMain.UpdTreeViewInfo(Common.btRefresh);
}
/*
*StartTimer
*
*2010-10-30
*void
*void
*
*/
private void StartTimer()
{
if (bStartTimer == false)
{
aTimer = new System.Timers.Timer(10000);
aTimer.Elapsed += new ElapsedEventHandler(OnTimedEvent);
if (aTimer.Enabled == false)
{
aTimer.Enabled = true;
}
bStartTimer = true;
}
}
/*
*StopTimer
*
*2010-10-30
*void
*void
*
*/
private void StopTimer()
{
if (bStartTimer == true)
{
if (aTimer != null && aTimer.Enabled == true)
{
aTimer.Enabled = false;
}
bStartTimer = false;
}
}
/*
*SetTargetIPToolStripMenuItem_Click
*
*2010-10-30
*void
*void
*IP
*/
private void SetTargetIPToolStripMenuItem_Click(object sender, EventArgs e)
{
bool res = false;
if (tbCurrentTerminal.Text == "")
{
MessageBox.Show("请选择终端编号");
return;
}
string sIP;
int nPort;
ServerIPPortInputForm inputDialog = new ServerIPPortInputForm();
inputDialog.LoadIPPort(Common.configReader.sServerIP, Common.configReader.sServerPort);
// Show testDialog as a modal dialog and determine if DialogResult = OK.
if (inputDialog.ShowDialog(this) == DialogResult.OK)
{
// Read the contents of testDialog's TextBox.
sIP = inputDialog.sIP;
nPort = inputDialog.nPort;
WriteTextBoxInfo(tbCurrentTerminal.Text + " 开始写目标服务器IP和Port...");
try
{
res = remoteobj.SetServerIPPort(sSelectedTID, sIP, nPort);
WriteTextBoxInfo(tbCurrentTerminal.Text + " 写目标服务器IP和Port 结果返回:" + res.ToString());
// struIPPort struSavedIPPort = new struIPPort();
// struSavedIPPort.sIP = sIP;
}
catch (Exception e1)
{
Console.WriteLine("exeption: " + e1.ToString());
}
}
inputDialog.Dispose();
}
//
/*
*callToolStripMenuItem_Click
*
*2010-10-30
*void
*void
*湿
*/
private void callToolStripMenuItem_Click(object sender, EventArgs e)
{
if (tbCurrentTerminal.Text == "" || sSelectedMID == "")
{
MessageBox.Show("请选择当前仪表");
return;
}
List<uint> lstParams;
Hashtable hsTable = null;
T_CallDataForm inputDialog = new T_CallDataForm();
inputDialog.sMID = sSelectedMID;
// Show testDialog as a modal dialog and determine if DialogResult = OK.
if (inputDialog.ShowDialog(this) == DialogResult.OK)
{
lstParams = inputDialog.lstOBJID;
WriteTextBoxInfo(tbCurrentTerminal.Text + " 开始招唤数据...");
string sComment = "";
try
{
bool res = remoteobj.GetData(sSelectedTID, sSelectedMID, lstParams, ref hsTable);
sComment += sSelectedTID + " " + sSelectedMID + " 招唤数据 结果返回:" + res + "\r\n";
if (res == true)
{
//int key = 0;
//foreach (DictionaryEntry de in hsTable)
{
//key = (int)de.Key;
if (hsTable.ContainsKey(THS_COMM_PARAMS.TEMP))
{
sComment += "\t\t\t\t温度" + hsTable[THS_COMM_PARAMS.TEMP] + "\r\n";
}
if (hsTable.ContainsKey(THS_COMM_PARAMS.HUMI))
{
sComment += "\t\t\t\t相对湿度" + hsTable[THS_COMM_PARAMS.HUMI] + "\r\n";
}
}
}
WriteTextBoxInfo(sComment);
}
catch (Exception e1)
{
Console.WriteLine("exeption: " + e1.ToString());
}
}
}
/*
*setAlarmThToolStripMenuItem_Click
*
*2010-10-30
*void
*void
*湿
*/
private void setAlarmThToolStripMenuItem_Click(object sender, EventArgs e)
{
if (tbCurrentTerminal.Text == "" || sSelectedMID == "")
{
MessageBox.Show("请选择当前仪表");
return;
}
T_AlarmSettingForm inputDialog = new T_AlarmSettingForm();
bool res = false;
string[] arr = null;
WriteTextBoxInfo(tbCurrentTerminal.Text + " 开始读取温湿度上下限...");
res = remoteobj.GetTempHumiThreshold(sSelectedTID, sSelectedMID, ref arr);
WriteTextBoxInfo(tbCurrentTerminal.Text + " 读取温湿度上下限 结果:" + res);
if (res == false || arr.Length != 8)
{
return;
}
for (int i = 0; i < 8; i++)
{
inputDialog.arrTextBox[i].Text = arr[i];
}
// Show testDialog as a modal dialog and determine if DialogResult = OK.
inputDialog.sMID = sSelectedMID;
if (inputDialog.ShowDialog(this) == DialogResult.OK)
{
res = false;
string[] arrThreshold = null;
WriteTextBoxInfo(tbCurrentTerminal.Text + " " + sSelectedMID + " 开始设置温湿度上下限...");
try
{
arrThreshold = new string[8];
for (int i = 0; i < 8; i++)
{
arrThreshold[i] = inputDialog.arrTextBox[i].Text;
}
res = remoteobj.SetTempHumiThreshold(sSelectedTID, sSelectedMID, ref arrThreshold);
WriteTextBoxInfo(tbCurrentTerminal.Text + " " + sSelectedMID + " 温湿度上下限:" + res);
}
catch (Exception e1)
{
Console.WriteLine("exeption: " + e1.ToString());
}
}
inputDialog.Dispose();
}
private void PTToolStripMenuItem_Click(object sender, EventArgs e)
{
if (tbCurrentTerminal.Text == "" || sSelectedMID == "")
{
MessageBox.Show("请选择当前仪表");
return;
}
E_CTPTSettingForm inputDialog = new E_CTPTSettingForm();
bool res = false;
string[] arr = null;
WriteTextBoxInfo(tbCurrentTerminal.Text + " 开始读电表PT CT...");
res = remoteobj.GetElecPTCT(sSelectedTID, sSelectedMID, ref arr);
WriteTextBoxInfo(tbCurrentTerminal.Text + " 读电表PT CT 结果:"+(res==true?"[PT]" + arr[0] + ",[CT]" + arr[1] : res.ToString()));
if (res == false || arr.Length != 2)
{
return;
}
for (int i = 0; i < 2; i++)
{
inputDialog.arrTextBox[i].Text = arr[i];
}
// Show testDialog as a modal dialog and determine if DialogResult = OK.
inputDialog.sMID = sSelectedMID;
if (inputDialog.ShowDialog(this) == DialogResult.OK)
{
res = false;
string[] arrThreshold = null;
WriteTextBoxInfo(tbCurrentTerminal.Text + " " + sSelectedMID + " 开始设置电表PT CT...");
try
{
arrThreshold = new string[2];
for (int i = 0; i < 2; i++)
{
arrThreshold[i] = inputDialog.arrTextBox[i].Text;
}
res = remoteobj.SetElecPTCT(sSelectedTID, sSelectedMID, ref arrThreshold);
WriteTextBoxInfo(tbCurrentTerminal.Text + " " + sSelectedMID + " 电表PT CT" + res);
}
catch (Exception e1)
{
Console.WriteLine("exeption: " + e1.ToString());
}
}
inputDialog.Dispose();
}
private void ToolStripMenuItem_Click(object sender, EventArgs e)
{
if (tbCurrentTerminal.Text == "")
{
MessageBox.Show("请选择终端编号");
return;
}
int nInterval;
HeartBeatIntervalForm inputDialog = new HeartBeatIntervalForm();
inputDialog.Text = "采集失败时间间隔";
inputDialog.label2.Text = "时间间隔";
// Show testDialog as a modal dialog and determine if DialogResult = OK.
if (inputDialog.ShowDialog(this) == DialogResult.OK)
{
// Read the contents of testDialog's TextBox.
//this.txtResult.Text = testDialog.TextBox1.Text;
nInterval = inputDialog.nInterval * Common.MULTIPLE;
WriteTextBoxInfo(tbCurrentTerminal.Text + " 开始写采集数据失败间隔...");
try
{
WriteTextBoxInfo(tbCurrentTerminal.Text + " 写采集数据失败间隔 结果返回:" + remoteobj.SetSteamFailInterval(sSelectedTID, nInterval).ToString());
}
catch (Exception e1)
{
Console.WriteLine("写采集数据失败间隔 exeption: " + e1.ToString());
}
}
inputDialog.Dispose();
}
private void ToolStripMenuItem_Click(object sender, EventArgs e)
{
if (tbCurrentTerminal.Text == "")
{
MessageBox.Show("请选择终端编号");
return;
}
WriteTextBoxInfo(tbCurrentTerminal.Text + " 开始校时...");
try
{
WriteTextBoxInfo(tbCurrentTerminal.Text + " 校时 结果返回:" + remoteobj.SetTime(sSelectedTID).ToString());
}
catch (Exception e1)
{
Console.WriteLine("exeption: " + e1.ToString());
}
}
}
/*
*struTerminal
*
*2010-10-30
*
*/
struct struTerminal
{
public string sTID;
public Hashtable htMeters;
public bool bOn;
}
}
namespace CommService
{
/*
*EMS_COMM_PARAMS
*
*2010-10-30
*
*/
struct EMS_COMM_PARAMS
{
//电类型
public const uint AI = 0x8E21;
public const uint BI = 0x8E22;
public const uint CI = 0x8E23;
public const uint AU = 0x8E11;
public const uint BU = 0x8E12;
public const uint CU = 0x8E13;
public const uint GLYS = 0xB650;
public const uint ZXYGZ = 0x9010;
}
/*
*THS_COMM_PARAMS
*
*2010-10-30
*湿
*/
struct THS_COMM_PARAMS
{
//温湿度类型
public const uint TEMP = 0xB400;
public const uint HUMI = 0xB401;
}
}