1.新增配置文件来修改镜头R边;
2.新增背板区分可视区和非可视区。
New file |
| | |
| | | using System; |
| | | |
| | | namespace Bro.Common.AbstractFSM |
| | | { |
| | | public class StateEventArgs : EventArgs |
| | | { |
| | | public StateEventArgs(int id) |
| | | { |
| | | m_id = id; |
| | | } |
| | | private int m_id; |
| | | public int Id |
| | | { |
| | | get { return m_id; } |
| | | } |
| | | } |
| | | |
| | | public class State |
| | | { |
| | | private String m_sState = null; |
| | | public State(string sState) |
| | | { |
| | | m_sState = sState; |
| | | } |
| | | protected virtual void ChangeState(object sender, StateEventArgs eventArgs) {} |
| | | |
| | | public override string ToString() |
| | | { |
| | | return m_sState; |
| | | } |
| | | } |
| | | } |
New file |
| | |
| | | using System; |
| | | |
| | | namespace Bro.Common.AbstractFSM |
| | | { |
| | | |
| | | public interface IStateManager : IDisposable |
| | | { |
| | | void ChangeState(object sender, StateEventArgs eventArgs); |
| | | bool CheckState(object sender, StateEventArgs eventArgs); |
| | | } |
| | | public abstract class StatesManager : IStateManager |
| | | { |
| | | // Declare the delegate (if using non-generic pattern). |
| | | public delegate void StateChangedEventHandler(object sender, StateEventArgs eventArgs); |
| | | // Declare the event. |
| | | public event StateChangedEventHandler StateChanged; |
| | | |
| | | public StatesManager() |
| | | { |
| | | //build transitions and set an initial state |
| | | m_activeState = BuildTransitionsTable(); |
| | | } |
| | | |
| | | public virtual void Dispose() |
| | | { |
| | | //virtual method |
| | | } |
| | | State m_activeState = null; |
| | | public State ActiveState |
| | | { |
| | | get { return m_activeState; } |
| | | } |
| | | |
| | | Transitions m_transitions = new Transitions(); |
| | | public Transitions Transitions |
| | | { |
| | | get { return m_transitions; } |
| | | } |
| | | //returns initial state |
| | | protected abstract State BuildTransitionsTable(); |
| | | // |
| | | public virtual void ChangeState(object sender, StateEventArgs eventArgs) |
| | | { |
| | | Transition transition = m_transitions[m_activeState, eventArgs]; |
| | | m_activeState = transition.finalState; |
| | | //raise 'StateChanged' event |
| | | if (StateChanged != null) |
| | | StateChanged(this, eventArgs); |
| | | if (transition.action != null) |
| | | transition.action(this, eventArgs); |
| | | //if the transitional is automatic - automatically go to the next state: |
| | | if (transition.AutoMode == true && transition.AutoTransition != null) |
| | | { |
| | | m_activeState = transition.AutoTransition.initialState; |
| | | ChangeState(sender, transition.AutoTransition.eventArgs); |
| | | } |
| | | } |
| | | public virtual bool CheckState(object sender, StateEventArgs eventArgs) |
| | | { |
| | | return m_transitions.ContainsKey(Transition.GetHashCode(m_activeState, eventArgs)); |
| | | } |
| | | } |
| | | } |
New file |
| | |
| | | using System; |
| | | using System.Collections.Generic; |
| | | |
| | | namespace Bro.Common.AbstractFSM |
| | | { |
| | | //actions that are performed when state changed |
| | | public delegate void StateAction(object sender, StateEventArgs eventArgs); |
| | | |
| | | public class Transition |
| | | { |
| | | private State m_initialState; |
| | | public State initialState |
| | | { |
| | | get { return m_initialState; } |
| | | } |
| | | private StateEventArgs m_eventArgs; |
| | | public StateEventArgs eventArgs |
| | | { |
| | | get { return m_eventArgs; } |
| | | } |
| | | private State m_finalState; |
| | | public State finalState |
| | | { |
| | | get { return m_finalState; } |
| | | } |
| | | private StateAction m_state_action; |
| | | public StateAction action |
| | | { |
| | | get { return m_state_action; } |
| | | } |
| | | private bool m_autoMode = false; |
| | | public bool AutoMode |
| | | { |
| | | get { return m_autoMode; } |
| | | } |
| | | |
| | | private Transition m_autoTransition = null; |
| | | public Transition AutoTransition |
| | | { |
| | | get { return m_autoTransition; } |
| | | } |
| | | |
| | | public Transition(State initialState, StateEventArgs sevent, State finalState, StateAction action) |
| | | { |
| | | m_initialState = initialState; |
| | | m_eventArgs = sevent; |
| | | m_finalState = finalState; |
| | | m_state_action = action; |
| | | } |
| | | public Transition(State initialState, StateEventArgs sevent, State finalState, StateAction action, bool autoMode, Transition autoTransition) |
| | | : this(initialState, sevent, finalState, action) |
| | | { |
| | | m_autoMode = autoMode; |
| | | m_autoTransition = autoTransition; |
| | | } |
| | | public override int GetHashCode() |
| | | { |
| | | //create a unique transition key |
| | | return GetHashCode(m_initialState, m_eventArgs); |
| | | } |
| | | |
| | | public static int GetHashCode(State state, StateEventArgs sevent) |
| | | { |
| | | return (state.GetHashCode() << 8) + sevent.Id; |
| | | } |
| | | } |
| | | /// <summary> |
| | | /// Represents a collection of transition objects. |
| | | /// </summary> |
| | | public class Transitions : System.Collections.Generic.Dictionary <int, Transition> |
| | | { |
| | | /// <summary>Adds the specified transition to the collection.</summary> |
| | | /// <param name="transition">Transition object</param> |
| | | /// <see cref="System.Collections.Generic.Dictionary {int, Transition}"/> |
| | | /// <exception cref="System.ArgumentNullException">Key is null</exception> |
| | | /// <exception cref="System.ArgumentException">An transition with the same key already exists.</exception> |
| | | public void Add(Transition transition) |
| | | { |
| | | // The Add method throws an exception if the new key is already in the dictionary. |
| | | try |
| | | { |
| | | base.Add(transition.GetHashCode(), transition); |
| | | } |
| | | catch (ArgumentException) |
| | | { |
| | | throw new ArgumentException("A transition with the key (Initials state " + |
| | | transition.initialState + ", Event " + |
| | | transition.eventArgs + ") already exists."); |
| | | } |
| | | } |
| | | // |
| | | public Transition this[State state, StateEventArgs sevent] |
| | | { |
| | | get |
| | | { |
| | | try |
| | | { |
| | | return this[Transition.GetHashCode(state, sevent)]; |
| | | } |
| | | catch(KeyNotFoundException) |
| | | { |
| | | throw new KeyNotFoundException("The given transition was not found."); |
| | | } |
| | | } |
| | | set |
| | | { |
| | | this[Transition.GetHashCode(state, sevent)] = value; |
| | | } |
| | | } |
| | | // |
| | | public bool Remove(State state, StateEventArgs sevent) |
| | | { |
| | | return base.Remove(Transition.GetHashCode(state, sevent)); |
| | | } |
| | | } |
| | | } |
New file |
| | |
| | | <?xml version="1.0" encoding="utf-8"?> |
| | | <Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> |
| | | <Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" /> |
| | | <PropertyGroup> |
| | | <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> |
| | | <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> |
| | | <ProjectGuid>{42407C78-FB75-4310-8910-DF515652A012}</ProjectGuid> |
| | | <OutputType>Library</OutputType> |
| | | <AppDesignerFolder>Properties</AppDesignerFolder> |
| | | <RootNamespace>Broc.Comn</RootNamespace> |
| | | <AssemblyName>Broc.Comn</AssemblyName> |
| | | <TargetFrameworkVersion>v4.5</TargetFrameworkVersion> |
| | | <FileAlignment>512</FileAlignment> |
| | | </PropertyGroup> |
| | | <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> |
| | | <DebugSymbols>true</DebugSymbols> |
| | | <DebugType>full</DebugType> |
| | | <Optimize>false</Optimize> |
| | | <OutputPath>bin\Debug\</OutputPath> |
| | | <DefineConstants>DEBUG;TRACE</DefineConstants> |
| | | <ErrorReport>prompt</ErrorReport> |
| | | <WarningLevel>4</WarningLevel> |
| | | <PlatformTarget>AnyCPU</PlatformTarget> |
| | | </PropertyGroup> |
| | | <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> |
| | | <DebugType>pdbonly</DebugType> |
| | | <Optimize>true</Optimize> |
| | | <OutputPath>bin\Release\</OutputPath> |
| | | <DefineConstants>TRACE</DefineConstants> |
| | | <ErrorReport>prompt</ErrorReport> |
| | | <WarningLevel>4</WarningLevel> |
| | | </PropertyGroup> |
| | | <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x86'"> |
| | | <DebugSymbols>true</DebugSymbols> |
| | | <OutputPath>bin\x86\Debug\</OutputPath> |
| | | <DefineConstants>DEBUG;TRACE</DefineConstants> |
| | | <DebugType>full</DebugType> |
| | | <PlatformTarget>x86</PlatformTarget> |
| | | <ErrorReport>prompt</ErrorReport> |
| | | <CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet> |
| | | </PropertyGroup> |
| | | <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x86'"> |
| | | <OutputPath>bin\x86\Release\</OutputPath> |
| | | <DefineConstants>TRACE</DefineConstants> |
| | | <Optimize>true</Optimize> |
| | | <DebugType>pdbonly</DebugType> |
| | | <PlatformTarget>x86</PlatformTarget> |
| | | <ErrorReport>prompt</ErrorReport> |
| | | <CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet> |
| | | </PropertyGroup> |
| | | <ItemGroup> |
| | | <Reference Include="log4net, Version=2.0.8.0, Culture=neutral, PublicKeyToken=669e0ddf0bb1aa2a, processorArchitecture=MSIL"> |
| | | <HintPath>..\packages\log4net.2.0.8\lib\net45-full\log4net.dll</HintPath> |
| | | </Reference> |
| | | <Reference Include="System" /> |
| | | <Reference Include="System.Configuration" /> |
| | | <Reference Include="System.Core" /> |
| | | <Reference Include="System.Drawing" /> |
| | | <Reference Include="System.Web" /> |
| | | <Reference Include="System.Windows.Forms" /> |
| | | <Reference Include="System.Xml.Linq" /> |
| | | <Reference Include="System.Data.DataSetExtensions" /> |
| | | <Reference Include="Microsoft.CSharp" /> |
| | | <Reference Include="System.Data" /> |
| | | <Reference Include="System.Xml" /> |
| | | </ItemGroup> |
| | | <ItemGroup> |
| | | <Compile Include="AbstractFSM\State.cs" /> |
| | | <Compile Include="AbstractFSM\StatesManager.cs" /> |
| | | <Compile Include="AbstractFSM\Transition.cs" /> |
| | | <Compile Include="Except\ExceptionBase.cs" /> |
| | | <Compile Include="FSM\SimpleFSM.cs" /> |
| | | <Compile Include="Link\LinkBase.cs" /> |
| | | <Compile Include="Link\SerialLink.cs" /> |
| | | <Compile Include="Link\SerialPort.cs" /> |
| | | <Compile Include="Link\TCPClient.cs" /> |
| | | <Compile Include="Link\TCPLink.cs" /> |
| | | <Compile Include="Link\TCPSvr.cs" /> |
| | | <Compile Include="Log\LogHelper.cs" /> |
| | | <Compile Include="Log\LogTraceListener.cs" /> |
| | | <Compile Include="OEE\OEEToolKit.cs" /> |
| | | <Compile Include="Procedure\IODataBase.cs" /> |
| | | <Compile Include="Procedure\ProcedureBase.cs" /> |
| | | <Compile Include="Procedure\ProcedureIO.cs" /> |
| | | <Compile Include="Procedure\UnitBase.cs" /> |
| | | <Compile Include="Properties\AssemblyInfo.cs" /> |
| | | <Compile Include="PubSub\IPublisher.cs" /> |
| | | <Compile Include="PubSub\ISubscriber.cs" /> |
| | | <Compile Include="PubSub\IPubSubCenter.cs" /> |
| | | <Compile Include="PubSub\PubSubCenter.cs" /> |
| | | <Compile Include="PubSub\SimplePubSubCenter.cs" /> |
| | | <Compile Include="PubSub\SimpleSubscriber.cs" /> |
| | | <Compile Include="Properties\Resource.Designer.cs"> |
| | | <AutoGen>True</AutoGen> |
| | | <DesignTime>True</DesignTime> |
| | | <DependentUpon>Resource.resx</DependentUpon> |
| | | </Compile> |
| | | <Compile Include="Util\ConfigHelper.cs" /> |
| | | <Compile Include="Util\LoginConfig.cs" /> |
| | | </ItemGroup> |
| | | <ItemGroup> |
| | | <EmbeddedResource Include="Properties\Resource.resx"> |
| | | <Generator>ResXFileCodeGenerator</Generator> |
| | | <LastGenOutput>Resource.Designer.cs</LastGenOutput> |
| | | </EmbeddedResource> |
| | | </ItemGroup> |
| | | <ItemGroup> |
| | | <EmbeddedResource Include="Log\BroClog4net.xml"> |
| | | <SubType>Designer</SubType> |
| | | <CopyToOutputDirectory>Always</CopyToOutputDirectory> |
| | | </EmbeddedResource> |
| | | </ItemGroup> |
| | | <ItemGroup> |
| | | <None Include="packages.config" /> |
| | | </ItemGroup> |
| | | <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> |
| | | <PropertyGroup> |
| | | <PostBuildEvent> |
| | | </PostBuildEvent> |
| | | </PropertyGroup> |
| | | <!-- To modify your build process, add your task inside one of the targets below and uncomment it. |
| | | Other similar extension points exist, see Microsoft.Common.targets. |
| | | <Target Name="BeforeBuild"> |
| | | </Target> |
| | | <Target Name="AfterBuild"> |
| | | </Target> |
| | | --> |
| | | </Project> |
New file |
| | |
| | | using System; |
| | | |
| | | namespace Bro.Common.AbstractFSM |
| | | { |
| | | /// <summary> |
| | | /// å¼å¸¸åºç±» |
| | | /// </summary> |
| | | public class ExceptionBase : Exception |
| | | { |
| | | } |
| | | } |
New file |
| | |
| | | using System.Collections.Generic; |
| | | |
| | | namespace Bro.Common.FSM |
| | | { |
| | | // ç¶æå¤ç代çå®ä¹ |
| | | public delegate void StatHandler(); |
| | | |
| | | |
| | | public class SimpleFSM |
| | | { |
| | | // ç¶ææºæè¿° |
| | | public string Desp { get;set; } |
| | | |
| | | // å½åç¶æ |
| | | private int curStat { get;set;} |
| | | |
| | | // ç¶æå¨ä½è¡¨ |
| | | private Dictionary<int, StatHandler> statTbl = new Dictionary<int,StatHandler>(); |
| | | |
| | | public SimpleFSM() |
| | | { |
| | | |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 注åç¶æå¤ç |
| | | /// </summary> |
| | | /// <param name="stat"></param> |
| | | /// <param name="handle"></param> |
| | | /// <returns></returns> |
| | | public bool Regist(int stat, StatHandler handle) |
| | | { |
| | | if ( null == handle || statTbl.ContainsKey(stat) ) |
| | | { |
| | | return false; |
| | | } |
| | | |
| | | statTbl.Add(stat, handle); |
| | | |
| | | return true; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 注åç¶æå¤ç表 |
| | | /// </summary> |
| | | /// <param name="statTbl"></param> |
| | | /// <returns></returns> |
| | | public bool Regist(Dictionary<int, StatHandler> statTbl) |
| | | { |
| | | this.statTbl = statTbl; |
| | | |
| | | return true; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 设置å½åç¶æ |
| | | /// </summary> |
| | | /// <param name="stat"></param> |
| | | public void SetStat(int stat) |
| | | { |
| | | this.curStat = stat; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// è·åå½åç¶æ |
| | | /// </summary> |
| | | /// <returns></returns> |
| | | public int GetStat() |
| | | { |
| | | return curStat; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// ç¶æåºè¿è¡ |
| | | /// </summary> |
| | | public void Run() |
| | | { |
| | | for (; ; ) |
| | | { |
| | | foreach (var item in statTbl) |
| | | { |
| | | StatHandler handle = item.Value; |
| | | if (null == handle) |
| | | { |
| | | continue; |
| | | } |
| | | |
| | | if (curStat == item.Key) |
| | | { |
| | | handle(); |
| | | break; |
| | | } |
| | | } |
| | | } |
| | | |
| | | } |
| | | } |
| | | } |
New file |
| | |
| | | using System; |
| | | using System.Diagnostics; |
| | | |
| | | namespace Bro.Common.Link |
| | | { |
| | | /// <summary> |
| | | /// 设å¤çè¿æ¥åºç±» |
| | | /// </summary> |
| | | public abstract class LinkBase |
| | | { |
| | | // é»è®¤ä¿åæ°æ®ç¼åé¿åº¦ |
| | | public const int DFT_BUFF_LEN = 4096; |
| | | |
| | | // è¿æ¥å¯¹è±¡æ¥æ¶ç¼åå¤§å° |
| | | public const int DFT_SEND_BUFF_LEN = 4096; |
| | | // è¿æ¥å¯¹è±¡åéç¼åå¤§å° |
| | | public const int DFT_RECV_BUFF_LEN = 4096; |
| | | |
| | | // è¿æ¥æè¿° |
| | | public string Desp { get;set;} |
| | | // åå§åç¶æ |
| | | public bool IsInit { get;set; } |
| | | // è¿æ¥ç¶æ |
| | | public bool IsConn { get;set;} |
| | | // æ¥æ¶ç¼åé¿åº¦ |
| | | public int BufferLen { get;set;} |
| | | // æ¥æ¶ç¼åå¤§å° |
| | | public int SendBuffLen { get;set;} |
| | | // åéç¼åå¤§å° |
| | | public int RecvBuffLen { get;set;} |
| | | |
| | | // æ¥æ¶ç¼å |
| | | protected byte[] rcvBuf = null; |
| | | |
| | | // è¿æ¥ç¶æ |
| | | public LinkBase() |
| | | { |
| | | Desp = this.GetType().Name; |
| | | IsInit = false; |
| | | IsConn = false; |
| | | SendBuffLen = DFT_SEND_BUFF_LEN; |
| | | RecvBuffLen = DFT_RECV_BUFF_LEN; |
| | | BufferLen = DFT_BUFF_LEN; |
| | | |
| | | } |
| | | |
| | | /// <summary> |
| | | /// è¿æ¥åå§å |
| | | /// </summary> |
| | | /// <returns></returns> |
| | | public virtual bool Init() |
| | | { |
| | | if ( IsInit ) |
| | | { |
| | | return true; |
| | | } |
| | | |
| | | try |
| | | { |
| | | rcvBuf = new byte[BufferLen]; |
| | | |
| | | return true; |
| | | } |
| | | catch(Exception ex) |
| | | { |
| | | Trace.TraceError("Link:{0} Init fail, ex:{1}-{2}", this.Desp, ex.Message, ex.StackTrace); |
| | | } |
| | | |
| | | return false; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// æå¼è¿æ¥ |
| | | /// </summary> |
| | | /// <returns></returns> |
| | | public abstract bool Open(); |
| | | |
| | | /// <summary> |
| | | /// å
³éè¿æ¥ |
| | | /// </summary> |
| | | public abstract void Close(); |
| | | |
| | | /// <summary> |
| | | /// 鿝 |
| | | /// </summary> |
| | | public abstract void Fnit(); |
| | | |
| | | /// <summary> |
| | | /// æ¥æ¶æ°æ® |
| | | /// </summary> |
| | | /// <param name="rcvBuf"></param> |
| | | /// <param name="offset"></param> |
| | | /// <returns></returns> |
| | | public abstract int Recv(byte[] rcvBuf, int offset); |
| | | |
| | | /// <summary> |
| | | /// åéæ°æ® |
| | | /// </summary> |
| | | /// <param name="sndBuf"></param> |
| | | /// <returns></returns> |
| | | public abstract bool Send(byte[] sndBuf, int offset, int len); |
| | | |
| | | } |
| | | |
| | | |
| | | } |
New file |
| | |
| | | using System; |
| | | using System.Diagnostics; |
| | | using System.IO.Ports; |
| | | |
| | | namespace Bro.Common.Link |
| | | { |
| | | /// <summary> |
| | | /// 串å£è¿æ¥ |
| | | /// </summary> |
| | | public class SerialLink : LinkBase |
| | | { |
| | | // é»è®¤ä¸²å£å· |
| | | public const int DFT_PORT = 1; |
| | | // é»è®¤æ³¢ç¹ç |
| | | public const int DFT_BAUD_RATE = 9600; |
| | | |
| | | // 串å£å· |
| | | public int Port { get;set;} |
| | | // æ³¢ç¹ç |
| | | public int BaudRate { get;set;} |
| | | // 串å£è¿æ¥ |
| | | private SerialPort SerialPort = new SerialPort(); |
| | | |
| | | public SerialLink() |
| | | { |
| | | IsConn = false; |
| | | |
| | | Port = DFT_PORT; |
| | | BaudRate = DFT_BAUD_RATE; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// æå¼ä¸²å£è¿æ¥ |
| | | /// </summary> |
| | | /// <returns></returns> |
| | | public override bool Open() |
| | | { |
| | | if ( SerialPort.IsOpen ) |
| | | { |
| | | return true; |
| | | } |
| | | |
| | | try |
| | | { |
| | | SerialPort.PortName = "COM" + this.Port; |
| | | SerialPort.BaudRate = this.BaudRate; |
| | | SerialPort.WriteBufferSize = this.SendBuffLen; |
| | | SerialPort.ReadBufferSize = this.RecvBuffLen; |
| | | |
| | | SerialPort.Open(); |
| | | |
| | | base.IsConn = true; |
| | | |
| | | return true; |
| | | } |
| | | catch(Exception ex) |
| | | { |
| | | Trace.TraceError("SerialLink:{0} Open fail, ex:{1}-{2}", this.Desp, ex.Message, ex.StackTrace); |
| | | } |
| | | |
| | | return false; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// å
³é串å£è¿æ¥ |
| | | /// </summary> |
| | | public override void Close() |
| | | { |
| | | try |
| | | { |
| | | if ( !SerialPort.IsOpen ) |
| | | { |
| | | return; |
| | | } |
| | | |
| | | SerialPort.Close(); |
| | | } |
| | | catch(Exception ex) |
| | | { |
| | | Trace.TraceError("SerialLink:{0} Close fail, ex:{1}-{2}", this.Desp, ex.Message, ex.StackTrace); |
| | | } |
| | | |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 鿝 |
| | | /// </summary> |
| | | public override void Fnit() |
| | | { |
| | | Close(); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// æ¥æ¶æ°æ® |
| | | /// </summary> |
| | | /// <param name="rcvBuf"></param> |
| | | /// <param name="bufLen"></param> |
| | | /// <returns></returns> |
| | | public override int Recv(byte[] rcvBuf, int offset) |
| | | { |
| | | int rcvLen = -1; |
| | | |
| | | if ( null == rcvBuf ) |
| | | { |
| | | return -1; |
| | | } |
| | | |
| | | try |
| | | { |
| | | var len = rcvBuf.Length - offset; |
| | | if ( len <= 0 ) |
| | | { |
| | | return -1; |
| | | } |
| | | |
| | | rcvLen = SerialPort.Read(rcvBuf, offset, len); |
| | | } |
| | | catch(Exception ex) |
| | | { |
| | | Trace.TraceError("SerialLink:{0} Recv fail, ex:{1}-{2}", this.Desp, ex.Message, ex.StackTrace); |
| | | } |
| | | |
| | | return rcvLen; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// åéæ°æ® |
| | | /// </summary> |
| | | /// <param name="sndBuf"></param> |
| | | /// <param name="offset"></param> |
| | | /// <returns></returns> |
| | | public override bool Send(byte[] sndBuf, int offset, int len) |
| | | { |
| | | if ( null == sndBuf ) |
| | | { |
| | | return false; |
| | | } |
| | | |
| | | try |
| | | { |
| | | SerialPort.Write(sndBuf, offset, len); |
| | | |
| | | return true; |
| | | } |
| | | catch(Exception ex) |
| | | { |
| | | Trace.TraceError("SerialLink:{0} Send fail, ex:{1}-{2}", this.Desp, ex.Message, ex.StackTrace); |
| | | } |
| | | |
| | | return false; |
| | | } |
| | | |
| | | } |
| | | } |
New file |
| | |
| | | using System; |
| | | using System.Text; |
| | | //using System.Threading.Tasks; |
| | | using System.IO.Ports; |
| | | using System.Windows.Forms; |
| | | using System.Diagnostics; |
| | | |
| | | namespace Bro.Common.Link |
| | | { |
| | | public class SerialComPort //: LinkBase |
| | | { |
| | | /// æ¥æ¶äºä»¶æ¯å¦ææ falseè¡¨ç¤ºææ |
| | | public bool ReceiveEventFlag = false; |
| | | /// ç»æç¬¦æ¯ç¹ |
| | | public byte EndByte = 0x23;//string End = "#"; |
| | | /// 宿´åè®®çè®°å½å¤çäºä»¶ |
| | | public event DataReceivedEventHandler DataReceived; |
| | | public event SerialErrorReceivedEventHandler Error; |
| | | #region åé屿§ |
| | | private string _portName = "COM1";//串å£å·ï¼é»è®¤COM1 |
| | | private SerialPortBaudRates _baudRate = SerialPortBaudRates.BaudRate_9600;//æ³¢ç¹ç |
| | | private Parity _parity = Parity.None;//æ ¡éªä½ |
| | | private StopBits _stopBits = StopBits.One;//åæ¢ä½ |
| | | private SerialPortDatabits _dataBits = SerialPortDatabits.EightBits;//æ°æ®ä½ |
| | | public SerialPort comPort = new SerialPort(); |
| | | /// 串å£å· |
| | | public string PortName |
| | | { |
| | | get { return _portName; } |
| | | set { _portName = value; comPort.PortName = _portName; } |
| | | } |
| | | /// æ³¢ç¹ç |
| | | public SerialPortBaudRates BaudRate |
| | | { |
| | | get { return _baudRate; } |
| | | set { _baudRate = value; comPort.BaudRate = (int)_baudRate; } |
| | | } |
| | | /// å¥å¶æ ¡éªä½ |
| | | public Parity Parity |
| | | { |
| | | get { return _parity; } |
| | | set { _parity = value; comPort.Parity = _parity; } |
| | | } |
| | | /// æ°æ®ä½ |
| | | public SerialPortDatabits DataBits |
| | | { |
| | | get { return _dataBits; } |
| | | set { _dataBits = value; comPort.DataBits = (int)_dataBits; } |
| | | } |
| | | /// åæ¢ä½ |
| | | public StopBits StopBits |
| | | |
| | | { |
| | | get { return _stopBits; } |
| | | set { _stopBits = value; comPort.StopBits = _stopBits; } |
| | | } |
| | | #endregion |
| | | #region æé 彿° |
| | | /// åæ°æé 彿°ï¼ä½¿ç¨æä¸¾åæ°æé ï¼ |
| | | /// <param name="baud">æ³¢ç¹ç</param> |
| | | /// <param name="par">å¥å¶æ ¡éªä½</param> |
| | | /// <param name="sBits">忢ä½</param> |
| | | |
| | | /// <param name="dBits">æ°æ®ä½</param> |
| | | /// <param name="name">串å£å·</param> |
| | | public SerialComPort(string name, SerialPortBaudRates baud, Parity par, SerialPortDatabits dBits, StopBits sBits) |
| | | { |
| | | _portName = name; |
| | | _baudRate = baud; |
| | | _parity = par; |
| | | _dataBits = dBits; |
| | | _stopBits = sBits; |
| | | comPort.DataReceived += new SerialDataReceivedEventHandler(comPort_DataReceived); |
| | | comPort.ErrorReceived += new SerialErrorReceivedEventHandler(comPort_ErrorReceived); |
| | | } |
| | | /// åæ°æé 彿°ï¼ä½¿ç¨åç¬¦ä¸²åæ°æé ï¼ |
| | | /// <param name="baud">æ³¢ç¹ç</param> |
| | | /// <param name="par">å¥å¶æ ¡éªä½</param> |
| | | /// <param name="sBits">忢ä½</param> |
| | | /// <param name="dBits">æ°æ®ä½</param> |
| | | /// <param name="name">串å£å·</param> |
| | | public SerialComPort(string name, string baud, string par, string dBits, string sBits) |
| | | { |
| | | _portName = name; |
| | | _baudRate = (SerialPortBaudRates)Enum.Parse(typeof(SerialPortBaudRates), baud); |
| | | _parity = (Parity)Enum.Parse(typeof(Parity), par); |
| | | _dataBits = (SerialPortDatabits)Enum.Parse(typeof(SerialPortDatabits), dBits); |
| | | _stopBits = (StopBits)Enum.Parse(typeof(StopBits), sBits); |
| | | comPort.DataReceived += new SerialDataReceivedEventHandler(comPort_DataReceived); |
| | | comPort.ErrorReceived += new SerialErrorReceivedEventHandler(comPort_ErrorReceived); |
| | | } |
| | | /// é»è®¤æé 彿° |
| | | public SerialComPort() |
| | | { |
| | | _portName = "COM1"; |
| | | _baudRate = SerialPortBaudRates.BaudRate_9600; |
| | | _parity = Parity.None; |
| | | _dataBits = SerialPortDatabits.EightBits; |
| | | _stopBits = StopBits.One; |
| | | comPort.DataReceived += new SerialDataReceivedEventHandler(comPort_DataReceived); |
| | | comPort.ErrorReceived += new SerialErrorReceivedEventHandler(comPort_ErrorReceived); |
| | | } |
| | | #endregion |
| | | /// ç«¯å£æ¯å¦å·²ç»æå¼ |
| | | public bool IsOpen |
| | | { |
| | | get |
| | | { |
| | | return comPort.IsOpen; |
| | | } |
| | | } |
| | | /// æå¼ç«¯å£ |
| | | public void OpenPort() |
| | | { |
| | | if (comPort.IsOpen) comPort.Close(); |
| | | comPort.PortName = _portName; |
| | | comPort.BaudRate = (int)_baudRate; |
| | | comPort.Parity = _parity; |
| | | comPort.DataBits = (int)_dataBits; |
| | | comPort.StopBits = _stopBits; |
| | | try |
| | | { |
| | | comPort.Open(); |
| | | |
| | | } |
| | | catch (System.Exception ex) |
| | | { |
| | | MessageBox.Show(ex.Message, "æç¤ºä¿¡æ¯", MessageBoxButtons.OK, MessageBoxIcon.Error); |
| | | } |
| | | } |
| | | /// å
³éç«¯å£ |
| | | public void ClosePort() |
| | | { |
| | | if (comPort.IsOpen) comPort.Close(); |
| | | } |
| | | /// 䏢弿¥èªä¸²è¡é©±å¨ç¨åºçæ¥æ¶ååéç¼å²åºçæ°æ® |
| | | public void DiscardBuffer() |
| | | { |
| | | comPort.DiscardInBuffer(); |
| | | comPort.DiscardOutBuffer(); |
| | | } |
| | | /// <summary> |
| | | /// æ°æ®æ¥æ¶å¤ç |
| | | /// </summary> |
| | | void comPort_DataReceived(object sender, SerialDataReceivedEventArgs e) |
| | | { |
| | | byte[] receviedBuf; |
| | | receviedBuf = new byte[comPort.BytesToRead]; |
| | | int itemp = comPort.BytesToRead; |
| | | int rcvByteLen = 0; |
| | | try |
| | | { |
| | | for (int i = 0; i < itemp; i++) |
| | | { |
| | | receviedBuf[i] = Convert.ToByte(comPort.ReadByte()); |
| | | rcvByteLen++; |
| | | } |
| | | if (receviedBuf != null) |
| | | { |
| | | DataReceived(new DataReceivedEventArgs(Encoding.ASCII.GetString(receviedBuf))); |
| | | } |
| | | } |
| | | catch (System.Exception ex) |
| | | { |
| | | Trace.TraceError("SerialPort receive fail,ex:{0}", ex); |
| | | } |
| | | } |
| | | |
| | | /// é误å¤ç彿° |
| | | |
| | | void comPort_ErrorReceived(object sender, SerialErrorReceivedEventArgs e) |
| | | { |
| | | if (Error != null) |
| | | { |
| | | Error(sender, e); |
| | | } |
| | | } |
| | | |
| | | #region æ°æ®åå
¥æä½ |
| | | |
| | | /// åå
¥æ°æ® |
| | | /// <param name="msg"></param> |
| | | public void WriteData(string msg) |
| | | { |
| | | //if (!(comPort.IsOpen)) comPort.Open(); |
| | | try |
| | | { |
| | | comPort.Write(msg); |
| | | } |
| | | catch (System.Exception ex) |
| | | { |
| | | Trace.TraceError("SerialPort write data fail,ex:{0}", ex); |
| | | } |
| | | } |
| | | /// <summary> |
| | | /// åå
¥æ°æ® |
| | | /// </summary> |
| | | /// <param name="msg">åå
¥ç«¯å£çåèæ°ç»</param> |
| | | public void WriteData(byte[] msg) |
| | | { |
| | | //if (!(comPort.IsOpen)) comPort.Open(); |
| | | try |
| | | { |
| | | comPort.Write(msg, 0, msg.Length); |
| | | } |
| | | catch (System.Exception ex) |
| | | { |
| | | Trace.TraceError("SerialPort write data fail,ex:{0}", ex); |
| | | } |
| | | |
| | | } |
| | | /// <summary> |
| | | /// åå
¥æ°æ® |
| | | /// </summary> |
| | | /// <param name="msg">å
å«è¦åå
¥ç«¯å£çåèæ°ç»</param> |
| | | /// <param name="offset">åæ°ä»0åèå¼å§çåèåç§»é</param> |
| | | /// <param name="count">è¦åå
¥çåèæ°</param> |
| | | public void WriteData(byte[] msg, int offset, int count) |
| | | { |
| | | //if (!(comPort.IsOpen)) comPort.Open(); |
| | | try |
| | | { |
| | | comPort.Write(msg, offset, count); |
| | | } |
| | | catch (System.Exception ex) |
| | | { |
| | | Trace.TraceError("SerialPort write data fail,ex:{0}", ex); |
| | | } |
| | | |
| | | } |
| | | |
| | | /// <summary> |
| | | /// åé串å£å½ä»¤ |
| | | /// </summary> |
| | | /// <param name="SendData">åéæ°æ®</param> |
| | | /// <param name="ReceiveData">æ¥æ¶æ°æ®</param> |
| | | /// <param name="Overtime">é夿¬¡æ°</param> |
| | | /// <returns></returns> |
| | | public int SendCommand(byte[] SendData, ref byte[] ReceiveData, int Overtime) |
| | | { |
| | | if (!(comPort.IsOpen)) comPort.Open(); |
| | | ReceiveEventFlag = true; //å
³éæ¥æ¶äºä»¶ |
| | | comPort.DiscardInBuffer(); //æ¸
ç©ºæ¥æ¶ç¼å²åº |
| | | comPort.Write(SendData, 0, SendData.Length); |
| | | int num = 0, ret = 0; |
| | | while (num++ < Overtime) |
| | | { |
| | | if (comPort.BytesToRead >= ReceiveData.Length) break; |
| | | System.Threading.Thread.Sleep(1); |
| | | } |
| | | if (comPort.BytesToRead >= ReceiveData.Length) |
| | | { |
| | | ret = comPort.Read(ReceiveData, 0, ReceiveData.Length); |
| | | } |
| | | ReceiveEventFlag = false; //æå¼äºä»¶ |
| | | |
| | | return ret; |
| | | } |
| | | #endregion |
| | | |
| | | #region 常ç¨çåè¡¨æ°æ®è·ååç»å®æä½ |
| | | /// <summary> |
| | | /// å°è£
è·å串å£å·å表 |
| | | /// </summary> |
| | | /// <returns></returns> |
| | | public static string[] GetPortNames() |
| | | { |
| | | return SerialPort.GetPortNames(); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 设置串å£å· |
| | | /// </summary> |
| | | /// <param name="obj"></param> |
| | | public static void SetPortNameValues(ComboBox obj) |
| | | { |
| | | obj.Items.Clear(); |
| | | foreach (string str in SerialPort.GetPortNames()) |
| | | { |
| | | obj.Items.Add(str); |
| | | } |
| | | } |
| | | /// <summary> |
| | | /// 设置波ç¹ç |
| | | /// </summary> |
| | | public static void SetBauRateValues(ComboBox obj) |
| | | { |
| | | obj.Items.Clear(); |
| | | foreach (SerialPortBaudRates rate in Enum.GetValues(typeof(SerialPortBaudRates))) |
| | | { |
| | | obj.Items.Add(((int)rate).ToString()); |
| | | } |
| | | } |
| | | /// <summary> |
| | | /// è®¾ç½®æ°æ®ä½ |
| | | /// </summary> |
| | | public static void SetDataBitsValues(ComboBox obj) |
| | | { |
| | | obj.Items.Clear(); |
| | | foreach (SerialPortDatabits databit in Enum.GetValues(typeof(SerialPortDatabits))) |
| | | { |
| | | obj.Items.Add(((int)databit).ToString()); |
| | | } |
| | | } |
| | | /// <summary> |
| | | /// è®¾ç½®æ ¡éªä½å表 |
| | | /// </summary> |
| | | public static void SetParityValues(ComboBox obj) |
| | | { |
| | | obj.Items.Clear(); |
| | | foreach (string str in Enum.GetNames(typeof(Parity))) |
| | | { |
| | | obj.Items.Add(str); |
| | | } |
| | | } |
| | | |
| | | /// <summary> |
| | | /// è®¾ç½®åæ¢ä½ |
| | | /// </summary> |
| | | public static void SetStopBitValues(ComboBox obj) |
| | | { |
| | | |
| | | obj.Items.Clear(); |
| | | foreach (string str in Enum.GetNames(typeof(StopBits))) |
| | | { |
| | | obj.Items.Add(str); |
| | | } |
| | | |
| | | } |
| | | |
| | | #endregion |
| | | |
| | | #region æ ¼å¼è½¬æ¢ |
| | | /// <summary> |
| | | /// 转æ¢åå
è¿å¶å符串å°åèæ°ç» |
| | | /// </summary> |
| | | /// <param name="msg">å¾
转æ¢å符串</param> |
| | | /// <returns>åèæ°ç»</returns> |
| | | public static byte[] HexToByte(string msg) |
| | | { |
| | | msg = msg.Replace(" ", "");//ç§»é¤ç©ºæ ¼ |
| | | |
| | | //create a byte array the length of the |
| | | |
| | | //divided by 2 (Hex is 2 characters in length) |
| | | |
| | | byte[] comBuffer = new byte[msg.Length / 2]; |
| | | for (int i = 0; i < msg.Length; i += 2) |
| | | { |
| | | comBuffer[i / 2] = (byte)Convert.ToByte(msg.Substring(i, 2), 16); |
| | | } |
| | | return comBuffer; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 转æ¢åèæ°ç»å°åå
è¿å¶å符串 |
| | | /// </summary> |
| | | /// <param name="comByte">å¾
转æ¢åèæ°ç»</param> |
| | | /// <returns>åå
è¿å¶å符串</returns> |
| | | public static string ByteToHex(byte[] comByte) |
| | | { |
| | | string returnStr = ""; |
| | | if (comByte != null) |
| | | { |
| | | for (int i = 0; i < comByte.Length; i++) |
| | | { |
| | | returnStr += comByte[i].ToString("X2")+" "; |
| | | } |
| | | } |
| | | return returnStr; |
| | | } |
| | | |
| | | #endregion |
| | | |
| | | /// <summary> |
| | | /// æ£æ¥ç«¯å£åç§°æ¯å¦åå¨ |
| | | /// </summary> |
| | | /// <param name="port_name"></param> |
| | | /// <returns></returns> |
| | | public static bool Exists(string port_name) |
| | | { |
| | | foreach (string port in SerialPort.GetPortNames()) if (port == port_name) return true; |
| | | return false; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// æ ¼å¼å端å£ç¸å
³å±æ§ |
| | | /// </summary> |
| | | /// <param name="port"></param> |
| | | /// <returns></returns> |
| | | public static string Format(SerialPort port) |
| | | { |
| | | return String.Format("{0} ({1},{2},{3},{4},{5})", |
| | | port.PortName, port.BaudRate, port.DataBits, port.Parity, port.StopBits, port.Handshake); |
| | | } |
| | | } |
| | | public class DataReceivedEventArgs : EventArgs |
| | | { |
| | | public string DataReceived; |
| | | public byte[] DataRecv; |
| | | public DataReceivedEventArgs(string m_DataReceived) |
| | | { |
| | | this.DataReceived = m_DataReceived; |
| | | } |
| | | public DataReceivedEventArgs(byte[] m_DataRecv) |
| | | { |
| | | this.DataRecv = m_DataRecv; |
| | | } |
| | | } |
| | | public delegate void DataReceivedEventHandler(DataReceivedEventArgs e); |
| | | |
| | | /// <summary> |
| | | /// 䏲壿°æ®ä½å表ï¼5,6,7,8ï¼ |
| | | /// </summary> |
| | | public enum SerialPortDatabits : int |
| | | { |
| | | FiveBits = 5, |
| | | SixBits = 6, |
| | | SeventBits = 7, |
| | | EightBits = 8 |
| | | } |
| | | /// <summary> |
| | | /// 䏲壿³¢ç¹çå表ã |
| | | /// 75,110,150,300,600,1 0,2400,4800,9600,14400,19200,28800,38400,56000,57600, |
| | | /// 115200,128000,230400,256000 |
| | | /// </summary> |
| | | public enum SerialPortBaudRates : int |
| | | { |
| | | BaudRate_75 = 75, |
| | | BaudRate_110 = 110, |
| | | BaudRate_150 = 150, |
| | | BaudRate_300 = 300, |
| | | BaudRate_600 = 600, |
| | | BaudRate_1200 = 1200, |
| | | BaudRate_2400 = 2400, |
| | | BaudRate_4800 = 4800, |
| | | BaudRate_9600 = 9600, |
| | | BaudRate_14400 = 14400, |
| | | BaudRate_19200 = 19200, |
| | | BaudRate_28800 = 28800, |
| | | BaudRate_38400 = 38400, |
| | | BaudRate_56000 = 56000, |
| | | BaudRate_57600 = 57600, |
| | | BaudRate_115200 = 115200, |
| | | BaudRate_128000 = 128000, |
| | | BaudRate_230400 = 230400, |
| | | BaudRate_256000 = 256000 |
| | | } |
| | | } |
New file |
| | |
| | | using System; |
| | | using System.Diagnostics; |
| | | using System.Net.Sockets; |
| | | using System.Threading; |
| | | |
| | | namespace Bro.Common.Link |
| | | { |
| | | public delegate void OnMessageRecv(byte[] dataBuff); |
| | | |
| | | /// <summary> |
| | | /// TCP客æ·ç«¯è¿æ¥ |
| | | /// </summary> |
| | | public class TCPClient : LinkBase |
| | | { |
| | | private static object synObj = new object(); |
| | | // æå¡å¨å°å |
| | | public string ServerIP { get;set;} |
| | | // æå¡å¨IP |
| | | public int ServerPort { get;set;} |
| | | // åå§åæ 示 |
| | | public bool IsInited { get;set; } |
| | | |
| | | public OnMessageRecv MessageRecv; |
| | | |
| | | // TCP客æ·ç«¯ |
| | | public TcpClient Client = new TcpClient(); |
| | | |
| | | private Thread pollTask; |
| | | |
| | | // 忢æ 示 |
| | | private bool bStop = false; |
| | | |
| | | public TCPClient() |
| | | { |
| | | IsInited = false; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// åå§å |
| | | /// </summary> |
| | | /// <returns></returns> |
| | | public override bool Init() |
| | | { |
| | | Client = new TcpClient(); |
| | | |
| | | // æ¥æ¶åéç¼åå¤§å° |
| | | Client.SendBufferSize = 4096; |
| | | Client.ReceiveBufferSize = 4096; |
| | | |
| | | // 读åè¶
æ¶ |
| | | Client.SendTimeout = 2000; |
| | | Client.ReceiveTimeout = 100; |
| | | |
| | | IsInited = true; |
| | | |
| | | return true; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 鿝 |
| | | /// </summary> |
| | | public override void Fnit() |
| | | { |
| | | IsInited = false; |
| | | |
| | | if ( null == Client ) |
| | | { |
| | | return; |
| | | } |
| | | |
| | | Client.Close(); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// è¿æ¥æå¡å¨ |
| | | /// </summary> |
| | | /// <returns></returns> |
| | | public override bool Open() |
| | | { |
| | | try |
| | | { |
| | | if ( Client.Connected ) |
| | | { |
| | | Trace.TraceInformation("TCPClient:{0} dunpliated open", this.Desp); |
| | | return true; |
| | | } |
| | | |
| | | Client.Connect(ServerIP, ServerPort); |
| | | |
| | | //pollTask = new Thread(new ThreadStart(PollThread)); |
| | | //pollTask.Start(); |
| | | |
| | | return true; |
| | | } |
| | | catch(Exception ex) |
| | | { |
| | | Trace.TraceError("TCPClient:{0} Open fail, ex:{1}-{2}", this.Desp, ex.Message, ex.StackTrace); |
| | | } |
| | | |
| | | return false; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// å
³éè¿æ¥ |
| | | /// </summary> |
| | | public override void Close() |
| | | { |
| | | try |
| | | { |
| | | if ( !Client.Connected ) |
| | | { |
| | | return; |
| | | } |
| | | bStop = true; |
| | | ClosePollTask(); |
| | | Client.Close(); |
| | | |
| | | } |
| | | catch(Exception ex) |
| | | { |
| | | Trace.TraceError("TCPClient:{0} Close fail, ex:{1}-{2}", this.Desp, ex.Message, ex.StackTrace); |
| | | } |
| | | } |
| | | |
| | | /// <summary> |
| | | /// å¤æå¯¹æ¹æ¯å¦å¨çº¿ï¼å¼ºå¶éæ°è¿æ¥ |
| | | /// </summary> |
| | | public void ReConnect() |
| | | { |
| | | if(!Client.IsOnline()) |
| | | { |
| | | Close(); |
| | | Init(); |
| | | Open(); |
| | | } |
| | | } |
| | | |
| | | /// <summary> |
| | | /// æ¥æ¶æ°æ® |
| | | /// </summary> |
| | | /// <returns></returns> |
| | | public override int Recv(byte[] rcvBuf, int offset) |
| | | { |
| | | int rcvLen = -1; |
| | | |
| | | if ( null == rcvBuf ) |
| | | { |
| | | return -1; |
| | | } |
| | | |
| | | try |
| | | { |
| | | var len = rcvBuf.Length - offset; |
| | | if ( len <= 0 ) |
| | | { |
| | | return -1; |
| | | } |
| | | rcvLen = Client.GetStream().Read(rcvBuf, offset, len); |
| | | } |
| | | catch(Exception ex) |
| | | { |
| | | Trace.TraceError("TCPClient:{0} Recv fail, ex:{1}-{2}", this.Desp, ex.Message, ex.StackTrace); |
| | | return -1; |
| | | } |
| | | |
| | | return rcvLen; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// åéæ°æ® |
| | | /// </summary> |
| | | /// <param name="sndBuf"></param> |
| | | /// <param name="bufLen"></param> |
| | | public override bool Send(byte[] sndBuf, int offset, int len) |
| | | { |
| | | if ( null == sndBuf ) |
| | | { |
| | | return false; |
| | | } |
| | | |
| | | try |
| | | { |
| | | Client.GetStream().Write(sndBuf, offset, len); |
| | | |
| | | return true; |
| | | } |
| | | catch(Exception ex) |
| | | { |
| | | Trace.TraceError("TCPClient:{0} Send fail, ex:{1}-{2}", this.Desp, ex.Message, ex.StackTrace); |
| | | } |
| | | |
| | | return false; |
| | | } |
| | | |
| | | public void ClosePollTask() |
| | | { |
| | | pollTask?.Abort(); |
| | | } |
| | | |
| | | public void StartPollTask() |
| | | { |
| | | pollTask = new Thread(new ThreadStart(PollThread)); |
| | | pollTask.Start(); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// çå¬çº¿ç¨ |
| | | /// </summary> |
| | | private void PollThread() |
| | | { |
| | | for (; ; ) |
| | | { |
| | | lock (synObj) |
| | | { |
| | | if (bStop) |
| | | break; |
| | | |
| | | var data = new byte[2048]; |
| | | if (Recv(data, 0) > 0) |
| | | { |
| | | MessageRecv(data); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | |
| | | } |
| | | |
| | | public static class TcpClientEx |
| | | { |
| | | public static bool IsOnline(this TcpClient c) |
| | | { |
| | | return !((c.Client.Poll(1000, SelectMode.SelectRead) && (c.Client.Available == 0)) || !c.Client.Connected); |
| | | } |
| | | } |
| | | } |
New file |
| | |
| | | using System; |
| | | using System.Diagnostics; |
| | | using System.Net.Sockets; |
| | | |
| | | namespace Bro.Common.Link |
| | | { |
| | | /// <summary> |
| | | /// TCPè¿æ¥ |
| | | /// </summary> |
| | | public class TCPLink : LinkBase |
| | | { |
| | | // ç½ç»è¿æ¥æ°æ®æµ |
| | | public NetworkStream netStream = null; |
| | | // è¿ç«¯ä¿¡æ¯ |
| | | public string remoteInfo {get;set;} |
| | | // æ¯å¦è¿ç«¯å
³é |
| | | public bool IsRemoteDisconn {get;set;} |
| | | |
| | | public TCPLink(NetworkStream stream) |
| | | { |
| | | this.netStream = stream; |
| | | this.IsRemoteDisconn = false; |
| | | } |
| | | |
| | | public TCPLink() |
| | | { |
| | | this.IsRemoteDisconn = false; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// åå§å |
| | | /// </summary> |
| | | /// <returns></returns> |
| | | public override bool Init() |
| | | { |
| | | // TODO: |
| | | return true; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// æå¼TCPè¿æ¥ |
| | | /// </summary> |
| | | /// <returns></returns> |
| | | public override bool Open() |
| | | { |
| | | // TODO: |
| | | return true; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// å
³éTCPè¿æ¥ |
| | | /// </summary> |
| | | public override void Close() |
| | | { |
| | | // TODO: |
| | | if ( null == this.netStream ) |
| | | { |
| | | return; |
| | | } |
| | | |
| | | try |
| | | { |
| | | this.netStream.Close(); |
| | | this.netStream = null; |
| | | |
| | | this.IsRemoteDisconn = true; |
| | | } |
| | | catch(Exception ex) |
| | | { |
| | | Trace.TraceError("TCPLink:{0} Close fail, ex:{1}-{2}", this.Desp, ex.Message, ex.StackTrace); |
| | | } |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 鿝 |
| | | /// </summary> |
| | | public override void Fnit() |
| | | { |
| | | this.Close(); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// æ¥æ¶æ°æ® |
| | | /// </summary> |
| | | /// <returns></returns> |
| | | public override int Recv(byte[] rcvBuf, int bufLen) |
| | | { |
| | | int len = -1; |
| | | try |
| | | { |
| | | len = netStream.Read(rcvBuf, 0, bufLen); |
| | | } |
| | | catch(Exception ex) |
| | | { |
| | | this.IsRemoteDisconn = true; |
| | | |
| | | Trace.TraceError("TCPLink:{0} Recv fail, ex:{1}-{2}", this.Desp, ex.Message, ex.StackTrace); |
| | | } |
| | | |
| | | return len; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// åéæ°æ® |
| | | /// </summary> |
| | | /// <param name="sndBuf"></param> |
| | | /// <param name="bufLen"></param> |
| | | public override bool Send(byte[] sndBuf, int offset, int len) |
| | | { |
| | | try |
| | | { |
| | | netStream.Write(sndBuf, offset, len); |
| | | |
| | | return true; |
| | | } |
| | | catch(Exception ex) |
| | | { |
| | | this.IsRemoteDisconn = true; |
| | | |
| | | Trace.TraceError("TCPLink:{0} Send fail, ex:{1}-{2}", this.Desp, ex.Message, ex.StackTrace); |
| | | } |
| | | |
| | | return false; |
| | | } |
| | | } |
| | | } |
New file |
| | |
| | | using System; |
| | | using System.Collections; |
| | | using System.Collections.Generic; |
| | | using System.Diagnostics; |
| | | using System.Net; |
| | | using System.Net.Sockets; |
| | | using System.Threading; |
| | | |
| | | namespace Bro.Common.Link |
| | | { |
| | | // 客æ·ç«¯å¨ä½ä»£ç |
| | | public delegate void OnClientOpen(TcpClient client); |
| | | public delegate void OnClientClose(TcpClient client); |
| | | public delegate void OnClientRecv(TcpClient client); |
| | | |
| | | /// <summary> |
| | | /// TCPæå¡å¨ |
| | | /// </summary> |
| | | public class TCPSvr |
| | | { |
| | | private static object synObj = new object(); |
| | | public OnClientOpen ClientOpen; |
| | | public OnClientClose ClientClose; |
| | | public OnClientRecv ClientRecv; |
| | | |
| | | // æå¡å¨æè¿° |
| | | public string Desp {get;set;} |
| | | // æå¡å¨IP |
| | | public string ServerIP { get;set; } |
| | | // æå¡å¨ç«¯å£ |
| | | public int ServerPort { get; set; } |
| | | // æå¡å¨çå¬ |
| | | private TcpListener tcpSvr = null; |
| | | // 忢æ 示 |
| | | private bool bStop = false; |
| | | // çå¬çº¿ç¨ |
| | | private Thread listenThread; |
| | | private Thread pollThread; |
| | | |
| | | private Dictionary<Socket,TcpClient> clientsMap = new Dictionary<Socket,TcpClient>(); |
| | | |
| | | public TCPSvr() |
| | | { |
| | | } |
| | | |
| | | public TCPSvr(string ip, int port) |
| | | { |
| | | ServerIP = ip; |
| | | ServerPort = port; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// åå§å |
| | | /// </summary> |
| | | /// <returns></returns> |
| | | public bool Init() |
| | | { |
| | | try |
| | | { |
| | | var ip = IPAddress.Parse(ServerIP); |
| | | |
| | | tcpSvr = new TcpListener(ip, ServerPort); |
| | | |
| | | bStop = false; |
| | | } |
| | | catch(Exception ex) |
| | | { |
| | | Trace.TraceError("TCP server init fail,ex:{0}", ex); |
| | | return false; |
| | | } |
| | | |
| | | return true; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// å¯å¨çå¬ |
| | | /// </summary> |
| | | /// <returns></returns> |
| | | public bool Start() |
| | | { |
| | | try |
| | | { |
| | | clientsMap.Clear(); |
| | | |
| | | tcpSvr.Start(); |
| | | |
| | | listenThread = new Thread(new ThreadStart(DoAcceptCallBack)); |
| | | listenThread.Start(); |
| | | |
| | | pollThread = new Thread(new ThreadStart(PollThread)); |
| | | pollThread.Start(); |
| | | |
| | | bStop = false; |
| | | } |
| | | catch(Exception ex) |
| | | { |
| | | Trace.TraceError("TCP server start listen fail,ex:{0}", ex); |
| | | return false; |
| | | } |
| | | |
| | | return true; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 忢çå¬ |
| | | /// </summary> |
| | | public void Stop() |
| | | { |
| | | bStop = true; |
| | | |
| | | try |
| | | { |
| | | tcpSvr.Stop(); |
| | | |
| | | listenThread.Join(); |
| | | pollThread.Join(); |
| | | |
| | | } |
| | | catch(Exception ex) |
| | | { |
| | | Trace.TraceError("TCP server stop listen fail,ex:{0}", ex); |
| | | } |
| | | |
| | | bStop = true; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// å
³é客æ·ç«¯ |
| | | /// </summary> |
| | | /// <param name="client"></param> |
| | | public void Close(TcpClient client) |
| | | { |
| | | lock(synObj) |
| | | { |
| | | clientsMap.Remove(client.Client); |
| | | |
| | | client.Close(); |
| | | } |
| | | } |
| | | |
| | | /// <summary> |
| | | /// ç§»é¤å®¢æ·ç«¯çå¬ |
| | | /// </summary> |
| | | /// <param name="client"></param> |
| | | public void Remove(TcpClient client) |
| | | { |
| | | lock (synObj) |
| | | { |
| | | clientsMap.Remove(client.Client); |
| | | } |
| | | } |
| | | |
| | | /// <summary> |
| | | /// çå¬çº¿ç¨ |
| | | /// </summary> |
| | | private void PollThread() |
| | | { |
| | | for(;;) |
| | | { |
| | | if (bStop) |
| | | { |
| | | CloseAllClient(); |
| | | |
| | | Trace.TraceInformation("{0} tcp server stop trigger", Desp); |
| | | break; |
| | | } |
| | | |
| | | lock(synObj) |
| | | { |
| | | PollRecv(); |
| | | } |
| | | |
| | | } |
| | | |
| | | Trace.TraceInformation("{0} tcp server stop finish", Desp); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// æ°æ¥å
¥å®¢æ·ç«¯è¿æ¥ |
| | | /// </summary> |
| | | /// <param name="ar"></param> |
| | | private void DoAcceptCallBack() |
| | | { |
| | | for (; ; ) |
| | | { |
| | | TcpClient client = null; |
| | | |
| | | try |
| | | { |
| | | if (!tcpSvr.Pending()) |
| | | { |
| | | Thread.Sleep(100); |
| | | continue; |
| | | } |
| | | |
| | | |
| | | client = tcpSvr.AcceptTcpClient(); |
| | | |
| | | // æ¥æ¶åéç¼åå¤§å° |
| | | client.ReceiveBufferSize = 2048; |
| | | client.SendBufferSize = 2048; |
| | | |
| | | // 读åè¶
æ¶ |
| | | client.SendTimeout = 2000; |
| | | client.ReceiveTimeout = 200; |
| | | |
| | | lock (synObj) |
| | | { |
| | | clientsMap.Add(client.Client, client); |
| | | |
| | | // éç¥å®¢æ·ç«¯è¿æ¥è¿å
¥ |
| | | if (null != ClientOpen) |
| | | { |
| | | Trace.TraceInformation("DoAcceptCallBack {0} tcp server, accept client{1}", Desp, client.Client.RemoteEndPoint); |
| | | |
| | | ClientOpen(client); |
| | | } |
| | | } |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | client?.Close(); |
| | | Trace.TraceInformation("DoAcceptCallBack fail, ex:{0},{1} tcp server, accept client{2}", ex.Message, |
| | | Desp, client?.Client.RemoteEndPoint.ToString()); |
| | | return; |
| | | } |
| | | } |
| | | } |
| | | |
| | | /// <summary> |
| | | /// æ£æ¥æ°æ®æ¥æ¶ |
| | | /// </summary> |
| | | private void PollRecv() |
| | | { |
| | | var rList = new ArrayList(); |
| | | var eList = new ArrayList(); |
| | | |
| | | foreach(var item in clientsMap) |
| | | { |
| | | var socket = item.Key; |
| | | |
| | | rList.Add(socket); |
| | | eList.Add(socket); |
| | | } |
| | | |
| | | if (clientsMap.Count == 0) |
| | | { |
| | | Thread.Sleep(200); |
| | | return; |
| | | } |
| | | |
| | | try |
| | | { |
| | | Thread.Sleep(200); |
| | | Socket.Select(rList, null, eList, 200); |
| | | |
| | | // 客æ·ç«¯å¼å¸¸åå
³é |
| | | foreach(var item in eList) |
| | | { |
| | | Socket socket = (Socket)item; |
| | | TcpClient client; |
| | | |
| | | if ( clientsMap.TryGetValue(socket, out client) && null != ClientClose ) |
| | | { |
| | | client.Close(); |
| | | |
| | | ClientClose(client); |
| | | } |
| | | |
| | | clientsMap.Remove(socket); |
| | | } |
| | | |
| | | // 客æ·ç«¯æ¯å¦ææ°æ® |
| | | foreach(var item in rList) |
| | | { |
| | | Socket socket = (Socket)item; |
| | | TcpClient client; |
| | | |
| | | if ( clientsMap.TryGetValue(socket, out client) && null != ClientRecv ) |
| | | { |
| | | ClientRecv(client); |
| | | |
| | | } |
| | | } |
| | | } |
| | | catch(Exception ex) |
| | | { |
| | | Trace.TraceInformation("CloseAllClient except{0}, {1} tcp server", ex.Message, Desp); |
| | | } |
| | | } |
| | | |
| | | /// <summary> |
| | | /// å
³éææå®¢æ·ç«¯è¿æ¥ |
| | | /// </summary> |
| | | private void CloseAllClient() |
| | | { |
| | | Trace.TraceInformation("CloseAllClient {0} tcp server, client cnt{0}", Desp, clientsMap.Count); |
| | | |
| | | foreach(var item in clientsMap) |
| | | { |
| | | var client = item.Value; |
| | | try |
| | | { |
| | | client.Close(); |
| | | |
| | | if ( null != ClientClose ) |
| | | { |
| | | ClientClose(client); |
| | | } |
| | | } |
| | | catch(Exception ex) |
| | | { |
| | | Trace.TraceInformation("CloseAllClient except{0}, {1} tcp server, accept client{2}", ex.Message, Desp, client.Client.RemoteEndPoint); |
| | | } |
| | | |
| | | } |
| | | |
| | | clientsMap.Clear(); |
| | | } |
| | | } |
| | | } |
New file |
| | |
| | | using System; |
| | | using System.Collections.Generic; |
| | | using System.IO; |
| | | using System.Linq; |
| | | using System.Text; |
| | | |
| | | namespace BroC.Comn.OEE |
| | | { |
| | | public class OEEToolKit |
| | | { |
| | | private DateTime lastClearTime = DateTime.Now; |
| | | |
| | | private int totalCount = 0; |
| | | |
| | | private int okCount = 0; |
| | | |
| | | private int ngCount = 0; |
| | | |
| | | private double ct = 0; |
| | | |
| | | private Dictionary<string, int> ngDic = new Dictionary<string, int>(); |
| | | |
| | | private List<DateTime> testEndTimeList = new List<DateTime>(); |
| | | |
| | | public int TotalCount |
| | | { |
| | | get => totalCount; |
| | | } |
| | | |
| | | public int OKCount |
| | | { |
| | | get => okCount; |
| | | } |
| | | |
| | | public int NGCount |
| | | { |
| | | get => ngCount; |
| | | } |
| | | |
| | | public double CT |
| | | { |
| | | get => ct; |
| | | set => ct = value; |
| | | } |
| | | |
| | | public double Rate |
| | | { |
| | | get |
| | | { |
| | | if (totalCount == 0) |
| | | return 0; |
| | | else |
| | | return okCount * 1.0 / totalCount; |
| | | } |
| | | } |
| | | |
| | | public int UPHAverage |
| | | { |
| | | get |
| | | { |
| | | var timeOffset = DateTime.Now - lastClearTime; |
| | | var averageUPH = timeOffset.TotalSeconds == 0 ? totalCount : totalCount / (timeOffset.TotalSeconds / 3600.0); |
| | | return Convert.ToInt32(averageUPH); |
| | | } |
| | | } |
| | | |
| | | public int UPHReal |
| | | { |
| | | get => testEndTimeList.Count; |
| | | } |
| | | |
| | | public OEEToolKit() |
| | | { |
| | | |
| | | } |
| | | |
| | | public void AddNgType(string type) |
| | | { |
| | | ngDic.Add(type, 0); |
| | | } |
| | | |
| | | public void Update(bool isok) |
| | | { |
| | | var time = DateTime.Now; |
| | | |
| | | testEndTimeList.Add(time); |
| | | |
| | | int removeCount = 0; |
| | | |
| | | for (int i = 0; i < testEndTimeList.Count; i++) |
| | | { |
| | | |
| | | if (testEndTimeList[i].CompareTo(time.AddHours(-1)) < 0) |
| | | { |
| | | removeCount++; |
| | | } |
| | | else |
| | | { |
| | | break; |
| | | } |
| | | } |
| | | |
| | | testEndTimeList.RemoveRange(0, removeCount); |
| | | |
| | | totalCount++; |
| | | if (isok) |
| | | okCount++; |
| | | else |
| | | ngCount++; |
| | | |
| | | } |
| | | |
| | | public void Update(string ngType) |
| | | { |
| | | if (ngType != "" && ngDic.ContainsKey(ngType)) |
| | | { |
| | | ngDic[ngType]++; |
| | | } |
| | | } |
| | | |
| | | public int GetNgTypeCount(string ngType) |
| | | { |
| | | if (!ngDic.Keys.Contains(ngType)) |
| | | return -1; |
| | | |
| | | return ngDic[ngType]; |
| | | } |
| | | |
| | | public void Clear() |
| | | { |
| | | lastClearTime = DateTime.Now; |
| | | |
| | | totalCount = 0; |
| | | |
| | | okCount = 0; |
| | | |
| | | ngCount = 0; |
| | | |
| | | var keys = ngDic.Keys.ToArray(); |
| | | |
| | | foreach (var item in keys) |
| | | { |
| | | ngDic[item] = 0; |
| | | } |
| | | |
| | | testEndTimeList.Clear(); |
| | | } |
| | | |
| | | public void Record(string fileName,string tag="-", string ct = "-") |
| | | { |
| | | FileInfo fileInfo = new FileInfo(fileName); |
| | | |
| | | if (!fileInfo.Directory.Exists) |
| | | fileInfo.Directory.Create(); |
| | | |
| | | if (!File.Exists(fileName)) |
| | | { |
| | | var title = "å¼å§æ¶é´,è®°å½æ¶é´,è¿è¡æ¶é´,æ ç¾,产é,è¯ç,OK,NG,"; |
| | | |
| | | foreach (var item in ngDic) |
| | | { |
| | | title += $"{item.Key},"; |
| | | } |
| | | |
| | | title += "CT,UPH(宿¶),UPH(å¹³å),"; |
| | | |
| | | File.AppendAllText(fileName, title, Encoding.UTF8); |
| | | File.AppendAllText(fileName, "\r\n", Encoding.UTF8); |
| | | } |
| | | |
| | | var recordTime = DateTime.Now; |
| | | var timeSpan = recordTime - lastClearTime; |
| | | |
| | | var content = $"{lastClearTime:yyyy-MM-dd-HH-mm-ss}," + |
| | | $"{recordTime:yyyy-MM-dd-HH-mm-ss}," + |
| | | $"{timeSpan.Minutes / 60.0:f2}," + |
| | | $"{tag}," + |
| | | $"{TotalCount}," + |
| | | $"{Rate * 100:f2}," + |
| | | $"{OKCount}," + |
| | | $"{NGCount},"; |
| | | |
| | | foreach (var item in ngDic) |
| | | { |
| | | content += $"{item.Value},"; |
| | | } |
| | | |
| | | content += $"{ct},{UPHReal},{UPHAverage}"; |
| | | |
| | | File.AppendAllText(fileName, content, Encoding.UTF8); |
| | | File.AppendAllText(fileName, "\r\n", Encoding.UTF8); |
| | | |
| | | Clear(); |
| | | } |
| | | |
| | | public void RecordNewLine(string fileName) |
| | | { |
| | | FileInfo fileInfo = new FileInfo(fileName); |
| | | |
| | | if (!fileInfo.Directory.Exists) |
| | | fileInfo.Directory.Create(); |
| | | |
| | | if (!File.Exists(fileName)) |
| | | { |
| | | var title = "å¼å§æ¶é´,è®°å½æ¶é´,è¿è¡æ¶é´,æ ç¾,产é,è¯ç,OK,NG,"; |
| | | |
| | | foreach (var item in ngDic) |
| | | { |
| | | title += $"{item.Key},"; |
| | | } |
| | | |
| | | title += "CT,UPH(宿¶),UPH(å¹³å),"; |
| | | |
| | | File.AppendAllText(fileName, title, Encoding.UTF8); |
| | | File.AppendAllText(fileName, "\r\n", Encoding.UTF8); |
| | | } |
| | | |
| | | var content = $"-," + |
| | | $"-," + |
| | | $"-," + |
| | | $"-," + |
| | | $"-," + |
| | | $"-," + |
| | | $"-," + |
| | | $"-,"; |
| | | |
| | | File.AppendAllText(fileName, content, Encoding.UTF8); |
| | | File.AppendAllText(fileName, "\r\n", Encoding.UTF8); |
| | | } |
| | | |
| | | public void StartAutoRecord() |
| | | { |
| | | |
| | | } |
| | | |
| | | private void AutoRecordThread() |
| | | { |
| | | |
| | | } |
| | | |
| | | } |
| | | } |
New file |
| | |
| | | using System; |
| | | using System.Collections; |
| | | using System.Collections.Generic; |
| | | using System.Reflection; |
| | | |
| | | namespace Bro.Common.Procedure |
| | | { |
| | | /// <summary> |
| | | /// IOæ°æ®ç¶æ |
| | | /// </summary> |
| | | public enum IODStat |
| | | { |
| | | IODSUndo, |
| | | IODSDoing, |
| | | IODSDone, |
| | | } |
| | | |
| | | /// <summary> |
| | | /// IOæ°æ®åºç±» |
| | | /// </summary> |
| | | public class IODataBase |
| | | { |
| | | #region 常é |
| | | |
| | | // é»è®¤çè¾å
¥å¤ç彿°åç§° |
| | | public const string DFT_HANDLE_METHOD_NAME = "HandleRequest"; |
| | | |
| | | #endregion |
| | | |
| | | #region 屿§ |
| | | |
| | | // æ¶æ¯å¤çè
|
| | | public List<object> Handlers {get;set;} |
| | | |
| | | public IODStat Stat { get { return curStat; }} |
| | | |
| | | // æ¶æ¯æè¿° |
| | | public string Desp { get;set; } |
| | | |
| | | // å建æ¶é´ |
| | | public DateTime CreateTime { get;set; } |
| | | |
| | | // å¤çå¼å§æ¶é´ |
| | | public DateTime BeginTime { get;set; } |
| | | |
| | | // å¤ç宿æ¶é´ |
| | | public DateTime EndTime { get;set; } |
| | | |
| | | // ç¨æ·æ°æ® |
| | | public object Data { get;set; } |
| | | |
| | | #endregion |
| | | |
| | | #region æååé |
| | | |
| | | private IODStat curStat = IODStat.IODSUndo; |
| | | |
| | | |
| | | #endregion |
| | | |
| | | #region ç»æä½ |
| | | |
| | | public IODataBase() |
| | | { |
| | | Handlers = null; |
| | | curStat = IODStat.IODSUndo; |
| | | |
| | | CreateTime = DateTime.Now; |
| | | BeginTime = DateTime.MinValue; |
| | | EndTime = DateTime.MinValue; |
| | | |
| | | Desp = this.GetType().ToString(); |
| | | Data = null; |
| | | } |
| | | |
| | | public IODataBase(List<object> handlers, string desp, object userData) |
| | | { |
| | | Handlers = handlers; |
| | | curStat = IODStat.IODSUndo; |
| | | |
| | | CreateTime = DateTime.Now; |
| | | BeginTime = DateTime.MinValue; |
| | | EndTime = DateTime.MinValue; |
| | | |
| | | this.Desp = desp; |
| | | this.Data = userData; |
| | | } |
| | | |
| | | #endregion |
| | | |
| | | #region æ¹æ³ |
| | | |
| | | /// <summary> |
| | | /// æ´¾é£å½æ°ï¼å©ç¨åå°æºå¶èªå¨æ´¾é£ç»è¾å
¥å¤çè
|
| | | /// |
| | | /// å¤çæ¹æ³ |
| | | /// 1. éåæ°æ®å¤çè
|
| | | /// 2. æ£å¯å¤çè
䏿¯å¦ææå®åç§°å½æ° |
| | | /// 3. æ£å¯æ¤å½æ°åæ°ï¼ä¸æ°è¿å弿®ç±»åä¸è´ |
| | | /// 4. å©ç¨åå°è°ç¨å½æ° |
| | | /// 5. è¿åå¼ä¸ºtrue,åå¤çç»æ |
| | | /// </summary> |
| | | public void Dispatch() |
| | | { |
| | | var paramType = this.GetType(); |
| | | var objParams = new object[1]; |
| | | |
| | | objParams[0] = this; |
| | | |
| | | if ( null == Handlers ) |
| | | { |
| | | return; |
| | | } |
| | | |
| | | foreach(var handler in Handlers) |
| | | { |
| | | if ( null == handler ) |
| | | { |
| | | continue; |
| | | } |
| | | |
| | | // è·ååæ°ç±»å |
| | | var instType = handler.GetType(); |
| | | |
| | | do |
| | | { |
| | | var instMthInfos = instType.GetMethods( BindingFlags.Instance | |
| | | BindingFlags.DeclaredOnly | |
| | | BindingFlags.Public | |
| | | BindingFlags.NonPublic |
| | | ); |
| | | var findsMthInfos = FindMethods(instMthInfos, paramType.Name); |
| | | |
| | | foreach (var item in findsMthInfos) |
| | | { |
| | | var mth = (MethodInfo)item; |
| | | |
| | | // è°ç¨å¯¹åºå®ä¾æ¹æ³ |
| | | var ret = (bool)mth.Invoke(handler, objParams); |
| | | if (ret) |
| | | { |
| | | return; |
| | | } |
| | | } |
| | | |
| | | instType = instType.BaseType; |
| | | |
| | | } while (instType != null); |
| | | |
| | | } |
| | | |
| | | } |
| | | |
| | | private Array FindMethods(MethodInfo[] mthInfos, string paramType) |
| | | { |
| | | var findMethods = new ArrayList(); |
| | | |
| | | foreach (var instMth in mthInfos) |
| | | { |
| | | var paramInfos = instMth.GetParameters(); |
| | | |
| | | // 鲿¢è°ç¨ç¶ç±»å½æ° |
| | | //if ( instType != instMth.DeclaringType ) |
| | | //{ |
| | | // continue; |
| | | //} |
| | | |
| | | // åæ°ä¸ªæ°æ£æ¥ |
| | | if (paramInfos.Length != 1) |
| | | { |
| | | continue; |
| | | } |
| | | |
| | | // æ¹æ³å¿
é¡»æ¯æå®åç§° |
| | | if (DFT_HANDLE_METHOD_NAME.CompareTo(instMth.Name) != 0) |
| | | { |
| | | continue; |
| | | } |
| | | |
| | | // åæ°ç±»åæ£æ¥ |
| | | if (paramInfos[0].ParameterType.Name.CompareTo(paramType) != 0) |
| | | { |
| | | continue; |
| | | } |
| | | |
| | | // æ¹æ³è¿å弿£å¯ |
| | | if (instMth.ReturnType.Name.CompareTo(typeof(bool).Name) != 0) |
| | | { |
| | | continue; |
| | | } |
| | | |
| | | findMethods.Add(instMth); |
| | | } |
| | | |
| | | return findMethods.ToArray(); |
| | | } |
| | | |
| | | #endregion |
| | | } |
| | | } |
New file |
| | |
| | | using System.Collections.Generic; |
| | | using System.Threading; |
| | | using Bro.Common.FSM; |
| | | using System.Diagnostics; |
| | | |
| | | namespace Bro.Common.Procedure |
| | | { |
| | | /// <summary> |
| | | /// æµç¨ç¶æ |
| | | /// </summary> |
| | | public enum ProcStat |
| | | { |
| | | PSInit = 0, // åå§å |
| | | PSOpen, // æå¼ |
| | | PSRunning, // è¿è¡ |
| | | PSReset, // éç½®, |
| | | PSReseting, // éç½®ä¸ |
| | | PSPause, // æå |
| | | PSClose, // å
³é |
| | | PSFnit // 鿝 |
| | | } |
| | | |
| | | /// <summary> |
| | | /// å¤çæµç¨åºç±» |
| | | /// |
| | | /// 说æï¼ |
| | | /// å·¥ç«ï¼å·¥ä½ç±»é½å¯ç»§æ¿æ¤ç±» |
| | | /// å®ä¹å¦ä¸å¨ä½ |
| | | /// 1. åå§å/鿝 |
| | | /// 2. æå¼/å
³é |
| | | /// 3. 读å |
| | | /// 4. 设置é项 |
| | | /// 5. äºä»¶è®¢é
/åæ¶ |
| | | /// </summary> |
| | | public abstract class ProcedureBase |
| | | { |
| | | #region 代çå®ä¹ |
| | | // ç¶æååäºä»¶ |
| | | public delegate void StatChange(ProcedureBase procedure, ProcStat srcStat, ProcStat dstStat); |
| | | |
| | | #endregion |
| | | |
| | | #region 常é |
| | | |
| | | // 线ç¨é»è®¤çå¾
æ¶é´ï¼åä½ï¼æ¯«ç§ï¼ |
| | | protected const int DFT_WAIT_INTERVAL = 200; |
| | | |
| | | #endregion |
| | | |
| | | #region äºä»¶ä»£ç |
| | | |
| | | // æµç¨ç¶æåå |
| | | public StatChange StatChangeEvent; |
| | | |
| | | #endregion |
| | | |
| | | #region 屿§ |
| | | // æµç¨æè¿° |
| | | public string Desp { get; set; } |
| | | // æµç¨ç¶æ |
| | | public ProcStat Stat{ get { return curStat; } } |
| | | |
| | | #endregion |
| | | |
| | | #region æååé |
| | | |
| | | // æµç¨ç¶ææº |
| | | protected SimpleFSM procFSM = new SimpleFSM(); |
| | | // æµç¨ç¶æ |
| | | protected ProcStat curStat = ProcStat.PSInit; |
| | | // ç产工åºåæ¥äºä»¶ |
| | | protected AutoResetEvent waitEvent = new AutoResetEvent(false); |
| | | // è¾å
¥éå |
| | | private Queue<IODataBase> requestQueue = new Queue<IODataBase>(); |
| | | // è¾å
¥å¤çè
|
| | | private List<object> requestHandlers = new List<object>(); |
| | | |
| | | #endregion |
| | | |
| | | #region ç»æä½ |
| | | |
| | | public ProcedureBase() |
| | | { |
| | | this.Desp = this.GetType().Name; |
| | | |
| | | // 设置é»è®¤çç¶æå¤çè
|
| | | AddRequestHandler(this); |
| | | |
| | | RegistProcFSM(); |
| | | } |
| | | |
| | | public ProcedureBase(SimpleFSM fsm) |
| | | { |
| | | this.Desp = this.GetType().Name; |
| | | this.procFSM = fsm; |
| | | |
| | | // 设置é»è®¤çç¶æå¤çè
|
| | | AddRequestHandler(this); |
| | | |
| | | RegistProcFSM(); |
| | | } |
| | | |
| | | #endregion |
| | | |
| | | #region å¤é¨æ¥å£ |
| | | |
| | | /// <summary> |
| | | /// æåæµç¨ |
| | | /// </summary> |
| | | public virtual void Pause() |
| | | { |
| | | Trace.TraceInformation("{0} Pause", Desp); |
| | | |
| | | var req = new ProcStatChangeReq(); |
| | | req.TargetStat = ProcStat.PSPause; |
| | | |
| | | AddRequest(req); |
| | | |
| | | } |
| | | |
| | | /// <summary> |
| | | /// éç½®æµç¨ |
| | | /// </summary> |
| | | public virtual void Reset() |
| | | { |
| | | Trace.TraceInformation("{0} Reset", Desp); |
| | | |
| | | var req = new ProcStatChangeReq(); |
| | | req.TargetStat = ProcStat.PSReset; |
| | | |
| | | AddRequest(req); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 请æ±å¤ç |
| | | /// </summary> |
| | | /// <param name="input"></param> |
| | | public void AddRequest(IODataBase req) |
| | | { |
| | | if (null == req) |
| | | { |
| | | return; |
| | | } |
| | | |
| | | lock (requestQueue) |
| | | { |
| | | // 设置è¾å
¥å¤çè
|
| | | req.Handlers = this.requestHandlers; |
| | | |
| | | requestQueue.Enqueue(req); |
| | | } |
| | | } |
| | | |
| | | #endregion |
| | | |
| | | #region åºç¡æµç¨ç¶ææº |
| | | |
| | | /// <summary> |
| | | /// 注ååºæ¬ç¶æå¤ç |
| | | /// </summary> |
| | | protected virtual bool RegistProcFSM() |
| | | { |
| | | int iRet = 0; |
| | | |
| | | if ( null == procFSM ) |
| | | { |
| | | return false; |
| | | } |
| | | |
| | | iRet += procFSM.Regist((int)ProcStat.PSInit, DoInit) ? 0 : 1; |
| | | iRet += procFSM.Regist((int)ProcStat.PSOpen, DoOpen) ? 0 : 1; |
| | | iRet += procFSM.Regist((int)ProcStat.PSClose, DoClose) ? 0 : 1; |
| | | iRet += procFSM.Regist((int)ProcStat.PSRunning, DoRunning) ? 0 : 1; |
| | | iRet += procFSM.Regist((int)ProcStat.PSReset, DoReset) ? 0 : 1; |
| | | iRet += procFSM.Regist((int)ProcStat.PSReseting, DoReseting) ? 0 : 1; |
| | | iRet += procFSM.Regist((int)ProcStat.PSPause, DoPause) ? 0 : 1; |
| | | iRet += procFSM.Regist((int)ProcStat.PSFnit, DoFnit) ? 0 : 1; |
| | | |
| | | // 设置åå§ç¶æ |
| | | SetState(ProcStat.PSInit); |
| | | |
| | | return (iRet == 0); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// åå§å |
| | | /// </summary> |
| | | public virtual void DoInit() |
| | | { |
| | | Trace.TraceInformation("{0} DoInit", Desp); |
| | | |
| | | ClearIOData(); |
| | | |
| | | SetState(ProcStat.PSOpen); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 鿝 |
| | | /// </summary> |
| | | public virtual void DoFnit() |
| | | { |
| | | Trace.TraceInformation("{0} DoFnit", Desp); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// å¼å§ |
| | | /// </summary> |
| | | public virtual void DoOpen() |
| | | { |
| | | Trace.TraceInformation("{0} DoOpen", Desp); |
| | | |
| | | SetState(ProcStat.PSRunning); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 忢 |
| | | /// </summary> |
| | | public virtual void DoClose() |
| | | { |
| | | Trace.TraceInformation("{0} DoClose", this.GetType().Name); |
| | | |
| | | SetState(ProcStat.PSFnit); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// éç½® |
| | | /// </summary> |
| | | public virtual void DoReset() |
| | | { |
| | | Trace.TraceInformation("{0} DoReset", this.GetType().Name); |
| | | |
| | | SetState(ProcStat.PSReseting); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// éç½®ä¸ |
| | | /// </summary> |
| | | public virtual void DoReseting() |
| | | { |
| | | Trace.TraceInformation("{0} DoReseting", this.GetType().Name); |
| | | |
| | | SetState(ProcStat.PSRunning); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// æå |
| | | /// </summary> |
| | | public virtual void DoPause() |
| | | { |
| | | // çå¾
|
| | | waitEvent.WaitOne(DFT_WAIT_INTERVAL); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 就绪 |
| | | /// </summary> |
| | | public virtual void DoRunning() |
| | | { |
| | | // TODO:æµç¨å°±ç»ªï¼ä¸»å¤ç |
| | | |
| | | } |
| | | |
| | | #endregion |
| | | |
| | | #region 请æ±å¤ç |
| | | |
| | | /// <summary> |
| | | /// ç¶æè½¬åè¯·æ± |
| | | /// </summary> |
| | | /// <param name="req"></param> |
| | | /// <returns></returns> |
| | | protected bool HandleRequest(ProcStatChangeReq req) |
| | | { |
| | | Trace.TraceInformation("{0} HandleRequest cur stat:{1} target:{2}", |
| | | Desp, GetStatDesp(Stat), GetStatDesp(req.TargetStat)); |
| | | |
| | | if ( req.TargetStat == Stat ) |
| | | { |
| | | Trace.TraceWarning("{0} HandleRequest fail, already in {1}", Desp, GetStatDesp(req.TargetStat)); |
| | | return true; |
| | | } |
| | | |
| | | if ( ProcStat.PSRunning != this.Stat ) |
| | | { |
| | | Trace.TraceWarning("{0} not running, can't turn to {1}", Desp, GetStatDesp(req.TargetStat)); |
| | | return true; |
| | | } |
| | | |
| | | SetState(req.TargetStat); |
| | | |
| | | return true; |
| | | } |
| | | |
| | | #endregion |
| | | |
| | | #region å
¶ä»æ¹æ³ |
| | | |
| | | /// <summary> |
| | | /// è¿è¡ |
| | | /// </summary> |
| | | public virtual void Run() |
| | | { |
| | | procFSM.Run(); |
| | | |
| | | Routine(); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// æµç¨æ¯æ¬¡è¿è¡çä¾ç¨ |
| | | /// </summary> |
| | | protected virtual void Routine() |
| | | { |
| | | // å¤çè¯·æ± |
| | | HandleRequests(); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// è®¾ç½®ç¶æ |
| | | /// </summary> |
| | | /// <param name="stat"></param> |
| | | protected internal void SetState(ProcStat stat) |
| | | { |
| | | var srcStat = GetStatDesp(curStat); |
| | | var dstStat = GetStatDesp(stat); |
| | | var tempStat = curStat; |
| | | |
| | | curStat = stat; |
| | | |
| | | if (null == procFSM) |
| | | { |
| | | return; |
| | | } |
| | | |
| | | Trace.TraceInformation("{0} stat [{1}]-->[{2}]", Desp, srcStat, dstStat); |
| | | |
| | | procFSM.SetStat((int)stat); |
| | | |
| | | // éç¥æµç¨ç¶æåå |
| | | if (null != StatChangeEvent) |
| | | { |
| | | StatChangeEvent(this, tempStat, stat); |
| | | } |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 设置è¾å
¥å¤çè
|
| | | /// </summary> |
| | | /// <param name="handler"></param> |
| | | public void AddRequestHandler(object handler) |
| | | { |
| | | requestHandlers.Add(handler); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// å¤çè¾å
¥ |
| | | /// </summary> |
| | | protected void HandleRequests() |
| | | { |
| | | var req = NextReq(); |
| | | if ( null == req ) |
| | | { |
| | | return; |
| | | } |
| | | |
| | | Trace.TraceInformation("[{0}] HandleRequest {1} ", Desp, req.GetType().Name); |
| | | |
| | | // è¾å
¥å¤çæ´¾é£ |
| | | req.Dispatch(); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// è·åä¸ä¸ªè¾å
¥ |
| | | /// </summary> |
| | | /// <returns></returns> |
| | | protected IODataBase NextReq() |
| | | { |
| | | return NextData(requestQueue); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// æ·»å æ°æ® |
| | | /// </summary> |
| | | /// <param name="data"></param> |
| | | /// <param name="dataQueue"></param> |
| | | protected void AddQueue(IODataBase data, Queue<IODataBase> dataQueue) |
| | | { |
| | | if ( null == data || null == dataQueue ) |
| | | { |
| | | return; |
| | | } |
| | | |
| | | lock(dataQueue) |
| | | { |
| | | dataQueue.Enqueue(data); |
| | | } |
| | | } |
| | | |
| | | /// <summary> |
| | | /// è·åä¸ä¸ªæ°æ® |
| | | /// </summary> |
| | | /// <param name="dataQueue"></param> |
| | | /// <returns></returns> |
| | | protected IODataBase NextData(Queue<IODataBase> dataQueue) |
| | | { |
| | | IODataBase ioData = null; |
| | | |
| | | lock(dataQueue) |
| | | { |
| | | if ( dataQueue.Count > 0 ) |
| | | { |
| | | ioData = dataQueue.Dequeue(); |
| | | } |
| | | } |
| | | |
| | | return ioData; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// æ
空è¾å
¥æ°æ® |
| | | /// </summary> |
| | | protected void ClearIOData() |
| | | { |
| | | lock(requestQueue) |
| | | { |
| | | requestQueue.Clear(); |
| | | } |
| | | } |
| | | |
| | | /// <summary> |
| | | /// è·åç¶ææè¿° |
| | | /// </summary> |
| | | /// <param name="procStat"></param> |
| | | /// <returns></returns> |
| | | private string GetStatDesp(ProcStat procStat) |
| | | { |
| | | var desp = ""; |
| | | |
| | | switch (procStat) |
| | | { |
| | | case ProcStat.PSInit: |
| | | desp = "PSInit"; |
| | | break; |
| | | case ProcStat.PSFnit: |
| | | desp = "PSFnit"; |
| | | break; |
| | | case ProcStat.PSOpen: |
| | | desp = "PSOpen"; |
| | | break; |
| | | case ProcStat.PSClose: |
| | | desp = "PSClose"; |
| | | break; |
| | | case ProcStat.PSRunning: |
| | | desp = "PSRunning"; |
| | | break; |
| | | case ProcStat.PSPause: |
| | | desp = "PSPause"; |
| | | break; |
| | | case ProcStat.PSReset: |
| | | desp = "PSReset"; |
| | | break; |
| | | case ProcStat.PSReseting: |
| | | desp = "PSReseting"; |
| | | break; |
| | | default: |
| | | desp = "Unknow"; |
| | | break; |
| | | } |
| | | |
| | | return desp; |
| | | } |
| | | |
| | | #endregion |
| | | } |
| | | |
| | | } |
New file |
| | |
| | | namespace Bro.Common.Procedure |
| | | { |
| | | /// <summary> |
| | | /// å·¥åºç¶æååè¾å
¥ |
| | | /// </summary> |
| | | public class ProcStatChangeReq : IODataBase |
| | | { |
| | | // ç®çç¶æ |
| | | public ProcStat TargetStat { get; set; } |
| | | } |
| | | } |
New file |
| | |
| | | namespace Bro.Common.Procedure |
| | | { |
| | | /// <summary> |
| | | /// åºç¡åå
|
| | | /// </summary> |
| | | public class UnitBase |
| | | { |
| | | |
| | | #region æä¸¾ |
| | | /// <summary> |
| | | /// åå
模åç¶æå®ä¹ |
| | | /// </summary> |
| | | public enum UnitStat |
| | | { |
| | | DSUninit = 0, // æªåå§å |
| | | DSInit, // å·²åå§å |
| | | DSOpen, // å·²æå¼ |
| | | DSClose, // å·²å
³é |
| | | DSExcept // å¼å¸¸ç¶æ |
| | | } |
| | | |
| | | #endregion |
| | | |
| | | #region 常éå®ä¹ |
| | | |
| | | #endregion |
| | | |
| | | #region 设å¤åºæ¬å±æ§ |
| | | |
| | | // è®¾å¤æè¿° |
| | | public string Desp { get;set; } |
| | | // 设å¤ç¶æ |
| | | public UnitStat Stat { get;set;} |
| | | // è®¾å¤æ¯å¦åå§å |
| | | public bool IsInit { |
| | | get { return UnitStat.DSInit == this.Stat; } |
| | | } |
| | | // è®¾å¤æ¯å¦æå¼ |
| | | public bool IsOpen { |
| | | get { return UnitStat.DSOpen == this.Stat;} |
| | | } |
| | | // 设å¤ID(å¯ç¨æ¥å¯ä¸æå®æ¬è®¾å¤) |
| | | public int Id { get;set; } |
| | | // 设å¤å¼å¸¸æè¿° |
| | | public string ExceptionDesp { get;set;} |
| | | // è®¾å¤æºå¸¦æ°æ® |
| | | public object Data { get;set; } |
| | | |
| | | #endregion |
| | | |
| | | /// <summary> |
| | | /// è®¾å¤æé 彿° |
| | | /// |
| | | /// 使ç¨äºé»è®¤ç设å¤id |
| | | /// </summary> |
| | | public UnitBase() |
| | | { |
| | | // é»è®¤æè¿° |
| | | this.Desp = this.GetType().Name; |
| | | // åå§ç¶æ |
| | | this.Stat = UnitStat.DSUninit; |
| | | // é»è®¤åå
ID |
| | | this.Id = this.GetHashCode(); |
| | | } |
| | | |
| | | #region åºæ¬å¨ä½ |
| | | /// <summary> |
| | | /// 设å¤åå§å |
| | | /// </summary> |
| | | /// <returns></returns> |
| | | public virtual bool Init() |
| | | { |
| | | Stat = UnitStat.DSInit; |
| | | |
| | | return true; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 设å¤éæ¯ |
| | | /// </summary> |
| | | public virtual void Fnit() |
| | | { |
| | | Stat = UnitStat.DSUninit; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// è®¾å¤æå¼ |
| | | /// </summary> |
| | | /// <returns></returns> |
| | | public virtual bool Open() |
| | | { |
| | | Stat = UnitStat.DSOpen; |
| | | |
| | | return true; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 设å¤å
³é |
| | | /// </summary> |
| | | public virtual void Close() |
| | | { |
| | | Stat = UnitStat.DSClose; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// æå¼åå¨ä½ |
| | | /// </summary> |
| | | public virtual void OnBeforeOpen() |
| | | { |
| | | |
| | | } |
| | | |
| | | /// <summary> |
| | | /// æå¼åå¨ä½ |
| | | /// </summary> |
| | | public virtual void OnAfterOpen() |
| | | { |
| | | |
| | | } |
| | | |
| | | /// <summary> |
| | | /// å
³éåå¨ä½ |
| | | /// </summary> |
| | | public virtual void OnBeforeClose() |
| | | { |
| | | |
| | | } |
| | | |
| | | /// <summary> |
| | | /// å
³éåå¨ä½ |
| | | /// </summary> |
| | | public virtual void OnAfterClose() |
| | | { |
| | | |
| | | } |
| | | |
| | | #endregion |
| | | |
| | | } |
| | | } |
New file |
| | |
| | | using System.Reflection; |
| | | using System.Runtime.InteropServices; |
| | | |
| | | // General Information about an assembly is controlled through the following |
| | | // set of attributes. Change these attribute values to modify the information |
| | | // associated with an assembly. |
| | | [assembly: AssemblyTitle("BroCComn")] |
| | | [assembly: AssemblyDescription("")] |
| | | [assembly: AssemblyConfiguration("")] |
| | | [assembly: AssemblyCompany("Microsoft")] |
| | | [assembly: AssemblyProduct("BroCComn")] |
| | | [assembly: AssemblyCopyright("Copyright © Microsoft 2016")] |
| | | [assembly: AssemblyTrademark("")] |
| | | [assembly: AssemblyCulture("")] |
| | | |
| | | // Setting ComVisible to false makes the types in this assembly not visible |
| | | // to COM components. If you need to access a type in this assembly from |
| | | // COM, set the ComVisible attribute to true on that type. |
| | | [assembly: ComVisible(false)] |
| | | |
| | | // The following GUID is for the ID of the typelib if this project is exposed to COM |
| | | [assembly: Guid("deb0c803-888e-42bb-b29c-448e9b6e09f0")] |
| | | |
| | | // Version information for an assembly consists of the following four values: |
| | | // |
| | | // Major Version |
| | | // Minor Version |
| | | // Build Number |
| | | // Revision |
| | | // |
| | | // You can specify all the values or you can default the Build and Revision Numbers |
| | | // by using the '*' as shown below: |
| | | [assembly: AssemblyVersion("1.0.*")] |
| | | //[assembly: AssemblyVersion("1.0.0.0")] |
| | | //[assembly: AssemblyFileVersion("1.0.0.0")] |
New file |
| | |
| | | //------------------------------------------------------------------------------ |
| | | // <auto-generated> |
| | | // æ¤ä»£ç ç±å·¥å
·çæã |
| | | // è¿è¡æ¶çæ¬:4.0.30319.42000 |
| | | // |
| | | // å¯¹æ¤æä»¶çæ´æ¹å¯è½ä¼å¯¼è´ä¸æ£ç¡®çè¡ä¸ºï¼å¹¶ä¸å¦æ |
| | | // éæ°çæä»£ç ï¼è¿äºæ´æ¹å°ä¼ä¸¢å¤±ã |
| | | // </auto-generated> |
| | | //------------------------------------------------------------------------------ |
| | | |
| | | namespace Broc.Comn.Properties { |
| | | using System; |
| | | |
| | | |
| | | /// <summary> |
| | | /// ä¸ä¸ªå¼ºç±»åçèµæºç±»ï¼ç¨äºæ¥æ¾æ¬å°åçå符串çã |
| | | /// </summary> |
| | | // æ¤ç±»æ¯ç± StronglyTypedResourceBuilder |
| | | // ç±»éè¿ç±»ä¼¼äº ResGen æ Visual Studio çå·¥å
·èªå¨çæçã |
| | | // è¥è¦æ·»å æç§»é¤æåï¼è¯·ç¼è¾ .ResX æä»¶ï¼ç¶åéæ°è¿è¡ ResGen |
| | | // (以 /str ä½ä¸ºå½ä»¤é项)ï¼æéæ°çæ VS 项ç®ã |
| | | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "15.0.0.0")] |
| | | [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] |
| | | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] |
| | | internal class Resource { |
| | | |
| | | private static global::System.Resources.ResourceManager resourceMan; |
| | | |
| | | private static global::System.Globalization.CultureInfo resourceCulture; |
| | | |
| | | [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] |
| | | internal Resource() { |
| | | } |
| | | |
| | | /// <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("Broc.Comn.Properties.Resource", typeof(Resource).Assembly); |
| | | resourceMan = temp; |
| | | } |
| | | return resourceMan; |
| | | } |
| | | } |
| | | |
| | | /// <summary> |
| | | /// éåå½å线ç¨ç CurrentUICulture 屿§ |
| | | /// éåå½å线ç¨ç CurrentUICulture 屿§ã |
| | | /// </summary> |
| | | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] |
| | | internal static global::System.Globalization.CultureInfo Culture { |
| | | get { |
| | | return resourceCulture; |
| | | } |
| | | set { |
| | | resourceCulture = value; |
| | | } |
| | | } |
| | | |
| | | /// <summary> |
| | | /// æ¥æ¾ç±»ä¼¼ <?xml version="1.0"?> |
| | | ///<configuration> |
| | | /// <configSections> |
| | | /// <section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net" /> |
| | | /// </configSections> |
| | | /// <log4net> |
| | | /// <!--Log4net Begin by Bruce 2016.06.14--> |
| | | /// <appender name="RollingFileAppender" type="log4net.Appender.RollingFileAppender"> |
| | | /// <file value=".\logs\" /> |
| | | /// <appendToFile value="true" /> |
| | | /// <!--logæ·æ¿ææ¾¶âæ--> |
| | | /// <maxSizeRollBackups value= "30"/> |
| | | /// <rollingStyle value="Composite" /> |
| | | /// <ma [å符串çå
¶ä½é¨åè¢«æªæ]"; çæ¬å°åå符串ã |
| | | /// </summary> |
| | | internal static string BroClog4net { |
| | | get { |
| | | return ResourceManager.GetString("BroClog4net", resourceCulture); |
| | | } |
| | | } |
| | | } |
| | | } |
New file |
| | |
| | | <?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> |
| | | <assembly alias="System.Windows.Forms" name="System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" /> |
| | | <data name="BroClog4net" type="System.Resources.ResXFileRef, System.Windows.Forms"> |
| | | <value>..\Log\BroClog4net.xml;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;gb2312</value> |
| | | </data> |
| | | </root> |
New file |
| | |
| | | using System; |
| | | |
| | | namespace Bro.Common.PubSub |
| | | { |
| | | /// <summary> |
| | | /// åå¸/订é
ä¸å¿ |
| | | /// </summary> |
| | | public interface IPubSubCenter |
| | | { |
| | | /// <summary> |
| | | /// 订é
äºä»¶ |
| | | /// </summary> |
| | | /// <param name="tag"></param> |
| | | /// <param name="method"></param> |
| | | /// <returns></returns> |
| | | bool Subscribe(string tag, Func<ISubscriber, object, object, object> method); |
| | | |
| | | /// <summary> |
| | | /// 订é
äºä»¶ |
| | | /// </summary> |
| | | /// <param name="tag"></param> |
| | | /// <param name="subscribe"></param> |
| | | /// <returns></returns> |
| | | bool Subscribe(string tag, ISubscriber subscribe); |
| | | |
| | | /// <summary> |
| | | /// åå¸äºä»¶ |
| | | /// </summary> |
| | | /// <param name="tag"></param> |
| | | /// <param name="data"></param> |
| | | void Publish(string tag, object param1, object param2); |
| | | |
| | | /// <summary> |
| | | /// è·åææè®¢é
è
|
| | | /// </summary> |
| | | /// <param name="tag"></param> |
| | | /// <returns></returns> |
| | | Subscribers GetSubscribers(string tag); |
| | | |
| | | /// <summary> |
| | | /// è·åæä¸ªè®¢é
è
|
| | | /// </summary> |
| | | /// <param name="tag"></param> |
| | | /// <param name="name"></param> |
| | | /// <returns></returns> |
| | | ISubscriber GetSubscriber(string tag, string name); |
| | | |
| | | /// <summary> |
| | | /// ç§»é¤æä¸ªè®¢é
è
|
| | | /// </summary> |
| | | /// <param name="tag"></param> |
| | | /// <param name="name"></param> |
| | | /// <returns></returns> |
| | | bool RemoveSubscriber(string tag, string name); |
| | | |
| | | /// <summary> |
| | | /// ç§»é¤æç±»ææè®¢é
è
|
| | | /// </summary> |
| | | /// <param name="tag"></param> |
| | | /// <returns></returns> |
| | | bool RemoveSubscribers(string tag); |
| | | } |
| | | } |
New file |
| | |
| | | namespace Bro.Common.PubSub |
| | | { |
| | | /// <summary> |
| | | /// åå¸è
|
| | | /// </summary> |
| | | public interface IPublisher |
| | | { |
| | | /// <summary> |
| | | /// åå¸çäºä»¶ |
| | | /// </summary> |
| | | string PublishTag { get; set; } |
| | | |
| | | object PublishData { get; set; } |
| | | } |
| | | } |
New file |
| | |
| | | using System; |
| | | |
| | | namespace Bro.Common.PubSub |
| | | { |
| | | /// <summary> |
| | | /// 订é
è
|
| | | /// </summary> |
| | | public interface ISubscriber |
| | | { |
| | | /// <summary> |
| | | /// 订é
çåç§° |
| | | /// </summary> |
| | | string SubscriberName { get; set; } |
| | | /// <summary> |
| | | /// ååºåå¸çæ¹æ³ |
| | | /// </summary> |
| | | Func<ISubscriber, object, object, object> SubMethod { get; set; } |
| | | } |
| | | } |
New file |
| | |
| | | namespace Bro.Common.PubSub |
| | | { |
| | | /// <summary> |
| | | /// E2E Coreäºä»¶ä¸å¿ |
| | | /// </summary> |
| | | public class PubSubCenter : SimplePubSubCenter |
| | | { |
| | | private static PubSubCenter inst = null; |
| | | |
| | | /// <summary> |
| | | /// Get Instance |
| | | /// </summary> |
| | | /// <returns></returns> |
| | | public static PubSubCenter GetInstance() |
| | | { |
| | | if (null == inst) |
| | | { |
| | | inst = new PubSubCenter(); |
| | | } |
| | | |
| | | return inst; |
| | | } |
| | | |
| | | private PubSubCenter() |
| | | { |
| | | } |
| | | } |
| | | } |
New file |
| | |
| | | using System; |
| | | using System.Collections.Generic; |
| | | using System.Diagnostics; |
| | | |
| | | namespace Bro.Common.PubSub |
| | | { |
| | | /// <summary> |
| | | /// ç®ååå¸/订é
ä¸å¿ |
| | | /// </summary> |
| | | public class SimplePubSubCenter : IPubSubCenter |
| | | { |
| | | /// <summary> |
| | | /// 订é
主é¢å订é
è
|
| | | /// </summary> |
| | | private Dictionary<string, Subscribers> subMap = new Dictionary<string, Subscribers>(); |
| | | |
| | | /// <summary> |
| | | /// 订é
äºä»¶ |
| | | /// </summary> |
| | | /// <param name="tag"></param> |
| | | /// <param name="method"></param> |
| | | /// <returns></returns> |
| | | public bool Subscribe(string tag, Func<ISubscriber, object, object, object> method) |
| | | { |
| | | var sub = new SimpleSubscriber(); |
| | | |
| | | // é»è®¤ä½¿ç¨hashå¼è®¾ç½®åç§°ï¼é²æ¢éå¤ |
| | | sub.SubscriberName = sub.GetHashCode().ToString(); |
| | | sub.SubMethod = method; |
| | | |
| | | return Subscribe(tag, sub); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 订é
äºä»¶ |
| | | /// </summary> |
| | | /// <param name="tag"></param> |
| | | /// <param name="subscribe"></param> |
| | | /// <returns></returns> |
| | | public bool Subscribe(string tag, ISubscriber subscribe) |
| | | { |
| | | if ( null == tag || null == subscribe ) |
| | | { |
| | | return false; |
| | | } |
| | | |
| | | if ( subMap.ContainsKey(tag) ) |
| | | { |
| | | var subs = subMap[tag]; |
| | | |
| | | return subs.Add(subscribe); |
| | | } |
| | | else |
| | | { |
| | | var subs = new Subscribers(); |
| | | if ( !subs.Add(subscribe) ) |
| | | { |
| | | return false; |
| | | } |
| | | |
| | | subMap.Add(tag, subs); |
| | | |
| | | return true; |
| | | } |
| | | } |
| | | |
| | | /// <summary> |
| | | /// åå¸äºä»¶ |
| | | /// </summary> |
| | | /// <param name="tag"></param> |
| | | /// <param name="data"></param> |
| | | public void Publish(string tag, object param1, object param2) |
| | | { |
| | | if ( null == tag ) |
| | | { |
| | | return; |
| | | } |
| | | |
| | | // è·åæætag订é
è
|
| | | var subs = GetSubscribers(tag); |
| | | if ( null == subs ) |
| | | { |
| | | return; |
| | | } |
| | | |
| | | var enmtor = subs.GetEnumerator(); |
| | | if ( null == enmtor ) |
| | | { |
| | | return; |
| | | } |
| | | |
| | | // éç¥ææè®¢é
è
äºä»¶ |
| | | while(enmtor.MoveNext()) |
| | | { |
| | | var cur = enmtor.Current; |
| | | if ( null == cur || null == cur.SubMethod) |
| | | { |
| | | continue; |
| | | } |
| | | |
| | | cur.SubMethod(cur, param1, param2); |
| | | } |
| | | } |
| | | |
| | | /// <summary> |
| | | /// è·åææè®¢é
è
|
| | | /// </summary> |
| | | /// <param name="tag"></param> |
| | | /// <returns></returns> |
| | | public Subscribers GetSubscribers(string tag) |
| | | { |
| | | if ( !subMap.ContainsKey(tag) ) |
| | | { |
| | | return null; |
| | | } |
| | | |
| | | return subMap[tag]; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// è·åæä¸ªè®¢é
è
|
| | | /// </summary> |
| | | /// <param name="tag"></param> |
| | | /// <param name="name"></param> |
| | | /// <returns></returns> |
| | | public ISubscriber GetSubscriber(string tag, string name) |
| | | { |
| | | var subs = GetSubscribers(tag); |
| | | if ( null == subs ) |
| | | { |
| | | return null; |
| | | } |
| | | |
| | | return subs.GetSubscriber(name); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// ç§»é¤æä¸ªè®¢é
è
|
| | | /// </summary> |
| | | /// <param name="tag"></param> |
| | | /// <param name="name"></param> |
| | | /// <returns></returns> |
| | | public bool RemoveSubscriber(string tag, string name) |
| | | { |
| | | var subs = GetSubscribers(tag); |
| | | if ( null == subs ) |
| | | { |
| | | return false; |
| | | } |
| | | |
| | | if ( !subs.Rmv(name) ) |
| | | { |
| | | return false; |
| | | } |
| | | |
| | | if ( subs.GetCount() == 0 ) |
| | | { |
| | | subMap.Remove(tag); |
| | | } |
| | | |
| | | return true; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// ç§»é¤è®¢é
|
| | | /// </summary> |
| | | /// <param name="tag"></param> |
| | | /// <param name="method"></param> |
| | | /// <returns></returns> |
| | | public bool RemoveSubscriber(string tag, Func<ISubscriber, object, object, object> method) |
| | | { |
| | | var subs = GetSubscribers(tag); |
| | | if ( null == subs ) |
| | | { |
| | | return false; |
| | | } |
| | | |
| | | if ( !subs.Rmv(method) ) |
| | | { |
| | | return false; |
| | | } |
| | | |
| | | if ( subs.GetCount() == 0 ) |
| | | { |
| | | subMap.Remove(tag); |
| | | } |
| | | |
| | | return true; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// ç§»é¤æç±»ææè®¢é
è
|
| | | /// </summary> |
| | | /// <param name="tag"></param> |
| | | /// <returns></returns> |
| | | public bool RemoveSubscribers(string tag) |
| | | { |
| | | var subs = GetSubscribers(tag); |
| | | if ( null == subs ) |
| | | { |
| | | return false; |
| | | } |
| | | |
| | | subMap.Remove(tag); |
| | | |
| | | return true; |
| | | } |
| | | |
| | | //IEnumerable<Object> Publish(string tag, object data); |
| | | |
| | | //IEnumerable<Object> Publish(string tag); |
| | | |
| | | //IEnumerable<Object> Publish(IPublisher publisher); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 订é
è
éå |
| | | /// </summary> |
| | | public class Subscribers |
| | | { |
| | | /// <summary> |
| | | /// 订é
è
éå |
| | | /// </summary> |
| | | private Dictionary<string, ISubscriber> subMap = new Dictionary<string,ISubscriber>(); |
| | | |
| | | /// <summary> |
| | | /// 订é
è
éå |
| | | /// </summary> |
| | | private List<ISubscriber> subList = new List<ISubscriber>(); |
| | | |
| | | public Subscribers() |
| | | { |
| | | |
| | | } |
| | | |
| | | /// <summary> |
| | | /// æ°å¢è®¢é
è
|
| | | /// </summary> |
| | | /// <param name="sub"></param> |
| | | /// <returns></returns> |
| | | public bool Add(ISubscriber sub) |
| | | { |
| | | if ( null == sub || subMap.ContainsKey(sub.SubscriberName) ) |
| | | { |
| | | return false; |
| | | } |
| | | |
| | | subMap.Add(sub.SubscriberName, sub); |
| | | subList.Add(sub); |
| | | |
| | | return true; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// ç§»é¤è®¢é
è
|
| | | /// </summary> |
| | | /// <param name="sub"></param> |
| | | /// <returns></returns> |
| | | public bool Rmv(ISubscriber sub) |
| | | { |
| | | if ( null == sub || !subMap.ContainsKey(sub.SubscriberName) ) |
| | | { |
| | | return false; |
| | | } |
| | | |
| | | subMap.Remove(sub.SubscriberName); |
| | | subList.Remove(sub); |
| | | |
| | | return true; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// ç§»é¤è®¢é
è
|
| | | /// </summary> |
| | | /// <param name="name"></param> |
| | | /// <returns></returns> |
| | | public bool Rmv(string name) |
| | | { |
| | | if ( !subMap.ContainsKey(name) ) |
| | | { |
| | | return false; |
| | | } |
| | | |
| | | var sub = subMap[name]; |
| | | |
| | | subMap.Remove(name); |
| | | subList.Remove(sub); |
| | | |
| | | return true; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// ç§»é¤è®¢é
è
|
| | | /// </summary> |
| | | /// <param name="method"></param> |
| | | /// <returns></returns> |
| | | public bool Rmv(Func<ISubscriber, object, object, object> method) |
| | | { |
| | | var names = new List<string>(); |
| | | |
| | | try |
| | | { |
| | | foreach(var item in subMap) |
| | | { |
| | | if ( null == item.Value ) |
| | | { |
| | | continue; |
| | | } |
| | | |
| | | // è¥æ¯ç¸å彿°ï¼åç§»é¤ |
| | | if ( item.Value.SubMethod == method ) |
| | | { |
| | | names.Add(item.Key); |
| | | } |
| | | } |
| | | |
| | | for(int i = 0; i < names.Count; i++) |
| | | { |
| | | subMap.Remove(names[i]); |
| | | } |
| | | |
| | | names.Clear(); |
| | | |
| | | return true; |
| | | } |
| | | catch(Exception ex) |
| | | { |
| | | Trace.TraceError("Remove subscriber fail,ex:{0}", ex); |
| | | } |
| | | |
| | | return false; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// æ£å¯è®¢é
è
æ¯å¦åå¨ |
| | | /// </summary> |
| | | /// <param name="sub"></param> |
| | | /// <returns></returns> |
| | | public bool Contains(ISubscriber sub) |
| | | { |
| | | if ( null == sub || !subMap.ContainsKey(sub.SubscriberName) ) |
| | | { |
| | | return false; |
| | | } |
| | | |
| | | return true; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// è·å订é
è
|
| | | /// </summary> |
| | | /// <param name="name"></param> |
| | | /// <returns></returns> |
| | | public ISubscriber GetSubscriber(string name) |
| | | { |
| | | if ( !subMap.ContainsKey(name) ) |
| | | { |
| | | return null; |
| | | } |
| | | |
| | | return subMap[name]; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// æ¸
餿æè®¢é
è
|
| | | /// </summary> |
| | | public void Clear() |
| | | { |
| | | subMap.Clear(); |
| | | subList.Clear(); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// è·å订é
è
æä¸¾ |
| | | /// </summary> |
| | | /// <returns></returns> |
| | | public IEnumerator<ISubscriber> GetEnumerator() |
| | | { |
| | | return subList.GetEnumerator(); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// è·å订é
è
æ°é |
| | | /// </summary> |
| | | /// <returns></returns> |
| | | public int GetCount() |
| | | { |
| | | return subMap.Count; |
| | | } |
| | | } |
| | | } |
New file |
| | |
| | | using System; |
| | | |
| | | namespace Bro.Common.PubSub |
| | | { |
| | | /// <summary> |
| | | /// ç®å订é
è
|
| | | /// </summary> |
| | | public class SimpleSubscriber : ISubscriber |
| | | { |
| | | /// <summary> |
| | | /// 订é
çåç§° |
| | | /// </summary> |
| | | public string SubscriberName { get; set; } |
| | | /// <summary> |
| | | /// ååºåå¸çæ¹æ³ |
| | | /// </summary> |
| | | public Func<ISubscriber, object, object, object> SubMethod { get; set; } |
| | | } |
| | | } |
New file |
| | |
| | | using System; |
| | | using System.Configuration; |
| | | using System.Diagnostics; |
| | | using System.IO; |
| | | using System.Xml.Serialization; |
| | | |
| | | namespace Bro.Common.Util |
| | | { |
| | | |
| | | /// <summary> |
| | | /// é
ç½®æä»¶å¸®å©ç±» |
| | | /// </summary> |
| | | public class ConfigHelper |
| | | { |
| | | |
| | | private static object ioLock = new object(); |
| | | |
| | | /// <summary> |
| | | /// è½½å
¥XMLé
ç½®æä»¶ |
| | | /// </summary> |
| | | /// <typeparam name="T"></typeparam> |
| | | /// <param name="filePath"></param> |
| | | /// <returns></returns> |
| | | public static T Load<T>(string filePath) |
| | | { |
| | | try |
| | | { |
| | | |
| | | lock (ioLock) |
| | | { |
| | | if (!File.Exists(filePath)) |
| | | { |
| | | return default(T); |
| | | } |
| | | |
| | | var fs = new FileStream(filePath, FileMode.Open); |
| | | var xs = new XmlSerializer(typeof(T)); |
| | | |
| | | var config = (T)xs.Deserialize(fs); |
| | | |
| | | fs.Close(); |
| | | |
| | | return config; |
| | | } |
| | | } |
| | | catch(Exception ex) |
| | | { |
| | | Trace.TraceError("ConfigHelper load fail, filepath:{0},ex:{1}", filePath, ex); |
| | | } |
| | | |
| | | return default(T); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// ä¿åXMLé
ç½®æä»¶ |
| | | /// </summary> |
| | | /// <typeparam name="T"></typeparam> |
| | | /// <param name="filePath"></param> |
| | | /// <param name="config"></param> |
| | | /// <returns></returns> |
| | | public static bool Save<T>(string filePath, T config) |
| | | { |
| | | try |
| | | { |
| | | lock(ioLock) |
| | | { |
| | | |
| | | var fs = new FileStream(filePath, FileMode.Create, FileAccess.Write, FileShare.None); |
| | | var xs = new XmlSerializer(typeof(T)); |
| | | |
| | | xs.Serialize(fs, config); |
| | | |
| | | fs.Close(); |
| | | } |
| | | |
| | | return true; |
| | | } |
| | | catch(Exception ex) |
| | | { |
| | | Trace.TraceError("ConfigHelper Save fail, filepath:{0},ex:{1}", filePath, ex); |
| | | } |
| | | |
| | | return false; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// ä¿®æ¹AppSettingsä¸é
ç½® |
| | | /// </summary> |
| | | /// <param name="key">keyå¼</param> |
| | | /// <param name="value">ç¸åºå¼</param> |
| | | public static bool SetConfigValue(string key, string value) |
| | | { |
| | | try |
| | | { |
| | | Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None); |
| | | if (config.AppSettings.Settings[key] != null) |
| | | config.AppSettings.Settings[key].Value = value; |
| | | else |
| | | config.AppSettings.Settings.Add(key, value); |
| | | config.Save(ConfigurationSaveMode.Modified); |
| | | ConfigurationManager.RefreshSection("appSettings"); |
| | | return true; |
| | | } |
| | | catch |
| | | { |
| | | return false; |
| | | } |
| | | } |
| | | } |
| | | } |
New file |
| | |
| | | using System.ComponentModel; |
| | | |
| | | namespace Broc.Comn.Util |
| | | { |
| | | public class LoginConfig |
| | | { |
| | | [Category("ç»å½ç¨æ·è®¾ç½®")] |
| | | [Description("ç¨æ·å")] |
| | | public string LoginUserName { get; set; } |
| | | |
| | | [Category("ç»å½ç¨æ·è®¾ç½®")] |
| | | [Description("ç¨æ·å¯ç ")] |
| | | public string LoginUserPassword { get; set; } |
| | | |
| | | [Category("ç»å½ç¨æ·è®¾ç½®")] |
| | | [Description("ç¨æ·ç»å½ç¶æ")] |
| | | public int LoginStatus { get; set; } |
| | | |
| | | public bool CheckLogin(LoginConfig loginConfig) |
| | | { |
| | | if (loginConfig.LoginUserName == "æä½å" && loginConfig.LoginUserPassword == "1") |
| | | { |
| | | loginConfig.LoginStatus = 1; |
| | | return true; |
| | | } |
| | | if (loginConfig.LoginUserName == "管çå" && loginConfig.LoginUserPassword == "2") |
| | | { |
| | | loginConfig.LoginStatus = 2; |
| | | return true; |
| | | } |
| | | if (loginConfig.LoginUserName == "å·¥ç¨å¸" && loginConfig.LoginUserPassword == "3") |
| | | { |
| | | loginConfig.LoginStatus = 3; |
| | | return true; |
| | | } |
| | | return false; |
| | | } |
| | | } |
| | | } |
New file |
| | |
| | | <?xml version="1.0" encoding="utf-8"?> |
| | | <packages> |
| | | <package id="log4net" version="2.0.8" targetFramework="net45" /> |
| | | </packages> |
| | |
| | |  |
| | | Microsoft Visual Studio Solution File, Format Version 12.00 |
| | | # Visual Studio 15 |
| | | VisualStudioVersion = 15.0.28307.1259 |
| | | # Visual Studio Version 16 |
| | | VisualStudioVersion = 16.0.30804.86 |
| | | MinimumVisualStudioVersion = 10.0.40219.1 |
| | | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "P066.Data", "P066.Data\P066.Data.csproj", "{8B8F7749-8823-48C6-B12A-54979E28C10C}" |
| | | EndProject |
| | | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Bro.Comn", "Bro.Comn\Bro.Comn.csproj", "{42407C78-FB75-4310-8910-DF515652A012}" |
| | | EndProject |
| | | Global |
| | | GlobalSection(SolutionConfigurationPlatforms) = preSolution |
| | | Debug|Any CPU = Debug|Any CPU |
| | | Debug|x86 = Debug|x86 |
| | | Release|Any CPU = Release|Any CPU |
| | | Release|x86 = Release|x86 |
| | | EndGlobalSection |
| | | GlobalSection(ProjectConfigurationPlatforms) = postSolution |
| | | {8B8F7749-8823-48C6-B12A-54979E28C10C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU |
| | | {8B8F7749-8823-48C6-B12A-54979E28C10C}.Debug|Any CPU.Build.0 = Debug|Any CPU |
| | | {8B8F7749-8823-48C6-B12A-54979E28C10C}.Debug|x86.ActiveCfg = Debug|Any CPU |
| | | {8B8F7749-8823-48C6-B12A-54979E28C10C}.Debug|x86.Build.0 = Debug|Any CPU |
| | | {8B8F7749-8823-48C6-B12A-54979E28C10C}.Release|Any CPU.ActiveCfg = Release|Any CPU |
| | | {8B8F7749-8823-48C6-B12A-54979E28C10C}.Release|Any CPU.Build.0 = Release|Any CPU |
| | | {8B8F7749-8823-48C6-B12A-54979E28C10C}.Release|x86.ActiveCfg = Release|Any CPU |
| | | {8B8F7749-8823-48C6-B12A-54979E28C10C}.Release|x86.Build.0 = Release|Any CPU |
| | | {42407C78-FB75-4310-8910-DF515652A012}.Debug|Any CPU.ActiveCfg = Debug|Any CPU |
| | | {42407C78-FB75-4310-8910-DF515652A012}.Debug|Any CPU.Build.0 = Debug|Any CPU |
| | | {42407C78-FB75-4310-8910-DF515652A012}.Debug|x86.ActiveCfg = Debug|x86 |
| | | {42407C78-FB75-4310-8910-DF515652A012}.Debug|x86.Build.0 = Debug|x86 |
| | | {42407C78-FB75-4310-8910-DF515652A012}.Release|Any CPU.ActiveCfg = Release|Any CPU |
| | | {42407C78-FB75-4310-8910-DF515652A012}.Release|Any CPU.Build.0 = Release|Any CPU |
| | | {42407C78-FB75-4310-8910-DF515652A012}.Release|x86.ActiveCfg = Release|x86 |
| | | {42407C78-FB75-4310-8910-DF515652A012}.Release|x86.Build.0 = Release|x86 |
| | | EndGlobalSection |
| | | GlobalSection(SolutionProperties) = preSolution |
| | | HideSolutionNode = FALSE |
| | |
| | | using System.Threading.Tasks; |
| | | using System.Windows.Forms; |
| | | using System.IO; |
| | | using Bro.Common; |
| | | using Bro.Common.Util; |
| | | |
| | | namespace P066.Data |
| | | { |
| | |
| | | { |
| | | DirectoryInfo directoryInfo1; |
| | | DirectoryInfo directoryInfo2; |
| | | private P066RunParam runparam = new P066RunParam(); |
| | | |
| | | |
| | | public Form1() |
| | | { |
| | | InitializeComponent(); |
| | | //ConfigHelper.Save(@"D:\P066-Data\P066XML\1.xml", runparam); |
| | | runparam = ConfigHelper.Load<P066RunParam>(@"D:\P066-Data\P066XML\Jin_Mid.xml"); |
| | | |
| | | |
| | | } |
| | | |
| | | private void btnLoadData1_Click(object sender, EventArgs e) |
| | |
| | | JudgeListSum.AddRange(judgeList); |
| | | |
| | | } |
| | | judgeList = GetLocation(judgeList); |
| | | //ç»é头åºåä½ç½®åè§åº¦ |
| | | list = GetLocation(list); |
| | | |
| | | string currPath = ""; |
| | | #region//夿æ¯åæ£æä»¶å¤¹è¿æ¯å¤æ£æä»¶å¤¹ |
| | | if (fileinfos1[i].Name.Contains("忣䏿¡")) |
| | |
| | | ChuNum++; |
| | | filenameDir = "忣䏿¡ç½ç¹"; |
| | | filename = "忣䏿¡ç½ç¹" + ChuNum; |
| | | judgeList = GetMidLocation(judgeList); |
| | | //ç»é头åºåä½ç½®åè§åº¦ |
| | | list = GetMidLocation(list); |
| | | } |
| | | else if (fileinfos1[i].Name.Contains("夿£ä¸æ¡")&& fileinfos1[i].Name.Contains("ç½ç¹")) |
| | | { |
| | | FuNum=FuNum+1; |
| | | filenameDir = "夿£ä¸æ¡ç½ç¹"; |
| | | filename = "夿£ä¸æ¡ç½ç¹" + FuNum; |
| | | judgeList = GetMidLocation(judgeList); |
| | | //ç»é头åºåä½ç½®åè§åº¦ |
| | | list = GetMidLocation(list); |
| | | } |
| | | else if ( fileinfos1[i].Name.Contains("夿£ä¸æ¡") &&fileinfos1[i].Name.Contains("å®ç½")) |
| | | { |
| | | GuaNum=GuaNum+1; |
| | | filenameDir = "夿£ä¸æ¡å®ç½"; |
| | | filename = "夿£ä¸æ¡å®ç½" + GuaNum; |
| | | } |
| | | judgeList = GetMidLocation(judgeList); |
| | | //ç»é头åºåä½ç½®åè§åº¦ |
| | | list = GetMidLocation(list); |
| | | } |
| | | else if (fileinfos1[i].Name.Contains("åæ£èæ¿")) |
| | | { |
| | | ChuNum++; |
| | | filenameDir = "åæ£èæ¿ç½ç¹"; |
| | | filename = "åæ£èæ¿ç½ç¹" + ChuNum; |
| | | judgeList = GetBkLocation(judgeList); |
| | | //ç»é头åºåä½ç½®åè§åº¦ |
| | | list = GetBkLocation(list); |
| | | } |
| | | else if (fileinfos1[i].Name.Contains("夿£èæ¿") && fileinfos1[i].Name.Contains("ç½ç¹")) |
| | | { |
| | | FuNum = FuNum + 1; |
| | | filenameDir = "夿£èæ¿ç½ç¹"; |
| | | filename = "夿£èæ¿ç½ç¹" + FuNum; |
| | | judgeList = GetBkLocation(judgeList); |
| | | //ç»é头åºåä½ç½®åè§åº¦ |
| | | list = GetBkLocation(list); |
| | | } |
| | | |
| | | currPath = directoryInfo1.Parent.Parent.FullName; |
| | |
| | | return dataList; |
| | | } |
| | | |
| | | |
| | | private List<ResultData> GetLocation(List<ResultData> list) |
| | | //è·å䏿¡è§åº¦åä½ç½® |
| | | private List<ResultData> GetMidLocation(List<ResultData> list) |
| | | { |
| | | var group = list.GroupBy(a => a.TimeTip); |
| | | foreach (var item in group) |
| | |
| | | listLensnumber1[k].angle = lenAngle; |
| | | |
| | | var distance = GetDistance(1050, 1050, listLensnumber1[k].X, listLensnumber1[k].Y); |
| | | if (distance <= 298.022) |
| | | if (distance <= runparam.MidLens1R1) |
| | | { |
| | | listLensnumber1[k].location = "é头"; |
| | | } |
| | | else if (298.022 < distance && distance <= 521.171) |
| | | else if (runparam.MidLens1R1 < distance && distance <= runparam.MidLens1R2) |
| | | { |
| | | listLensnumber1[k].location = "æé¢"; |
| | | } |
| | |
| | | } |
| | | listLensnumber2[k].angle = lenAngle; |
| | | var distance = GetDistance(1050, 1050, listLensnumber2[k].X, listLensnumber2[k].Y); |
| | | if (distance <= 367.696) |
| | | if (distance <= runparam.MidLens2R1) |
| | | { |
| | | listLensnumber2[k].location = "é头"; |
| | | } |
| | | else if (367.696 < distance && distance <= 653.911) |
| | | else if (runparam.MidLens2R1 < distance && distance <= runparam.MidLens2R2) |
| | | { |
| | | listLensnumber2[k].location = "æé¢"; |
| | | } |
| | |
| | | } |
| | | listLensnumber3[k].angle = lenAngle; |
| | | var distance = GetDistance(1050, 1050, listLensnumber3[k].X, listLensnumber3[k].Y); |
| | | if (distance <= 339.246) |
| | | if (distance <= runparam.MidLens3R1) |
| | | { |
| | | listLensnumber3[k].location = "é头"; |
| | | } |
| | | else if (distance < 339.246 && distance <= 520.584) |
| | | else if ( runparam.MidLens3R1< distance && distance <= runparam.MidLens3R2) |
| | | { |
| | | listLensnumber3[k].location = "æé¢"; |
| | | } |
| | |
| | | } |
| | | listLensnumber4[k].angle = lenAngle; |
| | | var distance = GetDistance(1050, 1050, listLensnumber4[k].X, listLensnumber4[k].Y); |
| | | if (distance <= 104.895) |
| | | if (distance <= runparam.MidLens4R1) |
| | | { |
| | | listLensnumber4[k].location = "é头"; |
| | | } |
| | | else if (104.895 < distance && distance <= 239.48) |
| | | else if (runparam.MidLens4R1 < distance && distance <= runparam.MidLens4R2) |
| | | { |
| | | listLensnumber4[k].location = "æé¢"; |
| | | } |
| | |
| | | } |
| | | return list; |
| | | } |
| | | //è·åèæ¿è§åº¦åä½ç½® |
| | | private List<ResultData> GetBkLocation(List<ResultData> list) |
| | | { |
| | | var group = list.GroupBy(a => a.TimeTip); |
| | | foreach (var item in group) |
| | | { |
| | | //计ç®é头1缺é·ä½ç½®åè§åº¦ |
| | | var listLensnumber1 = list.FindAll(a => a.TimeTip == item.Key && a.Lensnumber == 1); |
| | | for (int k = 0; k < listLensnumber1.Count; k++) |
| | | { |
| | | var lenAngle = GetAngle(listLensnumber1[k].X, listLensnumber1[k].Y); |
| | | if (lenAngle < 0) |
| | | { |
| | | lenAngle = 360 + lenAngle; |
| | | } |
| | | listLensnumber1[k].angle = lenAngle; |
| | | |
| | | var distance = GetDistance(1050, 1050, listLensnumber1[k].X, listLensnumber1[k].Y); |
| | | if (distance <= runparam.BkLens1R1) |
| | | { |
| | | listLensnumber1[k].location = "å¯è§åº"; |
| | | } |
| | | |
| | | else |
| | | { |
| | | listLensnumber1[k].location = "éå¯è§åº"; |
| | | } |
| | | |
| | | } |
| | | //计ç®é头2ä½ç½®åè§åº¦ |
| | | var listLensnumber2 = list.FindAll(a => a.TimeTip == item.Key && a.Lensnumber == 2); |
| | | for (int k = 0; k < listLensnumber2.Count; k++) |
| | | { |
| | | var lenAngle = GetAngle(listLensnumber2[k].X, listLensnumber2[k].Y); |
| | | if (lenAngle < 0) |
| | | { |
| | | lenAngle = 360 + lenAngle; |
| | | } |
| | | listLensnumber2[k].angle = lenAngle; |
| | | var distance = GetDistance(1050, 1050, listLensnumber2[k].X, listLensnumber2[k].Y); |
| | | if (distance <= runparam.BkLens2R1) |
| | | { |
| | | listLensnumber2[k].location = "å¯è§åº"; |
| | | } |
| | | else |
| | | { |
| | | listLensnumber2[k].location = "éå¯è§åº"; |
| | | } |
| | | } |
| | | //计ç®é头3ä½ç½®åè§åº¦ |
| | | var listLensnumber3 = list.FindAll(a => a.TimeTip == item.Key && a.Lensnumber == 3); |
| | | for (int k = 0; k < listLensnumber3.Count; k++) |
| | | { |
| | | var lenAngle = GetAngle(listLensnumber3[k].X, listLensnumber3[k].Y); |
| | | if (lenAngle < 0) |
| | | { |
| | | lenAngle = 360 + lenAngle; |
| | | } |
| | | listLensnumber3[k].angle = lenAngle; |
| | | var distance = GetDistance(1050, 1050, listLensnumber3[k].X, listLensnumber3[k].Y); |
| | | if (distance <= runparam.BkLens3R1) |
| | | { |
| | | listLensnumber3[k].location = "å¯è§åº"; |
| | | } |
| | | |
| | | else |
| | | { |
| | | listLensnumber3[k].location = "éå¯è§åº"; |
| | | } |
| | | } |
| | | //计ç®é头4ä½ç½®åè§åº¦ |
| | | var listLensnumber4 = list.FindAll(a => a.TimeTip == item.Key && a.Lensnumber == 4); |
| | | for (int k = 0; k < listLensnumber4.Count; k++) |
| | | { |
| | | var lenAngle = GetAngle(listLensnumber4[k].X, listLensnumber4[k].Y); |
| | | if (lenAngle < 0) |
| | | { |
| | | lenAngle = 360 + lenAngle; |
| | | } |
| | | listLensnumber4[k].angle = lenAngle; |
| | | var distance = GetDistance(1050, 1050, listLensnumber4[k].X, listLensnumber4[k].Y); |
| | | if (distance <= runparam.BkLens4R1) |
| | | { |
| | | listLensnumber4[k].location = "å¯è§åº"; |
| | | } |
| | | else |
| | | { |
| | | listLensnumber4[k].location = "éå¯è§åº"; |
| | | |
| | | } |
| | | } |
| | | |
| | | } |
| | | return list; |
| | | } |
| | | |
| | | private void WriteJR(List<ResultData> Lens,string item,int LensNumb, string file12) |
| | | { |
| | |
| | | <Compile Include="Form1.Designer.cs"> |
| | | <DependentUpon>Form1.cs</DependentUpon> |
| | | </Compile> |
| | | <Compile Include="P066RunParam.cs" /> |
| | | <Compile Include="Program.cs" /> |
| | | <Compile Include="Properties\AssemblyInfo.cs" /> |
| | | <EmbeddedResource Include="Form1.resx"> |
| | |
| | | <ItemGroup> |
| | | <None Include="App.config" /> |
| | | </ItemGroup> |
| | | <ItemGroup> |
| | | <ProjectReference Include="..\Bro.Comn\Bro.Comn.csproj"> |
| | | <Project>{42407c78-fb75-4310-8910-df515652a012}</Project> |
| | | <Name>Bro.Comn</Name> |
| | | </ProjectReference> |
| | | </ItemGroup> |
| | | <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> |
| | | </Project> |
New file |
| | |
| | | using System; |
| | | using System.Collections.Generic; |
| | | using System.Linq; |
| | | using System.Text; |
| | | using System.Threading.Tasks; |
| | | |
| | | namespace P066.Data |
| | | { |
| | | public class P066RunParam |
| | | { |
| | | public double MidLens1R1; |
| | | public double MidLens1R2; |
| | | public double MidLens2R1; |
| | | public double MidLens2R2; |
| | | public double MidLens3R1; |
| | | public double MidLens3R2; |
| | | public double MidLens4R1; |
| | | public double MidLens4R2; |
| | | |
| | | public double BkLens1R1; |
| | | //public double BkLens1R2; |
| | | public double BkLens2R1; |
| | | //public double BkLens2R2; |
| | | public double BkLens3R1; |
| | | //public double BkLens3R2; |
| | | public double BkLens4R1; |
| | | //public double BkLens4R2; |
| | | } |
| | | } |
New file |
| | |
| | | using System; |
| | | using System.Collections.Generic; |
| | | using System.Linq; |
| | | using System.Text; |
| | | using System.Threading.Tasks; |
| | | |
| | | namespace P066.Data |
| | | { |
| | | class P066RunPaream |
| | | { |
| | | public int Lens1R1; |
| | | public int Lens1R2; |
| | | public int Lens2R1; |
| | | public int Lens2R2; |
| | | public int Lens3R1; |
| | | public int Lens3R2; |
| | | public int Lens4R1; |
| | | public int Lens4R2; |
| | | |
| | | |
| | | |
| | | } |
| | | } |
New file |
| | |
| | | <?xml version="1.0"?> |
| | | <P066RunParam xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> |
| | | <MidLens1R1>298.022</MidLens1R1> |
| | | <MidLens1R2>521.171</MidLens1R2> |
| | | <MidLens2R1>367.696</MidLens2R1> |
| | | <MidLens2R2>653.911</MidLens2R2> |
| | | <MidLens3R1>339.246</MidLens3R1> |
| | | <MidLens3R2>520.584</MidLens3R2> |
| | | <MidLens4R1>104.895</MidLens4R1> |
| | | <MidLens4R2>239.48</MidLens4R2> |
| | | <BkLens1R1>0</BkLens1R1> |
| | | <BkLens2R1>0</BkLens2R1> |
| | | <BkLens3R1>0</BkLens3R1> |
| | | <BkLens4R1>0</BkLens4R1> |
| | | </P066RunParam> |
New file |
| | |
| | | <?xml version="1.0"?> |
| | | <P066RunParam xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> |
| | | <MidLens1R1>298.022</MidLens1R1> |
| | | <MidLens1R2>521.171</MidLens1R2> |
| | | <MidLens2R1>367.696</MidLens2R1> |
| | | <MidLens2R2>653.911</MidLens2R2> |
| | | <MidLens3R1>339.246</MidLens3R1> |
| | | <MidLens3R2>520.584</MidLens3R2> |
| | | <MidLens4R1>104.895</MidLens4R1> |
| | | <MidLens4R2>239.48</MidLens4R2> |
| | | <BkLens1R1>573.196</BkLens1R1> |
| | | <BkLens2R1>714.58</BkLens2R1> |
| | | <BkLens3R1>766</BkLens3R1> |
| | | <BkLens4R1>345</BkLens4R1> |
| | | </P066RunParam> |