Commit 9141e4ff authored by shaxuezheng's avatar shaxuezheng

添加项目文件。

parent 5b9ce250

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.27703.2042
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ModbusDemo", "ModbusDemo\ModbusDemo.csproj", "{7D83EE1F-F3D9-4592-A0ED-A0D92DCF91AB}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{7D83EE1F-F3D9-4592-A0ED-A0D92DCF91AB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{7D83EE1F-F3D9-4592-A0ED-A0D92DCF91AB}.Debug|Any CPU.Build.0 = Debug|Any CPU
{7D83EE1F-F3D9-4592-A0ED-A0D92DCF91AB}.Release|Any CPU.ActiveCfg = Release|Any CPU
{7D83EE1F-F3D9-4592-A0ED-A0D92DCF91AB}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {A1C8BC4E-F325-41B4-8D8A-6DD96C556151}
EndGlobalSection
EndGlobal
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ModbusDemo
{
class _414P
{
//铂电阻+2路开关
const int MAX_AN_CH_NUM = 4;
ushort[] typeData = new ushort[MAX_AN_CH_NUM];//当前量程读数
byte[] AbnoSignal = new byte[MAX_AN_CH_NUM];//通道异常信号
ushort[] Inputtype = new ushort[MAX_AN_CH_NUM];//输入类型
ushort[] m_u16ADData = new ushort[MAX_AN_CH_NUM]; //保存AD的值
string[] WireN=new string[] { "2-Wire","3-Wire" ,"4-Wire"};
string[] Strcom = new string[] {"PT100(385) -50~150℃","PT100(385) 0~100℃",
"PT100(385) 0~200℃","PT100(385) 0~400℃",
"PT100(385) -200~200℃","PT100(391) -50~150℃",
"PT100(391) 0~100℃","PT100(391) 0~200℃",
"PT100(391) 0~400℃","PT100(391) -200~200℃",
"PT1000 -40~160℃","BALCO 500 -30~120℃",
"Ni(50) -80~100℃","Ni(508) 0~100℃"};
public class UserInfo
{
public int UserId { get; set; }
public string UserCompany { get; set; }
public float Data { get; set; }
public ushort UserModel { get; set; }
public double[] NegMin = {-50, 0, 0, 0, -200.00, -50.00,
0, 0, 0, -200.00, -40, -30, -80, 0 }; //负数最小值
public double[] NegMax = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};//负数最大值
public double[] PosMin = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
//正数最小值
public double[] PosMax = { 150, 100, 200, 400, 200, 150, 100, 200,
400, 200, 160, 120 ,100, 100};
//正数最大值
public ushort[] usMin = {0xD556, 0x0000, 0x0000, 0x0000, 0x8000, 0xD556, 0x0000 ,
0x0000, 0x0000, 0x8000, 0xE000, 0xE000, 0x999A, 0x0000};
public ushort[] usMax = {0x7FFF, 0x7FFF, 0x7FFF, 0x7FFF, 0x7FFF,0x7FFF, 0x7FFF,
0x7FFF ,0x7FFF, 0x7FFF, 0x7FFF, 0x7FFF, 0x7FFF, 0x7FFF};
}
UserInfo passageway0 =new UserInfo();
UserInfo passageway1 = new UserInfo();
UserInfo passageway2 = new UserInfo();
UserInfo passageway3 = new UserInfo();
public string[] RtdValue(ushort[] typeData, ushort[] Inputtype)
{
string[] Valuepass = new string[MAX_AN_CH_NUM];
if (typeData != null || Inputtype != null)
{
passageway0.UserId = 0;//通道
passageway0.Data = typeData[0];//数据
passageway0.UserCompany = Strcom[Inputtype[0]];//通道类型
passageway0.UserModel = Inputtype[0];//确定计算公式
passageway1.UserId = 1;//通道
passageway1.Data = typeData[1];//数据
passageway1.UserCompany = Strcom[Inputtype[1]];//通道类型
passageway1.UserModel = Inputtype[1];//确定计算公式
passageway2.UserId = 2;//通道
passageway2.Data = typeData[2];//数据
passageway2.UserCompany = Strcom[Inputtype[2]];//通道类型
passageway2.UserModel = Inputtype[2];//确定计算公式
passageway3.UserId = 3;//通道
passageway3.Data = typeData[3];//数据
passageway3.UserCompany = Strcom[Inputtype[3]];//通道类型
passageway3.UserModel = Inputtype[3];//确定计算公式
//////输入格式为:NegMin NegMax PosMin PosMax usMin usMax
Valuepass[0] = current(passageway0.NegMin[passageway0.UserModel], passageway0.NegMax[passageway0.UserModel], passageway0.PosMin[passageway0.UserModel],
passageway0.PosMax[passageway0.UserModel], passageway0.usMin[passageway0.UserModel], passageway0.usMax[passageway0.UserModel],
passageway0.Data); //处理函数
Valuepass[1] = current(passageway1.NegMin[passageway1.UserModel], passageway1.NegMax[passageway1.UserModel], passageway1.PosMin[passageway1.UserModel],
passageway1.PosMax[passageway1.UserModel], passageway1.usMin[passageway1.UserModel], passageway1.usMax[passageway1.UserModel],
passageway1.Data); //处理函数
Valuepass[2] = current(passageway2.NegMin[passageway2.UserModel], passageway2.NegMax[passageway2.UserModel], passageway2.PosMin[passageway2.UserModel],
passageway2.PosMax[passageway2.UserModel], passageway2.usMin[passageway2.UserModel], passageway2.usMax[passageway2.UserModel],
passageway2.Data); //处理函数
Valuepass[3] = current(passageway3.NegMin[passageway3.UserModel], passageway3.NegMax[passageway3.UserModel], passageway3.PosMin[passageway3.UserModel],
passageway3.PosMax[passageway3.UserModel], passageway3.usMin[passageway3.UserModel], passageway3.usMax[passageway3.UserModel],
passageway3.Data); //处理函数
return Valuepass;
}
else
return Valuepass=null;
}
double parameter;
string parameter2;
//输入格式为:NegMin NegMax PosMin PosMax usMin usMax
public string current(double NegMin, double NegMax, double PosMin,
double PosMax, double usMin, double usMax,
float Input) //处理函数
{
if (Input >= 0x0000
&& Input <= 0x7FFF)
{
parameter = Convert.ToSingle(PosMin + ((PosMax - PosMin) * Input) / usMax);
parameter2 = parameter.ToString("F3");
}
else
{
parameter = -Convert.ToSingle(PosMin + ((PosMax - PosMin) * (0x10000 - Input)) / (0x10000 - usMax));
parameter2 = parameter.ToString("F3");
}
if (parameter2 == "0.000")
{
parameter2 = "0.0";
return parameter2;
}
else
return parameter2;
}
}
}
This diff is collapsed.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ModbusDemo
{
class _478C
{
public int [] IO(bool [] state)
{
int[] I = new int[state.Length];
for (int i = 0; i < state.Length; i++)
{
I[i] = Convert.ToInt32(state[i]);
}
return I;
}
}
}
namespace ModbusDemo
{
partial class ComPort
{
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// 清理所有正在使用的资源。
/// </summary>
/// <param name="disposing">如果应释放托管资源,为 true;否则为 false。</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region 组件设计器生成的代码
/// <summary>
/// 设计器支持所需的方法 - 不要修改
/// 使用代码编辑器修改此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.label7 = new System.Windows.Forms.Label();
this.labPort = new System.Windows.Forms.Label();
this.cmbPort = new System.Windows.Forms.ComboBox();
this.cmbStopBit = new System.Windows.Forms.ComboBox();
this.btCloseCOM = new System.Windows.Forms.Button();
this.cmbParity = new System.Windows.Forms.ComboBox();
this.btOpenCOM = new System.Windows.Forms.Button();
this.cmbDataBit = new System.Windows.Forms.ComboBox();
this.labStopBit = new System.Windows.Forms.Label();
this.labParity = new System.Windows.Forms.Label();
this.labBaud = new System.Windows.Forms.Label();
this.labDataBit = new System.Windows.Forms.Label();
this.cmbBaud = new System.Windows.Forms.ComboBox();
this.SuspendLayout();
//
// label7
//
this.label7.Font = new System.Drawing.Font("Arial", 8F);
this.label7.ForeColor = System.Drawing.Color.Blue;
this.label7.Location = new System.Drawing.Point(3, 17);
this.label7.Name = "label7";
this.label7.Size = new System.Drawing.Size(140, 17);
this.label7.TabIndex = 47;
this.label7.Text = "Connection Status";
//
// labPort
//
this.labPort.Font = new System.Drawing.Font("Arial", 8F);
this.labPort.Location = new System.Drawing.Point(3, 34);
this.labPort.Name = "labPort";
this.labPort.Size = new System.Drawing.Size(75, 15);
this.labPort.TabIndex = 53;
this.labPort.Text = "COM Port";
this.labPort.TextAlign = System.Drawing.ContentAlignment.TopCenter;
//
// cmbPort
//
this.cmbPort.Font = new System.Drawing.Font("Arial", 8F);
this.cmbPort.Location = new System.Drawing.Point(3, 49);
this.cmbPort.Name = "cmbPort";
this.cmbPort.Size = new System.Drawing.Size(75, 22);
this.cmbPort.TabIndex = 52;
//
// cmbStopBit
//
this.cmbStopBit.Font = new System.Drawing.Font("Arial", 8F);
this.cmbStopBit.Items.AddRange(new object[] {
"1",
"2"});
this.cmbStopBit.Location = new System.Drawing.Point(337, 49);
this.cmbStopBit.Name = "cmbStopBit";
this.cmbStopBit.Size = new System.Drawing.Size(56, 22);
this.cmbStopBit.TabIndex = 57;
//
// btCloseCOM
//
this.btCloseCOM.Enabled = false;
this.btCloseCOM.Font = new System.Drawing.Font("Arial", 8F);
this.btCloseCOM.Location = new System.Drawing.Point(315, 75);
this.btCloseCOM.Name = "btCloseCOM";
this.btCloseCOM.Size = new System.Drawing.Size(78, 23);
this.btCloseCOM.TabIndex = 59;
this.btCloseCOM.Text = "Close";
this.btCloseCOM.Click += new System.EventHandler(this.btCloseCOM_Click);
//
// cmbParity
//
this.cmbParity.Font = new System.Drawing.Font("Arial", 8F);
this.cmbParity.Items.AddRange(new object[] {
"0-None Parity",
"1-Odd Parity",
"2-Even Parity"});
this.cmbParity.Location = new System.Drawing.Point(224, 49);
this.cmbParity.Name = "cmbParity";
this.cmbParity.Size = new System.Drawing.Size(100, 22);
this.cmbParity.TabIndex = 56;
//
// btOpenCOM
//
this.btOpenCOM.Font = new System.Drawing.Font("Arial", 8F);
this.btOpenCOM.Location = new System.Drawing.Point(224, 75);
this.btOpenCOM.Name = "btOpenCOM";
this.btOpenCOM.Size = new System.Drawing.Size(78, 23);
this.btOpenCOM.TabIndex = 58;
this.btOpenCOM.Text = "Open";
this.btOpenCOM.Click += new System.EventHandler(this.btOpenCOM_Click);
//
// cmbDataBit
//
this.cmbDataBit.Font = new System.Drawing.Font("Arial", 8F);
this.cmbDataBit.Items.AddRange(new object[] {
"7",
"8"});
this.cmbDataBit.Location = new System.Drawing.Point(168, 49);
this.cmbDataBit.Name = "cmbDataBit";
this.cmbDataBit.Size = new System.Drawing.Size(48, 22);
this.cmbDataBit.TabIndex = 55;
//
// labStopBit
//
this.labStopBit.Font = new System.Drawing.Font("Arial", 8F);
this.labStopBit.Location = new System.Drawing.Point(337, 34);
this.labStopBit.Name = "labStopBit";
this.labStopBit.Size = new System.Drawing.Size(56, 15);
this.labStopBit.TabIndex = 60;
this.labStopBit.Text = "Stop Bit";
this.labStopBit.TextAlign = System.Drawing.ContentAlignment.TopCenter;
//
// labParity
//
this.labParity.Font = new System.Drawing.Font("Arial", 8F);
this.labParity.Location = new System.Drawing.Point(226, 34);
this.labParity.Name = "labParity";
this.labParity.Size = new System.Drawing.Size(98, 15);
this.labParity.TabIndex = 61;
this.labParity.Text = "Parity";
this.labParity.TextAlign = System.Drawing.ContentAlignment.TopCenter;
//
// labBaud
//
this.labBaud.Font = new System.Drawing.Font("Arial", 8F);
this.labBaud.Location = new System.Drawing.Point(84, 34);
this.labBaud.Name = "labBaud";
this.labBaud.Size = new System.Drawing.Size(75, 15);
this.labBaud.TabIndex = 62;
this.labBaud.Text = "Baudrate";
this.labBaud.TextAlign = System.Drawing.ContentAlignment.TopCenter;
//
// labDataBit
//
this.labDataBit.Font = new System.Drawing.Font("Arial", 8F);
this.labDataBit.Location = new System.Drawing.Point(168, 34);
this.labDataBit.Name = "labDataBit";
this.labDataBit.Size = new System.Drawing.Size(48, 15);
this.labDataBit.TabIndex = 63;
this.labDataBit.Text = "Data Bit";
this.labDataBit.TextAlign = System.Drawing.ContentAlignment.TopCenter;
//
// cmbBaud
//
this.cmbBaud.Font = new System.Drawing.Font("Arial", 8F);
this.cmbBaud.Items.AddRange(new object[] {
"1200",
"2400",
"4800",
"9600",
"19200",
"38400",
"57600",
"115200"});
this.cmbBaud.Location = new System.Drawing.Point(83, 49);
this.cmbBaud.Name = "cmbBaud";
this.cmbBaud.Size = new System.Drawing.Size(76, 22);
this.cmbBaud.TabIndex = 54;
//
// ComPort
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.Controls.Add(this.cmbStopBit);
this.Controls.Add(this.btCloseCOM);
this.Controls.Add(this.cmbParity);
this.Controls.Add(this.btOpenCOM);
this.Controls.Add(this.cmbDataBit);
this.Controls.Add(this.labStopBit);
this.Controls.Add(this.labParity);
this.Controls.Add(this.labBaud);
this.Controls.Add(this.labDataBit);
this.Controls.Add(this.cmbBaud);
this.Controls.Add(this.labPort);
this.Controls.Add(this.cmbPort);
this.Controls.Add(this.label7);
this.Name = "ComPort";
this.Size = new System.Drawing.Size(400, 106);
this.Load += new System.EventHandler(this.ComPort_Load);
this.ResumeLayout(false);
}
#endregion
private System.Windows.Forms.Label label7;
private System.Windows.Forms.Label labPort;
private System.Windows.Forms.ComboBox cmbPort;
private System.Windows.Forms.ComboBox cmbStopBit;
private System.Windows.Forms.Button btCloseCOM;
private System.Windows.Forms.ComboBox cmbParity;
private System.Windows.Forms.Button btOpenCOM;
private System.Windows.Forms.ComboBox cmbDataBit;
private System.Windows.Forms.Label labStopBit;
private System.Windows.Forms.Label labParity;
private System.Windows.Forms.Label labBaud;
private System.Windows.Forms.Label labDataBit;
private System.Windows.Forms.ComboBox cmbBaud;
}
}
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.IO.Ports;
namespace ModbusDemo
{
public partial class ComPort : UserControl
{
public ComPort()
{
InitializeComponent();
System.Windows.Forms.Control.CheckForIllegalCrossThreadCalls = false;//设置该属性 为false
}
private byte slaveID = 1;
private SerialPort comPort = new SerialPort();
private void ComPort_Load(object sender, EventArgs e)
{
cmbBaud.SelectedIndex = 7;
cmbDataBit.SelectedIndex = 1;
cmbParity.SelectedIndex = 0;
cmbStopBit.SelectedIndex = 0;
foreach (string s in SerialPort.GetPortNames())
cmbPort.Items.Add(s);
cmbPort.SelectedIndex = -1;
}
private void btOpenCOM_Click(object sender, EventArgs e)
{
if (cmbPort.Text == "")
{
MessageBox.Show("串口打开错误");
return;
}
comPort.PortName = cmbPort.Text;
comPort.BaudRate = int.Parse(cmbBaud.Text);
comPort.DataBits = int.Parse(cmbDataBit.Text);
if (cmbParity.Text.Substring(0, 1) == "0")
{
comPort.Parity = Parity.None;
}
else if (cmbParity.Text.Substring(0, 1) == "1")
{
comPort.Parity = Parity.Odd;
}
else if (cmbParity.Text.Substring(0, 1) == "2")
{
comPort.Parity = Parity.Even;
}
if (cmbStopBit.Text == "0")
{
comPort.StopBits = StopBits.None;
}
else if (cmbStopBit.Text == "1")
{
comPort.StopBits = StopBits.One;
}
try
{
comPort.Open();
//comPort.Write("01 03 00 00 00 05 85 C9");//写数据
comPort.DataReceived += new SerialDataReceivedEventHandler(post_DataReceived);//串口接收处理函数
btOpenCOM.Enabled = false;
btCloseCOM.Enabled = true;
Console.WriteLine(DateTime.Now.ToString() + " =>Open " + comPort.PortName + " sucessfully!");
//MessageBox.Show(DateTime.Now.ToString() + System.Environment.NewLine + " =>Open " + comPort.PortName + " sucessfully!");
}
catch (Exception ex)
{
Console.WriteLine("Error: " + ex.Message);
MessageBox.Show("Error: " + ex.Message);
return;
}
}
//字节数组转16进制字符串
public static string byteToHexStr(byte[] bytes)
{
string returnStr = "";
if (bytes != null)
{
for (int i = 0; i < bytes.Length; i++)
{
returnStr += bytes[i].ToString("X2");
}
}
return returnStr;
}
static int buffersize = 18; //十六进制数的大小(假设为9Byte,可调整数字大小)
byte[] buffer = new Byte[buffersize]; //创建缓冲区
private void post_DataReceived(object sender, SerialDataReceivedEventArgs e)
{
int size = 0;
comPort.Read(buffer, 0, buffersize);
string ss;
ss = byteToHexStr(buffer); //用到函数byteToHexStr
Console.WriteLine(comPort.ReadExisting());
Console.WriteLine(ss);
size = comPort.ReadBufferSize;
if (buffer[0]==255)
{
modbus_Master.TepArray[0] = buffer[0];
modbus_Master.Sign = 2;
Console.WriteLine(comPort.ReadExisting());
}
else
{
modbus_Master.Sign =1;
modbus_Master.TepArray[0] = 0;
}
}
private void btCloseCOM_Click(object sender, EventArgs e)
{
//Close comport first,then stop and dispose slave.
comPort.Close();
btOpenCOM.Enabled = true;
btCloseCOM.Enabled = false;
Console.WriteLine(DateTime.Now.ToString() + " =>Disconnect " + comPort.PortName);
MessageBox.Show(DateTime.Now.ToString() + System.Environment.NewLine + " =>Disconnect " + comPort.PortName);
}
}
}
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.objec
oap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>
\ No newline at end of file
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net;
using System.Net.Sockets;
using System.Threading;
using System.Text.RegularExpressions;
using System.Collections;
using System.Management;
using System.Net.NetworkInformation;
namespace ModbusDemo.windows
{
class ModSearch
{
public struct DeviceInfo
{
public string ModuleName;
public string MacAddr;
public string IpAddr;
public string Netmask;
public string Gateway;
public bool bActive;
};
public UdpClient client;
public IPEndPoint endpoint;
Thread searchth;
ManualResetEvent mre = new ManualResetEvent(false);
public DeviceInfo m_DeviceInfo;
public ArrayList myHMIList = new ArrayList();
string FMAC =null;
string localip = null;
/// <summary>
/// 构造函数
/// </summary>
public ModSearch()
{
myHMIList.Clear();
NetworkInterface[] nics = NetworkInterface.GetAllNetworkInterfaces();
foreach (NetworkInterface adapter in nics)
{
if (adapter.Name == "本地连接") //这里是为了匹配我自己电脑网卡
{
bool Pd1 = (adapter.NetworkInterfaceType == NetworkInterfaceType.Ethernet); //判断是否是以太网连接
if (Pd1)
{
{
IPInterfaceProperties ip = adapter.GetIPProperties(); //IP配置信息
UnicastIPAddressInformationCollection ipCollection = ip.UnicastAddresses;
foreach (UnicastIPAddressInformation ipadd in ipCollection)
{
if (ipadd.Address.AddressFamily == AddressFamily.InterNetwork)
this.localip = ipadd.Address.ToString();//获取ip
}
}
}
}
}
}
public void ThStart()
{
if (mre != null)
mre.Reset();
Console.WriteLine("搜索线程开始....");
searchth = new Thread(ThreadMethod);
searchth.IsBackground = true;
searchth.Start();
}
public void ThStop()
{
Console.WriteLine("搜索线程结束....");
mre.Set();
}
public int HMICount()
{
return myHMIList.Count;
}
private void ThreadMethod()
{
byte[] sendBytes = new byte[] { 0x57, 0x54, 0x04, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x55, 0xAA };
int iReadBytes = 0;
try
{
client = new UdpClient(new IPEndPoint(IPAddress.Any, 0));
// client = new UdpClient(new IPEndPoint(IPAddress.Parse(this.localip), 0));
endpoint = new IPEndPoint(IPAddress.Parse("255.255.255.255"), 5048);
client.Send(sendBytes, sendBytes.Length, endpoint);
Thread.Sleep(500);
byte[] recvBytes;
client.Client.Blocking = false;
while (!mre.WaitOne(500))
{
iReadBytes = 30;
int buffSizeCurrent;
buffSizeCurrent = client.Client.Available;
if (buffSizeCurrent > 0)
{
recvBytes = client.Receive(ref endpoint);
iReadBytes = recvBytes.Length;
DoRecvDataCallBack(recvBytes, iReadBytes);
}
}
}catch
{
}
}
public Boolean DoRecvDataCallBack(byte[] pcData, int iRecvLength)
{
int i;
int count = 0;
byte[] pBuf = pcData;
int iDataLength = 0;
if (iRecvLength < 8)
return false;
if ((pBuf[0] == (byte)0x57) && (pBuf[1] == (byte)0x54) && (pBuf[iRecvLength - 2] == (byte)0x55) && (pBuf[iRecvLength - 1] == (byte)0xAA))
{
iDataLength = (int)(pBuf[2] & 0xFF)
| (int)((pBuf[3] & 0xFF) << 8)
| (int)((pBuf[4] & 0xFF) << 16)
| (int)((pBuf[5] & 0xFF) << 24);
if ((iDataLength >= 4) && (iRecvLength == 8 + iDataLength))
{
System.Text.ASCIIEncoding asciiEncoding = new System.Text.ASCIIEncoding();
m_DeviceInfo.bActive = false;
for (i = 0; i < 100; i++ )
{
if (asciiEncoding.GetString(pBuf, 6 + i, 1) == "\0")
break;
count++;
}
// m_DeviceInfo.ModuleName = String.Format("{0}", asciiEncoding.GetString(pBuf, 6, count));
//脱机
m_DeviceInfo.ModuleName = String.Format("{0}{1}{2}{3}", asciiEncoding.GetString(pBuf, 6, 1),
asciiEncoding.GetString(pBuf, 7, 1),
asciiEncoding.GetString(pBuf, 8, 1),
asciiEncoding.GetString(pBuf, 9, 1));
m_DeviceInfo.MacAddr = String.Format("{0}:{1}:{2}:{3}:{4}:{5}", pBuf[10], pBuf[11], pBuf[12], pBuf[13], pBuf[14], pBuf[15]);
m_DeviceInfo.IpAddr = String.Format("{0}.{1}.{2}.{3}", pBuf[16], pBuf[17], pBuf[18], pBuf[19]);
m_DeviceInfo.Netmask = String.Format("{0}.{1}.{2}.{3}", pBuf[20], pBuf[21], pBuf[22], pBuf[23]);
m_DeviceInfo.Gateway = String.Format("{0}.{1}.{2}.{3}", pBuf[24], pBuf[25], pBuf[26], pBuf[27]);
if (m_DeviceInfo.IpAddr != "0.0.0.0")
{
myHMIList.Add(m_DeviceInfo);
}
return true;
}
}
return false;
}
}
}
This diff is collapsed.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;
namespace ModbusDemo.windows
{
class WTModbus
{
[DllImport(@"LibModbus.dll", EntryPoint = "fnLibModbus", CharSet = CharSet.Unicode)]
public static extern uint fnLibModbus();
[DllImport(@"LibModbus.dll", EntryPoint = "fnReadCoilStatus")]
public static extern int fnReadCoilStatus(uint handle, ushort address, ushort num, [MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 1)] System.Byte[] dest, byte[] Ip, ushort wTcpPort);
[DllImport(@"LibModbus.dll", EntryPoint = "fnReadInputStatus")]
public static extern int fnReadInputStatus(uint handle, ushort address, ushort num, [MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 1)] System.Char[] dest, byte[] Ip, ushort wTcpPort);
[DllImport(@"LibModbus.dll", EntryPoint = "fnReadHoldingReg")]
public static extern int fnReadHoldingReg(uint handle, ushort address, ushort num, [MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 1)] System.UInt16[] dest, byte[] Ip, ushort wTcpPort);
[DllImport(@"LibModbus.dll", EntryPoint = "fnReadInputReg")]
public static extern int fnReadInputReg(uint handle, ushort address, ushort num, [MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 1)] System.UInt16[] dest, byte[] Ip, ushort wTcpPort);
[DllImport(@"LibModbus.dll", EntryPoint = "fnWriteSingleCoil")]
public static extern int fnWriteSingleCoil(uint handle, ushort address, ushort state, byte[] Ip, ushort wTcpPort);
[DllImport(@"LibModbus.dll", EntryPoint = "fnWriteHoldingReg")]
public static extern int fnWriteHoldingReg(uint handle, ushort address, ushort state, byte[] Ip, ushort wTcpPort);
[DllImport(@"LibModbus.dll", EntryPoint = "fnWriteMultipleCoils")]
public static extern int fnWriteMultipleCoils(uint handle, ushort address, ushort num, [MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 1)] System.Char[] src, byte[] Ip, ushort wTcpPort);
[DllImport(@"LibModbus.dll", EntryPoint = "fnWriteMultipleRegs")]
public static extern int fnWriteMultipleRegs(uint handle, ushort address, ushort num, [MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 1)] System.UInt16[] src, byte[] Ip, ushort wTcpPort);
[DllImport(@"LibModbus.dll", EntryPoint = "fnReportSlaveID")]
public static extern int fnReportSlaveID(uint handle, [MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 1)] System.Char[] src, byte[] Ip, ushort wTcpPort);
[DllImport(@"LibModbus.dll", EntryPoint = "fnMaskWriteReg")]
public static extern int fnMaskWriteReg(uint handle, ushort address, ushort amask, ushort omask, byte[] Ip, ushort wTcpPort);
[DllImport(@"LibModbus.dll", EntryPoint = "fnReadWriteMultipleRegs")]
public static extern int fnReadWriteMultipleRegs(uint handle, ushort waddress, ushort wnum, ushort raddress, ushort rnum, [MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 1)] System.UInt16[] dest, byte[] Ip, ushort wTcpPort);
[DllImport(@"LibModbus.dll", EntryPoint = "fnLibModbusClose")]
public static extern void fnLibModbusClose(uint handle);
private uint hModbusHandle;
private System.UInt16[] dest = new System.UInt16[10] { 0, 0, 3, 4, 5, 6, 7, 8, 9, 0 };
public WTModbus()
{
this.hModbusHandle = fnLibModbus();
}
~WTModbus()
{
fnLibModbusClose(hModbusHandle);
}
/// <summary>
/// 读线圈状态
/// </summary>
/// <param name="addr">地址</param>
/// <param name="num">线圈数目</param>
/// <param name="ip">设备IP</param>
/// <param name="wport">端口号 默认502</param>
/// <param name="buf">读取结果</param>
/// <returns>
/// 0 -- no error
/// 1 -- illegal register address.
/// 2 -- illegal argument
/// 3 -- porting layer error
/// 4 -- insufficient resources
/// 5 -- I/O error
/// 6 -- protocol stack in illegal state
/// 7 -- timeout error occurred
/// 8 -- slave address error
/// 9 -- exception error occurred
/// 10-- CRC check error
/// 11-- send data error
/// 12-- receive data error
/// 13-- TCP connect error
/// 14-- close error
/// </returns>
public int ReadCoilStatus(ushort addr, ushort num, String ip, ushort wport, ref byte[] buf)
{
int ret;
byte[] bIp = Encoding.Unicode.GetBytes(ip);
ret = fnReadCoilStatus(hModbusHandle, (ushort)(addr - 1), num, buf, bIp, wport);
return ret;
}
public int ReadInputStatus(ushort addr, ushort num, String ip, ushort wport, ref char[] buf)
{
int ret;
byte[] bIp = Encoding.Unicode.GetBytes(ip);
ret = fnReadInputStatus(hModbusHandle, (ushort)(addr - 1), 1, buf, bIp, 502);
return ret;
}
public int ReadHoldingReg(ushort addr, ushort num, String ip, ushort wport, ref UInt16[] buf)
{
int ret;
byte[] bIp = Encoding.Unicode.GetBytes(ip);
ret = fnReadHoldingReg(hModbusHandle, (ushort)(addr - 1), num, buf, bIp, wport);
return ret;
}
public int ReadInputReg(ushort addr, ushort num, String ip, ushort wport, ref UInt16[] buf)
{
int ret;
byte[] bIp = Encoding.Unicode.GetBytes(ip);
ret = fnReadInputReg(hModbusHandle, (ushort)(addr - 1), 1, dest, bIp, wport);
buf[0] = dest[0];
return ret;
}
public int WriteSingleCoil(ushort addr, ushort state, String ip, ushort wport)
{
int ret = 0;
byte[] bIp = Encoding.Unicode.GetBytes(ip);
ret = fnWriteSingleCoil(hModbusHandle, (ushort)(addr - 1), state, bIp, wport);
return ret;
}
public int WriteHoldingReg(ushort addr, ushort state, String ip, ushort wport)
{
int ret = 0;
byte[] bIp = Encoding.Unicode.GetBytes(ip);
ret = fnWriteHoldingReg(hModbusHandle, (ushort)(addr - 1), state, bIp, wport);
return ret;
}
public int ReadHoldingReg(ushort addr, ushort num, String ip, ushort wport, ref char[] buf)
{
int ret;
byte[] bIp = Encoding.Unicode.GetBytes(ip);
ret = fnWriteMultipleCoils(hModbusHandle, (ushort)(addr - 1), 1, buf, bIp, wport);
return ret;
}
public int WriteMultipleRegs(ushort addr, ushort num, String ip, ushort wport, ref ushort[] buf)
{
int ret;
byte[] bIp = Encoding.Unicode.GetBytes(ip);
ret = fnWriteMultipleRegs(hModbusHandle, (ushort)(addr - 1), num, buf, bIp, wport);
return ret;
}
public int ReportSlaveID(ushort addr, ushort num, String ip, ushort wport, ref char[] buf)
{
int ret;
byte[] bIp = Encoding.Unicode.GetBytes(ip);
ret = fnReportSlaveID(hModbusHandle, buf, bIp, 502);
return ret;
}
public int MaskWriteReg(ushort addr, ushort amask, ushort omask, String ip, ushort wport)
{
int ret = 0;
byte[] bIp = Encoding.Unicode.GetBytes(ip);
ret = fnMaskWriteReg(hModbusHandle, (ushort)(addr - 1), amask, omask, bIp, wport);
return ret;
}
public int ReadWriteMultipleRegs(ushort waddr, ushort wnum, ushort raddr, ushort rnum, String ip, ushort wport, ref UInt16[] buf)
{
int ret = 0;
byte[] bIp = Encoding.Unicode.GetBytes(ip);
ret = fnReadWriteMultipleRegs(hModbusHandle, (ushort)(waddr - 1), wnum, raddr, rnum, buf, bIp, wnum);
return ret;
}
}
}
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<metadata name="timer.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>17, 17</value>
</metadata>
</root>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{7D83EE1F-F3D9-4592-A0ED-A0D92DCF91AB}</ProjectGuid>
<OutputType>WinExe</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>ModbusDemo</RootNamespace>
<AssemblyName>WTG93UG</AssemblyName>
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<PublishUrl>publish\</PublishUrl>
<Install>true</Install>
<InstallFrom>Disk</InstallFrom>
<UpdateEnabled>false</UpdateEnabled>
<UpdateMode>Foreground</UpdateMode>
<UpdateInterval>7</UpdateInterval>
<UpdateIntervalUnits>Days</UpdateIntervalUnits>
<UpdatePeriodically>false</UpdatePeriodically>
<UpdateRequired>false</UpdateRequired>
<MapFileExtensions>true</MapFileExtensions>
<ApplicationRevision>0</ApplicationRevision>
<ApplicationVersion>1.0.0.%2a</ApplicationVersion>
<IsWebBootstrapper>false</IsWebBootstrapper>
<UseApplicationTrust>false</UseApplicationTrust>
<BootstrapperEnabled>true</BootstrapperEnabled>
<TargetFrameworkProfile />
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>x86</PlatformTarget>
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<PropertyGroup>
<StartupObject>ModbusDemo.Program</StartupObject>
</PropertyGroup>
<PropertyGroup>
<ApplicationIcon>favicon.ico</ApplicationIcon>
</PropertyGroup>
<ItemGroup>
<Reference Include="log4net">
<HintPath>Lib\log4net.dll</HintPath>
</Reference>
<Reference Include="MQTTnet, Version=0.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\MQTTnet-CP.2.7.5\lib\net452\MQTTnet.dll</HintPath>
<EmbedInteropTypes>False</EmbedInteropTypes>
</Reference>
<Reference Include="Newtonsoft.Json, Version=12.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>..\packages\Newtonsoft.Json.12.0.1\lib\net45\Newtonsoft.Json.dll</HintPath>
</Reference>
<Reference Include="nmodbuspc">
<HintPath>Lib\nmodbuspc.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Deployment" />
<Reference Include="System.Drawing" />
<Reference Include="System.Windows.Forms" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="414P.cs" />
<Compile Include="478C.cs" />
<Compile Include="418X.cs" />
<Compile Include="Common\Modbuslib.cs" />
<Compile Include="ComPort.cs">
<SubType>UserControl</SubType>
</Compile>
<Compile Include="ComPort.Designer.cs">
<DependentUpon>ComPort.cs</DependentUpon>
</Compile>
<Compile Include="ConvertJson.cs" />
<Compile Include="windows\Form1.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="windows\Form1.Designer.cs">
<DependentUpon>Form1.cs</DependentUpon>
</Compile>
<Compile Include="modbus-Master.cs">
<SubType>UserControl</SubType>
</Compile>
<Compile Include="modbus-Master.Designer.cs">
<DependentUpon>modbus-Master.cs</DependentUpon>
</Compile>
<Compile Include="mqttpacke.cs" />
<Compile Include="RData.cs" />
<Compile Include="UData.cs" />
<Compile Include="windows\AC.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="windows\AC.Designer.cs">
<DependentUpon>AC.cs</DependentUpon>
</Compile>
<Compile Include="Common\ModSearch.cs" />
<Compile Include="Common\WTModbus.cs" />
<Compile Include="windows\Demo_818X.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="windows\Demo_818X.Designer.cs">
<DependentUpon>Demo_818X.cs</DependentUpon>
</Compile>
<Compile Include="windows\frmInputValue.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="windows\frmInputValue.designer.cs">
<DependentUpon>frmInputValue.cs</DependentUpon>
</Compile>
<Compile Include="windows\MDemo.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="windows\MDemo.Designer.cs">
<DependentUpon>MDemo.cs</DependentUpon>
</Compile>
<Compile Include="Modbus-slave.cs">
<SubType>UserControl</SubType>
</Compile>
<Compile Include="Modbus-slave.Designer.cs">
<DependentUpon>Modbus-slave.cs</DependentUpon>
</Compile>
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="windows\ProTest.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="windows\ProTest.Designer.cs">
<DependentUpon>ProTest.cs</DependentUpon>
</Compile>
<Compile Include="UserMQTT.cs">
<SubType>UserControl</SubType>
</Compile>
<Compile Include="UserMQTT.Designer.cs">
<DependentUpon>UserMQTT.cs</DependentUpon>
</Compile>
<Compile Include="windows\sanchen.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="windows\sanchen.Designer.cs">
<DependentUpon>sanchen.cs</DependentUpon>
</Compile>
<Compile Include="Totxt.cs" />
<EmbeddedResource Include="ComPort.resx">
<DependentUpon>ComPort.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="windows\Form1.resx">
<DependentUpon>Form1.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="modbus-Master.resx">
<DependentUpon>modbus-Master.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="windows\AC.resx">
<DependentUpon>AC.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="windows\Demo_818X.resx">
<DependentUpon>Demo_818X.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="windows\frmInputValue.resx">
<DependentUpon>frmInputValue.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="windows\MDemo.resx">
<DependentUpon>MDemo.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="Modbus-slave.resx">
<DependentUpon>Modbus-slave.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="Properties\Resources.resx">
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
<SubType>Designer</SubType>
</EmbeddedResource>
<Compile Include="Properties\Resources.Designer.cs">
<AutoGen>True</AutoGen>
<DependentUpon>Resources.resx</DependentUpon>
<DesignTime>True</DesignTime>
</Compile>
<EmbeddedResource Include="windows\ProTest.resx">
<DependentUpon>ProTest.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="UserMQTT.resx">
<DependentUpon>UserMQTT.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="windows\sanchen.resx">
<DependentUpon>sanchen.cs</DependentUpon>
</EmbeddedResource>
<None Include="app.config" />
<None Include="packages.config" />
<None Include="Properties\Settings.settings">
<Generator>SettingsSingleFileGenerator</Generator>
<LastGenOutput>Settings.Designer.cs</LastGenOutput>
</None>
<Compile Include="Properties\Settings.Designer.cs">
<AutoGen>True</AutoGen>
<DependentUpon>Settings.settings</DependentUpon>
<DesignTimeSharedInput>True</DesignTimeSharedInput>
</Compile>
</ItemGroup>
<ItemGroup />
<ItemGroup>
<None Include="Resources\057.png" />
</ItemGroup>
<ItemGroup>
<BootstrapperPackage Include="Microsoft.Net.Framework.3.5.SP1">
<Visible>False</Visible>
<ProductName>.NET Framework 3.5 SP1</ProductName>
<Install>false</Install>
</BootstrapperPackage>
</ItemGroup>
<ItemGroup>
<WCFMetadata Include="Connected Services\" />
</ItemGroup>
<ItemGroup>
<Content Include="favicon.ico" />
<Content Include="picture\Gear_102px_1197692_easyicon.net.ico" />
<Content Include="Lib\LibModbus.dll" />
<Content Include="Lib\LibSocket.dll" />
<Content Include="picture\nut_128px_1101797_easyicon.net.ico" />
<None Include="Resources\logo.png" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>
\ No newline at end of file

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.27703.2042
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ModbusDemo", "ModbusDemo\ModbusDemo.csproj", "{7D83EE1F-F3D9-4592-A0ED-A0D92DCF91AB}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{7D83EE1F-F3D9-4592-A0ED-A0D92DCF91AB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{7D83EE1F-F3D9-4592-A0ED-A0D92DCF91AB}.Debug|Any CPU.Build.0 = Debug|Any CPU
{7D83EE1F-F3D9-4592-A0ED-A0D92DCF91AB}.Release|Any CPU.ActiveCfg = Release|Any CPU
{7D83EE1F-F3D9-4592-A0ED-A0D92DCF91AB}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {A1C8BC4E-F325-41B4-8D8A-6DD96C556151}
EndGlobalSection
EndGlobal
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net;
using System.Net.Sockets;
using System.Threading;
using System.Text.RegularExpressions;
using System.Collections;
using System.Management;
using System.Net.NetworkInformation;
namespace ModbusDemo.Common
{
class ModSearch
{
public struct DeviceInfo
{
public string ModuleName;
public string MacAddr;
public string IpAddr;
public string Netmask;
public string Gateway;
public bool bActive;
};
public UdpClient client;
public IPEndPoint endpoint;
Thread searchth;
ManualResetEvent mre = new ManualResetEvent(false);
public DeviceInfo m_DeviceInfo;
public ArrayList myHMIList = new ArrayList();
string FMAC =null;
string localip = null;
/// <summary>
/// 构造函数
/// </summary>
public ModSearch()
{
myHMIList.Clear();
NetworkInterface[] nics = NetworkInterface.GetAllNetworkInterfaces();
foreach (NetworkInterface adapter in nics)
{
if (adapter.Name == "本地连接") //这里是为了匹配我自己电脑网卡
{
bool Pd1 = (adapter.NetworkInterfaceType == NetworkInterfaceType.Ethernet); //判断是否是以太网连接
if (Pd1)
{
{
IPInterfaceProperties ip = adapter.GetIPProperties(); //IP配置信息
UnicastIPAddressInformationCollection ipCollection = ip.UnicastAddresses;
foreach (UnicastIPAddressInformation ipadd in ipCollection)
{
if (ipadd.Address.AddressFamily == AddressFamily.InterNetwork)
this.localip = ipadd.Address.ToString();//获取ip
}
}
}
}
}
}
public void ThStart()
{
if (mre != null)
mre.Reset();
Console.WriteLine("搜索线程开始....");
searchth = new Thread(ThreadMethod);
searchth.IsBackground = true;
searchth.Start();
}
public void ThStop()
{
Console.WriteLine("搜索线程结束....");
mre.Set();
}
public int HMICount()
{
return myHMIList.Count;
}
private void ThreadMethod()
{
byte[] sendBytes = new byte[] { 0x57, 0x54, 0x04, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x55, 0xAA };
int iReadBytes = 0;
try
{
client = new UdpClient(new IPEndPoint(IPAddress.Any, 0));
// client = new UdpClient(new IPEndPoint(IPAddress.Parse(this.localip), 0));
endpoint = new IPEndPoint(IPAddress.Parse("255.255.255.255"), 5048);
client.Send(sendBytes, sendBytes.Length, endpoint);
Thread.Sleep(500);
byte[] recvBytes;
client.Client.Blocking = false;
while (!mre.WaitOne(500))
{
iReadBytes = 30;
int buffSizeCurrent;
buffSizeCurrent = client.Client.Available;
if (buffSizeCurrent > 0)
{
recvBytes = client.Receive(ref endpoint);
iReadBytes = recvBytes.Length;
DoRecvDataCallBack(recvBytes, iReadBytes);
}
}
}catch
{
}
}
public Boolean DoRecvDataCallBack(byte[] pcData, int iRecvLength)
{
int i;
int count = 0;
byte[] pBuf = pcData;
int iDataLength = 0;
if (iRecvLength < 8)
return false;
if ((pBuf[0] == (byte)0x57) && (pBuf[1] == (byte)0x54) && (pBuf[iRecvLength - 2] == (byte)0x55) && (pBuf[iRecvLength - 1] == (byte)0xAA))
{
iDataLength = (int)(pBuf[2] & 0xFF)
| (int)((pBuf[3] & 0xFF) << 8)
| (int)((pBuf[4] & 0xFF) << 16)
| (int)((pBuf[5] & 0xFF) << 24);
if ((iDataLength >= 4) && (iRecvLength == 8 + iDataLength))
{
System.Text.ASCIIEncoding asciiEncoding = new System.Text.ASCIIEncoding();
m_DeviceInfo.bActive = false;
for (i = 0; i < 100; i++ )
{
if (asciiEncoding.GetString(pBuf, 6 + i, 1) == "\0")
break;
count++;
}
// m_DeviceInfo.ModuleName = String.Format("{0}", asciiEncoding.GetString(pBuf, 6, count));
//脱机
m_DeviceInfo.ModuleName = String.Format("{0}{1}{2}{3}", asciiEncoding.GetString(pBuf, 6, 1),
asciiEncoding.GetString(pBuf, 7, 1),
asciiEncoding.GetString(pBuf, 8, 1),
asciiEncoding.GetString(pBuf, 9, 1));
m_DeviceInfo.MacAddr = String.Format("{0}:{1}:{2}:{3}:{4}:{5}", pBuf[10], pBuf[11], pBuf[12], pBuf[13], pBuf[14], pBuf[15]);
m_DeviceInfo.IpAddr = String.Format("{0}.{1}.{2}.{3}", pBuf[16], pBuf[17], pBuf[18], pBuf[19]);
m_DeviceInfo.Netmask = String.Format("{0}.{1}.{2}.{3}", pBuf[20], pBuf[21], pBuf[22], pBuf[23]);
m_DeviceInfo.Gateway = String.Format("{0}.{1}.{2}.{3}", pBuf[24], pBuf[25], pBuf[26], pBuf[27]);
if (m_DeviceInfo.IpAddr != "0.0.0.0")
{
myHMIList.Add(m_DeviceInfo);
}
return true;
}
}
return false;
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;
namespace ModbusDemo.Common
{
class WTModbus
{
[DllImport(@"LibModbus.dll", EntryPoint = "fnLibModbus", CharSet = CharSet.Unicode)]
public static extern uint fnLibModbus();
[DllImport(@"LibModbus.dll", EntryPoint = "fnReadCoilStatus")]
public static extern int fnReadCoilStatus(uint handle, ushort address, ushort num, [MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 1)] System.Byte[] dest, byte[] Ip, ushort wTcpPort);
[DllImport(@"LibModbus.dll", EntryPoint = "fnReadInputStatus")]
public static extern int fnReadInputStatus(uint handle, ushort address, ushort num, [MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 1)] System.Char[] dest, byte[] Ip, ushort wTcpPort);
[DllImport(@"LibModbus.dll", EntryPoint = "fnReadHoldingReg")]
public static extern int fnReadHoldingReg(uint handle, ushort address, ushort num, [MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 1)] System.UInt16[] dest, byte[] Ip, ushort wTcpPort);
[DllImport(@"LibModbus.dll", EntryPoint = "fnReadInputReg")]
public static extern int fnReadInputReg(uint handle, ushort address, ushort num, [MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 1)] System.UInt16[] dest, byte[] Ip, ushort wTcpPort);
[DllImport(@"LibModbus.dll", EntryPoint = "fnWriteSingleCoil")]
public static extern int fnWriteSingleCoil(uint handle, ushort address, ushort state, byte[] Ip, ushort wTcpPort);
[DllImport(@"LibModbus.dll", EntryPoint = "fnWriteHoldingReg")]
public static extern int fnWriteHoldingReg(uint handle, ushort address, ushort state, byte[] Ip, ushort wTcpPort);
[DllImport(@"LibModbus.dll", EntryPoint = "fnWriteMultipleCoils")]
public static extern int fnWriteMultipleCoils(uint handle, ushort address, ushort num, [MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 1)] System.Char[] src, byte[] Ip, ushort wTcpPort);
[DllImport(@"LibModbus.dll", EntryPoint = "fnWriteMultipleRegs")]
public static extern int fnWriteMultipleRegs(uint handle, ushort address, ushort num, [MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 1)] System.UInt16[] src, byte[] Ip, ushort wTcpPort);
[DllImport(@"LibModbus.dll", EntryPoint = "fnReportSlaveID")]
public static extern int fnReportSlaveID(uint handle, [MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 1)] System.Char[] src, byte[] Ip, ushort wTcpPort);
[DllImport(@"LibModbus.dll", EntryPoint = "fnMaskWriteReg")]
public static extern int fnMaskWriteReg(uint handle, ushort address, ushort amask, ushort omask, byte[] Ip, ushort wTcpPort);
[DllImport(@"LibModbus.dll", EntryPoint = "fnReadWriteMultipleRegs")]
public static extern int fnReadWriteMultipleRegs(uint handle, ushort waddress, ushort wnum, ushort raddress, ushort rnum, [MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 1)] System.UInt16[] dest, byte[] Ip, ushort wTcpPort);
[DllImport(@"LibModbus.dll", EntryPoint = "fnLibModbusClose")]
public static extern void fnLibModbusClose(uint handle);
private uint hModbusHandle;
private System.UInt16[] dest = new System.UInt16[10] { 0, 0, 3, 4, 5, 6, 7, 8, 9, 0 };
public WTModbus()
{
this.hModbusHandle = fnLibModbus();
}
~WTModbus()
{
fnLibModbusClose(hModbusHandle);
}
/// <summary>
/// 读线圈状态
/// </summary>
/// <param name="addr">地址</param>
/// <param name="num">线圈数目</param>
/// <param name="ip">设备IP</param>
/// <param name="wport">端口号 默认502</param>
/// <param name="buf">读取结果</param>
/// <returns>
/// 0 -- no error
/// 1 -- illegal register address.
/// 2 -- illegal argument
/// 3 -- porting layer error
/// 4 -- insufficient resources
/// 5 -- I/O error
/// 6 -- protocol stack in illegal state
/// 7 -- timeout error occurred
/// 8 -- slave address error
/// 9 -- exception error occurred
/// 10-- CRC check error
/// 11-- send data error
/// 12-- receive data error
/// 13-- TCP connect error
/// 14-- close error
/// </returns>
public int ReadCoilStatus(ushort addr, ushort num, String ip, ushort wport, ref byte[] buf)
{
int ret;
byte[] bIp = Encoding.Unicode.GetBytes(ip);
ret = fnReadCoilStatus(hModbusHandle, (ushort)(addr - 1), num, buf, bIp, wport);
return ret;
}
public int ReadInputStatus(ushort addr, ushort num, String ip, ushort wport, ref char[] buf)
{
int ret;
byte[] bIp = Encoding.Unicode.GetBytes(ip);
ret = fnReadInputStatus(hModbusHandle, (ushort)(addr - 1), 1, buf, bIp, 502);
return ret;
}
public int ReadHoldingReg(ushort addr, ushort num, String ip, ushort wport, ref UInt16[] buf)
{
int ret;
byte[] bIp = Encoding.Unicode.GetBytes(ip);
ret = fnReadHoldingReg(hModbusHandle, (ushort)(addr - 1), num, buf, bIp, wport);
return ret;
}
public int ReadInputReg(ushort addr, ushort num, String ip, ushort wport, ref UInt16[] buf)
{
int ret;
byte[] bIp = Encoding.Unicode.GetBytes(ip);
ret = fnReadInputReg(hModbusHandle, (ushort)(addr - 1), 1, dest, bIp, wport);
buf[0] = dest[0];
return ret;
}
public int WriteSingleCoil(ushort addr, ushort state, String ip, ushort wport)
{
int ret = 0;
byte[] bIp = Encoding.Unicode.GetBytes(ip);
ret = fnWriteSingleCoil(hModbusHandle, (ushort)(addr - 1), state, bIp, wport);
return ret;
}
public int WriteHoldingReg(ushort addr, ushort state, String ip, ushort wport)
{
int ret = 0;
byte[] bIp = Encoding.Unicode.GetBytes(ip);
ret = fnWriteHoldingReg(hModbusHandle, (ushort)(addr - 1), state, bIp, wport);
return ret;
}
public int ReadHoldingReg(ushort addr, ushort num, String ip, ushort wport, ref char[] buf)
{
int ret;
byte[] bIp = Encoding.Unicode.GetBytes(ip);
ret = fnWriteMultipleCoils(hModbusHandle, (ushort)(addr - 1), 1, buf, bIp, wport);
return ret;
}
public int WriteMultipleRegs(ushort addr, ushort num, String ip, ushort wport, ref ushort[] buf)
{
int ret;
byte[] bIp = Encoding.Unicode.GetBytes(ip);
ret = fnWriteMultipleRegs(hModbusHandle, (ushort)(addr - 1), num, buf, bIp, wport);
return ret;
}
public int ReportSlaveID(ushort addr, ushort num, String ip, ushort wport, ref char[] buf)
{
int ret;
byte[] bIp = Encoding.Unicode.GetBytes(ip);
ret = fnReportSlaveID(hModbusHandle, buf, bIp, 502);
return ret;
}
public int MaskWriteReg(ushort addr, ushort amask, ushort omask, String ip, ushort wport)
{
int ret = 0;
byte[] bIp = Encoding.Unicode.GetBytes(ip);
ret = fnMaskWriteReg(hModbusHandle, (ushort)(addr - 1), amask, omask, bIp, wport);
return ret;
}
public int ReadWriteMultipleRegs(ushort waddr, ushort wnum, ushort raddr, ushort rnum, String ip, ushort wport, ref UInt16[] buf)
{
int ret = 0;
byte[] bIp = Encoding.Unicode.GetBytes(ip);
ret = fnReadWriteMultipleRegs(hModbusHandle, (ushort)(waddr - 1), wnum, raddr, rnum, buf, bIp, wnum);
return ret;
}
}
}
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
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 ModbusDemo.Common;
using System.Threading;
using System.Text.RegularExpressions;
namespace ModbusDemo
{
public partial class MDemo : Form
{
WTModbus ReadTest;
const ushort address = 17;
const ushort num = 6;
const ushort DevicePort = 502;
string DeviceIP;
ManualResetEvent showmre = new ManualResetEvent(false);
public delegate void invokeDelegate();
public MDemo()
{
InitializeComponent();
ReadTest = new WTModbus();
}
Thread t_ReadCoil;
private void TestBtn_Click(object sender, EventArgs e)
{
this.TestBtn.Enabled = false;
if (this.IPsetBox.Text != "")
{
DeviceIP = this.IPsetBox.Text;
}
else
{
MessageBox.Show("请检查IP输入是否正确");
this.TestBtn.Enabled = true;
return;
}
if (showmre != null)
{
showmre.Reset();
}
t_ReadCoil = new Thread(ReadCoilProc);
t_ReadCoil.IsBackground = true;
t_ReadCoil.Start();
}
private void ReadCoilProc(object obj)
{
short allval;
byte[] temp = new byte[6];
int ret;
while (!showmre.WaitOne(500))
{
//读线圈
ret = ReadTest.ReadCoilStatus(address, num, DeviceIP, DevicePort, ref temp);
allval = BitConverter.ToInt16(temp, 0);
invokeDelegate update = () =>
{
foreach (Control control in this.CoilBox.Controls)
{
if(control is PictureBox)
{
if ((allval >> Convert.ToUInt16((control as PictureBox).Tag) & 0x1) == 1)
{
(control as PictureBox).BackColor = Color.Green;
}
else
{
(control as PictureBox).BackColor = Color.Black;
}
}
}
};
Invoke(update);
}
}
private void stopbtn_Click(object sender, EventArgs e)
{
this.TestBtn.Enabled = true;
if (showmre != null)
showmre.Set();
foreach (Control control in this.CoilBox.Controls)
{
if (control is PictureBox)
{
(control as PictureBox).BackColor = Color.Black;
}
}
}
}
}
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>
\ No newline at end of file
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment