Commit 59b2af93 张东亮

11

1 个父辈 53cce1c4
正在显示 103 个修改的文件 包含 222 行增加46 行删除
此文件类型无法预览
......@@ -31,16 +31,18 @@
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="log4net">
<HintPath>.\log4net.dll</HintPath>
<Reference Include="log4net, Version=2.0.12.0, Culture=neutral, PublicKeyToken=669e0ddf0bb1aa2a, processorArchitecture=MSIL">
<HintPath>..\packages\log4net.2.0.12\lib\net45\log4net.dll</HintPath>
</Reference>
<Reference Include="Newtonsoft.Json, Version=6.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>.\Newtonsoft.Json.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Configuration" />
<Reference Include="System.Core" />
<Reference Include="System.Drawing" />
<Reference Include="System.Web" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
......@@ -55,5 +57,8 @@
<Compile Include="Node.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
\ No newline at end of file
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
......@@ -10,6 +11,51 @@ namespace Agv
public class Common
{
//包开始字节
public static byte[] headPack = new byte[] { 0xAB, 0xBA };
public static int headSize = 6;//包头识别符2+包头长度4
/// <summary>
/// 节点信息解析方式,默认多个节点同时收发并解析
/// </summary>
public static bool EnDecodeSingleNode = false;
public static bool CheckHeadChar(byte[] head, out int starIdx)
{
starIdx = -1;
for (int i = 0; i < head.Length - headPack.Length+1; i++)
{
int j = 0;
for (j = 0; j < headPack.Length; j++)
{
if (!head[i + j].Equals(headPack[j]))
break;
}
if (j == headPack.Length)
{
starIdx = i;
return true;
}
}
return false;
}
public static string HexBuff(byte[] buff)
{
string s = "";
if (buff == null) return s;
for (int i = 0; i < buff.Length; i++)
s += buff[i].ToString("X2") + " ";
return s;
}
public static string HexBuffWithoutSpace(byte[] buff)
{
string s = "";
if (buff == null) return s;
for (int i = 0; i < buff.Length; i++)
s += buff[i].ToString("X2");
return s;
}
/// <summary>
/// 编码
/// </summary>
......@@ -19,9 +65,11 @@ namespace Agv
{
try
{
string json =JsonHelper.SerializeObject(node);
string json = JsonHelper.SerializeObject(node);
log.debug(string.Format("Encode[{0}]", json));
byte[] buff = System.Text.Encoding.UTF8.GetBytes(json);
byte[] body = Encoding.UTF8.GetBytes(json);
byte[] bodySize = IntToByteArray(body.Length);
byte[] buff = headPack.Concat(bodySize).Concat(body).ToArray();
return buff;
}
catch (Exception ex)
......@@ -42,7 +90,12 @@ namespace Agv
{
string json = JsonHelper.SerializeObject(nodes);
log.debug(string.Format("Encode[{0}]", json));
byte[] buff = System.Text.Encoding.UTF8.GetBytes(json);
byte[] body = Encoding.UTF8.GetBytes(json);
byte[] bodySize = IntToByteArray(body.Length);
byte[] buff = headPack.Concat(bodySize).Concat(body).ToArray();
log.debug(string.Format("headPack:{0}", Common.HexBuff(Common.headPack)));
log.debug(string.Format("bodysize:{0}[{1}]", Common.HexBuff(bodySize), body.Length));
log.debug(string.Format("body:{0}", Common.HexBuff(body)));
return buff;
}
catch (Exception ex)
......@@ -94,6 +147,23 @@ namespace Agv
return null;
}
}
//将数字转换成字节数组
//由数字创建字节数组
public static byte[] IntToByteArray(Int32 src)
{
//创建内存流MemoryStream,stream作为存放 二进制数据 的缓存
using (MemoryStream stream = new MemoryStream())
{
//创建一个BinaryWriter来写二进制数据到stream
using (BinaryWriter write = new BinaryWriter(stream))
{
write.Write(src);//将十进制数字src写到stream中,
return stream.ToArray();//将写到stream中的二进制数据转为字节数组
}
}
}
}
/// <summary>
......
......@@ -27,5 +27,9 @@ namespace Agv
{
LOGGER.Error(errorMsg, ex);
}
public static void warn(string warn)
{
LOGGER.Warn(warn);
}
}
}
......@@ -36,7 +36,10 @@ namespace Agv
/// 料架类型
/// </summary>
public ClientShelf Shelf { set; get; } = ClientShelf.None;
/// <summary>
/// 节点优先级,值越大优先级越低。默认值为0
/// </summary>
public int Priority { get; set; } = 0;
public Node(string name,string rfid="",string mark="",ClientAction action = ClientAction.None,
ClientLevel level = ClientLevel.Low,ClientShelf shelfType = ClientShelf.None,ClientType clientType = ClientType.None)
{
......
此文件的差异太大,无法显示。
此文件类型无法预览
35c3965847f80e2b5445247f75e89b4af09c6e34
196296d5e062c8186fa3b6a47ddf53dd7eeaeb33
......@@ -2,7 +2,9 @@ E:\Neotel\Projects\Gitee\AGV-Com\Agv\bin\Debug\Agv.dll
E:\Neotel\Projects\Gitee\AGV-Com\Agv\bin\Debug\Agv.pdb
E:\Neotel\Projects\Gitee\AGV-Com\Agv\bin\Debug\log4net.dll
E:\Neotel\Projects\Gitee\AGV-Com\Agv\bin\Debug\Newtonsoft.Json.dll
E:\Neotel\Projects\Gitee\AGV-Com\Agv\bin\Debug\log4net.xml
E:\Neotel\Projects\Gitee\AGV-Com\Agv\obj\Debug\Agv.csproj.CoreCompileInputs.cache
E:\Neotel\Projects\Gitee\AGV-Com\Agv\obj\Debug\Agv.csproj.CopyComplete
E:\Neotel\Projects\Gitee\AGV-Com\Agv\obj\Debug\Agv.dll
E:\Neotel\Projects\Gitee\AGV-Com\Agv\obj\Debug\Agv.pdb
E:\Neotel\Projects\Gitee\AGV-Com\Agv\obj\Debug\Agv.csprojAssemblyReference.cache
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="log4net" version="2.0.12" targetFramework="net472" />
</packages>
\ No newline at end of file
......@@ -35,9 +35,6 @@
<LangVersion>8.0</LangVersion>
</PropertyGroup>
<ItemGroup>
<Reference Include="log4net">
<HintPath>..\..\..\..\DLL\log4net.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Web.Extensions" />
......
此文件的差异太大,无法显示。
b85b5ff4afa439da48046bd004c84f66501d0684
7d5e8676cee1b0e36ad2454791cf299bb510c5f0
......@@ -2,7 +2,9 @@ E:\Neotel\Projects\Gitee\AGV-Com\AgvClient\bin\Debug\Agv.Client.dll
E:\Neotel\Projects\Gitee\AGV-Com\AgvClient\bin\Debug\Agv.Client.pdb
E:\Neotel\Projects\Gitee\AGV-Com\AgvClient\bin\Debug\Agv.dll
E:\Neotel\Projects\Gitee\AGV-Com\AgvClient\bin\Debug\Newtonsoft.Json.dll
E:\Neotel\Projects\Gitee\AGV-Com\AgvClient\bin\Debug\log4net.dll
E:\Neotel\Projects\Gitee\AGV-Com\AgvClient\bin\Debug\Agv.pdb
E:\Neotel\Projects\Gitee\AGV-Com\AgvClient\bin\Debug\log4net.xml
E:\Neotel\Projects\Gitee\AGV-Com\AgvClient\obj\Debug\Client.csprojAssemblyReference.cache
E:\Neotel\Projects\Gitee\AGV-Com\AgvClient\obj\Debug\Client.csproj.CoreCompileInputs.cache
E:\Neotel\Projects\Gitee\AGV-Com\AgvClient\obj\Debug\Client.csproj.CopyComplete
......
......@@ -34,11 +34,13 @@
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="log4net">
<HintPath>..\..\..\DLL\log4net.dll</HintPath>
<Reference Include="log4net, Version=2.0.12.0, Culture=neutral, PublicKeyToken=669e0ddf0bb1aa2a, processorArchitecture=MSIL">
<HintPath>..\packages\log4net.2.0.12\lib\net45\log4net.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Configuration" />
<Reference Include="System.Core" />
<Reference Include="System.Web" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
......@@ -71,6 +73,7 @@
<DependentUpon>Resources.resx</DependentUpon>
<DesignTime>True</DesignTime>
</Compile>
<None Include="packages.config" />
<None Include="Properties\Settings.settings">
<Generator>SettingsSingleFileGenerator</Generator>
<LastGenOutput>Settings.Designer.cs</LastGenOutput>
......
......@@ -7,19 +7,19 @@
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.2"/>
</startup>
<log4net>
<appender name="AgvClient" type="log4net.Appender.RollingFileAppender">
<file value="logs/AgvClient.log"/>
<appender name="Agv" type="log4net.Appender.RollingFileAppender">
<file value="logs/Agv.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"/>
<conversionPattern value="[%date][%t][%c:%L]%-5p %m%n"/>
</layout>
</appender>
<root>
<level value="debug"/>
<appender-ref ref="AgvClient"/>
<level value="Info"/>
<appender-ref ref="Agv"/>
</root>
</log4net>
</configuration>
......@@ -21,6 +21,7 @@ namespace AgvClientTest
private void Form1_Load(object sender, EventArgs e)
{
Agv.Common.EnDecodeSingleNode = false;
server = new Agv.Server();
server.NodeChanged += Server_NodeChanged;
server.NodeOnline += Server_NodeOnline;
......@@ -37,39 +38,32 @@ namespace AgvClientTest
client.Connected += Client_Connected;
}
private void Client_Log(string s)
{
Agv.log.info(s);
}
private void Server_NodeChanged(Agv.Node clientNode)
{
this.Invoke(new Action(() =>
{
label8.Text = "从客户端接收:" + clientNode.ToText();
listBox1.Items.Add(clientNode.ToText());
listBox1.SelectedIndex = listBox1.Items.Count - 1;
}
));
}
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
try
{
if (server != null)
{
server.NodeChanged -= Server_NodeChanged;
server.NodeOnline -= Server_NodeOnline;
server.Stop();
server = null;
}
if (client != null)
{
client.Received -= Client_Received;
client.Connected -= Client_Connected;
client.Close();
client = null;
}
}
catch { }
}
private void button1_Click(object sender, EventArgs e)
{
//comboBox1.Items.AddRange(Enum.GetNames(typeof(Agv.ClientAction)));
//comboBox2.Items.AddRange(Enum.GetNames(typeof(Agv.ClientLevel)));
//comboBox3.Items.AddRange(Enum.GetNames(typeof(Agv.ClientType)));
//comboBox4.Items.AddRange(Enum.GetNames(typeof(Agv.ClientShelf)));
int i1 = comboBox1.SelectedIndex;
int i2 = comboBox2.SelectedIndex;
int i3 = comboBox4.SelectedIndex;
......@@ -80,7 +74,11 @@ namespace AgvClientTest
//client.SetStatus(textBox1.Text,textBox3.Text,textBox2.Text, (Agv.ClientAction)i1,
// (Agv.ClientLevel)i2,(Agv.ClientShelf)i3,
// (Agv.ClientType)i4);
client.SetStatus(textBox1.Text, textBox3.Text, textBox2.Text, (Agv.ClientAction)i1, (Agv.ClientLevel)i2, (Agv.ClientShelf)i3);
client.SetStatus(textBox1.Text, textBox3.Text, textBox2.Text, (Agv.ClientAction)i1, (Agv.ClientLevel)i2, (Agv.ClientShelf)i3, (Agv.ClientType)i4);//, (Agv.ClientShelf)i3
//for (int i = 0; i < 100; i++)
//{
// client.SetStatus(string.Format("A{0}",i), textBox3.Text, textBox2.Text, (Agv.ClientAction)i1, (Agv.ClientLevel)i2, (Agv.ClientShelf)i3, (Agv.ClientType)i4);
//}
}));
task.Start();
......@@ -123,7 +121,6 @@ namespace AgvClientTest
private void button4_Click(object sender, EventArgs e)
{
client.Connect(textBox4.Text, int.Parse(textBox5.Text));
}
......@@ -131,6 +128,8 @@ namespace AgvClientTest
{
this.Invoke(new Action(() =>
{
if (label3 == null)
return;
if (!status)
label13.BackColor = Color.Red;
else
......@@ -143,7 +142,8 @@ namespace AgvClientTest
{
this.Invoke(new Action(() =>
{
label12.Text = "从服务端端接收:" + node.ToText();
listBox2.Items.Add(node.ToText());
listBox2.SelectedIndex = listBox2.Items.Count - 1;
}
));
}
......@@ -173,5 +173,55 @@ namespace AgvClientTest
}
}
private void button8_Click(object sender, EventArgs e)
{
textBox6.Text = "";
try
{
int i1 = comboBox1.SelectedIndex;
int i2 = comboBox2.SelectedIndex;
int i3 = comboBox4.SelectedIndex;
int i4 = comboBox3.SelectedIndex;
Agv.Node node = new Agv.Node()
{
Name = textBox1.Text,
Mark = textBox3.Text,
RFID = textBox2.Text,
Action = (Agv.ClientAction)i1,
Level = (Agv.ClientLevel)i2,
Shelf = (Agv.ClientShelf)i3,
Type = (Agv.ClientType)i4
};
byte[] buff = Agv.Common.Encode(node);
textBox6.Text = Agv.Common.HexBuffWithoutSpace(buff);
}
catch
{
textBox6.Text = "";
}
}
private void Form1_FormClosed(object sender, FormClosedEventArgs e)
{
//try
//{
// if (server != null)
// {
// server.NodeChanged -= Server_NodeChanged;
// server.NodeOnline -= Server_NodeOnline;
// server.Stop();
// server = null;
// }
// if (client != null)
// {
// client.Received -= Client_Received;
// client.Connected -= Client_Connected;
// client.Close();
// client = null;
// }
//}
//catch { }
}
}
}
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler,log4net"/>
</configSections>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.2"/>
</startup>
<log4net>
<appender name="Agv" type="log4net.Appender.RollingFileAppender">
<file value="logs/Agv.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][%c:%L]%-5p %m%n"/>
</layout>
</appender>
<root>
<level value="Info"/>
<appender-ref ref="Agv"/>
</root>
</log4net>
</configuration>
此文件的差异太大,无法显示。
......@@ -7,19 +7,19 @@
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.2"/>
</startup>
<log4net>
<appender name="AgvClient" type="log4net.Appender.RollingFileAppender">
<file value="logs/AgvClient.log"/>
<appender name="Agv" type="log4net.Appender.RollingFileAppender">
<file value="logs/Agv.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"/>
<conversionPattern value="[%date][%t][%c:%L]%-5p %m%n"/>
</layout>
</appender>
<root>
<level value="debug"/>
<appender-ref ref="AgvClient"/>
<level value="Info"/>
<appender-ref ref="Agv"/>
</root>
</log4net>
</configuration>
此文件的差异太大,无法显示。
[2021-04-26 16:46:04,148][5][Agv.log:19]INFO 连接到服务端[127.0.0.1:9501]成功
[2021-04-26 16:46:06,201][6][Agv.log:19]INFO SetStatus To Server[127.0.0.1:9501]:[Name=A1,RFID=D1,Mark=2-1A,cut,Action=None,Level=Low,Type=None,Shelf=None]
[2021-04-26 16:46:11,167][3][Agv.log:19]INFO 客户端已关闭
此文件的差异太大,无法显示。
f0308ac44290cb39c7a1e5c49291c49b056787f6
6dc610c4077a2c876673a453687d9aecd2273b3b
......@@ -44,10 +44,12 @@ E:\Neotel\Projects\Gitee\AGV-Com\AgvClientTest\bin\Debug\AgvClientTest.pdb
E:\Neotel\Projects\Gitee\AGV-Com\AgvClientTest\bin\Debug\Agv.Client.dll
E:\Neotel\Projects\Gitee\AGV-Com\AgvClientTest\bin\Debug\Agv.dll
E:\Neotel\Projects\Gitee\AGV-Com\AgvClientTest\bin\Debug\Agv.Server.dll
E:\Neotel\Projects\Gitee\AGV-Com\AgvClientTest\bin\Debug\log4net.dll
E:\Neotel\Projects\Gitee\AGV-Com\AgvClientTest\bin\Debug\Newtonsoft.Json.dll
E:\Neotel\Projects\Gitee\AGV-Com\AgvClientTest\bin\Debug\Agv.Client.pdb
E:\Neotel\Projects\Gitee\AGV-Com\AgvClientTest\bin\Debug\Agv.pdb
E:\Neotel\Projects\Gitee\AGV-Com\AgvClientTest\bin\Debug\Agv.Server.pdb
E:\Neotel\Projects\Gitee\AGV-Com\AgvClientTest\bin\Debug\log4net.xml
E:\Neotel\Projects\Gitee\AGV-Com\AgvClientTest\obj\Debug\AgvClientTest.csprojAssemblyReference.cache
E:\Neotel\Projects\Gitee\AGV-Com\AgvClientTest\obj\Debug\AgvClientTest.Form1.resources
E:\Neotel\Projects\Gitee\AGV-Com\AgvClientTest\obj\Debug\AgvClientTest.Properties.Resources.resources
......
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="log4net" version="2.0.12" targetFramework="net472" />
</packages>
\ No newline at end of file
此文件的差异太大,无法显示。
......@@ -4,6 +4,7 @@ E:\Neotel\Projects\Gitee\AGV-Com\Server\bin\Debug\Agv.dll
E:\Neotel\Projects\Gitee\AGV-Com\Server\bin\Debug\Newtonsoft.Json.dll
E:\Neotel\Projects\Gitee\AGV-Com\Server\bin\Debug\log4net.dll
E:\Neotel\Projects\Gitee\AGV-Com\Server\bin\Debug\Agv.pdb
E:\Neotel\Projects\Gitee\AGV-Com\Server\bin\Debug\log4net.xml
E:\Neotel\Projects\Gitee\AGV-Com\Server\obj\Debug\Server.csprojAssemblyReference.cache
E:\Neotel\Projects\Gitee\AGV-Com\Server\obj\Debug\Server.csproj.CoreCompileInputs.cache
E:\Neotel\Projects\Gitee\AGV-Com\Server\obj\Debug\Server.csproj.CopyComplete
......
此文件类型无法预览
此文件的差异太大,无法显示。
此文件的差异太大,无法显示。
此文件的差异太大,无法显示。
此文件的差异太大,无法显示。
此文件的差异太大,无法显示。
此文件的差异太大,无法显示。
此文件的差异太大,无法显示。
此文件的差异太大,无法显示。
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!