Commit bb5a8e0d 刘韬

添加项目文件。

1 个父辈 5d428bc4
正在显示 80 个修改的文件 包含 4956 行增加0 行删除
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler,log4net" />
</configSections>
<appSettings>
<!--是否开机自动启动料仓-->
<add key="App_AutoRun" value="1" />
<add key="CameraName" value="GigE:acA3800-10gc (23124327)#" />
<add key="Config_Pwd" value="123456" />
</appSettings>
<log4net>
<appender name="RollingLogFileAppender" type="log4net.Appender.RollingFileAppender">
<file value="logs/AutoScanAndLabel.log" />
<param name="Encoding" value="UTF-8" />
<appendToFile value="true" />
<rollingStyle value="Date" />
<datePattern value="yyyy-MM-dd" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="[%date][%t]%-5p %m%n" />
</layout>
</appender>
<logger name="RollingLogFileAppender">
<level value="ALL" />
<appender-ref ref="RollingLogFileAppender" />
</logger>
<logger name="HCBOARD">
<level value="ALL" />
<appender-ref ref="RollingLogFileAppender" />
</logger>
<!--<root>
<level value="Info" />
<appender-ref ref="RollingLogFileAppender" />
</root>-->
</log4net>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1" />
</startup>
</configuration>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" 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>{61FDFF14-8BB7-439A-85A0-592E3011F4C4}</ProjectGuid>
<OutputType>WinExe</OutputType>
<RootNamespace>AutoScanAndLabel</RootNamespace>
<AssemblyName>AutoScanAndLabel</AssemblyName>
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<Deterministic>true</Deterministic>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</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>
</PropertyGroup>
<ItemGroup>
<Reference Include="log4net, Version=2.0.12.0, Culture=neutral, PublicKeyToken=669e0ddf0bb1aa2a, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\增广夹爪\Rmaxis\bin\Debug\log4net.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.Net.Http" />
<Reference Include="System.Windows.Forms" />
<Reference Include="System.Xml" />
<Reference Include="UserFromControl">
<HintPath>..\..\SO775-DUOStore\dll\UserFromControl.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="AxisControl.cs">
<SubType>UserControl</SubType>
</Compile>
<Compile Include="AxisControl.Designer.cs">
<DependentUpon>AxisControl.cs</DependentUpon>
</Compile>
<Compile Include="Form1.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="Form1.Designer.cs">
<DependentUpon>Form1.cs</DependentUpon>
</Compile>
<Compile Include="IOControl.cs">
<SubType>UserControl</SubType>
</Compile>
<Compile Include="IOControl.Designer.cs">
<DependentUpon>IOControl.cs</DependentUpon>
</Compile>
<Compile Include="MainControl.cs">
<SubType>UserControl</SubType>
</Compile>
<Compile Include="MainControl.Designer.cs">
<DependentUpon>MainControl.cs</DependentUpon>
</Compile>
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<EmbeddedResource Include="AxisControl.resx">
<DependentUpon>AxisControl.cs</DependentUpon>
<SubType>Designer</SubType>
</EmbeddedResource>
<EmbeddedResource Include="Form1.resx">
<DependentUpon>Form1.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="IOControl.resx">
<DependentUpon>IOControl.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="MainControl.resx">
<DependentUpon>MainControl.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>
<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>
<None Include="App.config" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Common\Common.csproj">
<Project>{43cdd09e-fcf3-4960-a01d-3bbfe9933122}</Project>
<Name>Common</Name>
</ProjectReference>
<ProjectReference Include="..\DeviceLibrary\DeviceLibrary.csproj">
<Project>{bb23296c-aa1d-45c6-9fa6-5a37b2abfe9b}</Project>
<Name>DeviceLibrary</Name>
</ProjectReference>
<ProjectReference Include="..\LoadCVSLibrary\LoadCSVLibrary.csproj">
<Project>{064bebf5-8faa-4ea2-a5f3-a06e6e7d9251}</Project>
<Name>LoadCSVLibrary</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
\ No newline at end of file

namespace AutoScanAndLabel
{
partial class AxisControl
{
/// <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.groupBox3 = new System.Windows.Forms.GroupBox();
this.tableLayoutPanel1 = new System.Windows.Forms.TableLayoutPanel();
this.btnSavePos = new System.Windows.Forms.Button();
this.axisMoveControl1 = new DeviceLibrary.AxisMoveControl();
this.groupBox3.SuspendLayout();
this.SuspendLayout();
//
// groupBox3
//
this.groupBox3.Controls.Add(this.tableLayoutPanel1);
this.groupBox3.Location = new System.Drawing.Point(565, 3);
this.groupBox3.Name = "groupBox3";
this.groupBox3.Size = new System.Drawing.Size(628, 545);
this.groupBox3.TabIndex = 107;
this.groupBox3.TabStop = false;
this.groupBox3.Text = "点位列表";
//
// tableLayoutPanel1
//
this.tableLayoutPanel1.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.tableLayoutPanel1.ColumnCount = 6;
this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 30F));
this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 10F));
this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 10F));
this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 30F));
this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 10F));
this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 10F));
this.tableLayoutPanel1.Location = new System.Drawing.Point(6, 14);
this.tableLayoutPanel1.Name = "tableLayoutPanel1";
this.tableLayoutPanel1.RowCount = 1;
this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle());
this.tableLayoutPanel1.Size = new System.Drawing.Size(616, 525);
this.tableLayoutPanel1.TabIndex = 102;
//
// btnSavePos
//
this.btnSavePos.Location = new System.Drawing.Point(1054, 554);
this.btnSavePos.Name = "btnSavePos";
this.btnSavePos.Size = new System.Drawing.Size(133, 31);
this.btnSavePos.TabIndex = 108;
this.btnSavePos.Text = "全部保存";
this.btnSavePos.UseVisualStyleBackColor = true;
this.btnSavePos.Click += new System.EventHandler(this.btnSavePos_Click);
//
// axisMoveControl1
//
this.axisMoveControl1.Location = new System.Drawing.Point(0, 3);
this.axisMoveControl1.Name = "axisMoveControl1";
this.axisMoveControl1.Size = new System.Drawing.Size(559, 400);
this.axisMoveControl1.TabIndex = 0;
//
// AxisControl
//
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.None;
this.BackColor = System.Drawing.Color.White;
this.Controls.Add(this.btnSavePos);
this.Controls.Add(this.groupBox3);
this.Controls.Add(this.axisMoveControl1);
this.Font = new System.Drawing.Font("新宋体", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.Name = "AxisControl";
this.Size = new System.Drawing.Size(1274, 602);
this.Load += new System.EventHandler(this.AxisControl_Load);
this.groupBox3.ResumeLayout(false);
this.ResumeLayout(false);
}
#endregion
private DeviceLibrary.AxisMoveControl axisMoveControl1;
private System.Windows.Forms.GroupBox groupBox3;
private System.Windows.Forms.TableLayoutPanel tableLayoutPanel1;
private System.Windows.Forms.Button btnSavePos;
}
}
using DeviceLibrary;
using OnlineStore.LoadCSVLibrary;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace AutoScanAndLabel
{
public partial class AxisControl : UserControl
{
public AxisControl()
{
InitializeComponent();
}
private void AxisControl_Load(object sender, EventArgs e)
{
axisMoveControl1.LoadData(RobotManage.mainMachine);
LoadPosList();
}
void LoadPosList() {
this.tableLayoutPanel1.RowStyles.Clear();
//this.tableLayoutPanel1.RowStyles.Add(new RowStyle(SizeType., 26));
int r = 0;
int c = 0;
int lastSubType = 0;
Random random = new Random(1);
Color color = Color.Black;
foreach (ConfigBase configBase in RobotManage.Config.configList) {
if (configBase.SubType < 10 || configBase.ProType != "PRO")
continue;
if (configBase.SubType != lastSubType)
{
lastSubType = configBase.SubType;
color = Color.FromArgb(random.Next(30,150), random.Next(30, 150), random.Next(30, 150));
}
//this.tableLayoutPanel1.RowCount++;
Button button = new Button();
button.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
button.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
button.Name = configBase.ProName;
button.Size = new System.Drawing.Size(225, 34);
button.Text = configBase.Explain;
button.Click += Button_Click;
button.ForeColor = color;
TextBox textBox = new TextBox();
textBox.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
textBox.Name = configBase.ProName;
textBox.Margin = new Padding(4, 8, 0, 0);
textBox.Size = new System.Drawing.Size(80, 23);
textBox.Text = configBase.ProValue;
textBox.Tag = configBase.SubType - 10;
textBox.KeyPress += TextBox_KeyPress;
textBox.TextChanged += TextBox_TextChanged;
TextBox textBox2 = new TextBox();
textBox2.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
textBox2.Name = configBase.ProName+"_speed";
textBox2.Margin = new Padding(4, 8, 0, 0);
textBox2.Size = new System.Drawing.Size(80, 23);
textBox2.Text = configBase.TargetSpeed.ToString();
textBox2.Tag = configBase.SubType - 10;
textBox2.KeyPress += TextBox_KeyPress;
textBox2.TextChanged += TextBox_TextChanged;
tableLayoutPanel1.Controls.Add(button, c, r);
tableLayoutPanel1.Controls.Add(textBox, c + 1, r);
tableLayoutPanel1.Controls.Add(textBox2, c + 2, r);
r++;
if (r > 12)
{
r = 0;
c += 3;
}
}
}
private void TextBox_TextChanged(object sender, EventArgs e)
{
var s = (sender as TextBox).Text;
if (!int.TryParse(s, out _))
{
(sender as TextBox).Text = lastvalue;
}
}
string lastvalue = "";
private void TextBox_KeyPress(object sender, KeyPressEventArgs e)
{
var s = (sender as TextBox).Text;
if (int.TryParse(s, out _))
lastvalue = s;
}
private void Button_Click(object sender, EventArgs e)
{
var cc = tableLayoutPanel1.Controls.Find(((Button)sender).Name,false);
//Console.WriteLine(cc[1].Name);
//Console.WriteLine(cc[1].Tag);
//Console.WriteLine(cc[1].Text);
ConfigMoveAxis configMoveAxis = getConfigMoveAxis((int)cc[1].Tag);
AxisManager.AbsMove("", configMoveAxis.GetAxisValue(), int.Parse(cc[1].Text), configMoveAxis.TargetSpeed, configMoveAxis.AddSpeed, configMoveAxis.DelSpeed);
}
ConfigMoveAxis getConfigMoveAxis(int Axisid) {
foreach (ConfigMoveAxis configMoveAxis in RobotManage.Config.moveAxisList) {
if (configMoveAxis.GetAxisValue() == Axisid)
return configMoveAxis;
}
return null;
}
private void btnSavePos_Click(object sender, EventArgs e)
{
for (int i = 0; i < tableLayoutPanel1.Controls.Count; i++) {
if (tableLayoutPanel1.Controls[i].GetType().Name != "TextBox")
continue;
TextBox textBox = (TextBox)tableLayoutPanel1.Controls[i];
PropertyInfo pi= RobotManage.Config.GetType().GetProperty(textBox.Name);
pi.SetValue(RobotManage.Config, int.Parse(textBox.Text));
}
CSVConfigReader.SaveConfig(RobotManage.Config.ConfigFilePath, RobotManage.Config);
}
}
}
<?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

namespace AutoScanAndLabel
{
partial class Form1
{
/// <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 Windows 窗体设计器生成的代码
/// <summary>
/// 设计器支持所需的方法 - 不要修改
/// 使用代码编辑器修改此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.menuStrip1 = new System.Windows.Forms.MenuStrip();
this.设备操作ToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.启动ToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.toolStripSeparator1 = new System.Windows.Forms.ToolStripSeparator();
this.复位ToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.toolStripSeparator2 = new System.Windows.Forms.ToolStripSeparator();
this.停止ToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.toolStripSeparator3 = new System.Windows.Forms.ToolStripSeparator();
this.退出ToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.tabControl1 = new System.Windows.Forms.TabControl();
this.menuStrip1.SuspendLayout();
this.SuspendLayout();
//
// menuStrip1
//
this.menuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.设备操作ToolStripMenuItem});
this.menuStrip1.Location = new System.Drawing.Point(0, 0);
this.menuStrip1.Name = "menuStrip1";
this.menuStrip1.Padding = new System.Windows.Forms.Padding(7, 2, 0, 2);
this.menuStrip1.Size = new System.Drawing.Size(1342, 29);
this.menuStrip1.TabIndex = 0;
this.menuStrip1.Text = "menuStrip1";
//
// 设备操作ToolStripMenuItem
//
this.设备操作ToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.启动ToolStripMenuItem,
this.toolStripSeparator1,
this.复位ToolStripMenuItem,
this.toolStripSeparator2,
this.停止ToolStripMenuItem,
this.toolStripSeparator3,
this.退出ToolStripMenuItem});
this.设备操作ToolStripMenuItem.Font = new System.Drawing.Font("Microsoft YaHei UI", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.设备操作ToolStripMenuItem.Name = "设备操作ToolStripMenuItem";
this.设备操作ToolStripMenuItem.Size = new System.Drawing.Size(86, 25);
this.设备操作ToolStripMenuItem.Text = "设备操作";
//
// 启动ToolStripMenuItem
//
this.启动ToolStripMenuItem.Name = "启动ToolStripMenuItem";
this.启动ToolStripMenuItem.Size = new System.Drawing.Size(112, 26);
this.启动ToolStripMenuItem.Text = "启动";
//
// toolStripSeparator1
//
this.toolStripSeparator1.Name = "toolStripSeparator1";
this.toolStripSeparator1.Size = new System.Drawing.Size(109, 6);
//
// 复位ToolStripMenuItem
//
this.复位ToolStripMenuItem.Name = "复位ToolStripMenuItem";
this.复位ToolStripMenuItem.Size = new System.Drawing.Size(112, 26);
this.复位ToolStripMenuItem.Text = "复位";
//
// toolStripSeparator2
//
this.toolStripSeparator2.Name = "toolStripSeparator2";
this.toolStripSeparator2.Size = new System.Drawing.Size(109, 6);
//
// 停止ToolStripMenuItem
//
this.停止ToolStripMenuItem.Name = "停止ToolStripMenuItem";
this.停止ToolStripMenuItem.Size = new System.Drawing.Size(112, 26);
this.停止ToolStripMenuItem.Text = "停止";
//
// toolStripSeparator3
//
this.toolStripSeparator3.Name = "toolStripSeparator3";
this.toolStripSeparator3.Size = new System.Drawing.Size(109, 6);
//
// 退出ToolStripMenuItem
//
this.退出ToolStripMenuItem.Name = "退出ToolStripMenuItem";
this.退出ToolStripMenuItem.Size = new System.Drawing.Size(112, 26);
this.退出ToolStripMenuItem.Text = "退出";
//
// tabControl1
//
this.tabControl1.Dock = System.Windows.Forms.DockStyle.Fill;
this.tabControl1.Font = new System.Drawing.Font("微软雅黑", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.tabControl1.Location = new System.Drawing.Point(0, 29);
this.tabControl1.Name = "tabControl1";
this.tabControl1.SelectedIndex = 0;
this.tabControl1.Size = new System.Drawing.Size(1342, 695);
this.tabControl1.TabIndex = 1;
//
// Form1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 14F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.BackColor = System.Drawing.Color.White;
this.ClientSize = new System.Drawing.Size(1342, 724);
this.Controls.Add(this.tabControl1);
this.Controls.Add(this.menuStrip1);
this.Font = new System.Drawing.Font("宋体", 10.5F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.MainMenuStrip = this.menuStrip1;
this.Name = "Form1";
this.Text = "Form1";
this.Load += new System.EventHandler(this.Form1_Load);
this.menuStrip1.ResumeLayout(false);
this.menuStrip1.PerformLayout();
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private System.Windows.Forms.MenuStrip menuStrip1;
private System.Windows.Forms.ToolStripMenuItem 设备操作ToolStripMenuItem;
private System.Windows.Forms.ToolStripMenuItem 启动ToolStripMenuItem;
private System.Windows.Forms.ToolStripSeparator toolStripSeparator1;
private System.Windows.Forms.ToolStripMenuItem 复位ToolStripMenuItem;
private System.Windows.Forms.ToolStripSeparator toolStripSeparator2;
private System.Windows.Forms.ToolStripMenuItem 停止ToolStripMenuItem;
private System.Windows.Forms.ToolStripMenuItem 退出ToolStripMenuItem;
private System.Windows.Forms.TabControl tabControl1;
private System.Windows.Forms.ToolStripSeparator toolStripSeparator3;
}
}
using DeviceLibrary;
using OnlineStore.Common;
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;
namespace AutoScanAndLabel
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
LogUtil.info("开始初始化");
MainControl mc = new MainControl();
AddForm("控制", mc);
IOControl ioc = new IOControl();
AddForm("IO调试", ioc);
AxisControl ac = new AxisControl();
AddForm("伺服调试", ac);
}
private void AddForm(string text, UserControl form)
{
//text = text.PadLeft(10, ' ');
TabPage lineTabPage = new TabPage(text);
// lineTabPage.AutoScroll = true;
//lineTabPage.Tag = robot;
Panel linePan = new Panel();
linePan.Dock = DockStyle.Fill;
linePan.AutoScroll = true;
lineTabPage.Controls.Add(linePan);
//form.FormBorderStyle = FormBorderStyle.None;
//form.TopLevel = false;
linePan.Controls.Add(form);
form.Dock = DockStyle.Fill;
linePan.Anchor = ((AnchorStyles)((AnchorStyles.Top | AnchorStyles.Right | AnchorStyles.Bottom | AnchorStyles.Left)));
form.Anchor = ((AnchorStyles)((AnchorStyles.Top | AnchorStyles.Right | AnchorStyles.Bottom | AnchorStyles.Left)));
form.Show();
//tabPageList.Add(lineTabPage);
tabControl1.Controls.Add(lineTabPage);
}
}
}
<?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="menuStrip1.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
using DeviceLibrary;
using OnlineStore.Common;
using OnlineStore.LoadCSVLibrary;
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 UserFromControl;
namespace AutoScanAndLabel
{
public partial class IOControl : UserControl
{
readonly Timer t1 = new Timer();
public IOControl()
{
InitializeComponent();
t1.Stop();
t1.Interval = 500;
t1.Tick += T1_Tick;
GC.KeepAlive(t1);
LoadIOList();
}
private void T1_Tick(object sender, EventArgs e)
{
if (this.Visible)
{
ReadIOList();
}
}
Dictionary<string, IOTextControl> DIControlList = new Dictionary<string, IOTextControl>();
Dictionary<string, IOTextControl> DOControlList = new Dictionary<string, IOTextControl>();
private void IOControl_Load(object sender, EventArgs e)
{
}
private void LoadIOList()
{
int roleindex = 0;
this.tableLayoutPanel1.RowStyles.Clear();
this.tableLayoutPanel1.RowCount = RobotManage.Config.DIList.Count;
foreach (ConfigIO ioValue in RobotManage.Config.DIList.Values)
{
//if (ioValue.SubType.Equals(0))
{
this.tableLayoutPanel1.RowStyles.Add(new RowStyle(SizeType.Absolute, 26));
IOTextControl control = new IOTextControl(ioValue.ElectricalDefinition + "_" + ioValue.Explain, ioValue.ProName);
this.tableLayoutPanel1.Controls.Add(control, 0, roleindex);
roleindex++;
DIControlList.Add(ioValue.ProName, control);
}
}
tableLayoutPanel2.RowStyles.Clear();
this.tableLayoutPanel2.RowCount = RobotManage.Config.DOList.Count;
roleindex = 0;
foreach (ConfigIO ioValue in RobotManage.Config.DOList.Values)
{
//if (ioValue.SubType.Equals(0))
{
this.tableLayoutPanel2.RowStyles.Add(new RowStyle(SizeType.Absolute, 28));
IOTextControl control = new IOTextControl(ioValue.ElectricalDefinition + "_" + ioValue.Explain, ioValue.ProName);
control.Click += Control_Click;
this.tableLayoutPanel2.Controls.Add(control, 0, roleindex);
roleindex++;
DOControlList.Add(ioValue.ProName, control);
}
}
this.SuspendLayout(); //此处为不闪屏,一定要有的!
cmbWriteIO.DataSource = new List<ConfigIO>(RobotManage.Config.DOList.Values);
cmbWriteIO.ValueMember = "ProName";
cmbWriteIO.DisplayMember = "DisplayStr";
t1.Start();
}
private void ReadIOList()
{
foreach (string key in DIControlList.Keys)
{
IOTextControl control = DIControlList[key];
ConfigIO io = RobotManage.Config.DIList[key];
int iov = (int)IOManager.GetDIValue("", 0, io.GetIOAddr());
if (iov != control.IOValue)
{
control.IOValue = iov;
control.ShowData();
}
}
foreach (string key in this.DOControlList.Keys)
{
IOTextControl control = DOControlList[key];
ConfigIO io = RobotManage.Config.DOList[key];
int iov = (int)IOManager.GetDOValue("", 0, io.GetIOAddr());
if (iov != control.IOValue)
{
control.IOValue = iov;
control.ShowData();
}
}
}
private void Control_Click(object sender, EventArgs e)
{
IOTextControl control = (IOTextControl)sender;
string name = control.Name.Substring(3, control.Name.Length - 3);
List<string> keyList = new List<string>(DOControlList.Keys);
int index = keyList.IndexOf(name);
if (index >= 0)
{
cmbWriteIO.SelectedIndex = index;
}
}
IOTextControl selectControl = null;
private void cmbWriteIO_SelectedIndexChanged(object sender, EventArgs e)
{
if (cmbWriteIO.SelectedIndex >= 0)
{
ConfigIO io = GetSelectDO();
if (io != null)
{
// txtIp.Text = io.DeviceName;
txtDOIndex.Text = io.GetIOAddr().ToString();
IOTextControl newControl = DOControlList[io.ProName];
if (selectControl != null) { selectControl.BackColor = Color.White; }
newControl.BackColor = Color.SkyBlue;
selectControl = newControl;
}
}
}
private ConfigIO GetSelectDO()
{
string text = cmbWriteIO.SelectedValue.ToString();
if (RobotManage.Config.DOList.ContainsKey(text))
{
ConfigIO io = RobotManage.Config.DOList[text];
return io;
}
return null;
}
private void btnOpenDo_Click(object sender, EventArgs e)
{
WriteDO(IO_VALUE.HIGH);
}
private void btnCloseDO_Click(object sender, EventArgs e)
{
WriteDO(IO_VALUE.LOW);
}
private void WriteDO(IO_VALUE value)
{
int index = FormUtil.GetIntValue(txtDOIndex);
// IO_VALUE value = checkBox1.Checked ? IO_VALUE.HIGH : IO_VALUE.LOW;
int time = FormUtil.GetIntValue(txtWriteTime);
int slaveId = 0;
if (time > 0)
{
IOManager.WriteSingleDO("HC", (byte)slaveId, (ushort)index, (IO_VALUE)value, time);
}
else
{
IOManager.WriteSingleDO("HC", (byte)slaveId, (ushort)index, (IO_VALUE)value);
}
}
private void cmbWriteIO_DrawItem(object sender, DrawItemEventArgs e)
{
if (e.Index < 0)
{
return;
}
e.DrawBackground();
e.DrawFocusRectangle();
if (cmbWriteIO.Items.Count > e.Index)
{
ConfigIO io = (ConfigIO)cmbWriteIO.Items[e.Index];
e.Graphics.DrawString(io.DisplayStr, e.Font, new SolidBrush(e.ForeColor), e.Bounds.X, e.Bounds.Y + 3);
}
}
private void btnCloseAll_Click(object sender, EventArgs e)
{
IOManager.CloseAllDO();
}
}
}
<?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

