Commit c8656185 authored by wangwanxh@sina.com's avatar wangwanxh@sina.com

Merge branch 'wang_master' of https://gitee.com/wangwanxh/Vocs into wang_master

parents 4d23569a 08bdbac4
namespace GcDevicePc
{
partial class _424XTest
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.button1 = new System.Windows.Forms.Button();
this.button2 = new System.Windows.Forms.Button();
this.button3 = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// button1
//
this.button1.Location = new System.Drawing.Point(24, 46);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(75, 23);
this.button1.TabIndex = 0;
this.button1.Text = "测试1";
this.button1.UseVisualStyleBackColor = true;
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// button2
//
this.button2.Location = new System.Drawing.Point(141, 46);
this.button2.Name = "button2";
this.button2.Size = new System.Drawing.Size(75, 23);
this.button2.TabIndex = 1;
this.button2.Text = "测试2";
this.button2.UseVisualStyleBackColor = true;
this.button2.Click += new System.EventHandler(this.button2_Click);
//
// button3
//
this.button3.Location = new System.Drawing.Point(83, 86);
this.button3.Name = "button3";
this.button3.Size = new System.Drawing.Size(75, 23);
this.button3.TabIndex = 2;
this.button3.Text = "button3";
this.button3.UseVisualStyleBackColor = true;
this.button3.Click += new System.EventHandler(this.button3_Click);
//
// _424XTest
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(269, 121);
this.Controls.Add(this.button3);
this.Controls.Add(this.button2);
this.Controls.Add(this.button1);
this.Name = "_424XTest";
this.Text = "WTD424XTest";
this.Load += new System.EventHandler(this._424XTest_Load);
this.ResumeLayout(false);
}
#endregion
private System.Windows.Forms.Button button1;
private System.Windows.Forms.Button button2;
private System.Windows.Forms.Button button3;
}
}
\ No newline at end of file
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using GcDevicePc.Module;
namespace GcDevicePc
{
public partial class _424XTest : Form
{
private WTD424XOutput my424 = new WTD424XOutput();
private WTD624X my624 = new WTD624X("192.168.1.57",502);
public _424XTest()
{
InitializeComponent();
}
private void _424XTest_Load(object sender, EventArgs e)
{
my424.WTD424X_Open();
my624.WTD624X_Open();
}
private void button1_Click(object sender, EventArgs e)
{
float[] data = new float[] { 10.0f,8.8f, 13.3f,14.4f};
my624.UpdateData(data);
}
private void button2_Click(object sender, EventArgs e)
{
float[] data = new float[] { 10.0f, 8.8f, 13.3f, 14.4f };
my424.UpdateData2(data);
}
private void button3_Click(object sender, EventArgs e)
{
my624.UpdateIP("192.168.1.54","255.255.255.0","192.168.1.1");
}
}
}
<?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
...@@ -52,6 +52,24 @@ namespace GcDevicePc.Common ...@@ -52,6 +52,24 @@ namespace GcDevicePc.Common
} }
public int GCModbusClose()
{
try
{
fnLibModbusClose(hModbusHandle);
return 0;
}
catch (Exception e)
{
Console.WriteLine(e.Message);
return -1;
}
}
~GCModbus() ~GCModbus()
{ {
try try
......
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
namespace GcDevicePc.Common
{
class GCModbus485
{
[DllImport(@"LibModbus.dll", EntryPoint = "fnLibModbus485", CharSet = CharSet.Unicode)]
private static extern int fnLibModbus485(byte ucPort, int ulBaudRate, int timeout, ref UInt32 handle);
[DllImport(@"LibModbus.dll", EntryPoint = "fnReadCoilStatus")]
private static extern int fnReadCoilStatus(UInt32 handle, byte slaveaddress, UInt16 address, UInt16 num, [MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 1)] Byte[] dest, [MarshalAs(UnmanagedType.LPTStr)] string ip, UInt16 wTcpPort);
[DllImport(@"LibModbus.dll", EntryPoint = "fnReadInputStatus")]
private static extern int fnReadInputStatus(UInt32 handle, byte slaveaddress, ushort address, ushort num, [MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 1)] Byte[] dest, [MarshalAs(UnmanagedType.LPTStr)] string ipp, ushort wTcpPort);
[DllImport(@"LibModbus.dll", EntryPoint = "fnReadHoldingReg")]
private static extern int fnReadHoldingReg(UInt32 handle, byte slaveaddress, ushort address, ushort num, [MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 1)] UInt16[] dest, [MarshalAs(UnmanagedType.LPTStr)] string ipp, ushort wTcpPort);
[DllImport(@"LibModbus.dll", EntryPoint = "fnReadInputReg")]
private static extern int fnReadInputReg(UInt32 handle, byte slaveaddress, ushort address, ushort num, [MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 1)] UInt16[] dest, [MarshalAs(UnmanagedType.LPTStr)] string ipp, ushort wTcpPort);
[DllImport(@"LibModbus.dll", EntryPoint = "fnWriteSingleCoil")]
private static extern int fnWriteSingleCoil(UInt32 handle, byte slaveaddress, ushort address, ushort state, [MarshalAs(UnmanagedType.LPTStr)] string ip, ushort wTcpPort);
[DllImport(@"LibModbus.dll", EntryPoint = "fnWriteHoldingReg")]
private static extern int fnWriteHoldingReg(UInt32 handle, byte slaveaddress, ushort address, ushort state, [MarshalAs(UnmanagedType.LPTStr)] string ip, ushort wTcpPort);
[DllImport(@"LibModbus.dll", EntryPoint = "fnWriteMultipleCoils")]
private static extern int fnWriteMultipleCoils(UInt32 handle, byte slaveaddress, ushort address, ushort num, [MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 1)] Byte[] src, [MarshalAs(UnmanagedType.LPTStr)] string ip, ushort wTcpPort);
[DllImport(@"LibModbus.dll", EntryPoint = "fnWriteMultipleRegs")]
private static extern int fnWriteMultipleRegs(UInt32 handle, byte slaveaddress, ushort address, ushort num, [MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 1)] UInt16[] src, [MarshalAs(UnmanagedType.LPTStr)] string ipp, ushort wTcpPort);
[DllImport(@"LibModbus.dll", EntryPoint = "fnReportSlaveID")]
private static extern int fnReportSlaveID(UInt32 handle, [MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 1)] Byte[] src, [MarshalAs(UnmanagedType.LPTStr)] string ip, ushort wTcpPort);
[DllImport(@"LibModbus.dll", EntryPoint = "fnMaskWriteReg")]
private static extern int fnMaskWriteReg(UInt32 handle, byte slaveaddress, ushort address, ushort amask, ushort omask, [MarshalAs(UnmanagedType.LPTStr)] string ip, ushort wTcpPort);
[DllImport(@"LibModbus.dll", EntryPoint = "fnReadWriteMultipleRegs")]
private static extern int fnReadWriteMultipleRegs(UInt32 handle, byte slaveaddress, ushort waddress, ushort wnum, ushort raddress, ushort rnum, [MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 1)] UInt16[] dest, [MarshalAs(UnmanagedType.LPTStr)] string ip, ushort wTcpPort);
[DllImport(@"LibModbus.dll", EntryPoint = "fnLibModbusClose")]
private static extern void fnLibModbusClose(UInt32 handle);
private UInt32 hModbusHandle;
private byte Port = 1;
private int BaudRate = 9600;
private int timeout = 2000;
private string ip = "";
private ushort wport = 502;
public GCModbus485(byte uPort, int uBaudRate, int utimeout)
{
this.Port = uPort;
this.BaudRate = uBaudRate;
this.timeout = utimeout;
}
public int ModbusOpen()
{
int ret = 0;
try
{
ret = fnLibModbus485(Port, BaudRate, timeout, ref hModbusHandle);
}
catch (Exception e)
{
throw new Exception(e.Message);
}
return ret;
}
public int ModbusClose()
{
try
{
fnLibModbusClose(hModbusHandle);
hModbusHandle = 0;
return 0;
}
catch (Exception e)
{
Console.WriteLine(e.Message);
return -1;
}
}
~GCModbus485()
{
this.Port = 1;
this.BaudRate = 9600;
this.timeout = 2000;
}
public int ReadCoilStatus(byte slaveaddress, ushort addr, ushort num, ref byte[] buf)
{
int ret = 0;
try
{
if (hModbusHandle != 0)
ret = fnReadCoilStatus(hModbusHandle, slaveaddress, (ushort)(addr - 1), num, buf, ip, wport);
}
catch
{
ret = -1;
}
return ret;
}
public int ReadInputStatus(byte slaveaddress, ushort addr, ushort num, ref byte[] buf)
{
int ret = 0;
try
{
if (hModbusHandle != 0)
ret = fnReadInputStatus(hModbusHandle, slaveaddress, addr, num, buf, ip, wport);
}
catch
{
ret = -1;
}
return ret;
}
public int ReadHoldingReg(byte slaveaddress, ushort addr, ushort num, ref UInt16[] buf)
{
int ret = 0;
try
{
if (hModbusHandle != 0)
ret = fnReadHoldingReg(hModbusHandle, slaveaddress, (ushort)(addr - 1), num, buf, ip, wport);
}
catch
{
ret = -1;
}
return ret;
}
public int ReadInputReg(byte slaveaddress, ushort addr, ushort num, ref UInt16[] buf)
{
int ret = 0;
try
{
if (hModbusHandle != 0)
ret = fnReadInputReg(hModbusHandle, slaveaddress, addr, num, buf, ip, wport);
}
catch
{
ret = -1;
}
return ret;
}
public int WriteSingleCoil(byte slaveaddress, ushort addr, ushort state)
{
int ret = 0;
try
{
if (hModbusHandle != 0)
ret = fnWriteSingleCoil(hModbusHandle, slaveaddress, (ushort)(addr - 1), state, ip, wport);
}
catch
{
ret = -1;
}
return ret;
}
public int WriteHoldingReg(byte slaveaddress, ushort addr, ushort state)
{
int ret = 0;
try
{
if (hModbusHandle != 0)
ret = fnWriteHoldingReg(hModbusHandle, slaveaddress, (ushort)(addr - 1), state, ip, wport);
}
catch
{
ret = -1;
}
return ret;
}
public int WriteMultipleRegs(byte slaveaddress, ushort addr, ushort num, ref ushort[] buf)
{
int ret = 0;
try
{
if (hModbusHandle != 0)
ret = fnWriteMultipleRegs(hModbusHandle, slaveaddress, (ushort)(addr - 1), num, buf, ip, wport);
}
catch
{
ret = -1;
}
return ret;
}
public int ReportSlaveID(ref byte[] buf)
{
int ret = 0;
try
{
if (hModbusHandle != 0)
ret = fnReportSlaveID(hModbusHandle, buf, ip, wport);
}
catch
{
ret = -1;
}
return ret;
}
public int MaskWriteReg(byte slaveaddress, ushort addr, ushort amask, ushort omask)
{
int ret = 0;
try
{
if (hModbusHandle != 0)
ret = fnMaskWriteReg(hModbusHandle, slaveaddress, addr, amask, omask, ip, wport);
}
catch
{
ret = -1;
}
return ret;
}
public int ReadWriteMultipleRegs(byte slaveaddress, ushort waddr, ushort wnum, ushort raddr, ushort rnum, ref UInt16[] buf)
{
int ret = 0;
try
{
if (hModbusHandle != 0)
ret = fnReadWriteMultipleRegs(hModbusHandle, slaveaddress, waddr, wnum, raddr, rnum, buf, ip, wport);
}
catch
{
ret = -1;
}
return ret;
}
}
}
...@@ -30,9 +30,16 @@ namespace GcDevicePc.Common ...@@ -30,9 +30,16 @@ namespace GcDevicePc.Common
private uint hModbusHandle; private uint hModbusHandle;
public GCModbusSlave485(Byte port, int baudrate ) public GCModbusSlave485(Byte port, int baudrate )
{
try
{ {
this.hModbusHandle = fnLibModbusSlave485Init(port, baudrate); this.hModbusHandle = fnLibModbusSlave485Init(port, baudrate);
} }
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
}
~GCModbusSlave485() ~GCModbusSlave485()
{ {
...@@ -40,9 +47,9 @@ namespace GcDevicePc.Common ...@@ -40,9 +47,9 @@ namespace GcDevicePc.Common
{ {
fnLibModbusSlaveClose(hModbusHandle); fnLibModbusSlaveClose(hModbusHandle);
} }
catch catch (Exception ex)
{ {
Console.WriteLine(ex.Message);
} }
} }
......
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
...@@ -41,6 +42,14 @@ namespace GcDevicePc.GCBuffer ...@@ -41,6 +42,14 @@ namespace GcDevicePc.GCBuffer
// public bool sendtohw; // public bool sendtohw;
} }
public struct ModuleInfo
{
public string ip;
public string mask;
public string gw;
}
public struct ThreadInfo public struct ThreadInfo
{ {
public ushort HMI_Monitor_TH; // 0 --线程结束 1--线程运行中 public ushort HMI_Monitor_TH; // 0 --线程结束 1--线程运行中
...@@ -51,6 +60,7 @@ namespace GcDevicePc.GCBuffer ...@@ -51,6 +60,7 @@ namespace GcDevicePc.GCBuffer
public FolderInfo pcfolderinfo; public FolderInfo pcfolderinfo;
public GCFileInfo pcfileinfo; public GCFileInfo pcfileinfo;
public WorkInfo pcworkinfo; public WorkInfo pcworkinfo;
public ModuleInfo moduleinfo;
public ThreadInfo pcthreadinfo; public ThreadInfo pcthreadinfo;
} }
...@@ -81,10 +91,21 @@ namespace GcDevicePc.GCBuffer ...@@ -81,10 +91,21 @@ namespace GcDevicePc.GCBuffer
gcpcinfo.pcworkinfo.system_Statue = false; gcpcinfo.pcworkinfo.system_Statue = false;
gcpcinfo.pcworkinfo.work_Statue = 0; gcpcinfo.pcworkinfo.work_Statue = 0;
gcpcinfo.moduleinfo.ip = "192.168.1.54";
string file = System.Windows.Forms.Application.StartupPath + "\\startup.ini"; string file = System.Windows.Forms.Application.StartupPath + "\\startup.ini";
if (File.Exists(file))
{
INIOperation test = new INIOperation(file); INIOperation test = new INIOperation(file);
string opensys = test.INIGetStringValue("StartUp", "打开系统", null); string opensys = test.INIGetStringValue("StartUp", "打开系统", null);
string runtype = test.INIGetStringValue("StartUp", "运行类型", null); string runtype = test.INIGetStringValue("StartUp", "运行类型", null);
string wtd624x_ip = test.INIGetStringValue("WTD624X", "IP", null);
string wtd624x_mask = test.INIGetStringValue("WTD624X", "MASK", null);
string wtd624x_gw = test.INIGetStringValue("WTD624X", "GW", null);
//string senddata = test.INIGetStringValue("StartUp", "SendData", null); //string senddata = test.INIGetStringValue("StartUp", "SendData", null);
if (Convert.ToInt32(opensys) == 1) if (Convert.ToInt32(opensys) == 1)
...@@ -92,6 +113,22 @@ namespace GcDevicePc.GCBuffer ...@@ -92,6 +113,22 @@ namespace GcDevicePc.GCBuffer
gcpcinfo.pcworkinfo.RunType = Convert.ToUInt16(runtype); gcpcinfo.pcworkinfo.RunType = Convert.ToUInt16(runtype);
} }
if (!String.IsNullOrEmpty(wtd624x_ip))
{
gcpcinfo.moduleinfo.ip = wtd624x_ip;
}
if (!String.IsNullOrEmpty(wtd624x_mask))
{
gcpcinfo.moduleinfo.mask = wtd624x_mask;
}
if (!String.IsNullOrEmpty(wtd624x_gw))
{
gcpcinfo.moduleinfo.gw = wtd624x_gw;
}
}
// gcpcinfo.pcworkinfo.RunType = 0; //运行类型 0 打开运行 1 智能运行 2 批处理 // gcpcinfo.pcworkinfo.RunType = 0; //运行类型 0 打开运行 1 智能运行 2 批处理
} }
......
...@@ -146,6 +146,12 @@ ...@@ -146,6 +146,12 @@
</Reference> </Reference>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Compile Include="424XTest.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="424XTest.Designer.cs">
<DependentUpon>424XTest.cs</DependentUpon>
</Compile>
<Compile Include="AboutForm.cs"> <Compile Include="AboutForm.cs">
<SubType>Form</SubType> <SubType>Form</SubType>
</Compile> </Compile>
...@@ -198,6 +204,7 @@ ...@@ -198,6 +204,7 @@
<Compile Include="Common\FileTools.cs" /> <Compile Include="Common\FileTools.cs" />
<Compile Include="Common\FileTransfer.cs" /> <Compile Include="Common\FileTransfer.cs" />
<Compile Include="Common\GCModbus.cs" /> <Compile Include="Common\GCModbus.cs" />
<Compile Include="Common\GCModbus485.cs" />
<Compile Include="Common\GCModbusSlave.cs" /> <Compile Include="Common\GCModbusSlave.cs" />
<Compile Include="Common\FileHelper.cs" /> <Compile Include="Common\FileHelper.cs" />
<Compile Include="Common\GCModbusSlave485.cs" /> <Compile Include="Common\GCModbusSlave485.cs" />
...@@ -413,10 +420,13 @@ ...@@ -413,10 +420,13 @@
<DependentUpon>MethodNameInputForm.cs</DependentUpon> <DependentUpon>MethodNameInputForm.cs</DependentUpon>
</Compile> </Compile>
<Compile Include="Modbus.cs" /> <Compile Include="Modbus.cs" />
<Compile Include="Module\WTD424XOutput.cs" />
<Compile Include="Module\WTD624X.cs" />
<Compile Include="Program.cs" /> <Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" /> <Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="ProThread\ChannelDataSave.cs" /> <Compile Include="ProThread\ChannelDataSave.cs" />
<Compile Include="ProThread\CKvocUpdata.cs" /> <Compile Include="ProThread\CKvocUpdata.cs" />
<Compile Include="ProThread\DataOutput.cs" />
<Compile Include="ProThread\DataRcv.cs" /> <Compile Include="ProThread\DataRcv.cs" />
<Compile Include="ProThread\GcDataTh.cs" /> <Compile Include="ProThread\GcDataTh.cs" />
<Compile Include="ProThread\HMIControl.cs" /> <Compile Include="ProThread\HMIControl.cs" />
...@@ -499,6 +509,9 @@ ...@@ -499,6 +509,9 @@
<Compile Include="WaitForm.Designer.cs"> <Compile Include="WaitForm.Designer.cs">
<DependentUpon>WaitForm.cs</DependentUpon> <DependentUpon>WaitForm.cs</DependentUpon>
</Compile> </Compile>
<EmbeddedResource Include="424XTest.resx">
<DependentUpon>424XTest.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="AboutForm.resx"> <EmbeddedResource Include="AboutForm.resx">
<DependentUpon>AboutForm.cs</DependentUpon> <DependentUpon>AboutForm.cs</DependentUpon>
</EmbeddedResource> </EmbeddedResource>
......
...@@ -250,21 +250,21 @@ ...@@ -250,21 +250,21 @@
// HistoryDataMenu // HistoryDataMenu
// //
this.HistoryDataMenu.Name = "HistoryDataMenu"; this.HistoryDataMenu.Name = "HistoryDataMenu";
this.HistoryDataMenu.Size = new System.Drawing.Size(152, 22); this.HistoryDataMenu.Size = new System.Drawing.Size(148, 22);
this.HistoryDataMenu.Text = "历史数据查询"; this.HistoryDataMenu.Text = "历史数据查询";
this.HistoryDataMenu.Click += new System.EventHandler(this.HistoryDataMenu_Click); this.HistoryDataMenu.Click += new System.EventHandler(this.HistoryDataMenu_Click);
// //
// CalibrationMenu // CalibrationMenu
// //
this.CalibrationMenu.Name = "CalibrationMenu"; this.CalibrationMenu.Name = "CalibrationMenu";
this.CalibrationMenu.Size = new System.Drawing.Size(152, 22); this.CalibrationMenu.Size = new System.Drawing.Size(148, 22);
this.CalibrationMenu.Text = "校准查看"; this.CalibrationMenu.Text = "校准查看";
this.CalibrationMenu.Click += new System.EventHandler(this.CalibrationMenu_Click); this.CalibrationMenu.Click += new System.EventHandler(this.CalibrationMenu_Click);
// //
// HistoryPicMenu // HistoryPicMenu
// //
this.HistoryPicMenu.Name = "HistoryPicMenu"; this.HistoryPicMenu.Name = "HistoryPicMenu";
this.HistoryPicMenu.Size = new System.Drawing.Size(152, 22); this.HistoryPicMenu.Size = new System.Drawing.Size(148, 22);
this.HistoryPicMenu.Text = "历史谱图"; this.HistoryPicMenu.Text = "历史谱图";
this.HistoryPicMenu.Click += new System.EventHandler(this.HistoryPicMenu_Click); this.HistoryPicMenu.Click += new System.EventHandler(this.HistoryPicMenu_Click);
// //
...@@ -283,27 +283,27 @@ ...@@ -283,27 +283,27 @@
this.SingleStop, this.SingleStop,
this.SingleCancel}); this.SingleCancel});
this.SingleControlMenu.Name = "SingleControlMenu"; this.SingleControlMenu.Name = "SingleControlMenu";
this.SingleControlMenu.Size = new System.Drawing.Size(152, 22); this.SingleControlMenu.Size = new System.Drawing.Size(148, 22);
this.SingleControlMenu.Text = "单次流程控制"; this.SingleControlMenu.Text = "单次流程控制";
// //
// SingleStart // SingleStart
// //
this.SingleStart.Name = "SingleStart"; this.SingleStart.Name = "SingleStart";
this.SingleStart.Size = new System.Drawing.Size(152, 22); this.SingleStart.Size = new System.Drawing.Size(100, 22);
this.SingleStart.Text = "开始"; this.SingleStart.Text = "开始";
this.SingleStart.Click += new System.EventHandler(this.SingleStart_Click); this.SingleStart.Click += new System.EventHandler(this.SingleStart_Click);
// //
// SingleStop // SingleStop
// //
this.SingleStop.Name = "SingleStop"; this.SingleStop.Name = "SingleStop";
this.SingleStop.Size = new System.Drawing.Size(152, 22); this.SingleStop.Size = new System.Drawing.Size(100, 22);
this.SingleStop.Text = "停止"; this.SingleStop.Text = "停止";
this.SingleStop.Click += new System.EventHandler(this.SingleStop_Click); this.SingleStop.Click += new System.EventHandler(this.SingleStop_Click);
// //
// SingleCancel // SingleCancel
// //
this.SingleCancel.Name = "SingleCancel"; this.SingleCancel.Name = "SingleCancel";
this.SingleCancel.Size = new System.Drawing.Size(152, 22); this.SingleCancel.Size = new System.Drawing.Size(100, 22);
this.SingleCancel.Text = "取消"; this.SingleCancel.Text = "取消";
this.SingleCancel.Click += new System.EventHandler(this.SingleCancel_Click); this.SingleCancel.Click += new System.EventHandler(this.SingleCancel_Click);
// //
...@@ -318,7 +318,7 @@ ...@@ -318,7 +318,7 @@
// AboutMenu // AboutMenu
// //
this.AboutMenu.Name = "AboutMenu"; this.AboutMenu.Name = "AboutMenu";
this.AboutMenu.Size = new System.Drawing.Size(100, 22); this.AboutMenu.Size = new System.Drawing.Size(180, 22);
this.AboutMenu.Text = "关于"; this.AboutMenu.Text = "关于";
this.AboutMenu.Click += new System.EventHandler(this.AboutMenu_Click); this.AboutMenu.Click += new System.EventHandler(this.AboutMenu_Click);
// //
......
...@@ -395,13 +395,17 @@ namespace GcDevicePc ...@@ -395,13 +395,17 @@ namespace GcDevicePc
} }
public void WaitHMIFree() public void WaitHMIFree()
{
if (globaldata.m_hmibuffer.gcinfo.hmistatus != 0)
{ {
this.backgroundWorker1.RunWorkerAsync(); this.backgroundWorker1.RunWorkerAsync();
WaitForm form = new WaitForm(this.backgroundWorker1); WaitForm form = new WaitForm(this.backgroundWorker1, "Free");
form.ShowDialog(this); form.ShowDialog(this);
form.Close(); form.Close();
} }
}
private void backgroundWorker2_DoWork(object sender, DoWorkEventArgs e) private void backgroundWorker2_DoWork(object sender, DoWorkEventArgs e)
{ {
BackgroundWorker worker = sender as BackgroundWorker; BackgroundWorker worker = sender as BackgroundWorker;
...@@ -457,13 +461,17 @@ namespace GcDevicePc ...@@ -457,13 +461,17 @@ namespace GcDevicePc
} }
} }
public void WaitHMIWork() public void WaitHMIWork()
{
if (globaldata.m_hmibuffer.gcinfo.methodstatus < 0 || globaldata.m_hmibuffer.gcinfo.methodstatus > 5)
{ {
this.backgroundWorker2.RunWorkerAsync(); this.backgroundWorker2.RunWorkerAsync();
WaitForm form = new WaitForm(this.backgroundWorker2); WaitForm form = new WaitForm(this.backgroundWorker2, "Work");
form.ShowDialog(this); form.ShowDialog(this);
form.Close(); form.Close();
} }
}
public void SendStopCMD() public void SendStopCMD()
{ {
try try
...@@ -1212,6 +1220,19 @@ namespace GcDevicePc ...@@ -1212,6 +1220,19 @@ namespace GcDevicePc
} }
} }
/// <summary>
/// 直接执行STD批处理
/// </summary>
/// <param name="count">次数</param>
private void RunTableOptWithCount(ushort count)
{
if (!String.IsNullOrEmpty(globaldata.connection_ip))
{
hmiopt.SetBatCount(count);
SendSTDCMD();
}
}
/// <summary> /// <summary>
/// 更新所需,关闭HMI /// 更新所需,关闭HMI
/// </summary> /// </summary>
...@@ -1797,5 +1818,18 @@ namespace GcDevicePc ...@@ -1797,5 +1818,18 @@ namespace GcDevicePc
Trace.Write(ex); Trace.Write(ex);
} }
} }
//private void debugSubMenu_Click(object sender, EventArgs e)
//{
// try
// {
// _424XTest test = new _424XTest();
// test.Show();
// }
// catch (Exception ex)
// {
// Log.Error(ex.Message);
// }
//}
} }
} }
using System;
using GcDevicePc.Common;
namespace GcDevicePc.Module
{
class WTD424XOutput
{
private GCModbus485 rtumodbus = new GCModbus485(6, 9600, 2000);
private bool workflag = false;
public WTD424XOutput()
{
}
public int WTD424X_Open()
{
int ret = 0;
int count = 3;
try
{
ret = rtumodbus.ModbusOpen();
if (ret == 0)
{
workflag = true;
UInt16[] buf = new UInt16[4] { 1, 1, 1, 1 };
ret = rtumodbus.WriteMultipleRegs(1, 11, 4, ref buf);
while (ret != 0 && count > 0)
{
ret = rtumodbus.WriteMultipleRegs(1, 11, 4, ref buf);
count--;
}
}
}
catch (Exception ex)
{
Log.Error(ex.Message);
}
return ret;
}
public int WTD424X_Close()
{
int ret = 0;
try
{
ret = rtumodbus.ModbusClose();
if (ret == 0)
workflag = false;
}
catch (Exception ex)
{
Log.Error(ex.Message);
}
return ret;
}
private void GetMaVal(float[] data, ref UInt16[] buf)
{
if (data[0] >= 0 && data[0] <= 150.0f)
buf[0] = (UInt16) (data[0] * 20.0f / 150.0f * 4095 / 20.0f);
if (data[1] >= 0 && data[1] <= 10.0f)
buf[1] = (UInt16) (data[1] * 20.0f / 10.0f * 4095 / 20.0f);
if (data[2] >= 0 && data[2] <= 20.0f)
buf[2] = (UInt16) (data[2] * 20.0f / 20.0f * 4095 / 20.0f);
if (data[3] >= 0 && data[3] <= 30.0f)
buf[3] = (UInt16) (data[3] * 20.0f / 30.0f * 4095 / 20.0f);
}
public int UpdateData(float[] data)
{
UInt16[] buf = new UInt16[4] { 0, 4095, 2047, 1024 };
int ret = rtumodbus.WriteMultipleRegs(1, 1, 4, ref buf);
return ret;
}
public int UpdateData2(float[] data)
{
UInt16[] buf = new UInt16[4] { 0, 0, 0, 0 };
GetMaVal(data, ref buf);
int ret = rtumodbus.WriteMultipleRegs(1, 1, 4, ref buf);
return ret;
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using GcDevicePc.Common;
namespace GcDevicePc.Module
{
class WTD624X
{
private GCModbus tcpmodbus = null;
private bool workflag = false;
private string ip = "";
private ushort port = 502;
public WTD624X(String module_ip, ushort module_port)
{
ip = module_ip;
port = module_port;
}
public bool GetWorkFlag()
{
return workflag;
}
public int WTD624X_Open()
{
int ret = 0;
int count = 3;
try
{
tcpmodbus = new GCModbus();
if (tcpmodbus != null)
{
workflag = true;
UInt16[] buf = new UInt16[4] { 1, 1, 1, 1 };
ret = tcpmodbus.WriteMultipleRegs(11, 4, ip, port, ref buf);
while (ret != 0 && count > 0)
{
ret = tcpmodbus.WriteMultipleRegs(11, 4, ip, port, ref buf);
count--;
}
}
}
catch (Exception ex)
{
Log.Error(ex.Message);
}
return ret;
}
public int WTD624X_Close()
{
int ret = 0;
try
{
ret = tcpmodbus.GCModbusClose();
if (ret == 0)
workflag = false;
}
catch (Exception ex)
{
Log.Error(ex.Message);
}
return ret;
}
private void GetMaVal(float[] data, ref UInt16[] buf)
{
if (data[0] >= 0 && data[0] <= 150.0f)
buf[0] = (UInt16)(data[0] * 20.0f / 150.0f * 4095 / 20.0f);
if (data[1] >= 0 && data[1] <= 10.0f)
buf[1] = (UInt16)(data[1] * 20.0f / 10.0f * 4095 / 20.0f);
if (data[2] >= 0 && data[2] <= 20.0f)
buf[2] = (UInt16)(data[2] * 20.0f / 20.0f * 4095 / 20.0f);
if (data[3] >= 0 && data[3] <= 30.0f)
buf[3] = (UInt16)(data[3] * 20.0f / 30.0f * 4095 / 20.0f);
}
public int UpdateData(float[] data)
{
UInt16[] buf = new UInt16[4] { 0, 0, 0, 0 };
GetMaVal(data, ref buf);
int ret = tcpmodbus.WriteMultipleRegs(1, 4, ip, port, ref buf);
return ret;
}
public int UpdateIP(String IP, String Mask, String GW)
{
int ret = 0;
string[] slocal_ip = IP.Split('.');
string[] slocal_mask = Mask.Split('.');
string[] slocal_gw = GW.Split('.');
try
{
byte[] local_ip = new byte[4];
byte[] local_mask = new byte[4];
byte[] local_gw = new byte[4];
UInt16[] localdata = new UInt16[6];
for (int i = 0; i < 4;i++)
{
local_ip[i] = Convert.ToByte(slocal_ip[i]);
local_mask[i] = Convert.ToByte(slocal_mask[i]);
local_gw[i] = Convert.ToByte(slocal_gw[i]);
}
localdata[0] = (ushort)((local_ip[1] & 0x00FF) | ((local_ip[0] << 8) & 0xFF00));
localdata[1] = (ushort)((local_ip[3] & 0xFF) | ((local_ip[2] << 8) & 0xFF00));
localdata[2] = (ushort)((local_mask[1] & 0xFF) | ((local_mask[0] << 8) & 0xFF00));
localdata[3] = (ushort)((local_mask[3] & 0xFF) | ((local_mask[2] << 8) & 0xFF00));
localdata[4] = (ushort)((local_gw[1] & 0xFF) | ((local_gw[0] << 8) & 0xFF00));
localdata[5] = (ushort)((local_gw[3] & 0xFF) | ((local_gw[2] << 8) & 0xFF00));
ret = tcpmodbus.WriteMultipleRegs(306, 6, ip, port, ref localdata);
if (ret == 0)
{
ip = IP;
}
}
catch
{
}
return ret;
}
}
}
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using GcDevicePc.Module;
namespace GcDevicePc.ProThread
{
class DataOutput
{
ManualResetEvent outputmre = new ManualResetEvent(false);
Thread t_DataOut;
private WTD624X wtd624x = new WTD624X(globaldata.m_pcbuffer.gcpcinfo.moduleinfo.ip, 502);
private bool c6h6 = false;
private bool c7h8 = false;
private bool c8h10 = false;
//批量更新
//用于更新记录数据
private void OutPut_DataList()
{
try
{
string file = System.Windows.Forms.Application.StartupPath + "\\CarLine" + "\\Ingredient.ini";
int[] datano = new int[6] {1, 1, 1, 1, 1, 1};
if (File.Exists(file))
{
INIOperation test = new INIOperation(file);
string scount = test.INIGetStringValue("SYSINFO", "ECOUNT", null);
int count = Convert.ToInt32(scount);
for (int i = 0; i < count; i++)
{
string sid = test.INIGetStringValue("ENTITY" + i.ToString(), "ID", null);
string sname = test.INIGetStringValue("ENTITY" + i.ToString(), "NAME", null);
if (!String.IsNullOrEmpty(sname))
{
try
{
if (sname == "NMHC")
{
datano[0] = Convert.ToInt32(sid);
}
if (sname == "苯")
{
c6h6 = true;
datano[1] = Convert.ToInt32(sid);
}
if (sname == "甲苯")
{
c7h8 = true;
datano[2] = Convert.ToInt32(sid);
}
if (sname == "二甲苯")
{
c8h10 = true;
datano[3] = Convert.ToInt32(sid);
}
if (sname == "THC")
{
datano[4] = Convert.ToInt32(sid);
}
if (sname == "CH4")
{
datano[5] = Convert.ToInt32(sid);
}
}
catch
{
}
}
}
}
while (!outputmre.WaitOne(500))
{
if (SharedSpace.Data.change)
{
float[] data = new float[4] {0, 0, 0, 0};
double[] ratio = new double[4] {1, 3.487053571, 4.113392857, 4.739285714};
for (int count = 0; count < 4; count++)
{
switch (count)
{
case 0:
{
double nmhc_data =
(SharedSpace.Data.listValue[datano[4] - 1].vale -
SharedSpace.Data.listValue[datano[5] - 1].vale) * ratio[count] * 12.0f / 22.4f;
data[count] = float.Parse(nmhc_data.ToString());
}
break;
case 1:
{
data[count] = c6h6
? float.Parse(
(SharedSpace.Data.listValue[datano[count] - 1].vale * ratio[count])
.ToString())
: 0.0f;
}
break;
case 2:
{
data[count] = c7h8
? float.Parse(
(SharedSpace.Data.listValue[datano[count] - 1].vale * ratio[count])
.ToString())
: 0.0f;
}
break;
case 3:
{
data[count] = c8h10
? float.Parse(
(SharedSpace.Data.listValue[datano[count] - 1].vale * ratio[count])
.ToString())
: 0.0f;
}
break;
default:
data[count] = 0;
break;
}
Trace.WriteLine("周期结束" + count.ToString() + ":" + data[count].ToString(), "sys");
}
if (wtd624x.GetWorkFlag())
{
wtd624x.UpdateData(data);
}
}
}
}
catch (Exception ex)
{
Trace.WriteLine("WTD624X模块输出 Crash 由于:" + ex.Message, "sys");
}
}
public void DataOutStart()
{
if (outputmre != null)
{
outputmre.Reset();
}
t_DataOut = new Thread(OutPut_DataList);
t_DataOut.IsBackground = true;
t_DataOut.Start();
if (!wtd624x.GetWorkFlag())
{
wtd624x.WTD624X_Open();
}
}
public void DataOutStop()
{
outputmre.Set();
if (wtd624x.GetWorkFlag())
{
wtd624x.WTD624X_Open();
}
}
}
}
...@@ -108,8 +108,8 @@ namespace GcDevicePc.ProThread ...@@ -108,8 +108,8 @@ namespace GcDevicePc.ProThread
{ {
client = new UdpClient(new IPEndPoint(IPAddress.Any, 0)); client = new UdpClient(new IPEndPoint(IPAddress.Any, 0));
// client = new UdpClient(new IPEndPoint(IPAddress.Parse(this._localip), 0)); // client = new UdpClient(new IPEndPoint(IPAddress.Parse(this._localip), 0));
// endpoint = new IPEndPoint(IPAddress.Parse("255.255.255.255"), 233); endpoint = new IPEndPoint(IPAddress.Parse("255.255.255.255"), 233);
endpoint = new IPEndPoint(IPAddress.Parse("192.168.10.230"), 233); // endpoint = new IPEndPoint(IPAddress.Parse("192.168.10.230"), 233);
client.Send(sendBytes, sendBytes.Length, endpoint); client.Send(sendBytes, sendBytes.Length, endpoint);
Thread.Sleep(500); Thread.Sleep(500);
......
...@@ -21,6 +21,15 @@ namespace GcDevicePc ...@@ -21,6 +21,15 @@ namespace GcDevicePc
this.backgroundWorker1.RunWorkerCompleted += new RunWorkerCompletedEventHandler(backgroundWorker1_RunWorkerCompleted); this.backgroundWorker1.RunWorkerCompleted += new RunWorkerCompletedEventHandler(backgroundWorker1_RunWorkerCompleted);
} }
public WaitForm(BackgroundWorker backgroundWorker1,String title)
{
InitializeComponent();
this.backgroundWorker1 = backgroundWorker1;
this.backgroundWorker1.ProgressChanged += new ProgressChangedEventHandler(backgroundWorker1_ProgressChanged);
this.backgroundWorker1.RunWorkerCompleted += new RunWorkerCompletedEventHandler(backgroundWorker1_RunWorkerCompleted);
this.Text = "Wait For " + title;
}
void backgroundWorker1_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e) void backgroundWorker1_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
{ {
this.Close();//执行完之后,直接关闭页面 this.Close();//执行完之后,直接关闭页面
......
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