add emulator
This commit is contained in:
25
Emulator/AGVEmulator.sln
Normal file
25
Emulator/AGVEmulator.sln
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
|
||||||
|
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||||
|
# Visual Studio Version 17
|
||||||
|
VisualStudioVersion = 17.6.33801.468
|
||||||
|
MinimumVisualStudioVersion = 10.0.40219.1
|
||||||
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AGVEmulator", "AGVEmulator\AGVEmulator.csproj", "{9312AB43-72F6-4365-A266-E767215FA7F5}"
|
||||||
|
EndProject
|
||||||
|
Global
|
||||||
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
|
Debug|Any CPU = Debug|Any CPU
|
||||||
|
Release|Any CPU = Release|Any CPU
|
||||||
|
EndGlobalSection
|
||||||
|
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||||
|
{9312AB43-72F6-4365-A266-E767215FA7F5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
{9312AB43-72F6-4365-A266-E767215FA7F5}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{9312AB43-72F6-4365-A266-E767215FA7F5}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
{9312AB43-72F6-4365-A266-E767215FA7F5}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
|
EndGlobalSection
|
||||||
|
GlobalSection(SolutionProperties) = preSolution
|
||||||
|
HideSolutionNode = FALSE
|
||||||
|
EndGlobalSection
|
||||||
|
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||||
|
SolutionGuid = {6F494EC0-1316-409F-8C1A-D882BBF25D13}
|
||||||
|
EndGlobalSection
|
||||||
|
EndGlobal
|
||||||
121
Emulator/AGVEmulator/AGVEmulator.csproj
Normal file
121
Emulator/AGVEmulator/AGVEmulator.csproj
Normal file
@@ -0,0 +1,121 @@
|
|||||||
|
<?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>{9312AB43-72F6-4365-A266-E767215FA7F5}</ProjectGuid>
|
||||||
|
<OutputType>WinExe</OutputType>
|
||||||
|
<RootNamespace>AGVEmulator</RootNamespace>
|
||||||
|
<AssemblyName>AGVEmulator</AssemblyName>
|
||||||
|
<TargetFrameworkVersion>v4.8</TargetFrameworkVersion>
|
||||||
|
<FileAlignment>512</FileAlignment>
|
||||||
|
<Deterministic>true</Deterministic>
|
||||||
|
<TargetFrameworkProfile />
|
||||||
|
</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>
|
||||||
|
<Prefer32Bit>false</Prefer32Bit>
|
||||||
|
</PropertyGroup>
|
||||||
|
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||||
|
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||||
|
<DebugType>pdbonly</DebugType>
|
||||||
|
<Optimize>true</Optimize>
|
||||||
|
<OutputPath>bin\Release\</OutputPath>
|
||||||
|
<DefineConstants>TRACE</DefineConstants>
|
||||||
|
<ErrorReport>prompt</ErrorReport>
|
||||||
|
<WarningLevel>4</WarningLevel>
|
||||||
|
<Prefer32Bit>false</Prefer32Bit>
|
||||||
|
</PropertyGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<Reference Include="arControl.Net4">
|
||||||
|
<HintPath>..\arControl.Net4.dll</HintPath>
|
||||||
|
</Reference>
|
||||||
|
<Reference Include="arFrameControl">
|
||||||
|
<HintPath>..\arFrameControl.dll</HintPath>
|
||||||
|
</Reference>
|
||||||
|
<Reference Include="ArLog.Net4">
|
||||||
|
<HintPath>..\ArLog.Net4.dll</HintPath>
|
||||||
|
</Reference>
|
||||||
|
<Reference Include="ArSetting.Net4">
|
||||||
|
<HintPath>..\ArSetting.Net4.dll</HintPath>
|
||||||
|
</Reference>
|
||||||
|
<Reference Include="System" />
|
||||||
|
<Reference Include="System.Core" />
|
||||||
|
<Reference Include="System.Xml.Linq" />
|
||||||
|
<Reference Include="System.Data.DataSetExtensions" />
|
||||||
|
<Reference Include="Microsoft.CSharp" />
|
||||||
|
<Reference Include="System.Data" />
|
||||||
|
<Reference Include="System.Deployment" />
|
||||||
|
<Reference Include="System.Drawing" />
|
||||||
|
<Reference Include="System.Windows.Forms" />
|
||||||
|
<Reference Include="System.Xml" />
|
||||||
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<Compile Include="DevAGV.cs" />
|
||||||
|
<Compile Include="DevBMS.cs" />
|
||||||
|
<Compile Include="DevCAL.cs" />
|
||||||
|
<Compile Include="DevPLC.cs" />
|
||||||
|
<Compile Include="Form1.cs">
|
||||||
|
<SubType>Form</SubType>
|
||||||
|
</Compile>
|
||||||
|
<Compile Include="Form1.Designer.cs">
|
||||||
|
<DependentUpon>Form1.cs</DependentUpon>
|
||||||
|
</Compile>
|
||||||
|
<Compile Include="Program.cs" />
|
||||||
|
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||||
|
<Compile Include="RS232.cs" />
|
||||||
|
<Compile Include="UC\SerialConn.cs">
|
||||||
|
<SubType>UserControl</SubType>
|
||||||
|
</Compile>
|
||||||
|
<Compile Include="UC\SerialConn.Designer.cs">
|
||||||
|
<DependentUpon>SerialConn.cs</DependentUpon>
|
||||||
|
</Compile>
|
||||||
|
<Compile Include="UC\AgvViewer.cs">
|
||||||
|
<SubType>Component</SubType>
|
||||||
|
</Compile>
|
||||||
|
<Compile Include="UC\AgvViewer.Designer.cs">
|
||||||
|
<DependentUpon>AgvViewer.cs</DependentUpon>
|
||||||
|
</Compile>
|
||||||
|
<EmbeddedResource Include="Form1.resx">
|
||||||
|
<DependentUpon>Form1.cs</DependentUpon>
|
||||||
|
</EmbeddedResource>
|
||||||
|
<EmbeddedResource Include="Properties\Resources.resx">
|
||||||
|
<Generator>ResXFileCodeGenerator</Generator>
|
||||||
|
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
|
||||||
|
<SubType>Designer</SubType>
|
||||||
|
</EmbeddedResource>
|
||||||
|
<Compile Include="Properties\Resources.Designer.cs">
|
||||||
|
<AutoGen>True</AutoGen>
|
||||||
|
<DependentUpon>Resources.resx</DependentUpon>
|
||||||
|
<DesignTime>True</DesignTime>
|
||||||
|
</Compile>
|
||||||
|
<EmbeddedResource Include="UC\SerialConn.resx">
|
||||||
|
<DependentUpon>SerialConn.cs</DependentUpon>
|
||||||
|
</EmbeddedResource>
|
||||||
|
<None Include="app.config" />
|
||||||
|
<None Include="packetFD.bin">
|
||||||
|
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||||
|
</None>
|
||||||
|
<None Include="packetFC.bin">
|
||||||
|
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||||
|
</None>
|
||||||
|
<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>
|
||||||
|
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||||
|
</Project>
|
||||||
586
Emulator/AGVEmulator/DevAGV.cs
Normal file
586
Emulator/AGVEmulator/DevAGV.cs
Normal file
@@ -0,0 +1,586 @@
|
|||||||
|
using arCtl;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Drawing;
|
||||||
|
using System.Linq;
|
||||||
|
|
||||||
|
namespace AGVEmulator
|
||||||
|
{
|
||||||
|
class DevAGV : AR.Dev.RS232
|
||||||
|
{
|
||||||
|
//######### private variable
|
||||||
|
byte runtime = 0;
|
||||||
|
|
||||||
|
//######### public variable
|
||||||
|
public UInt16 system0 = 0;
|
||||||
|
public UInt16 system1 = 0;
|
||||||
|
public UInt16 error = 0;
|
||||||
|
public byte signal = 0;
|
||||||
|
public char sts_bunki = 'S';
|
||||||
|
public char sts_speed = 'L';
|
||||||
|
public char sts_dir = 'F';
|
||||||
|
public char sts_sensor = '1';
|
||||||
|
|
||||||
|
|
||||||
|
public enum eCommand : byte
|
||||||
|
{
|
||||||
|
LOAD = 0, //EEPROM 불러오기
|
||||||
|
SAVE, //EEPROM 저장
|
||||||
|
RESET, //초기화
|
||||||
|
PINGCHK,
|
||||||
|
SET_PINMODE, //PINMODE 설정
|
||||||
|
SET_DOUTPUT, //디지털출력설정(포트번호,값[1,0])
|
||||||
|
SET_AOUTPUT, //아날로그출력설정(포트GET_SETTING = 50, //셋팅값 요청
|
||||||
|
SET_FLAG,
|
||||||
|
SET_EEPROM,
|
||||||
|
SET_MANUALSPEED,
|
||||||
|
GET_SETTING = 50,
|
||||||
|
GUIDE_MOT = 90, //가이드커버(양쪽) 0=멈춤,1=UP,2=DN 아스키코드표 90=Z
|
||||||
|
SET_EEP_DIREV,
|
||||||
|
};
|
||||||
|
|
||||||
|
public enum DOName
|
||||||
|
{
|
||||||
|
PINO_GUIDEMOTOR_LDIR,
|
||||||
|
PINO_GUIDEMOTOR_LRUN,
|
||||||
|
PINO_GUIDEMOTOR_RDIR,
|
||||||
|
PINO_GUIDEMOTOR_RRUN,
|
||||||
|
PINO_EMPTY_26,
|
||||||
|
PINO_EMPTY_27,
|
||||||
|
PINO_EMPTY_28,
|
||||||
|
PINO_EMPTY_29,
|
||||||
|
}
|
||||||
|
|
||||||
|
public enum DIName
|
||||||
|
{
|
||||||
|
PINI_EMG,
|
||||||
|
PINI_BTN_1,
|
||||||
|
PINI_BTN_2,
|
||||||
|
PINI_BTN_3,
|
||||||
|
PINI_BTN_4,
|
||||||
|
PINI_OVERLOADL,
|
||||||
|
PINI_OVERLOADR,
|
||||||
|
PINI_EMPTY_36,
|
||||||
|
PINI_EMPTY_37,
|
||||||
|
PINI_EMPTY_38,
|
||||||
|
PINI_BTN_ZUP,
|
||||||
|
PINI_BTN_ZDN,
|
||||||
|
PINI_LIMIT_LU,
|
||||||
|
PINI_LIMIT_LD,
|
||||||
|
PINI_LIMIT_RU,
|
||||||
|
PINI_LIMIT_RD,
|
||||||
|
PINI_STOP,
|
||||||
|
}
|
||||||
|
public enum eerror
|
||||||
|
{
|
||||||
|
Emergency = 0,
|
||||||
|
Overcurrent,
|
||||||
|
Charger_run_error,
|
||||||
|
Charger_pos_error,
|
||||||
|
line_out_error = 4,
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 기동시 자석 감지 에러
|
||||||
|
/// </summary>
|
||||||
|
runerror_by_no_magent_line,
|
||||||
|
/// <summary>
|
||||||
|
/// 호출제어기 통신 오류
|
||||||
|
/// </summary>
|
||||||
|
controller_comm_error = 11,
|
||||||
|
/// <summary>
|
||||||
|
/// 도착경보기 통신 오류
|
||||||
|
/// </summary>
|
||||||
|
arrive_ctl_comm_error,
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 자동문제어기 통신 오류
|
||||||
|
/// </summary>
|
||||||
|
door_ctl_comm_error,
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 자동충전기 통신 오류
|
||||||
|
/// </summary>
|
||||||
|
charger_comm_error,
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 교차로 제어기 통신 오류
|
||||||
|
/// </summary>
|
||||||
|
cross_ctrl_comm_error,
|
||||||
|
}
|
||||||
|
public enum esignal
|
||||||
|
{
|
||||||
|
front_gate_out = 0,
|
||||||
|
rear_sensor_out,
|
||||||
|
mark_sensor_1,
|
||||||
|
mark_sensor_2,
|
||||||
|
front_left_sensor,
|
||||||
|
front_right_sensor,
|
||||||
|
front_center_sensor,
|
||||||
|
charger_align_sensor,
|
||||||
|
}
|
||||||
|
public enum esystemflag0
|
||||||
|
{
|
||||||
|
Memory_RW_State = 5,
|
||||||
|
EXT_IO_Conn_State,
|
||||||
|
RFID_Conn_State,
|
||||||
|
M5E_Module_Run_State = 8,
|
||||||
|
Front_Ultrasonic_Conn_State,
|
||||||
|
Front_Untrasonic_Sensor_State,
|
||||||
|
Side_Ultrasonic_Conn_State,
|
||||||
|
Side_Ultrasonic_Sensor_State = 12,
|
||||||
|
Front_Guide_Sensor_State,
|
||||||
|
Rear_Guide_Sensor_State,
|
||||||
|
Battery_Level_Check
|
||||||
|
}
|
||||||
|
public enum esystemflag1
|
||||||
|
{
|
||||||
|
Side_Detect_Ignore = 3,
|
||||||
|
Melody_check,
|
||||||
|
Mark2_check,
|
||||||
|
Mark1_check,
|
||||||
|
gateout_check,
|
||||||
|
Battery_charging = 8,
|
||||||
|
re_Start,
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 전방 감지 무시
|
||||||
|
/// </summary>
|
||||||
|
front_detect_ignore,
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 전방장애물감지상태
|
||||||
|
/// </summary>
|
||||||
|
front_detect_check,
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 전방감지 후 정지 상태
|
||||||
|
/// </summary>
|
||||||
|
stop_by_front_detect = 12,
|
||||||
|
/// <summary>
|
||||||
|
/// 교차로 진입 후 정지 상태
|
||||||
|
/// </summary>
|
||||||
|
stop_by_cross_in,
|
||||||
|
agv_stop,
|
||||||
|
agv_run
|
||||||
|
}
|
||||||
|
|
||||||
|
public enum evaluetype
|
||||||
|
{
|
||||||
|
system0,
|
||||||
|
system1,
|
||||||
|
error,
|
||||||
|
signal,
|
||||||
|
}
|
||||||
|
public enum estsvaluetype
|
||||||
|
{
|
||||||
|
bunki,
|
||||||
|
speed,
|
||||||
|
direction,
|
||||||
|
sensor
|
||||||
|
}
|
||||||
|
public class ValueChangedArgs : EventArgs
|
||||||
|
{
|
||||||
|
public int Idx { get; set; }
|
||||||
|
public bool Value { get; set; }
|
||||||
|
public evaluetype vtype { get; set; }
|
||||||
|
public ValueChangedArgs(int idx, bool val, evaluetype isOut)
|
||||||
|
{
|
||||||
|
this.Idx = idx;
|
||||||
|
this.Value = val;
|
||||||
|
this.vtype = isOut;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public class StsValueChangedArgs : EventArgs
|
||||||
|
{
|
||||||
|
public char Value { get; set; }
|
||||||
|
public estsvaluetype vtype { get; set; }
|
||||||
|
public StsValueChangedArgs(estsvaluetype vType, char val)
|
||||||
|
{
|
||||||
|
this.Value = val;
|
||||||
|
this.vtype = vType;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public class RequestStatusDataArgs : EventArgs
|
||||||
|
{
|
||||||
|
public UInt16 system0 { get; set; } = 0;
|
||||||
|
public UInt16 system1 { get; set; } = 0;
|
||||||
|
public char speed { get; set; } = 'L';
|
||||||
|
public char direction { get; set; } = 'F';
|
||||||
|
public char bunki { get; set; } = 'S';
|
||||||
|
|
||||||
|
public byte signal { get; set; } = 0;
|
||||||
|
public float volt { get; set; } = 0f;
|
||||||
|
public UInt16 error { get; set; } = 0;
|
||||||
|
public char sensor { get; set; } = '0';
|
||||||
|
public RequestStatusDataArgs()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public event EventHandler<RequestStatusDataArgs> RequestStatusData;
|
||||||
|
public event EventHandler<ValueChangedArgs> ValueChanged;
|
||||||
|
public event EventHandler<StsValueChangedArgs> StsValueChanged;
|
||||||
|
|
||||||
|
public class commandargs : EventArgs
|
||||||
|
{
|
||||||
|
public string Command { get; set; }
|
||||||
|
public commandargs(string cmd)
|
||||||
|
{
|
||||||
|
this.Command = cmd;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public event EventHandler<commandargs> Command;
|
||||||
|
public class FrameData
|
||||||
|
{
|
||||||
|
public string Checksum { get; set; }
|
||||||
|
public byte stx { get; set; }
|
||||||
|
public byte etx { get; set; }
|
||||||
|
public string cmd { get; set; }
|
||||||
|
public string data { get; set; }
|
||||||
|
public FrameData(byte[] data)
|
||||||
|
{
|
||||||
|
this.stx = data[0];
|
||||||
|
this.etx = data[data.Length - 1];
|
||||||
|
this.Checksum = System.Text.Encoding.Default.GetString(data, data.Length - 3, 2);
|
||||||
|
this.data = System.Text.Encoding.Default.GetString(data, 1, data.Length - 4);
|
||||||
|
this.cmd = this.data.Substring(0, 3);
|
||||||
|
this.data = this.data.Substring(3);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#region SetAGV/SetSTS/SetBIT/GetBIT
|
||||||
|
Boolean GetBit(ref UInt16 _value, int idx)
|
||||||
|
{
|
||||||
|
var offset = (UInt16)(1 << idx);
|
||||||
|
return (_value & offset) != 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
Boolean GetBit(ref byte _value, int idx)
|
||||||
|
{
|
||||||
|
var offset = (byte)(1 << idx);
|
||||||
|
return (_value & offset) != 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool SetBit(ref UInt16 _value, int idx, Boolean value)
|
||||||
|
{
|
||||||
|
var oldvalue = GetBit(ref _value, idx);
|
||||||
|
if (value)
|
||||||
|
{
|
||||||
|
var offset = (UInt16)(1 << idx);
|
||||||
|
_value = (UInt16)(_value | offset);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
var offset = (UInt16)(~(1 << idx));
|
||||||
|
_value = (UInt16)(_value & offset);
|
||||||
|
}
|
||||||
|
return oldvalue != value;
|
||||||
|
}
|
||||||
|
bool SetBit(ref byte _value, int idx, Boolean value)
|
||||||
|
{
|
||||||
|
var oldvalue = GetBit(ref _value, idx);
|
||||||
|
if (value)
|
||||||
|
{
|
||||||
|
var offset = (byte)(1 << idx);
|
||||||
|
_value = (byte)(_value | offset);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
var offset = (byte)(~(1 << idx));
|
||||||
|
_value = (byte)(_value & offset);
|
||||||
|
}
|
||||||
|
return oldvalue != value;
|
||||||
|
}
|
||||||
|
public bool GetAGV(DevAGV.esystemflag1 flag)
|
||||||
|
{
|
||||||
|
var idx = (int)flag;
|
||||||
|
return GetBit(ref system1, idx);
|
||||||
|
}
|
||||||
|
public void SetAGV(DevAGV.esystemflag0 flag, bool value)
|
||||||
|
{
|
||||||
|
var idx = (int)flag;
|
||||||
|
if (SetBit(ref system0, idx, value))
|
||||||
|
ValueChanged?.Invoke(this, new ValueChangedArgs(idx, value, evaluetype.system0));
|
||||||
|
}
|
||||||
|
public void SetAGV(DevAGV.esystemflag1 flag, bool value)
|
||||||
|
{
|
||||||
|
var idx = (int)flag;
|
||||||
|
if (SetBit(ref system1, idx, value))
|
||||||
|
ValueChanged?.Invoke(this, new ValueChangedArgs(idx, value, evaluetype.system1));
|
||||||
|
}
|
||||||
|
public void SetAGV(DevAGV.eerror flag, bool value)
|
||||||
|
{
|
||||||
|
var idx = (int)flag;
|
||||||
|
if (SetBit(ref error, idx, value))
|
||||||
|
ValueChanged?.Invoke(this, new ValueChangedArgs(idx, value, evaluetype.error));
|
||||||
|
}
|
||||||
|
public void SetAGV(DevAGV.esignal flag, bool value)
|
||||||
|
{
|
||||||
|
var idx = (int)flag;
|
||||||
|
if (SetBit(ref signal, idx, value))
|
||||||
|
ValueChanged?.Invoke(this, new ValueChangedArgs(idx, value, evaluetype.signal));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void SetSTS(estsvaluetype target, char value)
|
||||||
|
{
|
||||||
|
//bool changed = false;
|
||||||
|
switch (target)
|
||||||
|
{
|
||||||
|
case estsvaluetype.sensor:
|
||||||
|
//changed = this.sts_sensor.Equals(value);
|
||||||
|
sts_sensor = value;
|
||||||
|
break;
|
||||||
|
case estsvaluetype.direction:
|
||||||
|
//changed = this.sts_dir.Equals(value);
|
||||||
|
sts_dir = value;
|
||||||
|
break;
|
||||||
|
case estsvaluetype.speed:
|
||||||
|
//changed = this.sts_speed.Equals(value);
|
||||||
|
sts_speed = value;
|
||||||
|
break;
|
||||||
|
case estsvaluetype.bunki:
|
||||||
|
//changed = this.sts_bunki.Equals(value);
|
||||||
|
sts_bunki = value;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
//if(changed)
|
||||||
|
{
|
||||||
|
StsValueChanged?.Invoke(this, new StsValueChangedArgs(target, value));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
public override bool ProcessRecvData(byte[] data)
|
||||||
|
{
|
||||||
|
//dd로 시작하고 34개의 데이터
|
||||||
|
//STS258FFFF40000000LSF0000003A
|
||||||
|
//02 53 54 53 32 35 38 46 46 46 46 34 30 30 30 30 30 30 30 4C 53 46 30 30 30 30 30 30 33 41 03
|
||||||
|
var frame = new FrameData(data);
|
||||||
|
|
||||||
|
switch (frame.cmd)
|
||||||
|
{
|
||||||
|
case "CRN": //기동명령
|
||||||
|
//sts_dir = frame.data[0];
|
||||||
|
SetSTS(estsvaluetype.direction, frame.data[0]);
|
||||||
|
SetAGV(esystemflag1.agv_stop, false);
|
||||||
|
SetAGV(esystemflag1.agv_run, true);
|
||||||
|
break;
|
||||||
|
case "CST": //중지명령
|
||||||
|
//(바로 중지한다)
|
||||||
|
if (frame.data.StartsWith("M"))
|
||||||
|
{
|
||||||
|
Command?.Invoke(this, new commandargs("stopmark"));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
SetAGV(esystemflag1.agv_run, false);
|
||||||
|
SetAGV(esystemflag1.agv_stop, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
case "CBR": //분기명령
|
||||||
|
//FSL
|
||||||
|
SetSTS(estsvaluetype.direction, frame.data[0]);
|
||||||
|
SetSTS(estsvaluetype.bunki, frame.data[1]);
|
||||||
|
SetSTS(estsvaluetype.speed, frame.data[2]);
|
||||||
|
SetSTS(estsvaluetype.sensor, frame.data[3]);
|
||||||
|
break;
|
||||||
|
case "CRT"://수동제어
|
||||||
|
sts_dir = frame.data[0];
|
||||||
|
sts_bunki = frame.data[1];
|
||||||
|
sts_speed = frame.data[2];
|
||||||
|
sts_sensor = frame.data[3];
|
||||||
|
SetAGV(esystemflag1.agv_stop, false);
|
||||||
|
SetAGV(esystemflag1.agv_run, true);
|
||||||
|
break;
|
||||||
|
case "ACK": //응답ok
|
||||||
|
RaiseMessage(MessageType.Normal, $">> {frame.cmd} DATA={frame.data}");
|
||||||
|
break;
|
||||||
|
case "SFR": //reset
|
||||||
|
SetAGV(DevAGV.eerror.Emergency, false);
|
||||||
|
SetAGV(DevAGV.eerror.line_out_error, false);
|
||||||
|
SetAGV(DevAGV.eerror.Overcurrent, false);
|
||||||
|
SetAGV(DevAGV.esystemflag1.agv_run, false);
|
||||||
|
SetAGV(DevAGV.esystemflag1.agv_stop, true);
|
||||||
|
break;
|
||||||
|
case "CBT"://충전작업
|
||||||
|
SetAGV(DevAGV.esystemflag1.Battery_charging, true);
|
||||||
|
var id = frame.data.Substring(2, 2);
|
||||||
|
var cmd = frame.data[4];
|
||||||
|
var delaytime = int.Parse(frame.data.Substring(5));
|
||||||
|
if (cmd == 'I') SetAGV(DevAGV.esystemflag1.Battery_charging, true);
|
||||||
|
else SetAGV(esystemflag1.Battery_charging, false);
|
||||||
|
break;
|
||||||
|
case "SSH":
|
||||||
|
case "SSM":
|
||||||
|
case "SSL":
|
||||||
|
case "SSS":
|
||||||
|
case "SHS":
|
||||||
|
case "SLS":
|
||||||
|
case "SPK":
|
||||||
|
case "SPM":
|
||||||
|
case "SPL":
|
||||||
|
case "SPS":
|
||||||
|
case "SIK":
|
||||||
|
case "SIM":
|
||||||
|
case "SIH":
|
||||||
|
case "SIL":
|
||||||
|
case "SIS":
|
||||||
|
case "SDK":
|
||||||
|
case "SDW":
|
||||||
|
case "SDL":
|
||||||
|
case "SDS":
|
||||||
|
case "SRS":
|
||||||
|
case "SCK":
|
||||||
|
case "SSK":
|
||||||
|
case "STT":
|
||||||
|
case "SSI":
|
||||||
|
case "SMD":
|
||||||
|
case "SSC":
|
||||||
|
case "SPN":
|
||||||
|
case "SPH":
|
||||||
|
case "SCH":
|
||||||
|
case "SDH":
|
||||||
|
case "SDM":
|
||||||
|
case "SLB":
|
||||||
|
SendCmd("ACK", frame.cmd);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
RaiseMessage(MessageType.Normal, $"미처리명령 {frame.cmd} DATA={frame.data}");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
public void SendCmd(string cmd, string value)
|
||||||
|
{
|
||||||
|
|
||||||
|
var barr = new List<byte>();
|
||||||
|
barr.Add(0x02);
|
||||||
|
barr.AddRange(System.Text.Encoding.Default.GetBytes(cmd));
|
||||||
|
barr.AddRange(System.Text.Encoding.Default.GetBytes(value));
|
||||||
|
barr.Add((byte)'*');
|
||||||
|
barr.Add((byte)'*');
|
||||||
|
barr.Add(0x03);
|
||||||
|
var cmdstr = System.Text.Encoding.Default.GetString(barr.ToArray());
|
||||||
|
RaiseMessage(MessageType.Normal, "Tx:" + barr.ToArray().HexString());
|
||||||
|
WriteData(barr.ToArray());
|
||||||
|
}
|
||||||
|
|
||||||
|
public void SendTag(string tagno)
|
||||||
|
{
|
||||||
|
tagno = tagno.PadLeft(6, '0');
|
||||||
|
if (tagno.Length > 6) tagno = tagno.Substring(0, 6);
|
||||||
|
var barr = new List<byte>();
|
||||||
|
barr.Add(0x02);
|
||||||
|
barr.Add((byte)'T');
|
||||||
|
barr.Add((byte)'A');
|
||||||
|
barr.Add((byte)'G');
|
||||||
|
barr.AddRange(System.Text.Encoding.Default.GetBytes(tagno));
|
||||||
|
barr.Add((byte)'*');
|
||||||
|
barr.Add((byte)'*');
|
||||||
|
barr.Add(0x03);
|
||||||
|
var cmdstr = System.Text.Encoding.Default.GetString(barr.ToArray());
|
||||||
|
RaiseMessage(MessageType.Normal, "Tx:" + barr.ToArray().HexString());
|
||||||
|
WriteData(barr.ToArray());
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void AutoSendData()
|
||||||
|
{
|
||||||
|
//if (_device.DtrEnable == false) return;
|
||||||
|
//STS258FFFF40000000LSF0000003A
|
||||||
|
//02 53 54 53 32 35 38 46 46 46 46 34 30 30 30 30 30 30 30 4C 53 46 30 30 30 30 30 30 33 41 03
|
||||||
|
var sample = "02 53 54 53 32 35 38 46 46 46 46 34 30 30 30 30 30 30 30 4C 53 46 30 30 30 30 30 30 33 41 03";
|
||||||
|
var barr = sample.Split(' ').ToList().Select(t => Convert.ToByte(t, 16)).ToArray();
|
||||||
|
|
||||||
|
//if (RequestStatusData != null)
|
||||||
|
//{
|
||||||
|
//var p = new RequestStatusDataArgs();
|
||||||
|
//RequestStatusData.Invoke(this, p);
|
||||||
|
|
||||||
|
var voltstr = "255";// ((int)(p.volt * 10f)).ToString().PadRight(3, '0');
|
||||||
|
var bufarr = System.Text.Encoding.Default.GetBytes(voltstr);
|
||||||
|
Array.Copy(bufarr, 0, barr, 4, bufarr.Length);
|
||||||
|
|
||||||
|
bufarr = System.Text.Encoding.Default.GetBytes(system0.ToString("X2").PadLeft(4, '0'));
|
||||||
|
|
||||||
|
Array.Copy(bufarr, 0, barr, 7, bufarr.Length);
|
||||||
|
|
||||||
|
bufarr = System.Text.Encoding.Default.GetBytes(system1.ToString("X2").PadLeft(4, '0'));
|
||||||
|
Array.Copy(bufarr, 0, barr, 11, bufarr.Length);
|
||||||
|
|
||||||
|
bufarr = System.Text.Encoding.Default.GetBytes(error.ToString("X2").PadLeft(4, '0'));
|
||||||
|
Array.Copy(bufarr, 0, barr, 15, bufarr.Length);
|
||||||
|
|
||||||
|
|
||||||
|
barr[19] = (byte)this.sts_speed;
|
||||||
|
barr[20] = (byte)this.sts_bunki;
|
||||||
|
barr[21] = (byte)this.sts_dir;
|
||||||
|
barr[22] = (byte)this.sts_sensor;
|
||||||
|
//bufarr = System.Text.Encoding.Default.GetBytes(p.sensor.ToString().PadLeft(2, '0'));
|
||||||
|
//Array.Copy(bufarr, 0, barr, 22, bufarr.Length);
|
||||||
|
bufarr = System.Text.Encoding.Default.GetBytes(signal.ToString("X2").PadLeft(2, '0'));
|
||||||
|
Array.Copy(bufarr, 0, barr, 23, bufarr.Length);
|
||||||
|
//barr[22] = (byte)'5';
|
||||||
|
|
||||||
|
barr[barr.Length - 3] = (byte)'*';
|
||||||
|
barr[barr.Length - 2] = (byte)'*';
|
||||||
|
|
||||||
|
//}
|
||||||
|
|
||||||
|
var cmdstr = System.Text.Encoding.Default.GetString(barr);
|
||||||
|
RaiseMessage(MessageType.Normal, "Tx:" + barr.ToArray().HexString());
|
||||||
|
WriteData(barr.ToArray());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
protected override bool CustomParser(byte[] buf, out byte[] remainBuffer)
|
||||||
|
{
|
||||||
|
//DD A5 03 00 FF FD 77 0D
|
||||||
|
//remainBuffer = new byte[] { };
|
||||||
|
List<byte> remain = new List<byte>();
|
||||||
|
bool retval = false;
|
||||||
|
foreach (var b in buf)
|
||||||
|
{
|
||||||
|
if (retval)
|
||||||
|
{
|
||||||
|
remain.Add(b);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
if (b == 0x02) //stx
|
||||||
|
{
|
||||||
|
tempBuffer.Clear();
|
||||||
|
tempBuffer.Add(b);
|
||||||
|
}
|
||||||
|
|
||||||
|
else if (b == 0x03) //etx
|
||||||
|
{
|
||||||
|
tempBuffer.Add(b);
|
||||||
|
retval = true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
//데이터길이가 만족한 상태
|
||||||
|
tempBuffer.Add(b);
|
||||||
|
var maxlen = 100;
|
||||||
|
if (tempBuffer.Count > maxlen)
|
||||||
|
{
|
||||||
|
RaiseMessage(MessageType.Error, $"buffer over({maxlen})");
|
||||||
|
tempBuffer.Clear();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
remainBuffer = remain.ToArray();
|
||||||
|
return retval;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
64
Emulator/AGVEmulator/DevCAL.cs
Normal file
64
Emulator/AGVEmulator/DevCAL.cs
Normal file
@@ -0,0 +1,64 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
|
||||||
|
namespace AGVEmulator
|
||||||
|
{
|
||||||
|
class DevCAL : AR.Dev.RS232
|
||||||
|
{
|
||||||
|
public override bool ProcessRecvData(byte[] data)
|
||||||
|
{
|
||||||
|
var sample = "02 30 31 32 01 03";
|
||||||
|
var barr = sample.Split(' ').ToList().Select(t => Convert.ToByte(t, 16)).ToArray();
|
||||||
|
var sendstr = System.Text.Encoding.Default.GetString(barr);
|
||||||
|
//RaiseMessage(MessageType.Normal, "Tx:" + barr.HexString());
|
||||||
|
//WriteData(barr);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override bool CustomParser(byte[] buf, out byte[] remainBuffer)
|
||||||
|
{
|
||||||
|
|
||||||
|
List<byte> remain = new List<byte>();
|
||||||
|
bool retval = false;
|
||||||
|
foreach (var b in buf)
|
||||||
|
{
|
||||||
|
if (retval)
|
||||||
|
{
|
||||||
|
remain.Add(b);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (b == 0x02) //stx
|
||||||
|
{
|
||||||
|
tempBuffer.Clear();
|
||||||
|
tempBuffer.Add(b);
|
||||||
|
}
|
||||||
|
else if (b == 0x03) //etx
|
||||||
|
{
|
||||||
|
tempBuffer.Add(b);
|
||||||
|
retval = true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (tempBuffer.Count > 0 && tempBuffer[0] == 0xDD)
|
||||||
|
{
|
||||||
|
tempBuffer.Add(b);
|
||||||
|
if (tempBuffer.Count > 10)
|
||||||
|
{
|
||||||
|
RaiseMessage(MessageType.Error, "buffer over");
|
||||||
|
tempBuffer.Clear();
|
||||||
|
retval = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
//trash
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
remainBuffer = remain.ToArray();
|
||||||
|
return retval;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
298
Emulator/AGVEmulator/DevPLC.cs
Normal file
298
Emulator/AGVEmulator/DevPLC.cs
Normal file
@@ -0,0 +1,298 @@
|
|||||||
|
using System;
|
||||||
|
using static AGVEmulator.DevBMS;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Diagnostics.Contracts;
|
||||||
|
using arCtl;
|
||||||
|
using System.Xml.Schema;
|
||||||
|
using System.Drawing;
|
||||||
|
|
||||||
|
namespace AGVEmulator
|
||||||
|
{
|
||||||
|
class DevPLC : AR.Dev.RS232
|
||||||
|
{
|
||||||
|
byte runtime = 0;
|
||||||
|
|
||||||
|
|
||||||
|
public enum eCommand : byte
|
||||||
|
{
|
||||||
|
LOAD = 0, //EEPROM 불러오기
|
||||||
|
SAVE, //EEPROM 저장
|
||||||
|
RESET, //초기화
|
||||||
|
PINGCHK,
|
||||||
|
SET_PINMODE, //PINMODE 설정
|
||||||
|
SET_DOUTPUT, //디지털출력설정(포트번호,값[1,0])
|
||||||
|
SET_AOUTPUT, //아날로그출력설정(포트GET_SETTING = 50, //셋팅값 요청
|
||||||
|
SET_FLAG,
|
||||||
|
SET_EEPROM,
|
||||||
|
SET_MANUALSPEED,
|
||||||
|
GET_SETTING = 50,
|
||||||
|
GUIDE_MOT = 90, //가이드커버(양쪽) 0=멈춤,1=UP,2=DN 아스키코드표 90=Z
|
||||||
|
SET_EEP_DIREV,
|
||||||
|
};
|
||||||
|
|
||||||
|
public enum DOName
|
||||||
|
{
|
||||||
|
PINO_GUIDEMOTOR_LDIR,
|
||||||
|
PINO_GUIDEMOTOR_LRUN,
|
||||||
|
PINO_GUIDEMOTOR_RDIR,
|
||||||
|
PINO_GUIDEMOTOR_RRUN,
|
||||||
|
PINO_EMPTY_26,
|
||||||
|
PINO_EMPTY_27,
|
||||||
|
PINO_EMPTY_28,
|
||||||
|
PINO_EMPTY_29,
|
||||||
|
}
|
||||||
|
|
||||||
|
public enum DIName
|
||||||
|
{
|
||||||
|
PINI_EMG,
|
||||||
|
PINI_BTN_1,
|
||||||
|
PINI_BTN_2,
|
||||||
|
PINI_BTN_3,
|
||||||
|
PINI_BTN_4,
|
||||||
|
PINI_OVERLOADL,
|
||||||
|
PINI_OVERLOADR,
|
||||||
|
PINI_EMPTY_36,
|
||||||
|
PINI_EMPTY_37,
|
||||||
|
PINI_EMPTY_38,
|
||||||
|
PINI_BTN_ZUP,
|
||||||
|
PINI_BTN_ZDN,
|
||||||
|
PINI_LIMIT_LU,
|
||||||
|
PINI_LIMIT_LD,
|
||||||
|
PINI_LIMIT_RU,
|
||||||
|
PINI_LIMIT_RD,
|
||||||
|
PINI_STOP,
|
||||||
|
}
|
||||||
|
|
||||||
|
public class ValueChangedArgs : EventArgs
|
||||||
|
{
|
||||||
|
public int Idx { get; set; }
|
||||||
|
public bool Value { get; set; }
|
||||||
|
public bool IsOut { get; set; }
|
||||||
|
public ValueChangedArgs(int idx, bool val, bool isOut)
|
||||||
|
{
|
||||||
|
this.Idx = idx;
|
||||||
|
this.Value = val;
|
||||||
|
this.IsOut = isOut;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public class RequestBatteryDataArgs : EventArgs
|
||||||
|
{
|
||||||
|
public UInt32 IOValue { get; set; }
|
||||||
|
public UInt32 FGValue { get; set; }
|
||||||
|
public RequestBatteryDataArgs()
|
||||||
|
{
|
||||||
|
this.IOValue = 0x00;
|
||||||
|
this.FGValue = 0xFF;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public event EventHandler<RequestBatteryDataArgs> RequestData;
|
||||||
|
public event EventHandler<ValueChangedArgs> ValueChanged;
|
||||||
|
|
||||||
|
public override bool ProcessRecvData(byte[] data)
|
||||||
|
{
|
||||||
|
//dd로 시작하고 34개의 데이터
|
||||||
|
// var sample = "DD 03 00 1B 0A 65 00 00 21 63 29 04 00 00 2C 92 00 00 00 00 00 00 28 51 03 08 02 0B 69 0B 66 FC 9C 77";
|
||||||
|
// var barr = sample.Split(' ').ToList().Select(t => Convert.ToByte(t, 16)).ToArray();
|
||||||
|
var datalne = data[2];
|
||||||
|
byte[] buffer = new byte[datalen];
|
||||||
|
Array.Copy(data, 3, buffer, 0, buffer.Length);
|
||||||
|
|
||||||
|
var cmd = (eCommand)buffer[0];
|
||||||
|
if (cmd == eCommand.GUIDE_MOT)
|
||||||
|
{
|
||||||
|
var p1 = (char)buffer[1];
|
||||||
|
var p2 = (char)buffer[2];
|
||||||
|
|
||||||
|
switch (p1)
|
||||||
|
{
|
||||||
|
case 'A': //all
|
||||||
|
if (p2 == 'P')
|
||||||
|
{
|
||||||
|
ValueChanged?.Invoke(this, new ValueChangedArgs((int)DOName.PINO_GUIDEMOTOR_LRUN, true, true));
|
||||||
|
ValueChanged?.Invoke(this, new ValueChangedArgs((int)DOName.PINO_GUIDEMOTOR_RRUN, true, true));
|
||||||
|
ValueChanged?.Invoke(this, new ValueChangedArgs((int)DOName.PINO_GUIDEMOTOR_LDIR, true, true));
|
||||||
|
ValueChanged?.Invoke(this, new ValueChangedArgs((int)DOName.PINO_GUIDEMOTOR_RDIR, true, true));
|
||||||
|
}
|
||||||
|
else if (p2 == 'N')
|
||||||
|
{
|
||||||
|
ValueChanged?.Invoke(this, new ValueChangedArgs((int)DOName.PINO_GUIDEMOTOR_LRUN, true, true));
|
||||||
|
ValueChanged?.Invoke(this, new ValueChangedArgs((int)DOName.PINO_GUIDEMOTOR_RRUN, true, true));
|
||||||
|
ValueChanged?.Invoke(this, new ValueChangedArgs((int)DOName.PINO_GUIDEMOTOR_LDIR, false, true));
|
||||||
|
ValueChanged?.Invoke(this, new ValueChangedArgs((int)DOName.PINO_GUIDEMOTOR_RDIR, false, true));
|
||||||
|
}
|
||||||
|
else if(p2 == 'S')
|
||||||
|
{
|
||||||
|
ValueChanged?.Invoke(this, new ValueChangedArgs((int)DOName.PINO_GUIDEMOTOR_LRUN, false, true));
|
||||||
|
ValueChanged?.Invoke(this, new ValueChangedArgs((int)DOName.PINO_GUIDEMOTOR_RRUN, false, true));
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case 'L':
|
||||||
|
if (p2 == 'P')
|
||||||
|
{
|
||||||
|
ValueChanged?.Invoke(this, new ValueChangedArgs((int)DOName.PINO_GUIDEMOTOR_LRUN, true, true));
|
||||||
|
ValueChanged?.Invoke(this, new ValueChangedArgs((int)DOName.PINO_GUIDEMOTOR_LDIR, true, true));
|
||||||
|
}
|
||||||
|
else if (p2 == 'N')
|
||||||
|
{
|
||||||
|
ValueChanged?.Invoke(this, new ValueChangedArgs((int)DOName.PINO_GUIDEMOTOR_LRUN, true, true));
|
||||||
|
ValueChanged?.Invoke(this, new ValueChangedArgs((int)DOName.PINO_GUIDEMOTOR_LDIR, false, true));
|
||||||
|
}
|
||||||
|
else if (p2 == 'S')
|
||||||
|
{
|
||||||
|
ValueChanged?.Invoke(this, new ValueChangedArgs((int)DOName.PINO_GUIDEMOTOR_LRUN, false, true));
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case 'R':
|
||||||
|
if (p2 == 'P')
|
||||||
|
{
|
||||||
|
ValueChanged?.Invoke(this, new ValueChangedArgs((int)DOName.PINO_GUIDEMOTOR_RRUN, true, true));
|
||||||
|
ValueChanged?.Invoke(this, new ValueChangedArgs((int)DOName.PINO_GUIDEMOTOR_RDIR, true, true));
|
||||||
|
}
|
||||||
|
else if (p2 == 'N')
|
||||||
|
{
|
||||||
|
ValueChanged?.Invoke(this, new ValueChangedArgs((int)DOName.PINO_GUIDEMOTOR_RRUN, true, true));
|
||||||
|
ValueChanged?.Invoke(this, new ValueChangedArgs((int)DOName.PINO_GUIDEMOTOR_RDIR, false, true));
|
||||||
|
}
|
||||||
|
else if (p2 == 'S')
|
||||||
|
{
|
||||||
|
ValueChanged?.Invoke(this, new ValueChangedArgs((int)DOName.PINO_GUIDEMOTOR_RRUN, false, true));
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void AutoSendData()
|
||||||
|
{
|
||||||
|
//if (_device.DtrEnable == false) return;
|
||||||
|
|
||||||
|
List<byte> barr = new List<byte>();
|
||||||
|
barr.Add((byte)'@');
|
||||||
|
barr.Add((byte)'@');
|
||||||
|
barr.Add(10);
|
||||||
|
barr.Add((byte)'I');
|
||||||
|
|
||||||
|
//입/출력포트 각 16접 데이터 입력
|
||||||
|
UInt32 iovalue = 0;
|
||||||
|
//플래그 각 16접 데이터 입력
|
||||||
|
UInt32 fgvalue = 0;
|
||||||
|
|
||||||
|
|
||||||
|
if (RequestData != null)
|
||||||
|
{
|
||||||
|
var p = new RequestBatteryDataArgs();
|
||||||
|
RequestData.Invoke(this, p);
|
||||||
|
iovalue = p.IOValue;
|
||||||
|
fgvalue = p.FGValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
var arr_volt = BitConverter.GetBytes(iovalue).ToArray();
|
||||||
|
foreach (var b in arr_volt)
|
||||||
|
barr.Add(b);
|
||||||
|
|
||||||
|
|
||||||
|
arr_volt = BitConverter.GetBytes(fgvalue).ToArray();
|
||||||
|
foreach (var b in arr_volt)
|
||||||
|
barr.Add(b);
|
||||||
|
|
||||||
|
|
||||||
|
if (runtime < 255) runtime += 1;
|
||||||
|
else runtime = 0;
|
||||||
|
barr.Add(runtime);
|
||||||
|
|
||||||
|
//체크섬무시
|
||||||
|
barr.Add((byte)'*');
|
||||||
|
//barr.Add((byte)'*');
|
||||||
|
|
||||||
|
barr.Add(0x0D);
|
||||||
|
barr.Add(0x0A);
|
||||||
|
|
||||||
|
RaiseMessage(MessageType.Normal, "Tx:" + barr.ToArray().HexString());
|
||||||
|
WriteData(barr.ToArray());
|
||||||
|
}
|
||||||
|
|
||||||
|
bool findstx2 = false;
|
||||||
|
byte datalen = 0;
|
||||||
|
protected override bool CustomParser(byte[] buf, out byte[] remainBuffer)
|
||||||
|
{
|
||||||
|
//DD A5 03 00 FF FD 77 0D
|
||||||
|
//remainBuffer = new byte[] { };
|
||||||
|
List<byte> remain = new List<byte>();
|
||||||
|
bool retval = false;
|
||||||
|
foreach (var b in buf)
|
||||||
|
{
|
||||||
|
if (retval)
|
||||||
|
{
|
||||||
|
remain.Add(b);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if (findSTX == false)
|
||||||
|
{
|
||||||
|
if (b == '@')
|
||||||
|
{
|
||||||
|
tempBuffer.Clear();
|
||||||
|
tempBuffer.Add(b);
|
||||||
|
findSTX = true;
|
||||||
|
findstx2 = false;
|
||||||
|
datalen = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (findstx2 == false)
|
||||||
|
{
|
||||||
|
if (b == '@')
|
||||||
|
{
|
||||||
|
tempBuffer.Add(b);
|
||||||
|
findstx2 = true;
|
||||||
|
datalen = 0;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
tempBuffer.Clear();
|
||||||
|
findSTX = false;
|
||||||
|
findstx2 = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (datalen == 0)
|
||||||
|
{
|
||||||
|
tempBuffer.Add(b);
|
||||||
|
datalen = b;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
//데이터길이가 만족한 상태
|
||||||
|
tempBuffer.Add(b);
|
||||||
|
var maxlen = datalen + 3 + 3;
|
||||||
|
|
||||||
|
if (tempBuffer.Count == maxlen)
|
||||||
|
{
|
||||||
|
if (tempBuffer[tempBuffer.Count - 1] == 0x0A && tempBuffer[tempBuffer.Count - 2] == 0x0D)
|
||||||
|
{
|
||||||
|
//무조건 맞는걸로 하자 체크섬은 체크하지 말자
|
||||||
|
retval = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (tempBuffer.Count > maxlen)
|
||||||
|
{
|
||||||
|
RaiseMessage(MessageType.Error, $"buffer over({maxlen})");
|
||||||
|
findstx2 = false;
|
||||||
|
findSTX = false;
|
||||||
|
datalen = 0;
|
||||||
|
tempBuffer.Clear();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
remainBuffer = remain.ToArray();
|
||||||
|
return retval;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
1973
Emulator/AGVEmulator/Form1.Designer.cs
generated
Normal file
1973
Emulator/AGVEmulator/Form1.Designer.cs
generated
Normal file
File diff suppressed because it is too large
Load Diff
1154
Emulator/AGVEmulator/Form1.cs
Normal file
1154
Emulator/AGVEmulator/Form1.cs
Normal file
File diff suppressed because it is too large
Load Diff
160
Emulator/AGVEmulator/Form1.resx
Normal file
160
Emulator/AGVEmulator/Form1.resx
Normal file
@@ -0,0 +1,160 @@
|
|||||||
|
<?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="timer1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
||||||
|
<value>17, 17</value>
|
||||||
|
</metadata>
|
||||||
|
<metadata name="toolStrip1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
||||||
|
<value>104, 17</value>
|
||||||
|
</metadata>
|
||||||
|
<assembly alias="System.Drawing" name="System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
|
||||||
|
<data name="toolStripButton1.Image" type="System.Drawing.Bitmap, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
||||||
|
<value>
|
||||||
|
iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8
|
||||||
|
YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAAIDSURBVDhPpZLrS5NhGMb3j4SWh0oRQVExD4gonkDpg4hG
|
||||||
|
YKxG6WBogkMZKgPNCEVJFBGdGETEvgwyO9DJE5syZw3PIlPEE9pgBCLZ5XvdMB8Ew8gXbl54nuf63dd9
|
||||||
|
0OGSnwCahxbPRNPAPMw9Xpg6ZmF46kZZ0xSKzJPIrhpDWsVnpBhGkKx3nAX8Pv7z1zg8OoY/cITdn4fw
|
||||||
|
bf/C0kYAN3Ma/w3gWfZL5kzTKBxjWyK2DftwI9tyMYCZKXbNHaD91bLYJrDXsYbrWfUKwJrPE9M2M1Oc
|
||||||
|
VzOOpHI7Jr376Hi9ogHqFIANO0/MmmmbmSmm9a8ze+I4MrNWAdjtoJgWcx+PSzg166yZZ8xM8XvXDix9
|
||||||
|
c4jIqFYAjoriBV9AhEPv1mH/sonogha0afbZMMZz+yreTGyhpusHwtNNCsA5U1zS4BLxzJIfg299qO32
|
||||||
|
Ir7UJtZfftyATqeT+8o2D8JSjQrAJblrncYL7ZJ2+bfaFnC/1S1NjL3diRat7qrO7wLRP3HjWsojBeCo
|
||||||
|
mDEo5mNjuweFGvjWg2EBhCbpkW78htSHHwRyNdmgAFzPEee2iFkzayy2OLXzT4gr6UdUnlXrullsxxQ+
|
||||||
|
kx0g8BTA3aZlButjSTyjODq/WcQcW/B/Je4OQhLvKQDnzN1mp0nnkvAhR8VuMzNrpm1mpjgkoVwB/v8D
|
||||||
|
TgDQASA1MVpwzwAAAABJRU5ErkJggg==
|
||||||
|
</value>
|
||||||
|
</data>
|
||||||
|
<data name="toolStripButton2.Image" type="System.Drawing.Bitmap, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
||||||
|
<value>
|
||||||
|
iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8
|
||||||
|
YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAAIDSURBVDhPpZLrS5NhGMb3j4SWh0oRQVExD4gonkDpg4hG
|
||||||
|
YKxG6WBogkMZKgPNCEVJFBGdGETEvgwyO9DJE5syZw3PIlPEE9pgBCLZ5XvdMB8Ew8gXbl54nuf63dd9
|
||||||
|
0OGSnwCahxbPRNPAPMw9Xpg6ZmF46kZZ0xSKzJPIrhpDWsVnpBhGkKx3nAX8Pv7z1zg8OoY/cITdn4fw
|
||||||
|
bf/C0kYAN3Ma/w3gWfZL5kzTKBxjWyK2DftwI9tyMYCZKXbNHaD91bLYJrDXsYbrWfUKwJrPE9M2M1Oc
|
||||||
|
VzOOpHI7Jr376Hi9ogHqFIANO0/MmmmbmSmm9a8ze+I4MrNWAdjtoJgWcx+PSzg166yZZ8xM8XvXDix9
|
||||||
|
c4jIqFYAjoriBV9AhEPv1mH/sonogha0afbZMMZz+yreTGyhpusHwtNNCsA5U1zS4BLxzJIfg299qO32
|
||||||
|
Ir7UJtZfftyATqeT+8o2D8JSjQrAJblrncYL7ZJ2+bfaFnC/1S1NjL3diRat7qrO7wLRP3HjWsojBeCo
|
||||||
|
mDEo5mNjuweFGvjWg2EBhCbpkW78htSHHwRyNdmgAFzPEee2iFkzayy2OLXzT4gr6UdUnlXrullsxxQ+
|
||||||
|
kx0g8BTA3aZlButjSTyjODq/WcQcW/B/Je4OQhLvKQDnzN1mp0nnkvAhR8VuMzNrpm1mpjgkoVwB/v8D
|
||||||
|
TgDQASA1MVpwzwAAAABJRU5ErkJggg==
|
||||||
|
</value>
|
||||||
|
</data>
|
||||||
|
<metadata name="statusStrip1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
||||||
|
<value>210, 17</value>
|
||||||
|
</metadata>
|
||||||
|
</root>
|
||||||
34
Emulator/AGVEmulator/Program.cs
Normal file
34
Emulator/AGVEmulator/Program.cs
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Windows.Forms;
|
||||||
|
|
||||||
|
namespace AGVEmulator
|
||||||
|
{
|
||||||
|
static class Program
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 해당 애플리케이션의 주 진입점입니다.
|
||||||
|
/// </summary>
|
||||||
|
[STAThread]
|
||||||
|
static void Main()
|
||||||
|
{
|
||||||
|
Application.EnableVisualStyles();
|
||||||
|
Application.SetCompatibleTextRenderingDefault(false);
|
||||||
|
Application.Run(new Form1());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public static class methodext
|
||||||
|
{
|
||||||
|
public static string HexString(this byte[] buf)
|
||||||
|
{
|
||||||
|
var sb = new System.Text.StringBuilder();
|
||||||
|
foreach (var b in buf)
|
||||||
|
{
|
||||||
|
sb.Append(" " + b.ToString("X2"));
|
||||||
|
}
|
||||||
|
return sb.ToString();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
36
Emulator/AGVEmulator/Properties/AssemblyInfo.cs
Normal file
36
Emulator/AGVEmulator/Properties/AssemblyInfo.cs
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
using System.Reflection;
|
||||||
|
using System.Runtime.CompilerServices;
|
||||||
|
using System.Runtime.InteropServices;
|
||||||
|
|
||||||
|
// 어셈블리에 대한 일반 정보는 다음 특성 집합을 통해
|
||||||
|
// 제어됩니다. 어셈블리와 관련된 정보를 수정하려면
|
||||||
|
// 이러한 특성 값을 변경하세요.
|
||||||
|
[assembly: AssemblyTitle("AGVEmulator")]
|
||||||
|
[assembly: AssemblyDescription("")]
|
||||||
|
[assembly: AssemblyConfiguration("")]
|
||||||
|
[assembly: AssemblyCompany("")]
|
||||||
|
[assembly: AssemblyProduct("AGVEmulator")]
|
||||||
|
[assembly: AssemblyCopyright("Copyright © 2022")]
|
||||||
|
[assembly: AssemblyTrademark("")]
|
||||||
|
[assembly: AssemblyCulture("")]
|
||||||
|
|
||||||
|
// ComVisible을 false로 설정하면 이 어셈블리의 형식이 COM 구성 요소에
|
||||||
|
// 표시되지 않습니다. COM에서 이 어셈블리의 형식에 액세스하려면
|
||||||
|
// 해당 형식에 대해 ComVisible 특성을 true로 설정하세요.
|
||||||
|
[assembly: ComVisible(false)]
|
||||||
|
|
||||||
|
// 이 프로젝트가 COM에 노출되는 경우 다음 GUID는 typelib의 ID를 나타냅니다.
|
||||||
|
[assembly: Guid("9312ab43-72f6-4365-a266-e767215fa7f5")]
|
||||||
|
|
||||||
|
// 어셈블리의 버전 정보는 다음 네 가지 값으로 구성됩니다.
|
||||||
|
//
|
||||||
|
// 주 버전
|
||||||
|
// 부 버전
|
||||||
|
// 빌드 번호
|
||||||
|
// 수정 버전
|
||||||
|
//
|
||||||
|
// 모든 값을 지정하거나 아래와 같이 '*'를 사용하여 빌드 번호 및 수정 번호를
|
||||||
|
// 기본값으로 할 수 있습니다.
|
||||||
|
// [assembly: AssemblyVersion("1.0.*")]
|
||||||
|
[assembly: AssemblyVersion("1.0.0.0")]
|
||||||
|
[assembly: AssemblyFileVersion("1.0.0.0")]
|
||||||
63
Emulator/AGVEmulator/Properties/Resources.Designer.cs
generated
Normal file
63
Emulator/AGVEmulator/Properties/Resources.Designer.cs
generated
Normal file
@@ -0,0 +1,63 @@
|
|||||||
|
//------------------------------------------------------------------------------
|
||||||
|
// <auto-generated>
|
||||||
|
// 이 코드는 도구를 사용하여 생성되었습니다.
|
||||||
|
// 런타임 버전:4.0.30319.42000
|
||||||
|
//
|
||||||
|
// 파일 내용을 변경하면 잘못된 동작이 발생할 수 있으며, 코드를 다시 생성하면
|
||||||
|
// 이러한 변경 내용이 손실됩니다.
|
||||||
|
// </auto-generated>
|
||||||
|
//------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
namespace AGVEmulator.Properties {
|
||||||
|
using System;
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 지역화된 문자열 등을 찾기 위한 강력한 형식의 리소스 클래스입니다.
|
||||||
|
/// </summary>
|
||||||
|
// 이 클래스는 ResGen 또는 Visual Studio와 같은 도구를 통해 StronglyTypedResourceBuilder
|
||||||
|
// 클래스에서 자동으로 생성되었습니다.
|
||||||
|
// 멤버를 추가하거나 제거하려면 .ResX 파일을 편집한 다음 /str 옵션을 사용하여 ResGen을
|
||||||
|
// 다시 실행하거나 VS 프로젝트를 다시 빌드하십시오.
|
||||||
|
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "17.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("AGVEmulator.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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
117
Emulator/AGVEmulator/Properties/Resources.resx
Normal file
117
Emulator/AGVEmulator/Properties/Resources.resx
Normal file
@@ -0,0 +1,117 @@
|
|||||||
|
<?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>
|
||||||
26
Emulator/AGVEmulator/Properties/Settings.Designer.cs
generated
Normal file
26
Emulator/AGVEmulator/Properties/Settings.Designer.cs
generated
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
//------------------------------------------------------------------------------
|
||||||
|
// <auto-generated>
|
||||||
|
// 이 코드는 도구를 사용하여 생성되었습니다.
|
||||||
|
// 런타임 버전:4.0.30319.42000
|
||||||
|
//
|
||||||
|
// 파일 내용을 변경하면 잘못된 동작이 발생할 수 있으며, 코드를 다시 생성하면
|
||||||
|
// 이러한 변경 내용이 손실됩니다.
|
||||||
|
// </auto-generated>
|
||||||
|
//------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
namespace AGVEmulator.Properties {
|
||||||
|
|
||||||
|
|
||||||
|
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
|
||||||
|
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "17.4.0.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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
7
Emulator/AGVEmulator/Properties/Settings.settings
Normal file
7
Emulator/AGVEmulator/Properties/Settings.settings
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
<?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>
|
||||||
481
Emulator/AGVEmulator/RS232.cs
Normal file
481
Emulator/AGVEmulator/RS232.cs
Normal file
@@ -0,0 +1,481 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.ComponentModel;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading;
|
||||||
|
|
||||||
|
namespace AR.Dev
|
||||||
|
{
|
||||||
|
public abstract partial class RS232 : IDisposable
|
||||||
|
{
|
||||||
|
protected System.IO.Ports.SerialPort _device;
|
||||||
|
protected ManualResetEvent _mre;
|
||||||
|
protected byte[] LastReceiveBuffer;
|
||||||
|
|
||||||
|
protected List<byte> tempBuffer = new List<byte>();
|
||||||
|
protected Boolean findSTX = false;
|
||||||
|
|
||||||
|
|
||||||
|
public int WriteError = 0;
|
||||||
|
public string WriteErrorMessage = string.Empty;
|
||||||
|
public int WaitTimeout { get; set; } = 1000;
|
||||||
|
public int MinRecvLength { get; set; } = 1;
|
||||||
|
/// <summary>
|
||||||
|
/// 포트이름
|
||||||
|
/// </summary>
|
||||||
|
[Description("시리얼 포트 이름")]
|
||||||
|
[Category("설정"), DisplayName("Port Name")]
|
||||||
|
public string PortName
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
if (_device == null) return string.Empty;
|
||||||
|
else return _device.PortName;
|
||||||
|
}
|
||||||
|
set
|
||||||
|
{
|
||||||
|
if (this.IsOpen)
|
||||||
|
{
|
||||||
|
Message?.Invoke(this, new MessageEventArgs("포트가 열려있어 포트이름을 변경할 수 없습니다", true));
|
||||||
|
}
|
||||||
|
else if (String.IsNullOrEmpty(value) == false)
|
||||||
|
_device.PortName = value;
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Message?.Invoke(this, new MessageEventArgs("No PortName", true));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public int BaudRate
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
if (_device == null) return 0;
|
||||||
|
else return _device.BaudRate;
|
||||||
|
}
|
||||||
|
set
|
||||||
|
{
|
||||||
|
if (this.IsOpen)
|
||||||
|
{
|
||||||
|
Message?.Invoke(this, new MessageEventArgs("포트가 열려있어 BaudRate(를) 변경할 수 없습니다", true));
|
||||||
|
}
|
||||||
|
else if (value != 0)
|
||||||
|
_device.BaudRate = value;
|
||||||
|
else Message?.Invoke(this, new MessageEventArgs("No baud rate", true));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public string errorMessage { get; set; }
|
||||||
|
public DateTime LastConnTime { get; set; }
|
||||||
|
public DateTime LastConnTryTime { get; set; }
|
||||||
|
public DateTime lastSendTime;
|
||||||
|
/// <summary>
|
||||||
|
/// 메세지 수신시 사용하는 내부버퍼
|
||||||
|
/// </summary>
|
||||||
|
protected List<byte> _buffer = new List<byte>();
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 최종 전송 메세지
|
||||||
|
/// </summary>
|
||||||
|
public byte[] lastSendBuffer;
|
||||||
|
public byte[] LastRecvData;
|
||||||
|
public string LastRecvString
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
if (LastRecvData == null) return String.Empty;
|
||||||
|
else return System.Text.Encoding.Default.GetString(LastRecvData);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// 마지막으로 데이터를 받은 시간
|
||||||
|
/// </summary>
|
||||||
|
public DateTime lastRecvTime;
|
||||||
|
|
||||||
|
public RS232()
|
||||||
|
{
|
||||||
|
_device = new System.IO.Ports.SerialPort();
|
||||||
|
this.BaudRate = 9600;
|
||||||
|
|
||||||
|
_device.DataReceived += barcode_DataReceived;
|
||||||
|
_device.ErrorReceived += this.barcode_ErrorReceived;
|
||||||
|
_device.WriteTimeout = 5000;
|
||||||
|
_device.ReadTimeout = 5000;
|
||||||
|
_device.DtrEnable = false;
|
||||||
|
_device.RtsEnable = false;
|
||||||
|
_device.ReadBufferSize = 8192;
|
||||||
|
_device.WriteBufferSize = 8192;
|
||||||
|
|
||||||
|
errorMessage = string.Empty;
|
||||||
|
lastRecvTime = DateTime.Parse("1982-11-23");
|
||||||
|
LastConnTime = DateTime.Parse("1982-11-23");
|
||||||
|
LastConnTryTime = DateTime.Parse("1982-11-23");
|
||||||
|
lastRecvTime = DateTime.Parse("1982-11-23");
|
||||||
|
this._mre = new ManualResetEvent(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
~RS232()
|
||||||
|
{
|
||||||
|
Dispose(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Flag: Has Dispose already been called?
|
||||||
|
bool disposed = false;
|
||||||
|
|
||||||
|
// Public implementation of Dispose pattern callable by consumers.
|
||||||
|
public void Dispose()
|
||||||
|
{
|
||||||
|
Dispose(true);
|
||||||
|
GC.SuppressFinalize(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Protected implementation of Dispose pattern.
|
||||||
|
protected virtual void Dispose(bool disposing)
|
||||||
|
{
|
||||||
|
if (disposed)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (disposing)
|
||||||
|
{
|
||||||
|
// Free any other managed objects here.
|
||||||
|
//
|
||||||
|
}
|
||||||
|
|
||||||
|
_device.DataReceived -= barcode_DataReceived;
|
||||||
|
_device.ErrorReceived -= this.barcode_ErrorReceived;
|
||||||
|
|
||||||
|
// Free any unmanaged objects here.
|
||||||
|
//
|
||||||
|
disposed = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Boolean Open()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
_device.Open();
|
||||||
|
Message?.Invoke(this, new MessageEventArgs(msgtype: MessageType.Normal, $"port open:{_device.IsOpen}"));
|
||||||
|
return IsOpen;
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
errorMessage = ex.Message;
|
||||||
|
Message.Invoke(this, new MessageEventArgs(ex.Message, true));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public string GetHexString(Byte[] input)
|
||||||
|
{
|
||||||
|
System.Text.StringBuilder sb = new System.Text.StringBuilder();
|
||||||
|
foreach (byte b in input)
|
||||||
|
sb.Append(" " + b.ToString("X2"));
|
||||||
|
return sb.ToString();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 포트가 열려있는지 확인
|
||||||
|
/// </summary>
|
||||||
|
[Description("현재 시리얼포트가 열려있는지 확인합니다")]
|
||||||
|
[Category("정보"), DisplayName("Port Open")]
|
||||||
|
public Boolean IsOpen
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
if (_device == null) return false;
|
||||||
|
return _device.IsOpen;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public virtual void Close(Boolean PortClose = true)
|
||||||
|
{
|
||||||
|
if (_device != null && _device.IsOpen)
|
||||||
|
{
|
||||||
|
_device.DiscardInBuffer();
|
||||||
|
_device.DiscardOutBuffer();
|
||||||
|
if (PortClose) _device.Close(); //dispose에서는 포트를 직접 클리어하지 않게 해뒀다.
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public Boolean RaiseRecvData()
|
||||||
|
{
|
||||||
|
return RaiseRecvData(LastReceiveBuffer.ToArray());
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// 수신받은 메세지를 발생 시킵니다
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="data"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public virtual Boolean RaiseRecvData(byte[] Data)
|
||||||
|
{
|
||||||
|
//181206 - 최종수신 메세지 기록
|
||||||
|
lastRecvTime = DateTime.Now;
|
||||||
|
LastRecvData = Data;
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
Message?.Invoke(this, new MessageEventArgs(Data, true)); //recvmessage
|
||||||
|
if (ProcessRecvData(Data) == false)
|
||||||
|
{
|
||||||
|
//Message?.Invoke(this, new MessageEventArgs(Data, true)); //recvmessage
|
||||||
|
Message?.Invoke(this, new MessageEventArgs(this.errorMessage, true)); //errormessage
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
this.errorMessage = ex.Message;
|
||||||
|
this.Message?.Invoke(this, new MessageEventArgs(ex.Message, true));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 수신받은 자료를 처리한다
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="data"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public abstract bool ProcessRecvData(byte[] data);
|
||||||
|
|
||||||
|
#region "Internal Events"
|
||||||
|
|
||||||
|
void barcode_ErrorReceived(object sender, System.IO.Ports.SerialErrorReceivedEventArgs e)
|
||||||
|
{
|
||||||
|
Message?.Invoke(this, new MessageEventArgs(e.ToString(), true));
|
||||||
|
}
|
||||||
|
|
||||||
|
void barcode_DataReceived(object sender, System.IO.Ports.SerialDataReceivedEventArgs e)
|
||||||
|
{
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
int ReadCount = _device.BytesToRead;
|
||||||
|
|
||||||
|
byte[] buffer = new byte[ReadCount];
|
||||||
|
_device.Read(buffer, 0, buffer.Length);
|
||||||
|
|
||||||
|
System.Text.StringBuilder LogMsg = new StringBuilder();
|
||||||
|
|
||||||
|
byte[] remainBuffer;
|
||||||
|
Repeat:
|
||||||
|
if (CustomParser(buffer, out remainBuffer))
|
||||||
|
{
|
||||||
|
//parser ok
|
||||||
|
LastReceiveBuffer = tempBuffer.ToArray();
|
||||||
|
RaiseRecvData();
|
||||||
|
tempBuffer.Clear();
|
||||||
|
if (remainBuffer != null && remainBuffer.Length > 0)
|
||||||
|
{
|
||||||
|
//버퍼를 변경해서 다시 전송을 해준다.
|
||||||
|
buffer = new byte[remainBuffer.Length];
|
||||||
|
Array.Copy(remainBuffer, buffer, buffer.Length);
|
||||||
|
goto Repeat; //남은 버퍼가 있다면 진행을 해준다.
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
if (IsOpen)
|
||||||
|
{
|
||||||
|
//_device.DiscardInBuffer();
|
||||||
|
//_device.DiscardOutBuffer();
|
||||||
|
}
|
||||||
|
errorMessage = ex.Message;
|
||||||
|
this.Message?.Invoke(this, new MessageEventArgs(ex.Message, true));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region "External Events"
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 오류 및 기타 일반 메세지
|
||||||
|
/// </summary>
|
||||||
|
public event EventHandler<MessageEventArgs> Message;
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region "Event Args"
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 데이터를 수신할떄 사용함(RAW 포함)
|
||||||
|
/// </summary>
|
||||||
|
public class ReceiveDataEventArgs : EventArgs
|
||||||
|
{
|
||||||
|
private byte[] _buffer = null;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 바이트배열의 버퍼값
|
||||||
|
/// </summary>
|
||||||
|
public byte[] Value { get { return _buffer; } }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 버퍼(바이트배열)의 데이터를 문자로 반환합니다.
|
||||||
|
/// </summary>
|
||||||
|
public string StrValue
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
//return string.Empty;
|
||||||
|
|
||||||
|
if (_buffer == null || _buffer.Length < 1) return string.Empty;
|
||||||
|
else return System.Text.Encoding.Default.GetString(_buffer);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public ReceiveDataEventArgs(byte[] buffer)
|
||||||
|
{
|
||||||
|
_buffer = buffer;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 메세지를 강제 발생
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="mt"></param>
|
||||||
|
/// <param name="message"></param>
|
||||||
|
protected virtual void RaiseMessage(MessageType mt, string message)
|
||||||
|
{
|
||||||
|
this.Message?.Invoke(this, new MessageEventArgs(mt, message));
|
||||||
|
}
|
||||||
|
public enum MessageType
|
||||||
|
{
|
||||||
|
Normal,
|
||||||
|
Error,
|
||||||
|
Send,
|
||||||
|
Recv,
|
||||||
|
}
|
||||||
|
|
||||||
|
public class MessageEventArgs : EventArgs
|
||||||
|
{
|
||||||
|
public MessageType MsgType { get; set; }
|
||||||
|
private string _message = string.Empty;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Recv,Send,Normal,Error 모두 지원
|
||||||
|
/// </summary>
|
||||||
|
public string Message { get { return _message; } }
|
||||||
|
|
||||||
|
private byte[] _data = null;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Recv,Send에서만 값이 존재 합니다
|
||||||
|
/// </summary>
|
||||||
|
public byte[] Data { get { return _data; } }
|
||||||
|
public MessageEventArgs(string Message, bool isError = false)
|
||||||
|
{
|
||||||
|
if (isError) MsgType = MessageType.Error;
|
||||||
|
else MsgType = MessageType.Normal;
|
||||||
|
_message = Message;
|
||||||
|
}
|
||||||
|
public MessageEventArgs(MessageType msgtype, string Message)
|
||||||
|
{
|
||||||
|
MsgType = msgtype;
|
||||||
|
_message = Message;
|
||||||
|
_data = System.Text.Encoding.Default.GetBytes(Message);
|
||||||
|
}
|
||||||
|
|
||||||
|
public MessageEventArgs(byte[] buffer, bool isRecv = true)
|
||||||
|
{
|
||||||
|
if (isRecv) MsgType = MessageType.Recv;
|
||||||
|
else MsgType = MessageType.Send;
|
||||||
|
_data = new byte[buffer.Length];
|
||||||
|
Array.Copy(buffer, _data, Data.Length);
|
||||||
|
_message = System.Text.Encoding.Default.GetString(_data);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
|
||||||
|
public virtual void AutoSendData()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
protected abstract bool CustomParser(byte[] buf, out byte[] remainBuffer);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 데이터수신시간이 설정값보다 x 2.5를 초과하면 false 가 반환됨
|
||||||
|
/// </summary>
|
||||||
|
public Boolean IsValid
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
if (IsOpen == false) return false;
|
||||||
|
if (lastRecvTime.Year == 1982) return false;
|
||||||
|
var ts = DateTime.Now - lastRecvTime;
|
||||||
|
if (ts.TotalSeconds > 5) return false;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public bool WriteData(string cmd)
|
||||||
|
{
|
||||||
|
return WriteData(System.Text.Encoding.Default.GetBytes(cmd));
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// 포트에 쓰기(barcode_DataReceived 이벤트로 메세지수신)
|
||||||
|
/// </summary>
|
||||||
|
public Boolean WriteData(byte[] data)
|
||||||
|
{
|
||||||
|
Boolean bRet = false;
|
||||||
|
|
||||||
|
//171205 : 타임아웃시간추가
|
||||||
|
if (!_mre.WaitOne(WaitTimeout))
|
||||||
|
{
|
||||||
|
errorMessage = $"WriteData:MRE:WaitOne:TimeOut {WaitTimeout}ms";
|
||||||
|
this.Message?.Invoke(this, new MessageEventArgs(errorMessage, true));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
_mre.Reset();
|
||||||
|
|
||||||
|
//Array.Resize(ref data, data.Length + 2);
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
lastSendTime = DateTime.Now;
|
||||||
|
if (lastSendBuffer == null) lastSendBuffer = new byte[data.Length]; //171113
|
||||||
|
else Array.Resize(ref lastSendBuffer, data.Length);
|
||||||
|
Array.Copy(data, lastSendBuffer, data.Length);
|
||||||
|
|
||||||
|
for (int i = 0; i < data.Length; i++)
|
||||||
|
_device.Write(data, i, 1);
|
||||||
|
|
||||||
|
//_device.Write(data, 0, data.Length);
|
||||||
|
|
||||||
|
//171113
|
||||||
|
this.Message?.Invoke(this, new MessageEventArgs(data, false));
|
||||||
|
|
||||||
|
bRet = true;
|
||||||
|
WriteError = 0;
|
||||||
|
WriteErrorMessage = string.Empty;
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
// this.isinit = false;
|
||||||
|
this.Message?.Invoke(this, new MessageEventArgs(ex.Message, true));
|
||||||
|
bRet = false;
|
||||||
|
WriteError += 1; //연속쓰기오류횟수
|
||||||
|
WriteErrorMessage = ex.Message;
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
_mre.Set();
|
||||||
|
}
|
||||||
|
return bRet;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
37
Emulator/AGVEmulator/UC/AgvViewer.Designer.cs
generated
Normal file
37
Emulator/AGVEmulator/UC/AgvViewer.Designer.cs
generated
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
|
||||||
|
namespace AGVEmulator.UC
|
||||||
|
{
|
||||||
|
partial class AgvViewer
|
||||||
|
{
|
||||||
|
/// <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()
|
||||||
|
{
|
||||||
|
components = new System.ComponentModel.Container();
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
}
|
||||||
|
}
|
||||||
272
Emulator/AGVEmulator/UC/AgvViewer.cs
Normal file
272
Emulator/AGVEmulator/UC/AgvViewer.cs
Normal file
@@ -0,0 +1,272 @@
|
|||||||
|
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 AGVEmulator.UC
|
||||||
|
{
|
||||||
|
public partial class AgvViewer : Control
|
||||||
|
{
|
||||||
|
|
||||||
|
public AgvViewer()
|
||||||
|
{
|
||||||
|
InitializeComponent();
|
||||||
|
|
||||||
|
// Set Optimized Double Buffer to reduce flickering
|
||||||
|
this.SetStyle(ControlStyles.UserPaint, true);
|
||||||
|
this.SetStyle(ControlStyles.AllPaintingInWmPaint, true);
|
||||||
|
this.SetStyle(ControlStyles.OptimizedDoubleBuffer, true);
|
||||||
|
|
||||||
|
// Redraw when resized
|
||||||
|
this.SetStyle(ControlStyles.ResizeRedraw, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
public class TagArgs : EventArgs
|
||||||
|
{
|
||||||
|
public string Data { get; set; }
|
||||||
|
public bool Active { get; set; }
|
||||||
|
public TagArgs(string tag,bool act)
|
||||||
|
{
|
||||||
|
this.Data = tag;
|
||||||
|
this.Active = act;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public event EventHandler<TagArgs> TagTouched;
|
||||||
|
public event EventHandler<TagArgs> MarkTouched;
|
||||||
|
public event EventHandler<TagArgs> Command;
|
||||||
|
|
||||||
|
public bool StopbyMark { get; set; }
|
||||||
|
public float mpos = 100;
|
||||||
|
public float posmax = 1200;
|
||||||
|
public float posmin = 0;
|
||||||
|
public float mspd = 10;
|
||||||
|
public System.Diagnostics.Stopwatch wat = new System.Diagnostics.Stopwatch();
|
||||||
|
public Font FontTag { get; set; }
|
||||||
|
public Font FontMrk { get; set; }
|
||||||
|
public int dir = 1;
|
||||||
|
|
||||||
|
public class ptdata
|
||||||
|
{
|
||||||
|
public float pos { get; set; } = 0f;
|
||||||
|
public string data { get; set; } = string.Empty;
|
||||||
|
public Boolean active { get; set; } = false;
|
||||||
|
}
|
||||||
|
public ptdata[] listMRK { get; set; }
|
||||||
|
public ptdata[] listTAG { get; set; }
|
||||||
|
|
||||||
|
public string lasttag { get; set; } = string.Empty;
|
||||||
|
public string lasttagdir { get; set; } = string.Empty;
|
||||||
|
public string lastmark { get; set; } = string.Empty;
|
||||||
|
public string lastmarkdir { get; set; } = string.Empty;
|
||||||
|
|
||||||
|
protected override void OnPaint(PaintEventArgs pe)
|
||||||
|
{
|
||||||
|
pe.Graphics.Clear(this.BackColor);
|
||||||
|
var r = new Rectangle(DisplayRectangle.Left + Padding.Left,
|
||||||
|
DisplayRectangle.Top + Padding.Top,
|
||||||
|
DisplayRectangle.Width - Padding.Right - Padding.Left - 1,
|
||||||
|
DisplayRectangle.Height - Padding.Top - Padding.Bottom - 1);
|
||||||
|
|
||||||
|
|
||||||
|
// pe.Graphics.FillRectangle(new SolidBrush(this.BackColor), DisplayRectangle);
|
||||||
|
pe.Graphics.DrawRectangle(Pens.Black, r);
|
||||||
|
|
||||||
|
|
||||||
|
var ptwidth = 25;
|
||||||
|
var ptheight = 35;
|
||||||
|
if (listMRK != null && listMRK.Any() && FontMrk != null)
|
||||||
|
{
|
||||||
|
foreach (var item in listMRK)
|
||||||
|
{
|
||||||
|
var x = r.Left + ((item.pos * 1f) / posmax) * r.Width;
|
||||||
|
var rr = new RectangleF(x - ptwidth, r.Top + r.Height / 2f - ptheight / 2f, ptwidth * 2, ptheight);
|
||||||
|
pe.Graphics.DrawLine(Pens.Gray, x, r.Top, x, r.Bottom);
|
||||||
|
pe.Graphics.FillRectangle(new SolidBrush(Color.FromArgb(120, Color.Gold)), rr);
|
||||||
|
pe.Graphics.DrawRectangle(Pens.DimGray, rr.Left, rr.Top, rr.Width, rr.Height);
|
||||||
|
pe.Graphics.DrawString(item.data, FontMrk, Brushes.Gray, rr, new StringFormat
|
||||||
|
{
|
||||||
|
Alignment = StringAlignment.Center,
|
||||||
|
LineAlignment = StringAlignment.Center,
|
||||||
|
});
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ptwidth = 15;
|
||||||
|
if (listTAG != null && listTAG.Any() && FontTag != null)
|
||||||
|
{
|
||||||
|
var lst = listTAG.Where(t => t.data.EndsWith("1"));
|
||||||
|
foreach (var item in lst)
|
||||||
|
{
|
||||||
|
var x = r.Left + ((item.pos * 1f) / posmax) * r.Width;
|
||||||
|
var rr = new RectangleF(x - ptwidth, r.Top + 5, ptwidth * 2, 15);
|
||||||
|
pe.Graphics.DrawLine(Pens.Orange, x, r.Top, x, rr.Top);
|
||||||
|
pe.Graphics.FillRectangle(Brushes.Orange, rr);
|
||||||
|
pe.Graphics.DrawRectangle(Pens.DimGray, rr.Left, rr.Top, rr.Width, rr.Height);
|
||||||
|
pe.Graphics.DrawString(item.data, FontTag, Brushes.Black, rr, new StringFormat
|
||||||
|
{
|
||||||
|
Alignment = StringAlignment.Center,
|
||||||
|
LineAlignment = StringAlignment.Center,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
lst = listTAG.Where(t => t.data.EndsWith("0"));
|
||||||
|
foreach (var item in lst)
|
||||||
|
{
|
||||||
|
var x = r.Left + ((item.pos * 1f) / posmax) * r.Width;
|
||||||
|
var rr = new RectangleF(x - ptwidth, r.Bottom - 20, ptwidth * 2, 15);
|
||||||
|
pe.Graphics.DrawLine(Pens.Orange, x, rr.Bottom, x, r.Bottom);
|
||||||
|
pe.Graphics.FillRectangle(Brushes.Orange, rr);
|
||||||
|
pe.Graphics.DrawRectangle(Pens.DimGray, rr.Left, rr.Top, rr.Width, rr.Height);
|
||||||
|
pe.Graphics.DrawString(item.data, FontTag, Brushes.Black, rr, new StringFormat
|
||||||
|
{
|
||||||
|
Alignment = StringAlignment.Center,
|
||||||
|
LineAlignment = StringAlignment.Center,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var posX = r.Left + (mpos / posmax) * r.Width;
|
||||||
|
var posY = r.Top + r.Height / 2f;
|
||||||
|
var boxw = r.Width * 0.030f;
|
||||||
|
var boxh = r.Height * 0.15f;
|
||||||
|
var box = new RectangleF(posX - boxw, posY - boxh, boxw * 2, boxh * 2);
|
||||||
|
var box2 = new RectangleF(box.Left - 5, box.Top + 3, 10, box.Height - 6);
|
||||||
|
for (int i = 0; i < posmax; i += 100)
|
||||||
|
{
|
||||||
|
var x = r.Left + ((i * 1f) / posmax) * r.Width;
|
||||||
|
pe.Graphics.DrawLine(Pens.Black, x, r.Bottom - 3, x, r.Bottom);
|
||||||
|
if (i > 0)
|
||||||
|
pe.Graphics.DrawString($"{i / 10f}m", this.Font, Brushes.Black, x - 12, r.Bottom - 15);
|
||||||
|
}
|
||||||
|
pe.Graphics.FillRectangle(Brushes.LightSkyBlue, box);
|
||||||
|
pe.Graphics.DrawRectangle(Pens.Black, box.Left, box.Top, box.Width, box.Height);
|
||||||
|
pe.Graphics.DrawLine(new Pen(Color.Black, 4), posX, box.Top - 5, posX, box.Bottom + 5);
|
||||||
|
|
||||||
|
pe.Graphics.FillRectangle(Brushes.Gold, box2);
|
||||||
|
pe.Graphics.DrawRectangle(Pens.Black, box2.Left, box2.Top, box2.Width, box2.Height);
|
||||||
|
//pe.Graphics.DrawString((mpos / 10f).ToString("N1") + "m", this.Font, Brushes.Black, box, new StringFormat
|
||||||
|
//{
|
||||||
|
// Alignment = StringAlignment.Center,
|
||||||
|
// LineAlignment = StringAlignment.Center,
|
||||||
|
//});
|
||||||
|
|
||||||
|
if (StopbyMark)
|
||||||
|
pe.Graphics.DrawString("!MRK-STP!", this.Font, Brushes.Blue, r.Left+2, r.Top+2);
|
||||||
|
|
||||||
|
if (wat.IsRunning)
|
||||||
|
{
|
||||||
|
var newpos = mspd * (wat.ElapsedMilliseconds / 1000f);
|
||||||
|
if (dir < 0) //forward
|
||||||
|
{
|
||||||
|
if (mpos - newpos < 0)
|
||||||
|
mpos = posmax;
|
||||||
|
else mpos -= newpos;
|
||||||
|
|
||||||
|
//내위치주변에 마커가 있는지 본다
|
||||||
|
var mlist = listMRK.Where(t => t.pos <= mpos && (mpos - t.pos) < 10);
|
||||||
|
var mrk = mlist.FirstOrDefault();
|
||||||
|
if (mrk != null)
|
||||||
|
{
|
||||||
|
//대상마커가있다
|
||||||
|
if (lastmark.Equals(mrk.data) == false || lastmarkdir.Equals("F") == false)
|
||||||
|
{
|
||||||
|
lastmark = mrk.data;
|
||||||
|
lastmarkdir = "F";
|
||||||
|
mrk.active = true;
|
||||||
|
MarkTouched?.Invoke(this, new TagArgs(mrk.data,true));
|
||||||
|
if(StopbyMark)
|
||||||
|
{
|
||||||
|
Command?.Invoke(this, new TagArgs("stop",true));
|
||||||
|
StopbyMark = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (string.IsNullOrEmpty(lastmark) == false)
|
||||||
|
{
|
||||||
|
foreach(var item in listMRK.Where(t=>t.active))
|
||||||
|
{
|
||||||
|
item.active = false;
|
||||||
|
MarkTouched?.Invoke(this, new TagArgs(item.data,false));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//주변태그확인
|
||||||
|
var tlist = listTAG.Where(t => t.pos <= mpos && (mpos - t.pos) < 10);
|
||||||
|
var tag = tlist.FirstOrDefault();
|
||||||
|
if (tag != null)
|
||||||
|
{
|
||||||
|
//대상마커가있다
|
||||||
|
if (lasttag.Equals(tag.data) == false || lasttagdir.Equals("F") == false)
|
||||||
|
{
|
||||||
|
lasttag = tag.data;
|
||||||
|
lasttagdir = "F";
|
||||||
|
TagTouched?.Invoke(this, new TagArgs(tag.data, true));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else //backward
|
||||||
|
{
|
||||||
|
if (mpos + newpos > posmax)
|
||||||
|
mpos = 0;
|
||||||
|
else mpos += newpos;
|
||||||
|
|
||||||
|
//내위치주변에 마커가 있는지 본다
|
||||||
|
var mlist = listMRK.Where(t => t.pos >= mpos && (t.pos - mpos) < 10);
|
||||||
|
var mrk = mlist.FirstOrDefault();
|
||||||
|
if (mrk != null)
|
||||||
|
{
|
||||||
|
//대상마커가있다
|
||||||
|
if (lastmark.Equals(mrk.data) == false || lastmarkdir.Equals("B") == false)
|
||||||
|
{
|
||||||
|
lastmark = mrk.data;
|
||||||
|
lastmarkdir = "B";
|
||||||
|
mrk.active = true;
|
||||||
|
MarkTouched?.Invoke(this, new TagArgs(mrk.data, true));
|
||||||
|
if (StopbyMark)
|
||||||
|
{
|
||||||
|
Command?.Invoke(this, new TagArgs("stop", true));
|
||||||
|
StopbyMark = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (string.IsNullOrEmpty(lastmark) == false)
|
||||||
|
{
|
||||||
|
foreach (var item in listMRK.Where(t => t.active))
|
||||||
|
{
|
||||||
|
item.active = false;
|
||||||
|
MarkTouched?.Invoke(this, new TagArgs(item.data, false));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//주변태그확인
|
||||||
|
var tlist = listTAG.Where(t => t.pos >= mpos && (t.pos - mpos) < 10);
|
||||||
|
var tag = tlist.FirstOrDefault();
|
||||||
|
if (tag != null)
|
||||||
|
{
|
||||||
|
//대상마커가있다
|
||||||
|
if (lasttag.Equals(tag.data) == false || lasttagdir.Equals("B") == false)
|
||||||
|
{
|
||||||
|
lasttag = tag.data;
|
||||||
|
lasttagdir = "B";
|
||||||
|
TagTouched?.Invoke(this, new TagArgs(tag.data, true));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
wat.Restart();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
162
Emulator/AGVEmulator/UC/SerialConn.Designer.cs
generated
Normal file
162
Emulator/AGVEmulator/UC/SerialConn.Designer.cs
generated
Normal file
@@ -0,0 +1,162 @@
|
|||||||
|
|
||||||
|
namespace AGVEmulator
|
||||||
|
{
|
||||||
|
partial class SerialConn
|
||||||
|
{
|
||||||
|
/// <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.cmbBaud = new System.Windows.Forms.ComboBox();
|
||||||
|
this.cmbPOrt = new System.Windows.Forms.ComboBox();
|
||||||
|
this.panel1 = new System.Windows.Forms.Panel();
|
||||||
|
this.tableLayoutPanel1 = new System.Windows.Forms.TableLayoutPanel();
|
||||||
|
this.lbrx = new System.Windows.Forms.Label();
|
||||||
|
this.lbtx = new System.Windows.Forms.Label();
|
||||||
|
this.button1 = new System.Windows.Forms.Button();
|
||||||
|
this.panel1.SuspendLayout();
|
||||||
|
this.tableLayoutPanel1.SuspendLayout();
|
||||||
|
this.SuspendLayout();
|
||||||
|
//
|
||||||
|
// cmbBaud
|
||||||
|
//
|
||||||
|
this.cmbBaud.Dock = System.Windows.Forms.DockStyle.Top;
|
||||||
|
this.cmbBaud.Font = new System.Drawing.Font("굴림", 15F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(129)));
|
||||||
|
this.cmbBaud.FormattingEnabled = true;
|
||||||
|
this.cmbBaud.Items.AddRange(new object[] {
|
||||||
|
"9600",
|
||||||
|
"12800",
|
||||||
|
"25600",
|
||||||
|
"38400",
|
||||||
|
"512000"});
|
||||||
|
this.cmbBaud.Location = new System.Drawing.Point(0, 28);
|
||||||
|
this.cmbBaud.Name = "cmbBaud";
|
||||||
|
this.cmbBaud.Size = new System.Drawing.Size(134, 28);
|
||||||
|
this.cmbBaud.TabIndex = 0;
|
||||||
|
this.cmbBaud.Text = "9600";
|
||||||
|
//
|
||||||
|
// cmbPOrt
|
||||||
|
//
|
||||||
|
this.cmbPOrt.Dock = System.Windows.Forms.DockStyle.Top;
|
||||||
|
this.cmbPOrt.Font = new System.Drawing.Font("굴림", 15F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(129)));
|
||||||
|
this.cmbPOrt.FormattingEnabled = true;
|
||||||
|
this.cmbPOrt.Location = new System.Drawing.Point(0, 0);
|
||||||
|
this.cmbPOrt.Name = "cmbPOrt";
|
||||||
|
this.cmbPOrt.Size = new System.Drawing.Size(134, 28);
|
||||||
|
this.cmbPOrt.TabIndex = 1;
|
||||||
|
//
|
||||||
|
// panel1
|
||||||
|
//
|
||||||
|
this.panel1.Controls.Add(this.tableLayoutPanel1);
|
||||||
|
this.panel1.Controls.Add(this.cmbBaud);
|
||||||
|
this.panel1.Controls.Add(this.cmbPOrt);
|
||||||
|
this.panel1.Dock = System.Windows.Forms.DockStyle.Fill;
|
||||||
|
this.panel1.Location = new System.Drawing.Point(0, 0);
|
||||||
|
this.panel1.Name = "panel1";
|
||||||
|
this.panel1.Size = new System.Drawing.Size(134, 96);
|
||||||
|
this.panel1.TabIndex = 2;
|
||||||
|
//
|
||||||
|
// tableLayoutPanel1
|
||||||
|
//
|
||||||
|
this.tableLayoutPanel1.ColumnCount = 2;
|
||||||
|
this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 50F));
|
||||||
|
this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 50F));
|
||||||
|
this.tableLayoutPanel1.Controls.Add(this.lbrx, 0, 0);
|
||||||
|
this.tableLayoutPanel1.Controls.Add(this.lbtx, 1, 0);
|
||||||
|
this.tableLayoutPanel1.Dock = System.Windows.Forms.DockStyle.Fill;
|
||||||
|
this.tableLayoutPanel1.Location = new System.Drawing.Point(0, 56);
|
||||||
|
this.tableLayoutPanel1.Name = "tableLayoutPanel1";
|
||||||
|
this.tableLayoutPanel1.RowCount = 1;
|
||||||
|
this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 50F));
|
||||||
|
this.tableLayoutPanel1.Size = new System.Drawing.Size(134, 40);
|
||||||
|
this.tableLayoutPanel1.TabIndex = 4;
|
||||||
|
//
|
||||||
|
// lbrx
|
||||||
|
//
|
||||||
|
this.lbrx.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
|
||||||
|
this.lbrx.Dock = System.Windows.Forms.DockStyle.Fill;
|
||||||
|
this.lbrx.Font = new System.Drawing.Font("Microsoft Sans Serif", 15F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(129)));
|
||||||
|
this.lbrx.Location = new System.Drawing.Point(0, 0);
|
||||||
|
this.lbrx.Margin = new System.Windows.Forms.Padding(0);
|
||||||
|
this.lbrx.Name = "lbrx";
|
||||||
|
this.lbrx.Size = new System.Drawing.Size(67, 40);
|
||||||
|
this.lbrx.TabIndex = 2;
|
||||||
|
this.lbrx.Text = "RX";
|
||||||
|
this.lbrx.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
|
||||||
|
//
|
||||||
|
// lbtx
|
||||||
|
//
|
||||||
|
this.lbtx.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
|
||||||
|
this.lbtx.Dock = System.Windows.Forms.DockStyle.Fill;
|
||||||
|
this.lbtx.Font = new System.Drawing.Font("Microsoft Sans Serif", 15F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(129)));
|
||||||
|
this.lbtx.Location = new System.Drawing.Point(67, 0);
|
||||||
|
this.lbtx.Margin = new System.Windows.Forms.Padding(0);
|
||||||
|
this.lbtx.Name = "lbtx";
|
||||||
|
this.lbtx.Size = new System.Drawing.Size(67, 40);
|
||||||
|
this.lbtx.TabIndex = 3;
|
||||||
|
this.lbtx.Text = "TX";
|
||||||
|
this.lbtx.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
|
||||||
|
//
|
||||||
|
// button1
|
||||||
|
//
|
||||||
|
this.button1.Dock = System.Windows.Forms.DockStyle.Right;
|
||||||
|
this.button1.FlatAppearance.BorderColor = System.Drawing.Color.DodgerBlue;
|
||||||
|
this.button1.FlatAppearance.BorderSize = 3;
|
||||||
|
this.button1.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
|
||||||
|
this.button1.Font = new System.Drawing.Font("맑은 고딕", 18F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(129)));
|
||||||
|
this.button1.Location = new System.Drawing.Point(134, 0);
|
||||||
|
this.button1.Margin = new System.Windows.Forms.Padding(0);
|
||||||
|
this.button1.Name = "button1";
|
||||||
|
this.button1.Size = new System.Drawing.Size(82, 96);
|
||||||
|
this.button1.TabIndex = 3;
|
||||||
|
this.button1.Text = "연결";
|
||||||
|
this.button1.UseVisualStyleBackColor = true;
|
||||||
|
this.button1.Click += new System.EventHandler(this.button1_Click);
|
||||||
|
//
|
||||||
|
// SerialConn
|
||||||
|
//
|
||||||
|
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 12F);
|
||||||
|
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||||
|
this.Controls.Add(this.panel1);
|
||||||
|
this.Controls.Add(this.button1);
|
||||||
|
this.Name = "SerialConn";
|
||||||
|
this.Size = new System.Drawing.Size(216, 96);
|
||||||
|
this.panel1.ResumeLayout(false);
|
||||||
|
this.tableLayoutPanel1.ResumeLayout(false);
|
||||||
|
this.ResumeLayout(false);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
private System.Windows.Forms.ComboBox cmbBaud;
|
||||||
|
private System.Windows.Forms.ComboBox cmbPOrt;
|
||||||
|
private System.Windows.Forms.Panel panel1;
|
||||||
|
private System.Windows.Forms.Button button1;
|
||||||
|
private System.Windows.Forms.Label lbtx;
|
||||||
|
private System.Windows.Forms.Label lbrx;
|
||||||
|
private System.Windows.Forms.TableLayoutPanel tableLayoutPanel1;
|
||||||
|
}
|
||||||
|
}
|
||||||
130
Emulator/AGVEmulator/UC/SerialConn.cs
Normal file
130
Emulator/AGVEmulator/UC/SerialConn.cs
Normal file
@@ -0,0 +1,130 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.ComponentModel;
|
||||||
|
using System.Data;
|
||||||
|
using System.Drawing;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Windows.Forms;
|
||||||
|
|
||||||
|
namespace AGVEmulator
|
||||||
|
{
|
||||||
|
public partial class SerialConn : UserControl
|
||||||
|
{
|
||||||
|
public AR.Dev.RS232 dev { get; set; }
|
||||||
|
public SerialConn()
|
||||||
|
{
|
||||||
|
InitializeComponent();
|
||||||
|
}
|
||||||
|
|
||||||
|
void AttachEvent()
|
||||||
|
{
|
||||||
|
dev.Message += Dev_Message;
|
||||||
|
}
|
||||||
|
void DetachEvent()
|
||||||
|
{
|
||||||
|
dev.Message -= Dev_Message;
|
||||||
|
}
|
||||||
|
private void Dev_Message(object sender, AR.Dev.RS232.MessageEventArgs e)
|
||||||
|
{
|
||||||
|
if (e.MsgType == AR.Dev.RS232.MessageType.Recv)
|
||||||
|
ToggleRX();
|
||||||
|
else if (e.MsgType == AR.Dev.RS232.MessageType.Send)
|
||||||
|
ToggleTX();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void SetPortList(string[] list)
|
||||||
|
{
|
||||||
|
cmbPOrt.Items.Clear();
|
||||||
|
foreach (var item in list)
|
||||||
|
cmbPOrt.Items.Add(item);
|
||||||
|
}
|
||||||
|
public string PortName
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return cmbPOrt.Text;
|
||||||
|
}
|
||||||
|
set { this.cmbPOrt.Text = value; }
|
||||||
|
}
|
||||||
|
public int BaudRate
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return int.Parse(cmbBaud.Text);
|
||||||
|
}
|
||||||
|
set
|
||||||
|
{
|
||||||
|
cmbBaud.Text = value.ToString();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public void ToggleTX()
|
||||||
|
{
|
||||||
|
if (lbtx.BackColor == Color.DeepSkyBlue)
|
||||||
|
lbtx.BackColor = Color.White;
|
||||||
|
else lbtx.BackColor = Color.DeepSkyBlue;
|
||||||
|
}
|
||||||
|
public void ToggleRX()
|
||||||
|
{
|
||||||
|
if (lbrx.BackColor == Color.Lime)
|
||||||
|
lbrx.BackColor = Color.White;
|
||||||
|
else lbrx.BackColor = Color.Lime;
|
||||||
|
}
|
||||||
|
public void Disconnect()
|
||||||
|
{
|
||||||
|
if (this.dev.IsOpen)
|
||||||
|
{
|
||||||
|
DetachEvent();
|
||||||
|
dev.Close();
|
||||||
|
}
|
||||||
|
if (dev.IsOpen)
|
||||||
|
button1.BackColor = Color.Lime;
|
||||||
|
else button1.BackColor = Color.Tomato;
|
||||||
|
}
|
||||||
|
public void Connect()
|
||||||
|
{
|
||||||
|
if (this.dev.IsOpen)
|
||||||
|
{
|
||||||
|
DetachEvent();
|
||||||
|
dev.Close();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
this.dev.PortName = cmbPOrt.Text;
|
||||||
|
this.dev.BaudRate = int.Parse(cmbBaud.Text);
|
||||||
|
AttachEvent();
|
||||||
|
try
|
||||||
|
{
|
||||||
|
dev.Open();
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
button1.BackColor = Color.Red;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (dev.IsOpen)
|
||||||
|
button1.BackColor = Color.Lime;
|
||||||
|
else button1.BackColor = Color.Tomato;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void button1_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (this.dev == null)
|
||||||
|
{
|
||||||
|
MessageBox.Show("시리얼 개체가 연결되지 않았습니다");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if(int.TryParse(cmbBaud.Text,out int baud)==false)
|
||||||
|
{
|
||||||
|
MessageBox.Show("Baudrate 값이 올바르지 않습니다");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Connect();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
120
Emulator/AGVEmulator/UC/SerialConn.resx
Normal file
120
Emulator/AGVEmulator/UC/SerialConn.resx
Normal file
@@ -0,0 +1,120 @@
|
|||||||
|
<?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>
|
||||||
3
Emulator/AGVEmulator/app.config
Normal file
3
Emulator/AGVEmulator/app.config
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<configuration>
|
||||||
|
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.8"/></startup></configuration>
|
||||||
228
Emulator/AGVEmulator/devBMS.cs
Normal file
228
Emulator/AGVEmulator/devBMS.cs
Normal file
@@ -0,0 +1,228 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
|
namespace AGVEmulator
|
||||||
|
{
|
||||||
|
class DevBMS : AR.Dev.RS232
|
||||||
|
{
|
||||||
|
public class RequestBatteryDataArgs : EventArgs
|
||||||
|
{
|
||||||
|
|
||||||
|
public float Volt { get; set; }
|
||||||
|
public float Remain { get; set; }
|
||||||
|
public int CurA { get; set; }
|
||||||
|
public int MaxA { get; set; }
|
||||||
|
public RequestBatteryDataArgs()
|
||||||
|
{
|
||||||
|
this.Volt = 25;
|
||||||
|
this.Remain = 79f;
|
||||||
|
this.CurA = 40;
|
||||||
|
this.MaxA = 80;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public class RequestVoltageDataArgs : EventArgs
|
||||||
|
{
|
||||||
|
public UInt16[] cellVolt { get; set; }
|
||||||
|
public RequestVoltageDataArgs()
|
||||||
|
{
|
||||||
|
|
||||||
|
cellVolt = new UInt16[] { 0, 0, 0, 0, 0, 0, 0, 0 };
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public event EventHandler<RequestBatteryDataArgs> RequestBatteryData;
|
||||||
|
public event EventHandler<RequestVoltageDataArgs> RequestVoltageData;
|
||||||
|
public override bool ProcessRecvData(byte[] data)
|
||||||
|
{
|
||||||
|
//dd로 시작하고 34개의 데이터(명령이 0D로 끝나면 34이고, 77로 끝나면 34보다크다)
|
||||||
|
var sample000D = "DD 03 00 1B 0A 65 00 00 21 63 29 04 00 00 2C 92 00 00 00 00 00 00 28 51 03 08 02 0B 69 0B 66 FC 9C 77";
|
||||||
|
var sampleFC77 = "DD 03 00 1B 0A 6E 0D DD 04 00 10 0D 0A 0D 09 0D 0C 0D 09 0D 0A 0D 09 0D 09 0D 0C FF 38 77 DD 04 00 10 0D 0A 0D 09 0D 0C 0D 09 0D 0A 0D 09 0D 09 0D 0C FF 38 77";
|
||||||
|
var sampleFD77 = "DD 03 00 1B 0A 6E 00 00 1F 4A 29 04 00 4E 2C D7 00 00 00 00 00 00 28 4C 03 08 02 0B 9F 0B A9 FB A7 77 DD 03 00 1B 0A 6E 00 00 1F 4A 29 04 00 4E 2C D7 00 00 00 00 00 00 28 4C 03 08 02 0B 9F 0B AA FB A6 77";
|
||||||
|
|
||||||
|
//basic
|
||||||
|
var basicinfosmaple = "0A 65 00 00 21 63 29 04 00 00 2C 92 00 00 00 00 00 00 28 51 03 08 02 0B 69 0B 66";
|
||||||
|
var basic_payload = basicinfosmaple.Split(' ').ToList().Select(t => Convert.ToByte(t, 16)).ToArray(); //old
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
var barr0D = sample000D.Split(' ').ToList().Select(t => Convert.ToByte(t, 16)).ToArray(); //old
|
||||||
|
var barrFC77 = sampleFC77.Split(' ').ToList().Select(t => Convert.ToByte(t, 16)).ToArray(); //setting
|
||||||
|
var barrFD77 = sampleFD77.Split(' ').ToList().Select(t => Convert.ToByte(t, 16)).ToArray(); //normal
|
||||||
|
|
||||||
|
if (data.First() != 0xDD || data.Last() != 0x77)
|
||||||
|
{
|
||||||
|
RaiseMessage(MessageType.Error, "stx,etx error");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
var sts = data[1];
|
||||||
|
var cmd = data[2];
|
||||||
|
|
||||||
|
RaiseMessage(MessageType.Normal, "Rx:" + data.HexString());
|
||||||
|
byte sendOld = 0;
|
||||||
|
|
||||||
|
if (cmd == 0x03) //get basic info
|
||||||
|
{
|
||||||
|
if (RequestBatteryData != null)
|
||||||
|
{
|
||||||
|
var p = new RequestBatteryDataArgs();
|
||||||
|
RequestBatteryData.Invoke(this, p);
|
||||||
|
|
||||||
|
//전압
|
||||||
|
var Volt = (UInt16)(p.Volt * 100);
|
||||||
|
var arr_volt = BitConverter.GetBytes(Volt).Reverse().ToArray();
|
||||||
|
Array.Copy(arr_volt, 0, basic_payload, 0, arr_volt.Length);
|
||||||
|
|
||||||
|
//잔량A
|
||||||
|
var CurA = (UInt16)p.CurA;
|
||||||
|
var arr_cura = BitConverter.GetBytes(CurA).Reverse().ToArray();
|
||||||
|
Array.Copy(arr_cura, 0, basic_payload, 4, arr_cura.Length);
|
||||||
|
|
||||||
|
|
||||||
|
//최대A
|
||||||
|
var MaxA = (UInt16)p.MaxA;
|
||||||
|
var arr_maxa = BitConverter.GetBytes(MaxA).Reverse().ToArray();
|
||||||
|
Array.Copy(arr_maxa, 0, basic_payload, 6, arr_maxa.Length);
|
||||||
|
|
||||||
|
//%
|
||||||
|
var perc = (byte)(int)p.Remain;
|
||||||
|
Array.Copy(new byte[] { perc }, 0, basic_payload, 19, 1);
|
||||||
|
|
||||||
|
var datalen = (byte)basic_payload.Length;
|
||||||
|
var payload_cs = new List<byte>();
|
||||||
|
payload_cs.Add(datalen);
|
||||||
|
payload_cs.AddRange(basic_payload);
|
||||||
|
var chks = MakeCheckSum(payload_cs);
|
||||||
|
|
||||||
|
var buffer = new List<byte>();
|
||||||
|
buffer.Add(0xdd);
|
||||||
|
buffer.Add(cmd);
|
||||||
|
buffer.Add(0x00);
|
||||||
|
buffer.Add(datalen);
|
||||||
|
buffer.AddRange(basic_payload);
|
||||||
|
buffer.AddRange(chks);
|
||||||
|
buffer.Add(0x77);
|
||||||
|
|
||||||
|
|
||||||
|
////makechecksum
|
||||||
|
//UInt16 chksum = 0;
|
||||||
|
//for (int i = 3; i <= 19; i++)
|
||||||
|
//{
|
||||||
|
// chksum += barrFD77[i];
|
||||||
|
//}
|
||||||
|
//chksum = (UInt16)(0xFFFF - chksum + 1);
|
||||||
|
//Array.Copy(BitConverter.GetBytes(chksum).Reverse().ToArray(), 0, barrFD77, 20, 2);
|
||||||
|
|
||||||
|
|
||||||
|
RaiseMessage(MessageType.Normal, $"Volt:{p.Volt}v,Remain:{p.Remain}%");
|
||||||
|
|
||||||
|
var sendstr = System.Text.Encoding.Default.GetString(barr0D);
|
||||||
|
RaiseMessage(MessageType.Normal, "Tx:" + barr0D.HexString());
|
||||||
|
WriteData(buffer.ToArray());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (cmd == 0x04) //get cellvoltage
|
||||||
|
{
|
||||||
|
if (RequestVoltageData != null)
|
||||||
|
{
|
||||||
|
var p = new RequestVoltageDataArgs();
|
||||||
|
RequestVoltageData.Invoke(this, p);
|
||||||
|
|
||||||
|
//var sig = data.Skip(data.Length - 2).Take(1).First();
|
||||||
|
|
||||||
|
//cellvolt 240201
|
||||||
|
var payload = new byte[8 * 2];
|
||||||
|
for (int i = 0; i < 8; i++)
|
||||||
|
{
|
||||||
|
var volt = p.cellVolt[i];
|
||||||
|
var arr_cellvolt = BitConverter.GetBytes(volt).Reverse().ToArray();
|
||||||
|
Array.Copy(arr_cellvolt, 0, payload, ( i * 2), arr_cellvolt.Length);
|
||||||
|
}
|
||||||
|
|
||||||
|
//makechecksum
|
||||||
|
var datalen = (byte)payload.Length;
|
||||||
|
var payload_cs = new List<byte>();
|
||||||
|
payload_cs.Add(datalen);
|
||||||
|
payload_cs.AddRange(payload);
|
||||||
|
var chksum = MakeCheckSum(payload_cs);
|
||||||
|
|
||||||
|
var buffer = new List<byte>();
|
||||||
|
buffer.Add(0xDD);
|
||||||
|
buffer.Add(cmd);
|
||||||
|
buffer.Add(0x00);
|
||||||
|
buffer.Add(datalen);
|
||||||
|
buffer.AddRange(payload);
|
||||||
|
buffer.AddRange(chksum);
|
||||||
|
buffer.Add(0x77);
|
||||||
|
WriteData(buffer.ToArray());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
public byte[] MakeCheckSum(IEnumerable<byte> payload)
|
||||||
|
{
|
||||||
|
UInt16 retval = 0;
|
||||||
|
var payloadsum = payload.Sum(t => t);
|
||||||
|
retval = (UInt16)(payloadsum);
|
||||||
|
retval = (UInt16)(0xFFFF - retval);
|
||||||
|
retval += 1;
|
||||||
|
|
||||||
|
return BitConverter.GetBytes(retval).Reverse().ToArray();
|
||||||
|
}
|
||||||
|
protected override bool CustomParser(byte[] buf, out byte[] remainBuffer)
|
||||||
|
{
|
||||||
|
//DD A5 03 00 FF FD 77 0D
|
||||||
|
//remainBuffer = new byte[] { };
|
||||||
|
List<byte> remain = new List<byte>();
|
||||||
|
bool retval = false;
|
||||||
|
foreach (var b in buf)
|
||||||
|
{
|
||||||
|
if (retval)
|
||||||
|
{
|
||||||
|
remain.Add(b);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (b == 0xDD) //stx
|
||||||
|
{
|
||||||
|
tempBuffer.Clear();
|
||||||
|
tempBuffer.Add(b);
|
||||||
|
}
|
||||||
|
else if (b == 0x0D || b == 0x77) //etx
|
||||||
|
{
|
||||||
|
//과거데이터 34개이다 (DD A5 03 00 FF FD 77 0D)
|
||||||
|
//대쉬보드상태일때(DD A5 03 00 FF FD 77)
|
||||||
|
//설정상태일때-셀전압표시(DD A5 04 00 FF FC 77)
|
||||||
|
|
||||||
|
tempBuffer.Add(b);
|
||||||
|
retval = true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (tempBuffer.Count > 0 && tempBuffer[0] == 0xDD)
|
||||||
|
{
|
||||||
|
tempBuffer.Add(b);
|
||||||
|
if (tempBuffer.Count > 10)
|
||||||
|
{
|
||||||
|
RaiseMessage(MessageType.Error, "buffer over");
|
||||||
|
tempBuffer.Clear();
|
||||||
|
retval = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
//trash
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
remainBuffer = remain.ToArray();
|
||||||
|
return retval;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
BIN
Emulator/AGVEmulator/packetFC.bin
Normal file
BIN
Emulator/AGVEmulator/packetFC.bin
Normal file
Binary file not shown.
BIN
Emulator/AGVEmulator/packetFD.bin
Normal file
BIN
Emulator/AGVEmulator/packetFD.bin
Normal file
Binary file not shown.
BIN
Emulator/ArLog.Net4.dll
Normal file
BIN
Emulator/ArLog.Net4.dll
Normal file
Binary file not shown.
BIN
Emulator/ArSetting.Net4.dll
Normal file
BIN
Emulator/ArSetting.Net4.dll
Normal file
Binary file not shown.
BIN
Emulator/CarlosAg.ExcelXmlWriter.dll
Normal file
BIN
Emulator/CarlosAg.ExcelXmlWriter.dll
Normal file
Binary file not shown.
BIN
Emulator/Winsock Orcas.dll
Normal file
BIN
Emulator/Winsock Orcas.dll
Normal file
Binary file not shown.
BIN
Emulator/arControl.Net4.dll
Normal file
BIN
Emulator/arControl.Net4.dll
Normal file
Binary file not shown.
BIN
Emulator/arFrameControl.dll
Normal file
BIN
Emulator/arFrameControl.dll
Normal file
Binary file not shown.
Reference in New Issue
Block a user