namespace AutoScanAndLabel
{
partial class MainControl
{
/// <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.btn_run = new System.Windows.Forms.Button();
this.btn_stop = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// btn_run
//
this.btn_run.Location = new System.Drawing.Point(57, 46);
this.btn_run.Name = "btn_run";
this.btn_run.Size = new System.Drawing.Size(75, 23);
this.btn_run.TabIndex = 0;
this.btn_run.Text = "启动";
this.btn_run.UseVisualStyleBackColor = true;
//
// btn_stop
//
this.btn_stop.Location = new System.Drawing.Point(153, 46);
this.btn_stop.Name = "btn_stop";
this.btn_stop.Size = new System.Drawing.Size(75, 23);
this.btn_stop.TabIndex = 0;
this.btn_stop.Text = "停止";
this.btn_stop.UseVisualStyleBackColor = true;
//
// MainControl
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.Controls.Add(this.btn_stop);
this.Controls.Add(this.btn_run);
this.Name = "MainControl";
this.Size = new System.Drawing.Size(1001, 470);
this.ResumeLayout(false);
}
#endregion
private System.Windows.Forms.Button btn_run;
private System.Windows.Forms.Button btn_stop;
}
}
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;
namespace AutoScanAndLabel
{
public partial class MainControl : UserControl
{
public MainControl()
{
InitializeComponent();
}
}
}
<?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
using log4net.Config;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace AutoScanAndLabel
{
static class Program
{
/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main()
{
XmlConfigurator.Configure();
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
}
}
}
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// 有关程序集的一般信息由以下
// 控制。更改这些特性值可修改
// 与程序集关联的信息。
[assembly: AssemblyTitle("SO827-AutoScanAndLabel")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("SO827-AutoScanAndLabel")]
[assembly: AssemblyCopyright("Copyright © 2021")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// 将 ComVisible 设置为 false 会使此程序集中的类型
//对 COM 组件不可见。如果需要从 COM 访问此程序集中的类型
//请将此类型的 ComVisible 特性设置为 true。
[assembly: ComVisible(false)]
// 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID
[assembly: Guid("61fdff14-8bb7-439a-85a0-592e3011f4c4")]
// 程序集的版本信息由下列四个值组成:
//
// 主版本
// 次版本
// 生成号
// 修订号
//
//可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值
//通过使用 "*",如下所示:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
//------------------------------------------------------------------------------
// <auto-generated>
// 此代码由工具生成。
// 运行时版本:4.0.30319.42000
//
// 对此文件的更改可能会导致不正确的行为,并且如果
// 重新生成代码,这些更改将会丢失。
// </auto-generated>
//------------------------------------------------------------------------------
namespace AutoScanAndLabel.Properties {
using System;
/// <summary>
/// 一个强类型的资源类,用于查找本地化的字符串等。
/// </summary>
// 此类是由 StronglyTypedResourceBuilder
// 类通过类似于 ResGen 或 Visual Studio 的工具自动生成的。
// 若要添加或移除成员,请编辑 .ResX 文件,然后重新运行 ResGen
// (以 /str 作为命令选项),或重新生成 VS 项目。
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "16.0.0.0")]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
internal class Resources {
private static global::System.Resources.ResourceManager resourceMan;
private static global::System.Globalization.CultureInfo resourceCulture;
[global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
internal Resources() {
}
/// <summary>
/// 返回此类使用的缓存的 ResourceManager 实例。
/// </summary>
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
internal static global::System.Resources.ResourceManager ResourceManager {
get {
if (object.ReferenceEquals(resourceMan, null)) {
global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("AutoScanAndLabel.Properties.Resources", typeof(Resources).Assembly);
resourceMan = temp;
}
return resourceMan;
}
}
/// <summary>
/// 重写当前线程的 CurrentUICulture 属性,对
/// 使用此强类型资源类的所有资源查找执行重写。
/// </summary>
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
internal static global::System.Globalization.CultureInfo Culture {
get {
return resourceCulture;
}
set {
resourceCulture = value;
}
}
}
}
<?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.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: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" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
</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" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
</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=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>
\ No newline at end of file
//------------------------------------------------------------------------------
// <auto-generated>
// 此代码由工具生成。
// 运行时版本:4.0.30319.42000
//
// 对此文件的更改可能会导致不正确的行为,并且如果
// 重新生成代码,这些更改将会丢失。
// </auto-generated>
//------------------------------------------------------------------------------
namespace AutoScanAndLabel.Properties {
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "16.8.1.0")]
internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase {
private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));
public static Settings Default {
get {
return defaultInstance;
}
}
}
}
<?xml version='1.0' encoding='utf-8'?>
<SettingsFile xmlns="http://schemas.microsoft.com/VisualStudio/2004/01/settings" CurrentProfile="(Default)">
<Profiles>
<Profile Name="(Default)" />
</Profiles>
<Settings />
</SettingsFile>
<?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>{43CDD09E-FCF3-4960-A01D-3BBFE9933122}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>OnlineStore.Common</RootNamespace>
<AssemblyName>MyCommon</AssemblyName>
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<TargetFrameworkProfile />
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<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' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<ItemGroup>
<Reference Include="log4net, Version=2.0.8.0, Culture=neutral, PublicKeyToken=669e0ddf0bb1aa2a, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\增广夹爪\Rmaxis\bin\Debug\log4net.dll</HintPath>
</Reference>
<Reference Include="Newtonsoft.Json">
<HintPath>..\..\dll\Newtonsoft.Json.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Configuration" />
<Reference Include="System.Core" />
<Reference Include="System.Drawing" />
<Reference Include="System.Windows.Forms" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="bean\Bean.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Setting_Init.cs" />
<Compile Include="util\AcSerialBean.cs" />
<Compile Include="util\ConfigAppSettings.cs" />
<Compile Include="util\FormUtil.cs" />
<Compile Include="util\JsonHelper.cs" />
<Compile Include="util\LogUtil.cs" />
<Compile Include="util\MyWebClient.cs">
<SubType>Component</SubType>
</Compile>
<Compile Include="util\NetTCPServer.cs">
<SubType>Code</SubType>
</Compile>
<Compile Include="util\CTcpClient.cs" />
<Compile Include="util\TcpServer.cs" />
<Compile Include="util\UdpServer.cs" />
</ItemGroup>
<ItemGroup>
<WCFMetadata Include="Service References\" />
</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
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// 有关程序集的常规信息通过以下
// 特性集控制。更改这些特性值可修改
// 与程序集关联的信息。
[assembly: AssemblyTitle("Common")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("Common")]
[assembly: AssemblyCopyright("Copyright © 2016")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// 将 ComVisible 设置为 false 使此程序集中的类型
// 对 COM 组件不可见。如果需要从 COM 访问此程序集中的类型,
// 则将该类型上的 ComVisible 特性设置为 true。
[assembly: ComVisible(false)]
// 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID
[assembly: Guid("f8eab140-5f98-4df7-842c-0d866e759c9a")]
// 程序集的版本信息由下面四个值组成:
//
// 主版本
// 次版本
// 生成号
// 修订号
//
// 可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值,
// 方法是按如下所示使用“*”:
[assembly: AssemblyVersion("1.0.*")]
//[assembly: AssemblyVersion("1.0.0.0")]
//[assembly: AssemblyFileVersion("1.0.0.0")]
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace OnlineStore.Common
{
/// <summary>
/// 记录配置的key
/// </summary>
public class Setting_Init
{ /// <summary>
/// 系统启动时自动启动料仓,=1时自动启动,并隐藏窗口,=0时不需要
/// </summary>
public static string App_AutoRun = "App_AutoRun";
/// <summary>
/// 系统主界面标题
/// </summary>
public static string App_Title = "App_Title";
/// <summary>
/// 摄像机名称
/// </summary>
public static string CameraName = "CameraName";
public static string Config_Pwd = "Config_Pwd";
public static string UseBuzzer = "UseBuzzer";
/// <summary>
/// 检测到料串自动入料
/// </summary>
public static string AutoInput = "AutoInput";
/// <summary>
/// 进出轴待机点位,进出轴在此位置时,升降和旋转才可以走
/// </summary>
public static string InoutDefaultPosition = "InoutDefaultPosition";
public static string LabelName = "LabelName";
public static string PrinterName = "PrinterName";
public static string NeedPrintLabel = "NeedPrintLabel";
public static string StickingPosJudgment = "StickingPosJudgment";
public static string GratingSignal = " GratingSignal";
/// <summary>
/// 启用贴标功能
/// </summary>
public static string UseLabel = "UseLabel";
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace OnlineStore.Common
{
public class LineGetPosOp
{
public LineGetPosOp(string cids,string code)
{
this.cids = cids;
this.code = code;
}
public string cids = "";
public string code = "";
}
public class LineOperation
{
// //{"result":"0","msg":"","pos":"11#AC1_18_4_28","barcode":"R506072019102200414","cid":"line-ac-11"}
// 返回: {"code": 0, "msg":"ok", data:7}
/// <summary>
/// 0=成功
/// </summary>
public int result;
public string cid;
public string msg = "";
public string pos = "";
public string barcode = "";
}
/// <summary>
/// 与服务器通信用对象
/// </summary>
public class Operation
{
/// <summary>
/// 料仓唯一标识,分号分割
/// </summary>
private string _cid = "";
public string cid
{
get { return _cid; }
set { _cid = value; }
}
/// <summary>
/// 请求序列号
/// </summary>
public int seq { get; set; }
/// <summary>
/// 操作码(0无操作(发送料仓状态给服务器),
/// 1扫码入库(扫码成功后发送给服务器),
/// 2 出库(服务器发送),3表示错误信息 )
/// 4,发送给服务表示二维码扫码入库,收到开始扫码
/// </summary>
public int op { get; set; }
/// <summary>
/// 操作相关数据,
/// op=1时,客户端发送 code 二维码给服务器,服务器返回时有:posId库位编号,plateW:料盘宽度,plateH:料盘高度
/// 如果需要更新温湿度的报警值,服务器会发送alarmTemperature,alarmHumidity给客户端,客户端缓存,如果没有发送,不处理
/// op=3时,data发送BoxID和AlarmCode
/// =4时扫码入库
/// =5时服务器发送预警温度
/// </summary>
private Dictionary<string, string> _data = new Dictionary<string, string>();
public Dictionary<string, string> data
{
get { return _data; }
set { _data = value; }
}
/// <summary>
/// 整体料仓状态
/// 1=正常运行中
/// 2=急停中
/// 3=故障(气压检测不到等,用msg发送详细故障说明)
/// 4=警告(用msg发送提醒,如出库到达工位但是没有工人操作)
/// </summary>
public int status { get; set; }
/// <summary>
/// 提示消息
/// 出入库错误: BOX正在调试中,不能出入库
/// 出入库错误: 急停了不能出入库
/// 入库错误:料盘过大,放不到指定的位置中去
/// 故障:气压信号检测不到
/// 警告:出库盘到达工位但是没有工人操作
/// </summary>
public string msg { get; set; }
/// <summary>
/// 包含的多个 BOX 的状态信息
/// </summary>
public Dictionary<int, BoxStatus> boxStatus = new Dictionary<int, BoxStatus>();
/// <summary>
/// 报警集合
/// </summary>
public List<AlarmInfo> alarmList = new List<AlarmInfo>();
}
/// <summary>
/// 单台料仓状态(包含流水线)
/// </summary>
public class BoxStatus
{
/// <summary>
/// Box编号,从1开始
/// </summary>
public int boxId { get; set; }
/// <summary>
/// 单台BOX状态
/// 急停,故障,调试中,就绪状态(正常待机)
/// 入库执行中,入库完成,入库失败
/// 出库执行中,出库完成,出库失败
/// </summary>
public int status { get; set; }
/// <summary>
/// 单台BOX的消息
/// 正在调试中,不能出入库
/// 入库失败原因:
/// 出库失败原因:
/// </summary>
public string msg { get; set; }
/// <summary>
/// 温度
/// </summary>
public string temperature { get; set; }
/// <summary>
/// 湿度
/// </summary>
public string humidity { get; set; }
/// <summary>
/// 操作相关数据,
/// 出库完成后发送posId库位编号给服务器
/// </summary>
private Dictionary<string, string> _data = new Dictionary<string, string>();
public Dictionary<string, string> data
{
get { return _data; }
set { _data = value; }
}
}
public class AlarmInfo
{
public AlarmInfo(int StoreID, int aType, string alarmDetial, string WarnMsg, int inoutStatus)
{
// TODO: Complete member initialization
this.boxId = StoreID;
this.alarmType = aType;
this.alarmDetail = alarmDetial;
this.alarmMsg = WarnMsg;
this.inOutStatus = inoutStatus;
}
public AlarmInfo()
{
// TODO: Complete member initialization
}
/// <summary>
/// 料仓ID,0表示流水线
/// </summary>
public int boxId { get; set; }
/// <summary>
/// 报警类型,
/// </summary>
public int alarmType { get; set; }
/// <summary>
/// 报警详情
///AlarmType= 0 消息 "1=原点返回
//AlarmType= 0 消息 2=复位"
//AlarmType=1 总体错误 "1=急停
//AlarmType=1 总体错误 2=没有气压信号
//AlarmType=1 总体错误,3=盘错乱"
//AlarmType=2 运动轴错误 1=第一轴(旋转)
//AlarmType=2 运动轴错误 2=第二轴(上下轴)
//AlarmType=2 运动轴错误 3=第三轴(前进轴)
//AlarmType=2 运动轴错误 4=第四轴(压紧轴)"
//AlarmType=2 电钢报警 5=上下电钢
//AlarmType=3 IO报警,信号超时 io电器定义(电器定义)
/// </summary>
public string alarmDetail { get; set; }
/// <summary>
/// 报警消息
/// </summary>
public string alarmMsg { get; set; }
/// <summary>
/// 0,1=入库,2=出库
/// </summary>
public int inOutStatus { get; set; }
}
public class ParamDefine
{
/// <summary>
/// 库位 ID
/// </summary>
public static string posId = "posId";
/// <summary>
/// 料盘宽
/// </summary>
public static string plateW = "plateW";
/// <summary>
/// 料盘高
/// </summary>
public static string plateH = "plateH";
/// <summary>
/// 料仓ID
/// </summary>
public static string storeId = "storeId";
/// <summary>
/// 报警码
/// </summary>
public static string alarmCode = "alarmCode";
/// <summary>
/// 报警详情或参数
/// </summary>
public static string alarmDetial = "alarmDetial";
/// <summary>
/// 湿度报警值
/// </summary>
public static string maxHumidity = "humi";
/// <summary>
/// 温度报警值
/// </summary>
public static string maxTemperature = "temp";
/// <summary>
/// urgentReel: true 表示紧急料,需要出到料串上
/// </summary>
public static string urgentReel = "urgentReel";
/// <summary>
/// cutReel: true 表示分盘料,需要出到料串上
/// </summary>
public static string cutReel = "cutReel";
/// <summary>
/// smallReel: true 小料(7x8),放置到小料串上
/// </summary>
public static string smallReel = "smallReel";
/// <summary>
/// rfid: 分配的料串RFID
/// </summary>
public static string rfid = "rfid";
/// <summary>
/// rfidLoc: 料串的架位,值为 - 1时,可以自由分配皮带线, 小料时,架位为1 - 46优先走1 / 2号皮带线,47 - 92优先走3 / 4号皮带线,
/// 70,71,72时只能分配到3 / 4号皮带线; 大料时,架位1 - 6优先走1 / 2号皮带线, 7 - 12优先走3 / 4号皮带线
/// </summary>
public static string rfidLoc = "rfidLoc";
public static string barcode = "barcode";
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net;
using System.Net.Sockets;
using System.Reflection;
using System.Threading;
namespace OnlineStore.Common
{
public class CTcpClient
{
// public static readonly ILog LOGGER = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
public delegate void HandleMessage(string message);
private Socket m_clientSocket = null;
private byte[] m_receiveBuffer = new byte[1024];
private HandleMessage onReceived;
public int TimeOutTime = 0;
/// <summary>
/// 当前连接状态
/// </summary>
public bool IsConnected()
{
if (m_clientSocket == null)
{
return false;
}
if (m_clientSocket.Connected)
{
return true;
}
#region remarks
/********************************************************************************************
* 当Socket.Conneted为false时, 如果您需要确定连接的当前状态,请进行非阻塞、零字节的 Send 调用。
* 如果该调用成功返回或引发 WAEWOULDBLOCK 错误代码 (10035),则该套接字仍然处于连接状态;
* 否则,该套接字不再处于连接状态。
* Depending on http://msdn.microsoft.com/zh-cn/library/system.net.sockets.socket.connected.aspx?cs-save-lang=1&cs-lang=csharp#code-snippet-2
********************************************************************************************/
#endregion
try
{
#region 过程
// This is how you can determine whether a socket is still connected.
bool connectState = true;
bool blockingState = m_clientSocket.Blocking;
try
{
byte[] tmp = new byte[1];
m_clientSocket.Blocking = false;
m_clientSocket.Send(tmp, 0, 0);
//Console.WriteLine("Connected!");
connectState = true; //若Send错误会跳去执行catch体,而不会执行其try体里其之后的代码
}
catch (SocketException e)
{
// 10035 == WSAEWOULDBLOCK
if (e.NativeErrorCode.Equals(10035))
{
connectState = true;
}
else
{
connectState = false;
}
}
finally
{
if (m_clientSocket != null && m_clientSocket.Connected)
{
m_clientSocket.Blocking = blockingState;
}
}
//Console.WriteLine("Connected: {0}", client.Connected);
return connectState;
#endregion
}
catch (Exception ex)
{
LogUtil.error( "出错啦" + ex.ToString());
return false;
}
}
/// <summary>
/// 连接服务器
/// </summary>
public bool connect(string serverIP, int serverPort, HandleMessage HandleMessage)
{
m_clientSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
if (TimeOutTime <= 0)
{
IPEndPoint remoteEndPoint = new IPEndPoint(IPAddress.Parse(serverIP), serverPort);
m_clientSocket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, true);
try
{
if (!m_clientSocket.Connected)
{
m_clientSocket.Connect(remoteEndPoint);
}
if (m_clientSocket.Connected)
{
m_clientSocket.BeginReceive(m_receiveBuffer, 0, m_receiveBuffer.Length, 0, new AsyncCallback(ReceiveCallBack), null);
onReceived = HandleMessage;
LogUtil.info( "Connect to " + serverIP + ":" + serverPort + " success!");
return true;
}
else
{
LogUtil.info( "Connect to " + serverIP + ":" + serverPort + " fail!");
}
}
catch (Exception ex)
{
LogUtil.error( "Connect to " + serverIP + ":" + serverPort + " fail!" + ex.ToString(), 103);
//m_clientSocket = null;
}
}
else
{
m_clientSocket.ReceiveTimeout = TimeOutTime;
m_clientSocket.SendTimeout = TimeOutTime;
IAsyncResult connResult = m_clientSocket.BeginConnect(serverIP, serverPort, null, null);
connResult.AsyncWaitHandle.WaitOne(this.TimeOutTime, true); //等待2秒
if (!connResult.IsCompleted || (!m_clientSocket.Connected))
{
LogUtil.info( "Connect to " + serverIP + ":" + serverPort + " fail!");
m_clientSocket.Close();
//处理连接不成功的动作
return false;
}
else
{
//处理连接成功的动作
m_clientSocket.BeginReceive(m_receiveBuffer, 0, m_receiveBuffer.Length, 0, new AsyncCallback(ReceiveCallBack), null);
onReceived = HandleMessage;
LogUtil.info( "Connect to " + serverIP + ":" + serverPort + " success!");
return true;
}
}
return false;
}
/// <summary>
/// 断开连接
/// </summary>
public void close()
{
try
{
if (m_clientSocket != null && m_clientSocket.Connected)
{
m_clientSocket.Shutdown(SocketShutdown.Both);
//Thread.Sleep(300);
//m_clientSocket.Disconnect(true);
//Thread.Sleep(300);
m_clientSocket.Close();
//m_clientSocket = null;
LogUtil.info( "Socket closed!");
}
else
{
LogUtil.error( "No socket is running!");
}
}
catch (Exception ex)
{
LogUtil.error( "close error :" + ex.ToString());
}
}
/// <summary>
/// 发送信息
/// </summary>
public void send(string strSendData)
{
byte[] sendBuffer = new byte[1024];
sendBuffer = Encoding.UTF8.GetBytes(strSendData);
if (m_clientSocket != null && m_clientSocket.Connected)
{
m_clientSocket.Send(sendBuffer);
LogUtil.debug( "Send >> " + strSendData);
}
}
/// <summary>
/// 发送信息
/// </summary>
public void sendLine(string strSendData)
{
if (strSendData.StartsWith("save"))
{
LogUtil.debug( "发送数据:" + strSendData);
}
else
{
LogUtil.info( "发送数据:" + strSendData);
}
strSendData = strSendData + "\r\n";
byte[] sendBuffer = new byte[1024];
sendBuffer = Encoding.UTF8.GetBytes(strSendData);
if (m_clientSocket != null && m_clientSocket.Connected)
{
m_clientSocket.Send(sendBuffer);
LogUtil.debug( "Send >> " + strSendData);
}
}
private void ReceiveCallBack(IAsyncResult ar)
{
try
{
if (m_clientSocket != null && m_clientSocket.Connected)
{
int REnd = m_clientSocket.EndReceive(ar);
string strReceiveData = Encoding.Default.GetString(m_receiveBuffer, 0, REnd);
onReceived(strReceiveData);
Thread.Sleep(100);
//LOGGER.Debug("m_clientSocket:" + m_clientSocket + "\n m_receiveBuffer" + m_receiveBuffer);
m_clientSocket.BeginReceive(m_receiveBuffer, 0, m_receiveBuffer.Length, 0, new AsyncCallback(ReceiveCallBack), null);
}
}
catch (Exception ex)
{
LogUtil.error( "socket received error:" + ex.ToString(), 104);
}
}
}
}
using System;
using System.Configuration;
using System.Threading;
using System.Xml;
using System.Windows.Forms;
namespace OnlineStore.Common
{
public class ConfigAppSettings
{
//public static readonly ILog LOGGER = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
private static int seq = 1;
public static int nextSeq()
{
if (seq.Equals(Int32.MaxValue))
{
LogUtil.info("seq当前值:" + seq + ",重置seq=0");
seq = 0;
}
Interlocked.Increment(ref seq);
return seq;
}
public static string GetValue(string keyStr, string storeStr)
{
string key = keyStr + storeStr;
System.Configuration.Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
if (config.AppSettings.Settings[key] == null)
{
return GetValue(keyStr);
}
else
{
return config.AppSettings.Settings[key].Value;
}
}
public static decimal GetNumValue(string keyStr, string storeStr)
{
string key = keyStr + storeStr;
decimal a = 0;
System.Configuration.Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
if (config.AppSettings.Settings[key] == null)
{
return GetNumValue(keyStr);
}
else
{
{
Decimal.TryParse(config.AppSettings.Settings[key].Value, out a);
}
}
return a;
}
public static int GetIntValue(string keyStr, string storeStr)
{
string key = keyStr + storeStr;
int a = 0;
System.Configuration.Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
if (config.AppSettings.Settings[key] == null)
{
return GetIntValue(keyStr);
}
else
{
{
Int32.TryParse(config.AppSettings.Settings[key].Value, out a);
}
} return a;
}
public static string GetValue(string key)
{
System.Configuration.Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
if (config.AppSettings.Settings[key] == null)
{
LogUtil.error("未找到配置:" + key + ",请检查配置是否完整!");
return "";
}
else
{
return config.AppSettings.Settings[key].Value;
}
}
public static decimal GetNumValue(string key)
{
decimal a = 0;
System.Configuration.Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
if (config.AppSettings.Settings[key] == null)
{
LogUtil.error("未找到配置:" + key + ",请检查配置是否完整!");
return a;
}
else
{
{
Decimal.TryParse(config.AppSettings.Settings[key].Value, out a);
}
}
return a;
}
public static int GetIntValue(string key)
{
int a = 0;
System.Configuration.Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
if (config.AppSettings.Settings[key] == null)
{
LogUtil.error("未找到配置:" + key + ",请检查配置是否完整!");
return a;
}
else
{
{
Int32.TryParse(config.AppSettings.Settings[key].Value, out a);
}
} return a;
}
public static void SaveValue(string key, int value)
{
SaveValue(key, value.ToString());
}
public static void SaveValue(string key, string value)
{
try
{
if (key.Equals("") || value.Equals(""))
{
return;
}
//增加的内容写在appSettings段下 <add key="RegCode" value="0"/>
System.Configuration.Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
if (config.AppSettings.Settings[key] == null)
{
SetValue(key, value);
}
else
{
UpdateConfig(key, value);
}
}
catch (Exception ex)
{
LogUtil.error( "SaveValue保存配置出错:AppKey=" + key + ",AppValue=" + value + ",",ex);
}
}
public static string GetValue(object debugDeviceId)
{
throw new NotImplementedException();
}
/// <summary>
/// 更新配置文件信息
/// </summary>
/// <param name="name">配置文件字段名称</param>
/// <param name="Xvalue">值</param>
private static void UpdateConfig(string name, string Xvalue)
{
try
{
XmlDocument doc = new XmlDocument();
doc.Load(Application.ExecutablePath + ".config");
XmlNode node = doc.SelectSingleNode(@"//add[@key='" + name + "']");
XmlElement ele = (XmlElement)node;
ele.SetAttribute("value", Xvalue);
doc.Save(Application.ExecutablePath + ".config");
}
catch (Exception ex)
{
LogUtil.error( "UpdateConfig保存配置出错:name=" + name + ",Xvalue=" + Xvalue + ",",ex);
}
}
///<summary>
///向.config文件的appKey结写入信息AppValue 保存设置
///</summary>
///<param name="AppKey">节点名</param>
///<param name="AppValue">值</param>
private static void SetValue(String AppKey, String AppValue)
{
try
{
XmlDocument xDoc = new XmlDocument();
xDoc.Load(System.Windows.Forms.Application.ExecutablePath + ".config");
XmlNode xNode;
XmlElement xElem1;
XmlElement xElem2;
xNode = xDoc.SelectSingleNode("//appSettings");
xElem1 = (XmlElement)xNode.SelectSingleNode("//add[@key='" + AppKey + "']");
if (xElem1 != null)
xElem1.SetAttribute("value", AppValue);
else
{
xElem2 = xDoc.CreateElement("add");
xElem2.SetAttribute("key", AppKey);
xElem2.SetAttribute("value", AppValue);
xNode.AppendChild(xElem2);
}
xDoc.Save(System.Windows.Forms.Application.ExecutablePath + ".config");
}
catch (Exception ex)
{
LogUtil.error( "SetValue保存配置出错:AppKey=" + AppKey + ",AppValue=" + AppValue + ",",ex);
}
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace OnlineStore.Common
{
public class FormUtil
{
public static string GetValue(TextBox txt)
{
string value = txt.Text;
return value;
}
public static int GetIntValue(TextBox txt)
{
int value = 0;
try
{
value = int.Parse(txt.Text);
}
catch (Exception ex)
{
value = 0;
}
return value;
}
public static short GetShortValue(TextBox txt)
{
short value = 0;
try
{
value = short.Parse(txt.Text);
}
catch (Exception ex)
{
value = 0;
}
return value;
}
public static double getDoubleValue(TextBox txt)
{
double value = 0;
try
{
value = double.Parse(txt.Text);
}
catch (Exception ex)
{
value = 0;
}
return value;
}
public static short get16ShortValue(TextBox txt)
{
short value = 0;
try
{
value = System.Convert.ToInt16(txt.Text,16);
}
catch
{
value = 0;
}
return value;
}
//public static string GetShowStr(double value)
//{
// string wStr = "";
// if (value == (int)value)
// {
// wStr = string.Format("{0:d}", (int)value);
// }
// else
// {
// wStr = string.Format("{0:f}", value);
// }
// return wStr;
//}
public static string GetSpanStr(TimeSpan span)
{
//return Convert.ToDateTime(span.ToString()).ToString("HH:mm:ss");
string seconds = Math.Round(span.TotalSeconds % 60, 1).ToString();
if (seconds.IndexOf(".") >= 0)
{
seconds = seconds.ToString().PadLeft(4, '0');
}
else
{
seconds = seconds.ToString().PadLeft(2, '0');
}
return span.Hours.ToString().PadLeft(2, '0') + ":" + span.Minutes.ToString().PadLeft(2, '0') + ":" + seconds;
}
}
}
using System;
using System.IO;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
using System.Collections;
using System.Net;
using System.Net.Security;
using System.Security;
using System.Security.Cryptography;
using System.Security.Cryptography.X509Certificates;
using System.Reflection;
using log4net;
namespace OnlineStore.Common
{
public class HttpHelper
{
public static readonly ILog LOGGER = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
public static string Post(string url, string paramData)
{
return Post(url, paramData, Encoding.UTF8);
}
private static int isLog = ConfigAppSettings.GetIntValue(Setting_Init.Server_Log_Open);
public static string Post(string url, string paramData, Encoding encoding)
{
if (isLog == 1)
{
LOGGER.Info("给服务器发送数据【" + paramData + "】 ");
}
if (paramData != "null" && paramData != null)
{
// LogUtil.debug(LOGGER, "HTTP POST to " + url + " \n\t >> " + paramData);
}
string result = "";
if (url.ToLower().IndexOf("https", System.StringComparison.Ordinal) > -1)
{
ServicePointManager.ServerCertificateValidationCallback =
new RemoteCertificateValidationCallback((sender, certificate, chain, errors) => { return true; });
}
try
{
var wc = new MyWebClient(5000);
if (string.IsNullOrEmpty(wc.Headers["Content-Type"]))
wc.Headers.Add("Content-Type", "application/json;charset=UTF-8");
wc.Encoding = encoding;
result = wc.UploadString(url, "POST", paramData);
//LogUtil.info(result);
}
catch (Exception e)
{
LogUtil.error( "POST ERROR:" + e.StackTrace, 1001);
}
if (!result.Contains("null") && result.Length != 0)
{
//LogUtil.debug(LOGGER,"receive << " + result);
}
if (isLog == 1)
{
LOGGER.Info("收到服务器数据【" + result + "】");
}
return result;
}
public static string Get(string url)
{
return Get(url, Encoding.UTF8);
}
public static string Get(string url, Encoding encoding)
{
try
{
LogUtil.info(LOGGER, "HTTP GET FROM: " + url);
var wc = new WebClient { Encoding = encoding };
var readStream = wc.OpenRead(url);
using (var sr = new StreamReader(readStream, encoding))
{
var result = sr.ReadToEnd();
LogUtil.info(LOGGER, "receive << " + result);
return result;
}
}
catch (Exception e)
{
LogUtil.error( "HTTP GET ERROR:" + e.Message, 1002);
}
return "";
}
}
}
\ No newline at end of file
using log4net;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Reflection;
using System.Text;
namespace OnlineStore.Common
{
/// <summary>
/// 奥松温湿度服务器
/// </summary>
public class HumitureServer
{
private static readonly ILog LOGGER = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
/// <summary>
/// 最后一次接受到的温度信息,key=温湿度传感器IP地址
/// </summary>
public static Dictionary<string, ASTemperateParam> TemperateParamMap = new Dictionary<string, ASTemperateParam>();
/// <summary>
/// 根据IP 地址获得最后一次取到的温湿度
/// </summary>
public static ASTemperateParam GetTemperateParam(string ipAddr)
{
ASTemperateParam temperate = null;
TemperateParamMap.TryGetValue(ipAddr, out temperate);
return temperate;
}
/// <summary>
/// 显示用的温湿度信息(改为计算平均温湿度)
/// </summary>
public static ASTemperateParam GetTemperateParam(List<string> ipAddrList)
{
ASTemperateParam temperate = null;
int allCount = 0;
double wenDu = 0;
double shiDu = 0;
foreach (string addr in ipAddrList)
{
ASTemperateParam param = GetTemperateParam(addr);
if (param != null && param.IsValid())
{
allCount++;
wenDu = wenDu + param.Temperate;
shiDu = shiDu + param.Humidity;
}
}
if (allCount > 0)
{
double avgWendu = Math.Round(wenDu / allCount, 1);
double avgShidu = Math.Round(shiDu / allCount, 1);
temperate = new ASTemperateParam(avgWendu, avgShidu);
}
return temperate;
}
public static double GetMaxHumidity(List<string> ipAddrList)
{
double maxValue = 0;
foreach (string addr in ipAddrList)
{
ASTemperateParam param = GetTemperateParam(addr);
if (param != null && param.IsValid())
{
if (param.Humidity > maxValue)
{
maxValue = param.Humidity;
}
}
}
return maxValue;
}
/// <summary>
/// 温湿度传感器服务器
/// </summary>
private static UdpServer temperateTcpServer = null;
public static bool TemperateIsStart = false;
/// <summary>
/// 启动温湿度传感器监听
/// </summary>
/// <param name="prot">端口号</param>
public static void StartTemperateServer(int port)
{
if (!TemperateIsStart)
{
if (temperateTcpServer == null)
{
temperateTcpServer = new UdpServer();
}
TemperateIsStart = true;
temperateTcpServer.Start(port);
LogUtil.info(LOGGER, "温湿度已开始在端口[" + port + "]监听!");
temperateTcpServer.ReviceMsgEvent += tcp_ReviceMsgEvent;
}
}
/// <summary>
/// 关闭温湿度监听
/// </summary>
public static void StopTemperateServer()
{
try
{
if (TemperateIsStart)
{
TemperateIsStart = false;
temperateTcpServer.Stop();
}
}
catch (Exception ex)
{
LogUtil.error(LOGGER, "关闭温湿度监听出错:" + ex.ToString());
}
}
/// <summary>
/// 温湿度传感器 服务器回调函数
/// </summary>
private static void tcp_ReviceMsgEvent(EndPoint remote, string Msg)
{
IPEndPoint clientipe = (IPEndPoint)remote;
string add = clientipe.Address.ToString();
try
{
string[] strList = Msg.Split('+');
if (strList.Length == 12)
{
double wendu = double.Parse(strList[2]) / 10;
double shidu = double.Parse(strList[3]) / 10;
string deviceId = strList[10];
string pwd = strList[11];
LogUtil.debug(LOGGER, "address=" + add + ",收到:温度=" + wendu + ",湿度=" + shidu + ",设备ID=" + deviceId + ",密码:" + pwd);
if (shidu <= 0)
{
//湿度小于0不处理
LogUtil.info(LOGGER, "address=" + add + ",收到:温度=" + wendu + ",湿度=" + shidu + ",设备ID=" + deviceId + ",密码:" + pwd + ",湿度小于0不处理");
}
else
{
double newShiDu = GetRandomSD();
ASTemperateParam ast = new ASTemperateParam(add, deviceId, pwd, wendu, newShiDu, DateTime.Now);
if (TemperateParamMap.ContainsKey(add))
{
TemperateParamMap.Remove(add);
}
TemperateParamMap.Add(add, ast);
}
}
}
catch (Exception ex)
{
LogUtil.error(LOGGER, ex.ToString());
}
}
private static double PreShiDu = 7;
private static double PreWenDu = 25;
public static void RandomData(List<string> ipAddrList)
{
try
{
foreach (string IP in ipAddrList)
{
double newShiDu = GetRandomSD();
double newWenDu = GetRandomWD();
ASTemperateParam ast = new ASTemperateParam(IP, "", "", newWenDu, newShiDu, DateTime.Now);
if (TemperateParamMap.ContainsKey(IP))
{
TemperateParamMap.Remove(IP);
}
TemperateParamMap.Add(IP, ast);
//LogUtil.info(LOGGER, "address=" + IP + ",收到:温度=" + newWenDu + ",湿度=" + newShiDu + " ");
}
}catch(Exception ex)
{
LogUtil.error("温湿度数据保存出错:"+ex.ToString());
}
}
public static double GetRandomWD()
{
Random rd = new Random((int)DateTime.Now.Ticks + 99);
int num = rd.Next(-20, 20);
double newWendu = Math.Round(PreWenDu + (double)num / 1000F, 3);
if (newWendu > 25.5 || newWendu < 24.5)
{
newWendu = PreWenDu;
}
else
{
PreWenDu = newWendu;
}
return newWendu;
}
public static double GetRandomSD()
{
Random rd = new Random((int)DateTime.Now.Ticks);
int num = rd.Next(-100, 100);
double newShiDu = Math.Round(PreShiDu + (double)num / 1000F, 3);
if (newShiDu > 9.8 || newShiDu < 5.6)
{
newShiDu = PreShiDu;
}
else
{
PreShiDu = newShiDu;
}
return newShiDu;
}
}
/// <summary>
/// 奥松温湿度上传参数
/// </summary>
public class ASTemperateParam
{
public ASTemperateParam(string clientipe, string add, string pwd, double wendu, double shidu, DateTime updateTime)
{
this.IpAddress = clientipe;
this.DeviceAddress = add;
this.Password = pwd;
this.Temperate = wendu;
this.Humidity = shidu;
this.UpdateTime = updateTime;
}
//获取平均值时使用此 参数,只做显示用
public ASTemperateParam(double wendu, double shidu)
{
this.IpAddress = "";
this.DeviceAddress = "";
this.Password = "";
this.Temperate = wendu;
this.Humidity = shidu;
this.UpdateTime = DateTime.Now;
}
/// <summary>
/// 判断值是否在有效期内。默认有效期是一分钟
/// </summary>
/// <returns></returns>
public bool IsValid()
{
TimeSpan span = DateTime.Now - UpdateTime;
if (span.TotalMinutes > 3)
{
return false;
}
return true;
}
/// <summary>
/// 更新时间
/// </summary>
public DateTime UpdateTime { get; set; }
/// <summary>
/// IP地址
/// </summary>
public string IpAddress { get; set; }
/// <summary>
/// 设备地址
/// </summary>
public string DeviceAddress { get; set; }
/// <summary>
/// 访问密码
/// </summary>
public string Password { get; set; }
/// <summary>
/// 温度
/// </summary>
public double Temperate { get; set; }
/// <summary>
/// 湿度
/// </summary>
public double Humidity { get; set; }
}
}
using System.Collections.Generic;
using System.IO;
using Newtonsoft.Json;
namespace OnlineStore.Common
{
/// <summary>
/// Json帮助类
/// </summary>
public class JsonHelper
{
/// <summary>
/// 将对象序列化为JSON格式
/// </summary>
/// <param name="o">对象</param>
/// <returns>json字符串</returns>
public static string SerializeObject(object o)
{
string json = JsonConvert.SerializeObject(o);
return json;
}
/// <summary>
/// 解析JSON字符串生成对象实体
/// </summary>
/// <typeparam name="T">对象类型</typeparam>
/// <param name="json">json字符串(eg.{"ID":"112","Name":"石子儿"})</param>
/// <returns>对象实体</returns>
public static T DeserializeJsonToObject<T>(string json) where T : class
{
JsonSerializer serializer = new JsonSerializer();
StringReader sr = new StringReader(json);
object o = serializer.Deserialize(new JsonTextReader(sr), typeof(T));
T t = o as T;
return t;
}
/// <summary>
/// 解析JSON数组生成对象实体集合
/// </summary>
/// <typeparam name="T">对象类型</typeparam>
/// <param name="json">json数组字符串(eg.[{"ID":"112","Name":"石子儿"}])</param>
/// <returns>对象实体集合</returns>
public static List<T> DeserializeJsonToList<T>(string json) where T : class
{
JsonSerializer serializer = new JsonSerializer();
StringReader sr = new StringReader(json);
object o = serializer.Deserialize(new JsonTextReader(sr), typeof(List<T>));
List<T> list = o as List<T>;
return list;
}
/// <summary>
/// 反序列化JSON到给定的匿名对象.
/// </summary>
/// <typeparam name="T">匿名对象类型</typeparam>
/// <param name="json">json字符串</param>
/// <param name="anonymousTypeObject">匿名对象</param>
/// <returns>匿名对象</returns>
public static T DeserializeAnonymousType<T>(string json, T anonymousTypeObject)
{
T t = JsonConvert.DeserializeAnonymousType(json, anonymousTypeObject);
return t;
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using log4net;
using System.Reflection;
using System.Drawing;
using System.Runtime.ExceptionServices;
using System.Collections.Concurrent;
using System.Threading;
namespace OnlineStore.Common
{
public class LogUtil
{
//public static readonly ILog AIOLog = LogManager.GetLogger("AIOBOX");
//private static LogUtil instance = new LogUtil();
public delegate void ShowLogDelegate(string msg, Color color);
public event ShowLogDelegate ShowLog;
public static readonly ILog LOGGER = LogManager.GetLogger("RollingLogFileAppender");
public static readonly ILog rfidLog = LogManager.GetLogger("RfidLog");
//public static readonly ILog timeCount = LogManager.GetLogger("Count");
public static ConcurrentDictionary<int, DateTime> lastErrorLogTime = new ConcurrentDictionary<int, DateTime>();
public static int showCount = 15;
public static bool debug_opened = false;
public static void info(ILog log, string msg)
{
if (log == null)
{
return;
}
log.Info(msg);
AddToBox(msg, Color.Black);
}
public static void info(ILog log, string msg, Color color)
{
log.Info(msg);
AddToBox(msg, color);
}
public static void debug(ILog log, string msg, Color color)
{
log.Debug(msg);
if (debug_opened)
{
AddToBox(msg, color);
}
}
public static void debug(ILog log, string msg)
{
log.Debug(msg);
if (debug_opened)
{
AddToBox(msg, Color.Gray);
}
}
public static void RfidLog(string msg)
{
rfidLog.Debug(msg);
}
public static void error(string errorMsg, int type, int seconds = 10)
{
try
{
if (lastErrorLogTime.ContainsKey(type))
{
TimeSpan span = DateTime.Now - lastErrorLogTime[type];
if (span.TotalSeconds > seconds)
{
lastErrorLogTime[type] = DateTime.Now;
error(LOGGER, errorMsg);
}
}
else
{
lastErrorLogTime.TryAdd(type, DateTime.Now);
error(LOGGER, errorMsg);
}
}
catch (Exception ex)
{
LOGGER.Error(" 打印日志【" + type + "-" + errorMsg + "】出错:" + ex.ToString());
}
}
public static void error(ILog log, string errorMsg, Exception ex = null)
{
if (errorMsg.Trim().Equals("") && (ex == null))
{
return;
}
if (ex == null)
{
log.Error(errorMsg);
}
else
{
log.Error(errorMsg, ex);
}
AddToBox(errorMsg, Color.Red);
}
private static object lockObj = "";
private static void AddToBox(string msg, Color color)
{
if (Monitor.TryEnter(lockObj, 2))
{
try
{
ShowLogPro(msg, color);
}
catch (Exception ex)
{
LOGGER.Error("出错:", ex);
}
finally
{
Monitor.Exit(lockObj);
}
}
else
{
LOGGER.Debug("ShowLogPro【" + msg + "】失败,未得到锁");
}
}
private static List<string> logList = new List<string>();
public static string LastText = "";
[HandleProcessCorruptedStateExceptions]
private static void ShowLogPro(string msg, Color color)
{
try
{
if (logList.Count >= showCount)
{
logList.RemoveAt(0);
}
string text = "";
foreach (string str in logList)
{
text += str;
}
System.DateTime now = System.DateTime.Now;
logList.Add(now.ToLongTimeString() + " " + msg + Environment.NewLine);
}
catch (AccessViolationException e)
{
LOGGER.Error(" ShowLogPro 出错:" + e.ToString());
}
catch (Exception ex)
{
LOGGER.Error("出错:" + ex.ToString());
}
}
private static DateTime lastTime = DateTime.Now;
public static void debug(string msg)
{
debug(LOGGER, msg);
}
public static void error(string errorMsg, Exception ex = null)
{
error(LOGGER, errorMsg, ex);
}
public static void info(string msg)
{
info(LOGGER, msg);
}
}
}
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Net.NetworkInformation;
using System.Net.Security;
using System.Reflection;
using System.Text;
namespace OnlineStore.Common
{
public class MyWebClient : WebClient
{
private int _timeout;
/// <summary>
/// 超时时间(毫秒)
/// </summary>
public int Timeout
{
get
{
return _timeout;
}
set
{
_timeout = value;
}
}
public MyWebClient()
{
this._timeout = 60000;
}
public MyWebClient(int timeout)
{
this._timeout = timeout;
}
protected override WebRequest GetWebRequest(Uri address)
{
HttpWebRequest result = (HttpWebRequest)base.GetWebRequest(address);
result.Timeout = this._timeout;
return result;
}
}
public class HttpHelper
{
public static bool PingURLIP(string url, int ms = 100)
{
string[] urlArray = url.Split('/');
if (urlArray.Length > 3)
{
string ip = urlArray[2];
Ping pingSender = new Ping();
PingReply reply = pingSender.Send(ip, ms);//第一个参数为ip地址,第二个参数为ping的时间
if (reply.Status == IPStatus.Success)
{
//通
return true;
}
else
{
LogUtil.error("Ping IP " + ip + " : false");
//不通
return false;
}
}
return true;
}
public static string Post(string url, string paramData, int timeOut = 10000)
{
return Post(url, paramData, Encoding.UTF8, timeOut);
}
public static string Post(string url, string paramData, Encoding encoding, int timeOut = 10000)
{
string result = "";
if (url.ToLower().IndexOf("https", System.StringComparison.Ordinal) > -1)
{
ServicePointManager.ServerCertificateValidationCallback =
new RemoteCertificateValidationCallback((sender, certificate, chain, errors) => { return true; });
}
try
{
using (var wc = new MyWebClient(10000))
{
if (string.IsNullOrEmpty(wc.Headers["Content-Type"]))
{
wc.Headers.Add("Content-Type", "application/json;charset=UTF-8");
}
wc.Headers.Add("User-Agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1;SV1)");
wc.Encoding = encoding;
result = wc.UploadString(url, "POST", paramData);
}
//LogUtil.info(result);
}
catch (Exception e)
{
LogUtil.error("POST ERROR:" + e.ToString(), 101);
}
return result;
}
public static string Get(string url)
{
return Get(url, Encoding.UTF8);
}
public static string Get(string url, Encoding encoding, int timeOut = 10000)
{
try
{
LogUtil.debug("HTTP GET FROM: " + url);
using (var wc = new MyWebClient { Encoding = encoding })
{
var readStream = wc.OpenRead(url);
using (var sr = new StreamReader(readStream, encoding))
{
var result = sr.ReadToEnd();
LogUtil.debug("receive << " + result);
return result;
}
}
}
catch (Exception e)
{
LogUtil.error("HTTP GET ERROR:" + e.Message, 102);
}
return "";
}
}
}
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Net.Sockets;
using System.Net;
using System.IO;
using log4net;
using System.Text;
using OnlineStore.Common;
namespace OnlineStore
{
public class NetTCPServer
{
// public static readonly ILog LOGGER = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
/// <summary>
/// TCP服务端监听
/// </summary>
TcpListener tcpsever = null;
/// <summary>
/// 监听状态
/// </summary>
bool isListen = false;
public BindingList<NewClient> lstClient = new BindingList<NewClient>();
public IPAddress[] getLoacalIPAddress()
{
IPHostEntry ipHostEntry = Dns.GetHostEntry(Dns.GetHostName());
return ipHostEntry.AddressList;
}
public delegate void ReviceData(NewClient client, string ip, byte[] data);
public event ReviceData ReviceDataEvent;
/// <summary>
/// 开启TCP监听
/// </summary>
/// <returns></returns>
public void StartTCPServer(int port)
{
try
{
tcpsever = new TcpListener(IPAddress.Any, port);
tcpsever.Start();
tcpsever.BeginAcceptTcpClient(new AsyncCallback(Acceptor), tcpsever);
isListen = true;
}
catch (Exception ex)
{
}
}
/// <summary>
/// 停止TCP监听
/// </summary>
/// <returns></returns>
public void StopTCPServer()
{
tcpsever.Stop();
isListen = false;
}
/// <summary>
/// 客户端连接初始化
/// </summary>
/// <param name="o"></param>
private void Acceptor(IAsyncResult o)
{
TcpListener server = o.AsyncState as TcpListener;
try
{
//初始化连接的客户端
NewClient newClient = new NewClient();
newClient.tcpClient = server.EndAcceptTcpClient(o);
lstClient.Add(newClient);
newClient.tcpClient.GetStream().BeginRead(newClient.Buffer, 0, newClient.Buffer.Length, new AsyncCallback(TCPCallBack), newClient);
server.BeginAcceptTcpClient(new AsyncCallback(Acceptor), server);//继续监听客户端连接
}
catch (ObjectDisposedException ex)
{ //监听被关闭
}
catch (Exception ex)
{
}
}
/// <summary>
/// 对当前选中的客户端发送数据
/// </summary>
/// <param name="sender"></param>
/// <param name="data"></param>
public bool SendData(NewClient selClient, byte[] data)
{
try
{
selClient.tcpClient.GetStream().Write(data, 0, data.Length);
}
catch (Exception ex)
{
return false;
}
return true;
}
/// <summary>
/// 客户端通讯回调函数
/// </summary>
/// <param name="ar"></param>
private void TCPCallBack(IAsyncResult ar)
{
NewClient client = (NewClient)ar.AsyncState;
if (client.tcpClient.Connected)
{
NetworkStream ns = client.tcpClient.GetStream();
StreamReader sr = new StreamReader(ns);
string str = sr.ReadLine();
LogUtil.info("读取到数据:"+str);
byte[] recdata = new byte[ns.EndRead(ar)];
if (recdata.Length > 0)
{
//Array.Copy(client.Buffer, recdata, recdata.Length);
LogUtil.info("读取到数据1111:" + Encoding.ASCII.GetString(recdata));
//ns.BeginRead(client.Buffer, 0, client.Buffer.Length, new AsyncCallback(TCPCallBack), client);
}
else
{
client.tcpClient.Close();
lstClient.Remove(client);
}
}
}
/// <summary>
/// 清理
/// </summary>
public void ClearSelf()
{
foreach (NewClient client in lstClient)
{
client.tcpClient.Close();
}
lstClient.Clear();
if (tcpsever != null)
{
tcpsever.Stop();
}
}
}
public class NewClient
{
public TcpClient tcpClient { get; set; }
public byte[] Buffer = new byte[1024];
}
}
using log4net;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
namespace OnlineStore.Common
{
/// <summary>
/// 扫码枪连接类
/// </summary>
public class ScanSocket
{
private readonly ILog LOGGER = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
public event ScanRevice OnScanRevice;
public delegate void ScanRevice(string message);
/// <summary>
/// 扫码枪链接
/// </summary>
private TcpClient scannerSocket;
/// <summary>
/// 扫描枪 是否开始运行
/// </summary>
public bool isScannerRun = false;
/// <summary>
/// 连接扫码枪
/// </summary>
/// <param name="serverIp">扫码枪Ip</param>
/// <param name="port">扫码枪端口号</param>
/// <returns>是否连接成功</returns>
public bool ConnectScanner(string serverIp, int port)
{
return StartScanner(serverIp, port, false);
}
/// <summary>
/// 停止扫码枪
/// </summary>
public void StopScanner()
{
try
{
scannerSocket.close();
isScannerRun = false;
}
catch (Exception ex)
{
LogUtil.error(LOGGER, "出错:" + ex);
}
}
/// <summary>
/// 发送扫码命令开始扫码
/// </summary>
public void BeginScannering()
{
string str = ConfigAppSettings.GetValue(Setting_Init.scanner_start_command);
if (str.Equals(""))
{
str = "S";
}
scannerSocket.send(str);
//onCodeReceived("AAAA");
}
/// <summary>
/// 开启扫码枪
/// </summary>
private bool StartScanner(string serverIp, int port, bool isMustCon)
{
bool result = true;
try
{
if (!isScannerRun || isMustCon)
{
if (scannerSocket == null)
{
scannerSocket = new TcpClient();
}
result = scannerSocket.connect(serverIp, port, new TcpClient.HandleMessage(onCodeReceived));
if (result)
{
isScannerRun = true;
}
}
}
catch (Exception ex)
{
LogUtil.error(LOGGER, "出错:" + ex);
}
return result;
}
/// <summary>
/// 扫码枪数据接收
/// </summary>
/// <param name="message"></param>
private void onCodeReceived(string message)
{
try
{
message = ScanCodeManager.ReplaceCode(message);
if (OnScanRevice != null)
{
OnScanRevice.Invoke(message);
}
}
catch (Exception ex)
{
LogUtil.error(LOGGER, "出错:" + ex.ToString());
}
}
}
}
using System;
using System.Text;
using System.Windows.Forms;
using System.Net;
using System.Net.Sockets;
using System.Threading;
using System.Collections.Concurrent;
namespace OnlineStore.Common
{
public class TcpServer
{
// public static readonly ILog LOGGER = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
/// <summary>
/// 接受消息时的间隔
/// </summary>
public static int ReviceMsgMS = 10;
private Thread m_serverThread;
private Socket m_serverSocket;
public delegate void ReviceMsg(TcpClientBean client, string Msg);
public event ReviceMsg ReviceMsgEvent;
private delegate void ReceiveMessageDelegate(TcpClientBean client);
public event AcceptClientDelegate AcceptClientEvent;
public delegate void AcceptClientDelegate(TcpClientBean client);
ReceiveMessageDelegate receiveMessageDelegate;
private bool isRun = true;
private int serverPort = 0;
private void logLocalIp()
{
string[] addresses = GetLocalAddresses();
string iplist = "本机IP:[";
if (addresses.Length > 0)
{
for (int i = 0; i < addresses.Length; i++)
{
if (addresses.Length != 0)
{
iplist = iplist + " " + addresses[i];
}
}
}
LogUtil.info( iplist + "]");
}
/// <summary>
/// 开始服务
/// </summary>
public void Start(int m_serverPort)
{
try
{
isRun = true;
m_serverSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
IPEndPoint localEndPoint = new IPEndPoint(IPAddress.Any, m_serverPort);
this.serverPort = m_serverPort;
m_serverSocket.Bind(localEndPoint);
m_serverSocket.Listen(10);
m_serverThread = new Thread(new ThreadStart(ReceiveAccept));
m_serverThread.Start();
LogUtil.info( " Server start listen : " + m_serverPort);
logLocalIp();
//this.AddRunningInfo(">> " + DateTime.Now.ToString() + " Server started.");
}
catch (SocketException se)
{
throw new Exception(se.Message);
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
}
/// <summary>
/// 停止服务
/// </summary>
public void Stop()
{
try
{
isRun = false;
m_serverThread.Interrupt(); // 线程终止
m_serverSocket.Close(); // Socket Close
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
}
private void ReceiveAccept()
{
while (isRun)
{
TcpClientBean client = new TcpClientBean();
try
{
client.ClientSocket = m_serverSocket.Accept();
IPEndPoint clientipe = (IPEndPoint)client.ClientSocket.RemoteEndPoint;
client.AddStr = clientipe.Address.ToString()+":"+clientipe.Port.ToString();
LogUtil.info( "["+serverPort+"]有新的客户端链接上:[" + client.AddStr+"]");
AcceptClientEvent?.Invoke(client);
receiveMessageDelegate = new ReceiveMessageDelegate(ReceiveMessages);
receiveMessageDelegate.BeginInvoke(client, ReceiveMessagesCallback, "");
}
catch (Exception ex)
{
LogUtil.error( "ReceiveAccept方法,客户端【"+client.AddStr+"】:" + ex.Message);
//throw new Exception(ex.Message);
}
}
}
// private StringBuilder sb = new StringBuilder(); //这个是用来保存:接收到了的,但是还没有结束的消息
private int receiveBufferSize = 1024;
private string terminateString = "\r";
public void ReceiveMessages(TcpClientBean client) //这个函数会被以线程方式运行
{
try
{
StringBuilder sb = new StringBuilder();
Socket socket = (Socket)client.ClientSocket;
while (true)
{
byte[] buffer = new byte[receiveBufferSize]; //buffer大小,此处为1024
int receivedSize = socket.Receive(buffer);
if (receivedSize > 0)
{
string rawMsg = Encoding.ASCII.GetString(buffer, 0, receivedSize);
int rnFixLength = terminateString.Length; //这个是指消息结束符的长度,此处为\r\n
for (int i = 0; i < rawMsg.Length;) //遍历接收到的整个buffer文本
{
if (i <= rawMsg.Length - rnFixLength)
{
if (rawMsg.Substring(i, rnFixLength) != terminateString)//非消息结束符,则加入sb
{
sb.Append(rawMsg[i]);
i++;
}
else
{
this.ReviceMsgEvent.Invoke(client, sb.ToString());//找到了消息结束符,触发消息接收完成事件
sb = new StringBuilder();
i += rnFixLength;
}
}
else
{
sb.Append(rawMsg[i]);
i++;
}
}
}
Thread.Sleep(ReviceMsgMS);
}
}
catch (SocketException e)
{
LogUtil.error("客户端{" + client.AddStr + "]:" + e.ToString(), 106);
}
catch (Exception ex)
{
LogUtil.error("客户端{" + client.AddStr + "]:" + ex.ToString(), 105);
}
}
//private void ReceiveMessages(Client client)
//{
// try
// {
// while (true)
// {
// byte[] receiveBuffer = new byte[1024];
// //int size = ;
// int size = client.ClientSocket.Receive(receiveBuffer);
// string strReceiveData = Encoding.ASCII.GetString(receiveBuffer, 0, size);
// if (!string.IsNullOrEmpty(strReceiveData))
// {
// LogUtil.info(LOGGER, "收到数据:" + strReceiveData);
// // this.AddRunningInfo(">> Receive data from [" + client.ClientSocket.RemoteEndPoint.ToString()+ "]:" + strReceiveData);
// string strSendData = "OK. The content is:" + strReceiveData;
// //LogUtil.info(LOGGER, "OK. The content is:" + strReceiveData);
// int sendBufferSize = Encoding.Unicode.GetByteCount(strSendData);
// byte[] sendBuffer = new byte[sendBufferSize];
// sendBuffer = Encoding.Unicode.GetBytes(strSendData);
// client.ClientSocket.Send(sendBuffer);
// }
// }
// }
// catch (SocketException e)
// {
// LogUtil.error(LOGGER, e.ToString());
// }
// catch (Exception ex)
// {
// LOGGER.Error(ex.ToString());
// }
//}
private void ReceiveMessagesCallback(IAsyncResult AR)
{
try
{
receiveMessageDelegate.EndInvoke(AR);
}
catch (Exception ex)
{
LogUtil.error(ex.ToString());
}
}
/// <summary>
/// 获取本机地址列表
/// </summary>
public string[] GetLocalAddresses()
{
// 获取主机名
string strHostName = Dns.GetHostName();
// 根据主机名进行查找
IPHostEntry iphostentry = Dns.GetHostEntry(strHostName);
string[] retval = new string[iphostentry.AddressList.Length];
int i = 0;
foreach (IPAddress ipaddress in iphostentry.AddressList)
{
if (ipaddress.AddressFamily != AddressFamily.InterNetworkV6)
{
retval[i] = ipaddress.ToString();
i++;
}
}
return retval;
}
}
/// <summary>
/// 客户端会话信息类
/// </summary>
public class TcpClientBean
{
Socket m_clientSocket;
public TcpClientBean() { }
public string AddStr = "";
public Socket ClientSocket
{
get { return m_clientSocket; }
set { this.m_clientSocket = value; }
}
}
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Sockets;
using System.Text;
using System.Threading;
namespace OnlineStore.Common
{
public class UdpServer
{
// public static readonly ILog LOGGER = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
private Thread m_serverThread;
private Socket udpServer;
public delegate void ReviceMsg(EndPoint address, string Msg);
/// <summary>
/// 接受到数据事件
/// </summary>
public event ReviceMsg ReviceMsgEvent;
private bool isRun = true;
private void logLocalIp()
{
string[] addresses = GetLocalAddresses();
string iplist = "本机IP:[";
if (addresses.Length > 0)
{
for (int i = 0; i < addresses.Length; i++)
{
if (addresses.Length != 0)
{
iplist = iplist + " " + addresses[i];
}
}
}
LogUtil.info( iplist + "]");
}
/// <summary>
/// 开始服务
/// </summary>
public void Start(int m_serverPort)
{
try
{
IPEndPoint ipep = new IPEndPoint(IPAddress.Any, m_serverPort);//定义一网络端点
udpServer = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);//定义一个Socket
udpServer.Bind(ipep);//Socket与本地的一个终结点相关联
m_serverThread = new Thread(new ThreadStart(ReceiveData));
m_serverThread.Start();
logLocalIp();
isRun = true;
}
catch (Exception ex)
{
LogUtil.error("启动udpserver出错:" + ex.ToString());
}
}
/// <summary>
/// 停止服务
/// </summary>
public void Stop()
{
try
{
isRun = false;
m_serverThread.Interrupt(); // 线程终止
udpServer.Close(); // Socket Close
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
}
private StringBuilder sb = new StringBuilder(); //这个是用来保存:接收到了的,但是还没有结束的消息
private int receiveBufferSize = 1024;
private string terminateString = "\r";
private void ReceiveData()
{
try
{
IPEndPoint sender = new IPEndPoint(IPAddress.Any, 0);//定义要发送的计算机的地址
EndPoint Remote = (EndPoint)(sender);//
while (true)
{
byte[] buffer = new byte[receiveBufferSize];
int receivedSize = udpServer.ReceiveFrom(buffer, ref Remote);
if (receivedSize > 0)
{
string rawMsg = Encoding.ASCII.GetString(buffer, 0, receivedSize);
int rnFixLength = terminateString.Length; //这个是指消息结束符的长度,此处为\r\n
for (int i = 0; i < rawMsg.Length; ) //遍历接收到的整个buffer文本
{
if (i <= rawMsg.Length - rnFixLength)
{
if (rawMsg.Substring(i, rnFixLength) != terminateString)//非消息结束符,则加入sb
{
sb.Append(rawMsg[i]);
i++;
}
else
{
this.ReviceMsgEvent.Invoke(Remote, sb.ToString());//找到了消息结束符,触发消息接收完成事件
sb = new StringBuilder();
i += rnFixLength;
}
}
else
{
sb.Append(rawMsg[i]);
i++;
}
}
}
Thread.Sleep(500);
}
}
catch (Exception ex)
{
LogUtil.error("启动udpserver出错:" + ex.ToString());
}
}
/// <summary>
/// 获取本机地址列表
/// </summary>
public string[] GetLocalAddresses()
{
// 获取主机名
string strHostName = Dns.GetHostName();
// 根据主机名进行查找
IPHostEntry iphostentry = Dns.GetHostEntry(strHostName);
string[] retval = new string[iphostentry.AddressList.Length];
int i = 0;
foreach (IPAddress ipaddress in iphostentry.AddressList)
{
if (ipaddress.AddressFamily != AddressFamily.InterNetworkV6)
{
retval[i] = ipaddress.ToString();
i++;
}
}
return retval;
}
}
}
using OnlineStore.LoadCSVLibrary;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DeviceLibrary
{
public interface IRobot
{
//List<ConfigMoveAxis> moveAxisList { get; set; }
Robot_Config config { get; set; }
string Name { get; set; }
bool canRunning { get; set; }
bool isBusy { get; set; }
bool isAlarm { get; set; }
RunStatus runStatus { get; set; }
void Run();
}
public enum RunStatus
{
Stop,
Running,
HomeReset
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DeviceLibrary
{
public class LabelParam
{
/// <summary>
/// 创建新出入库信息
/// </summary>
/// <param name="type">出入库类型</param>
/// <param name="wareNo">二维码内容</param>
/// <param name="platew">宽度</param>
/// <param name="plateh">高度</param>
/// <param name="IsNg">是否是入库NG料</param>
/// <param name="ngMsg">NG消息</param>
public LabelParam(MoveType type, string wareNo = "", int platew = 0, int plateh = 0, bool _IsNg = false, string ngMsg = "")
{
WareCode = wareNo;
PlateW = platew;
PlateH = plateh;
IsNg = _IsNg;
NgMsg = ngMsg;
moveType = type;
}
public MoveType moveType = MoveType.None;
/// <summary>
/// 物品二维码信息
/// </summary>
public string WareCode { get; set; }
/// <summary>
/// 料盘高度
/// </summary>
public int PlateH { get; set; }
/// <summary>
/// 料盘宽度
/// </summary>
public int PlateW { get; set; }
/// <summary>
/// 是否是入料NG料
/// </summary>
public bool IsNg = false;
/// <summary>
/// 入料NG消息
/// </summary>
public string NgMsg = "";
public string ToStr()
{
if (IsNg)
{
return " 入库失败[BOX_" + "] [" + WareCode + "], [" + PlateW + "x" + PlateH + "] ";
}
else
{
return " 入库 [" + "] [" + WareCode + "], [" + PlateW + "x" + PlateH + "] ";
}
}
}
}
using OnlineStore.LoadCSVLibrary;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DeviceLibrary
{
partial class MainMachine
{
void WorkProcess() {
}
}
}
using OnlineStore.Common;
using OnlineStore.LoadCSVLibrary;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
namespace DeviceLibrary
{
public partial class MainMachine : IRobot
{
public string Name { get; set; } = "移载";
public bool canRunning { get; set; } = false;
public bool isBusy { get; set; } = false;
public bool isAlarm { get; set; } = false;
public RunStatus runStatus { get; set; } = RunStatus.Stop;
public Robot_Config config { get; set; }
public MoveInfo MoveInfo;
public AxisBean Take_Middle_Axis;
public AxisBean Take_UpDown_Axis;
public AxisBean Left_Batch_Axis;
public AxisBean Right_Batch_Axis;
public AxisBean Label_X_Axis;
public AxisBean Label_Y_Axis;
public AxisBean Label_Z_Axis;
public AxisBean Label_R_Axis;
/// <summary>
/// 开始运行的时间
/// </summary>
public DateTime StartTime { get; set; }
/// <summary>
/// 是否在急停中
/// </summary>
public bool isInSuddenDown = false;
public MainMachine(Robot_Config _config) {
config = _config;
Take_Middle_Axis = new AxisBean(config.Take_Middle_Axis, Name);
Take_UpDown_Axis = new AxisBean(config.Take_UpDown_Axis, Name);
Left_Batch_Axis = new AxisBean(config.Left_Batch_Axis, Name);
Right_Batch_Axis = new AxisBean(config.Right_Batch_Axis, Name);
Label_X_Axis = new AxisBean(config.Label_X_Axis, Name);
Label_Y_Axis = new AxisBean(config.Label_Y_Axis, Name);
Label_Z_Axis = new AxisBean(config.Label_Z_Axis, Name);
Label_R_Axis = new AxisBean(config.Label_R_Axis, Name);
}
public void Run() {
while (true) {
canRunning = DeviceCheck();
if (canRunning)
canRunning = SafeCheck();
Thread.Sleep(50);
if (!canRunning)
continue;
if (runStatus == RunStatus.Running)
{
WorkProcess();
}
else if (runStatus == RunStatus.HomeReset)
{
HomeReset();
}
}
}
public void BeginHomeReset() {
StopMove();
Thread.Sleep(500);
OpenAllServo();
alarmType = AlarmType.None;
runStatus = RunStatus.HomeReset;
MoveInfo.NextMoveStep(MoveStep.H01_HomeReset);
LogInfo(MoveInfo.MoveType + ": 开始回原 ");
MoveInfo.WaitList.Add(WaitResultInfo.WaitTime(1000));
}
void HomeReset()
{
if (CheckWait())
return;
switch (MoveInfo.MoveStep)
{
case MoveStep.H01_HomeReset:
MoveInfo.NextMoveStep(MoveStep.H02_HomeReset);
//MoveInfo.WaitList.Add(WaitResultInfo.WaitTime(1000));
LogInfo(MoveInfo.MoveType + ":正在回原");
Take_Middle_Axis.HomeMove(MoveInfo);
Take_UpDown_Axis.HomeMove(MoveInfo);
Left_Batch_Axis.HomeMove(MoveInfo);
Right_Batch_Axis.HomeMove(MoveInfo);
break;
case MoveStep.H02_HomeReset:
MoveInfo.NextMoveStep(MoveStep.H03_HomeReset);
LogInfo(MoveInfo.moveStep + ":正在回原");
Label_Z_Axis.HomeMove(MoveInfo);
Take_Middle_Axis.AbsMove(MoveInfo, config.Take_Middle_P1, config.Take_Middle_P1_speed);
Take_UpDown_Axis.AbsMove(MoveInfo, config.Take_UpDown_P1, config.Take_UpDown_P1_speed);
Right_Batch_Axis.AbsMove(MoveInfo, config.Right_Batch_P1, config.Right_Batch_P1_speed);
Left_Batch_Axis.AbsMove(MoveInfo, config.Left_Batch_P1, config.Left_Batch_P1_speed);
break;
case MoveStep.H03_HomeReset:
MoveInfo.NextMoveStep(MoveStep.H04_HomeReset);
LogInfo(MoveInfo.moveStep + ":正在回原");
Label_Z_Axis.HomeMove(MoveInfo);
Label_X_Axis.HomeMove(MoveInfo);
Label_Y_Axis.HomeMove(MoveInfo);
Label_R_Axis.HomeMove(MoveInfo);
break;
case MoveStep.H04_HomeReset:
MoveInfo.NextMoveStep(MoveStep.H05_HomeReset);
LogInfo(MoveInfo.moveStep + ":正在回原");
Label_Z_Axis.AbsMove(MoveInfo, config.Label_Z_P1, config.Label_Z_P1_speed);
Label_X_Axis.AbsMove(MoveInfo, config.Label_X_P1, config.Label_X_P1_speed);
Label_Y_Axis.AbsMove(MoveInfo, config.Label_Y_P1, config.Label_Y_P1_speed);
Label_R_Axis.AbsMove(MoveInfo, config.Label_R_P1, config.Label_R_P1_speed);
break;
case MoveStep.H05_HomeReset:
MoveInfo.NextMoveStep(MoveStep.HEND_HomeReset);
LogInfo(MoveInfo.moveStep + ":正在回原 阻挡气缸判断");
if (IOManager.IOValue(IO_Type.LeftEnd_Check) == IO_VALUE.LOW)
{
CylinderMove(MoveInfo, IO_Type.LeftStopUP, IO_Type.LeftStopDown);
}
if (IOManager.IOValue(IO_Type.RightEnd_Check) == IO_VALUE.LOW)
{
CylinderMove(MoveInfo, IO_Type.RightStopUP, IO_Type.RightStopDown);
}
break;
case MoveStep.HEND_HomeReset:
LogInfo(MoveInfo.moveStep + ": 完成");
MoveEndProcess();
break;
}
}
bool SafeCheck() {
List<string> msglist = new List<string>();
if (IOValue(IO_Type.GratingSignal_Check).Equals(IO_VALUE.LOW))
{
msglist.Add("安全光栅被遮挡");
}
if (IOValue(IO_Type.HasNgBox).Equals(IO_VALUE.LOW))
{
msglist.Add("没有检测到NG料箱");
}
if (IOValue(IO_Type.HasPrinter).Equals(IO_VALUE.LOW))
{
msglist.Add("没有检测到NG料箱");
}
if (IOValue(IO_Type.LeftBackDoor_Check).Equals(IO_VALUE.LOW))
{
msglist.Add("左后门没有关闭");
}
if (IOValue(IO_Type.RightBackDoor_Check).Equals(IO_VALUE.LOW))
{
msglist.Add("右后门没有关闭");
}
return (msglist.Count == 0);
}
/// <summary>
/// 最后一次气压检测变为0的时间
/// </summary>
DateTime lastAirCloseTime = DateTime.MinValue;
bool DeviceCheck() {
List<string> msglist = new List<string>();
if (IOValue(IO_Type.SuddenStop_BTN).Equals(IO_VALUE.LOW))
{
msglist.Add("急停中");
}
if (IOValue(IO_Type.Airpressure_Check).Equals(IO_VALUE.LOW))
{
if (lastAirCloseTime == DateTime.MinValue)
lastAirCloseTime = DateTime.Now;
TimeSpan span = DateTime.Now - lastAirCloseTime;
if (span.TotalSeconds > RobotManage.Config.AirCheckSeconds)
{
msglist.Add("急停中");
}
}
else {
lastAirCloseTime = DateTime.MinValue;
}
return (msglist.Count == 0);
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DeviceLibrary
{
public enum MoveStep
{
Wait,
H01_HomeReset,
H02_HomeReset,
H03_HomeReset,
H04_HomeReset,
H05_HomeReset,
H06_HomeReset,
H07_HomeReset,
HEND_HomeReset,
}
public enum AlarmType
{
/// <summary>
/// 没有报警
/// </summary>
None = 0,
/// <summary>
/// 轴报警
/// </summary>
AxisAlarm = 1,
/// <summary>
/// 收到急停
/// </summary>
SuddenStop = 10,
/// <summary>
/// 没有气压信号
/// </summary>
NoAirCheck = 11,
/// <summary>
/// 轴运动错误,没有达到指定脉冲,但是io判断已停止运动
/// </summary>
AxisMoveError = 20,
/// <summary>
/// io信号超时未收到
/// </summary>
IoSingleTimeOut = 30,
}
}
using OnlineStore.LoadCSVLibrary;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace DeviceLibrary
{
public static class RobotManage
{
public static MainMachine mainMachine;
public static Robot_Config Config;
public static bool IsLoadOk = false;
static string baseDir = Application.StartupPath;
static Thread mainThread;
static RobotManage() {
CodeManager.LoadConfig();
string configFile = Path.Combine(baseDir, "config\\Config.csv");
Config = new Robot_Config(0, "", configFile);
Config = (Robot_Config)CSVConfigReader.LoadConfig(Config);
mainMachine = new MainMachine(RobotManage.Config);
if (!IOManager.ConnectionIOList(new List<string>())) {
IsLoadOk = false;
return;
}
IsLoadOk = true;
}
static void Start() {
mainThread = new Thread(new ThreadStart(mainMachine.Run));
mainThread.Start();
GC.KeepAlive(mainThread);
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DeviceLibrary
{
public class Class1
{
}
}
类型,分类编号,说明,名称,属性值,设备名称,电器定义,目标速度,加速时间,减速时间,原点低速度,原点高速,原点加速度,脉冲最小误差,脉冲最大误差,脉冲最小限位,脉冲最大限位
AXIS,,取料机构旋转轴_SVD01,Take_Middle_Axis,0,HC,,500,1000,1000,100,200,1000,10,1000,0,0
AXIS,,取料机构上下轴_SVD02,Take_UpDown_Axis,1,HC,,1000,1000,1000,200,500,500,10,1000,0,0
AXIS,,左轨道提升轴_SVD04,Left_Batch_Axis,2,HC,,3000,1000,1000,200,1000,200,10,1000,0,0
AXIS,,右轨道提升轴_SVD05,Right_Batch_Axis,3,HC,,3000,1000,1000,200,1000,200,10,1000,0,0
AXIS,,贴标移栽机构X轴_SVD08,Label_X_Axis,4,HC,,100,700,700,50,250,500,10,1000,0,0
AXIS,,贴标移栽机构Y轴_SVD09,Label_Y_Axis,5,HC,,100,700,700,50,150,500,10,1000,0,0
AXIS,,贴标移栽机构Z轴_SVD10,Label_Z_Axis,6,HC,,100,800,800,50,150,500,10,1000,0,0
AXIS,,贴标移栽机构R轴_SVD11,Label_R_Axis,7,HC,,10,2000,2000,1,5,200,500,1000,0,0
,,,,,,,,,,,,,,,,
PRO,0,IO信号超时时间(秒),IOSingle_TimerOut,15,,,,,,,,,,,,
PRO,10,取料旋转轴待机点P1,Take_Middle_P1,1,,,,,,,,,,,,
PRO,10,取料旋转轴右取料点P2,Take_Middle_P2,2,,,,,,,,,,,,
PRO,10,取料旋转轴左取料点P3,Take_Middle_P3,3,,,,,,,,,,,,
PRO,10,取料旋转轴NG放料点P5,Take_Middle_P5,4,,,,,,,,,,,,
,,,,,,,,,,,,,,,,
PRO,11,取料上下轴待机点P1,Take_UpDown_P1,6,,,,,,,,,,,,
PRO,11,取料上下轴取料高点P2,Take_UpDown_P2,7,,,,,,,,,,,,
PRO,11,取料上下轴取右料低点P3,Take_UpDown_P3,8,,,,,,,,,,,,
PRO,11,取料上下轴取左料低点P4,Take_UpDown_P4,9,,,,,,,,,,,,
PRO,11,取料上下轴NG放料点P5,Take_UpDown_P5,10,,,,,,,,,,,,
,,,,,,,,,,,,,,,,
PRO,12,右提升轴低点P1,Right_Batch_P1,12,,,,,,,,,,,,
PRO,12,右提升轴高点P2,Right_Batch_P2,13,,,,,,,,,,,,
PRO,12,左提升轴低点P1,Left_Batch_P1,14,,,,,,,,,,,,
PRO,12,左提升轴高点P2,Left_Batch_P2,15,,,,,,,,,,,,
,,,,,,,,,,,,,,,,
PRO,13,贴标X轴待机点P1,Label_X_P1,17,,,,,,,,,,,,
PRO,13,贴标X轴取标点P2,Label_X_P2,18,,,,,,,,,,,,
PRO,13,贴标X轴贴标点P3,Label_X_P3,19,,,,,,,,,,,,
,,,,,,,,,,,,,,,,
PRO,14,贴标Y轴待机点P1,Label_Y_P1,21,,,,,,,,,,,,
PRO,14,贴标Y轴取标点P2,Label_Y_P2,22,,,,,,,,,,,,
PRO,14,贴标Y轴贴标点P3,Label_Y_P3,23,,,,,,,,,,,,
,,,,,,,,,,,,,,,,
PRO,15,贴标Z轴待机点P1,Label_Z_P1,25,,,,,,,,,,,,
PRO,15,贴标Z轴取标点P2,Label_Z_P2,26,,,,,,,,,,,,
PRO,15,贴标Z轴贴标点P3,Label_Z_P3,27,,,,,,,,,,,,
,,,,,,,,,,,,,,,,
PRO,16,贴标R轴待机点P1,Label_R_P1,29,,,,,,,,,,,,
PRO,16,贴标R轴取标点P2,Label_R_P2,30,,,,,,,,,,,,
PRO,16,贴标R轴360度脉冲,Label_R_P3,31,,,,,,,,,,,,
,,,,,,,,,,,,,,,,
DI,0,急停,SuddenStop_BTN,0,HC,X00,,,,,,,,,,
DI,0,进料口确认按钮,Reset_BTN,1,HC,X01,,,,,,,,,,
DI,0,出料口确认按钮,Start_BTN,2,HC,X02,,,,,,,,,,
DI,0,后门左门禁,LeftBackDoor_Check,3,HC,X03,,,,,,,,,,
DI,0,后门右门禁,RightBackDoor_Check,4,HC,X04,,,,,,,,,,
DI,0,气压检测,Airpressure_Check,5,HC,X05,,,,,,,,,,
DI,0,光栅信号,GratingSignal_Check,6,HC,X06,,,,,,,,,,
DI,0,NG料箱检测,HasNgBox,7,HC,X07,,,,,,,,,,
DI,0,打印机到位检测,HasPrinter,8,HC,X08,,,,,,,,,,
DI,0,旋转臂进料侧检测,RightArm_Check,9,HC,X09,,,,,,,,,,
DI,0,旋转臂出料侧检测,LeftArm_Check,10,HC,X10,,,,,,,,,,
DI,0,进料口料车检测,RightCar_Check,11,HC,X11,,,,,,,,,,
DI,0,进料口前端料串检测,RightFornt_Check,12,HC,X12,,,,,,,,,,
DI,0,进料口料串到位检测,RightEnd_Check,13,HC,X13,,,,,,,,,,
DI,0,进料口阻挡气缸上升端,RightStopUP,14,HC,X14,,,,,,,,,,
DI,0,进料口阻挡气缸下降端,RightStopDown,15,HC,X15,,,,,,,,,,
DI,0,出料口料车检测,LeftCar_Check,16,HC,X16,,,,,,,,,,
DI,0,出料口前端料串检测,LeftFornt_Check,17,HC,X17,,,,,,,,,,
DI,0,出料口料串到位检测,LeftEnd_Check,18,HC,X18,,,,,,,,,,
DI,0,出料口阻挡气缸上升端,LeftStopUP,19,HC,X19,,,,,,,,,,
DI,0,出料口阻挡气缸下降端,LeftStopDown,20,HC,X20,,,,,,,,,,
DI,0,进料定位料盘检测,RightTop_Check,21,HC,X21,,,,,,,,,,
DI,0,进料定位料盘超限检测,RightOverHead_Check,22,HC,X22,,,,,,,,,,
DI,0,出料定位料盘检测,LeftTop_Check,23,HC,X23,,,,,,,,,,
DI,0,出料定位料盘超限检测,LeftOverHead_Check,24,HC,X24,,,,,,,,,,
DI,0,吸嘴气缸前进端,LabelCylinder_Fwd,25,HC,X25,,,,,,,,,,
DI,0,吸嘴气缸后退端,LabelCylinder_Bck,26,HC,X26,,,,,,,,,,
,,,,,,,,,,,,,,,,
DO,0,自动指示灯,AutoRun_HddLed,0,HC,Y00,,,,,,,,,,
DO,0,故障指示灯,Alarm_HddLed,1,HC,Y01,,,,,,,,,,
DO,0,待机指示灯,RunSign_HddLed,2,HC,Y02,,,,,,,,,,
DO,0,报警蜂鸣器,Alarm_Buzzer,3,HC,Y03,,,,,,,,,,
DO,0,进料口状态指示灯,RightState_Led,4,HC,Y04,,,,,,,,,,
DO,0,出料口状态指示灯,LeftState_Led,5,HC,Y05,,,,,,,,,,
DO,0,设备照明,Device_Led,6,HC,Y06,,,,,,,,,,
DO,0,相机照明,Camera_Led,7,HC,Y07,,,,,,,,,,
DO,0,进料口电机启动,RightMoto_Run,8,HC,Y08,,,,,,,,,,
DO,0,进料口电机反转指令,RightMoto_Reverse,9,HC,Y09,,,,,,,,,,
DO,0,出料口电机启动,LeftMoto_Run,10,HC,Y10,,,,,,,,,,
DO,0,出料口电机反转指令,LeftMoto_Reverse,11,HC,Y11,,,,,,,,,,
DO,0,进料口阻挡气缸上升,RightStopUP,12,HC,Y12,,,,,,,,,,
DO,0,进料口阻挡气缸下降,RightStopDown,13,HC,Y13,,,,,,,,,,
DO,0,出料口阻挡气缸上升,LeftStopUP,14,HC,Y14,,,,,,,,,,
DO,0,出料口阻挡气缸下降,LeftStopDown,15,HC,Y15,,,,,,,,,,
DO,0,吸嘴气缸前进,LabelCylinder_Fwd,16,HC,Y16,,,,,,,,,,
DO,0,吸嘴气缸后退,LabelCylinder_Bck,17,HC,Y17,,,,,,,,,,
DO,0,吸嘴取标,LabelCylinder_Work,18,HC,Y18,,,,,,,,,,
,,,,,,,,,,,,,,,,
类型,分类编号,说明,名称,属性值,设备名称,电器定义,目标速度,加速时间,减速时间,原点低速度,原点高速,原点加速度,脉冲最小误差,脉冲最大误差,脉冲最小限位,脉冲最大限位
AXIS,,取料机构旋转轴_SVD01,Take_Middle_Axis,0,HC,,500,1000,1000,100,200,1000,10,1000,0,0
AXIS,,取料机构上下轴_SVD02,Take_UpDown_Axis,1,HC,,1000,1000,1000,200,500,500,10,1000,0,0
AXIS,,左轨道提升轴_SVD04,Left_Batch_Axis,2,HC,,3000,1000,1000,200,1000,200,10,1000,0,0
AXIS,,右轨道提升轴_SVD05,Right_Batch_Axis,3,HC,,3000,1000,1000,200,1000,200,10,1000,0,0
AXIS,,贴标移栽机构X轴_SVD08,Label_X_Axis,4,HC,,100,700,700,50,250,500,10,1000,0,0
AXIS,,贴标移栽机构Y轴_SVD09,Label_Y_Axis,5,HC,,100,700,700,50,150,500,10,1000,0,0
AXIS,,贴标移栽机构Z轴_SVD10,Label_Z_Axis,6,HC,,100,800,800,50,150,500,10,1000,0,0
AXIS,,贴标移栽机构R轴_SVD11,Label_R_Axis,7,HC,,10,2000,2000,1,5,200,500,1000,0,0
,,,,,,,,,,,,,,,,
PRO,0,IO信号超时时间(秒),IOSingle_TimerOut,15,,,,,,,,,,,,
PRO,0,气压检测超时,AirCheckSeconds,5,,,,,,,,,,,,
PRO,10,取料旋转轴待机点P1,Take_Middle_P1,1,,,99,,,,,,,,,
PRO,10,取料旋转轴右取料点P2,Take_Middle_P2,2,,,99,,,,,,,,,
PRO,10,取料旋转轴左取料点P3,Take_Middle_P3,3,,,99,,,,,,,,,
PRO,10,取料旋转轴NG放料点P5,Take_Middle_P5,4,,,99,,,,,,,,,
,,,,,,,,,,,,,,,,
PRO,11,取料上下轴待机点P1,Take_UpDown_P1,6,,,88,,,,,,,,,
PRO,11,取料上下轴取料高点P2,Take_UpDown_P2,7,,,88,,,,,,,,,
PRO,11,取料上下轴取右料低点P3,Take_UpDown_P3,8,,,88,,,,,,,,,
PRO,11,取料上下轴取左料低点P4,Take_UpDown_P4,9,,,88,,,,,,,,,
PRO,11,取料上下轴NG放料点P5,Take_UpDown_P5,10,,,88,,,,,,,,,
,,,,,,,,,,,,,,,,
PRO,12,右提升轴低点P1,Right_Batch_P1,12,,,66,,,,,,,,,
PRO,12,右提升轴高点P2,Right_Batch_P2,13,,,66,,,,,,,,,
PRO,12,左提升轴低点P1,Left_Batch_P1,14,,,66,,,,,,,,,
PRO,12,左提升轴高点P2,Left_Batch_P2,15,,,66,,,,,,,,,
,,,,,,,,,,,,,,,,
PRO,13,贴标X轴待机点P1,Label_X_P1,17,,,77,,,,,,,,,
PRO,13,贴标X轴取标点P2,Label_X_P2,18,,,77,,,,,,,,,
PRO,13,贴标X轴贴标点P3,Label_X_P3,19,,,77,,,,,,,,,
,,,,,,,,,,,,,,,,
PRO,14,贴标Y轴待机点P1,Label_Y_P1,21,,,44,,,,,,,,,
PRO,14,贴标Y轴取标点P2,Label_Y_P2,22,,,44,,,,,,,,,
PRO,14,贴标Y轴贴标点P3,Label_Y_P3,23,,,44,,,,,,,,,
,,,,,,,,,,,,,,,,
PRO,15,贴标Z轴待机点P1,Label_Z_P1,25,,,44,,,,,,,,,
PRO,15,贴标Z轴取标点P2,Label_Z_P2,26,,,44,,,,,,,,,
PRO,15,贴标Z轴贴标点P3,Label_Z_P3,27,,,44,,,,,,,,,
,,,,,,,,,,,,,,,,
PRO,16,贴标R轴待机点P1,Label_R_P1,29,,,22,,,,,,,,,
PRO,16,贴标R轴取标点P2,Label_R_P2,30,,,22,,,,,,,,,
PRO,16,贴标R轴360度脉冲,Label_R_P3,31,,,22,,,,,,,,,
,,,,,,,,,,,,,,,,
DI,0,急停,SuddenStop_BTN,0,HC,X00,,,,,,,,,,
DI,0,进料口确认按钮,Reset_BTN,1,HC,X01,,,,,,,,,,
DI,0,出料口确认按钮,Start_BTN,2,HC,X02,,,,,,,,,,
DI,0,后门左门禁,LeftBackDoor_Check,3,HC,X03,,,,,,,,,,
DI,0,后门右门禁,RightBackDoor_Check,4,HC,X04,,,,,,,,,,
DI,0,气压检测,Airpressure_Check,5,HC,X05,,,,,,,,,,
DI,0,光栅信号,GratingSignal_Check,6,HC,X06,,,,,,,,,,
DI,0,NG料箱检测,HasNgBox,7,HC,X07,,,,,,,,,,
DI,0,打印机到位检测,HasPrinter,8,HC,X08,,,,,,,,,,
DI,0,旋转臂进料侧检测,RightArm_Check,9,HC,X09,,,,,,,,,,
DI,0,旋转臂出料侧检测,LeftArm_Check,10,HC,X10,,,,,,,,,,
DI,0,进料口料车检测,RightCar_Check,11,HC,X11,,,,,,,,,,
DI,0,进料口前端料串检测,RightFornt_Check,12,HC,X12,,,,,,,,,,
DI,0,进料口料串到位检测,RightEnd_Check,13,HC,X13,,,,,,,,,,
DI,0,进料口阻挡气缸上升端,RightStopUP,14,HC,X14,,,,,,,,,,
DI,0,进料口阻挡气缸下降端,RightStopDown,15,HC,X15,,,,,,,,,,
DI,0,出料口料车检测,LeftCar_Check,16,HC,X16,,,,,,,,,,
DI,0,出料口前端料串检测,LeftFornt_Check,17,HC,X17,,,,,,,,,,
DI,0,出料口料串到位检测,LeftEnd_Check,18,HC,X18,,,,,,,,,,
DI,0,出料口阻挡气缸上升端,LeftStopUP,19,HC,X19,,,,,,,,,,
DI,0,出料口阻挡气缸下降端,LeftStopDown,20,HC,X20,,,,,,,,,,
DI,0,进料定位料盘检测,RightTop_Check,21,HC,X21,,,,,,,,,,
DI,0,进料定位料盘超限检测,RightOverHead_Check,22,HC,X22,,,,,,,,,,
DI,0,出料定位料盘检测,LeftTop_Check,23,HC,X23,,,,,,,,,,
DI,0,出料定位料盘超限检测,LeftOverHead_Check,24,HC,X24,,,,,,,,,,
DI,0,吸嘴气缸前进端,LabelCylinder_Fwd,25,HC,X25,,,,,,,,,,
DI,0,吸嘴气缸后退端,LabelCylinder_Bck,26,HC,X26,,,,,,,,,,
,,,,,,,,,,,,,,,,
DO,0,自动指示灯,AutoRun_HddLed,0,HC,Y00,,,,,,,,,,
DO,0,故障指示灯,Alarm_HddLed,1,HC,Y01,,,,,,,,,,
DO,0,待机指示灯,RunSign_HddLed,2,HC,Y02,,,,,,,,,,
DO,0,报警蜂鸣器,Alarm_Buzzer,3,HC,Y03,,,,,,,,,,
DO,0,进料口状态指示灯,RightState_Led,4,HC,Y04,,,,,,,,,,
DO,0,出料口状态指示灯,LeftState_Led,5,HC,Y05,,,,,,,,,,
DO,0,设备照明,Device_Led,6,HC,Y06,,,,,,,,,,
DO,0,相机照明,Camera_Led,7,HC,Y07,,,,,,,,,,
DO,0,进料口电机启动,RightMoto_Run,8,HC,Y08,,,,,,,,,,
DO,0,进料口电机反转指令,RightMoto_Reverse,9,HC,Y09,,,,,,,,,,
DO,0,出料口电机启动,LeftMoto_Run,10,HC,Y10,,,,,,,,,,
DO,0,出料口电机反转指令,LeftMoto_Reverse,11,HC,Y11,,,,,,,,,,
DO,0,进料口阻挡气缸上升,RightStopUP,12,HC,Y12,,,,,,,,,,
DO,0,进料口阻挡气缸下降,RightStopDown,13,HC,Y13,,,,,,,,,,
DO,0,出料口阻挡气缸上升,LeftStopUP,14,HC,Y14,,,,,,,,,,
DO,0,出料口阻挡气缸下降,LeftStopDown,15,HC,Y15,,,,,,,,,,
DO,0,吸嘴气缸前进,LabelCylinder_Fwd,16,HC,Y16,,,,,,,,,,
DO,0,吸嘴气缸后退,LabelCylinder_Bck,17,HC,Y17,,,,,,,,,,
DO,0,吸嘴取标,LabelCylinder_Work,18,HC,Y18,,,,,,,,,,
,,,,,,,,,,,,,,,,
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" 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>{BB23296C-AA1D-45C6-9FA6-5A37B2ABFE9B}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>DeviceLibrary</RootNamespace>
<AssemblyName>DeviceLibrary</AssemblyName>
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<Deterministic>true</Deterministic>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="CodeLibrary">
<HintPath>..\..\GeneralClassLibrary\CodeLibraryProject\CodeLibrary\bin\Debug\CodeLibrary.dll</HintPath>
</Reference>
<Reference Include="halcondotnet">
<HintPath>..\..\RC1271-DUOStore\dll\halcondotnet.dll</HintPath>
</Reference>
<Reference Include="HuichuanLibrary">
<HintPath>..\..\HuichuanLibrary\HuichuanLibrary\bin\Debug\HuichuanLibrary.dll</HintPath>
</Reference>
<Reference Include="log4net">
<HintPath>..\..\增广夹爪\Rmaxis\bin\Debug\log4net.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Drawing" />
<Reference Include="System.Windows.Forms" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="AutoScanAndLabel\AxisBean.cs" />
<Compile Include="AutoScanAndLabel\LabelParam.cs" />
<Compile Include="AutoScanAndLabel\MoveInfo.cs" />
<Compile Include="AutoScanAndLabel\MoveStep.cs" />
<Compile Include="AutoScanAndLabel\MainMachine _Common.cs" />
<Compile Include="AutoScanAndLabel\MainMachine _WorkProcess.cs" />
<Compile Include="DeviceLibrary\CodeManager.cs" />
<Compile Include="AutoScanAndLabel\RobotManage.cs" />
<Compile Include="AutoScanAndLabel\IRobot.cs" />
<Compile Include="AutoScanAndLabel\MainMachine.cs" />
<Compile Include="Class1.cs" />
<Compile Include="DeviceLibrary\IAxisManager.cs" />
<Compile Include="DeviceLibrary\AxisManager.cs" />
<Compile Include="DeviceLibrary\HC\HCAxisManager.cs" />
<Compile Include="DeviceLibrary\HC\HCIOManager.cs" />
<Compile Include="DeviceLibrary\I_IOManager.cs" />
<Compile Include="DeviceLibrary\IOManager.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="userControl\AxisMoveControl.cs">
<SubType>UserControl</SubType>
</Compile>
<Compile Include="userControl\AxisMoveControl.Designer.cs">
<DependentUpon>AxisMoveControl.cs</DependentUpon>
</Compile>
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="userControl\AxisMoveControl.resx">
<DependentUpon>AxisMoveControl.cs</DependentUpon>
</EmbeddedResource>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Common\Common.csproj">
<Project>{43cdd09e-fcf3-4960-a01d-3bbfe9933122}</Project>
<Name>Common</Name>
</ProjectReference>
<ProjectReference Include="..\LoadCVSLibrary\LoadCSVLibrary.csproj">
<Project>{064bebf5-8faa-4ea2-a5f3-a06e6e7d9251}</Project>
<Name>LoadCSVLibrary</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<Content Include="Config\Config.csv">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
</ItemGroup>
<ItemGroup>
<Content Include="Config\Config - 复制.csv">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
\ No newline at end of file
using OnlineStore.Common;
using OnlineStore.LoadCSVLibrary;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DeviceLibrary
{
public class AxisManager
{
public bool IsShowMsg = false;
static IAxisManager instance;
public static bool UseHCBoard = true;
static AxisManager() {
instance = new HCAxisManager();
}
public static bool IsServeoOn(string portName, short slvAddr) {
return instance.IsServeoOn(portName, slvAddr);
}
public static bool OpenCard() {
return instance.OpenCard();
}
public bool CloseCard() {
return instance.CloseCard();
}
public static bool IsHomeMoveEnd(string portName, short slvAddr) {
return instance.IsHomeMoveEnd(portName, slvAddr);
}
public static bool AbsMoveIsEnd(string portName, short axisNo, int targetPosition, int canErrorCount, out bool countError)
{
return instance.AbsMoveIsEnd(portName, axisNo, targetPosition, canErrorCount, out countError);
}
public static void ServoOn(string portName, short slvAddr)
{
instance.ServoOn(portName, slvAddr);
}
public static void ServoOff(string portName, short slvAddr)
{
instance.ServoOff(portName, slvAddr);
}
public static void RelMove(string portName, short slvAddr, int position, int targetSpeed , int ptpAcc , int ptpDec )
{
instance.RelMove(portName, slvAddr, position, targetSpeed, ptpAcc, ptpDec);
}
public static void HomeMove(string portName, short slvAddr, int highVel, int lowVel, int acc)
{
instance.HomeMove(portName, slvAddr, highVel, lowVel, acc);
}
public static void SpeedMove(string portName, short slvAddr, int speed)
{
instance.SpeedMove(portName, slvAddr, speed);
}
public static void SuddenStop(string portName, short slvAddr)
{
instance.SuddenStop(portName, slvAddr);
}
public static bool isInPosition(string portName, short slvAddr, int PPosition, int canErrorCount, bool isLog = false)
{
return instance.isInPosition(portName, slvAddr, PPosition, canErrorCount, isLog);
}
public static void AbsMove(string portName, short slvAddr, int targetPosition, int targetSpeed , int ptpAcc , int ptpDec )
{
instance.AbsMove(portName, slvAddr, targetPosition, targetSpeed, ptpAcc, ptpDec);
}
public static void AlarmClear(string portName, short slvAddr)
{
instance.AlarmClear(portName, slvAddr);
}
public static int GetTargetPosition(string portName, short slvAddr)
{
return instance.GetTargetPosition(portName, slvAddr);
}
public static int GetActualtPosition(string portName, short slvAddr)
{
return instance.GetActualtPosition(portName, slvAddr);
}
public static int GetAlarmStatus(string portName, short slvAddr)
{
return instance.GetAlarmStatus(portName, slvAddr);
}
public static int GetBusyStatus(string portName, short slvAddr)
{
return instance.GetBusyStatus(portName, slvAddr);
}
public static int GetHomeEndStatus(string portName, short slvAddr)
{
return instance.GetHomeEndStatus(portName, slvAddr);
}
public static int GetHomeSingle(string portName, short slvAddr)
{
return instance.GetHomeSingle(portName, slvAddr);
}
/// <summary>
/// 负极限
/// </summary>
public static int GetLimitNegativeSingle(string portName, short slvAddr)
{
return instance.GetLimitNegativeSingle(portName, slvAddr);
}
/// <summary>
/// 正极限
/// </summary>
public static int GetLimitPositiveSingle(string portName, short slvAddr)
{
return instance.GetLimitPositiveSingle(portName, slvAddr);
}
public static short GetErrorCode(string portName, short slvAddr)
{
return instance.GetErrorCode(portName, slvAddr);
}
public static void SuddenStop(ConfigMoveAxis configMoveAxis)
{
SuddenStop(configMoveAxis.DeviceName, configMoveAxis.GetAxisValue());
}
public static int GetActualtPosition(ConfigMoveAxis configMoveAxis) {
return GetActualtPosition(configMoveAxis.DeviceName, configMoveAxis.GetAxisValue());
}
public static bool ServerOnStatus(string portName, short slvAddr) {
return IsServeoOn(portName, slvAddr);
}
public static bool isInPosition(ConfigMoveAxis configMoveAxis, int PPosition, bool isLog = false) {
return isInPosition(configMoveAxis.DeviceName, configMoveAxis.GetAxisValue(), PPosition, configMoveAxis.CanErrorCountMax, isLog);
}
}
}
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!