2014-09-16 update 1
This commit is contained in:
@@ -4,11 +4,44 @@ using System.Linq;
|
|||||||
using System.Net;
|
using System.Net;
|
||||||
using System.Net.Http;
|
using System.Net.Http;
|
||||||
using System.Web.Http;
|
using System.Web.Http;
|
||||||
|
using CrossLampControl.WebApi.Models;
|
||||||
|
using ModBus.Net;
|
||||||
|
|
||||||
namespace CrossLampControl.WebApi.Controllers
|
namespace CrossLampControl.WebApi.Controllers
|
||||||
{
|
{
|
||||||
public class CrossLampController : ApiController
|
public class CrossLampController : ApiController
|
||||||
{
|
{
|
||||||
|
ModbusUtility _utility = new ModbusUtility("COM6", (int)ModbusType.Rtu);
|
||||||
|
[HttpGet]
|
||||||
|
public Lamp GetLamp()
|
||||||
|
{
|
||||||
|
Lamp light = new Lamp();
|
||||||
|
bool[] lamps = _utility.GetCoils(2, "0", 6);
|
||||||
|
if (lamps[0])
|
||||||
|
{
|
||||||
|
light.MainLamp = LightLamp.Green.ToString();
|
||||||
|
}
|
||||||
|
else if (lamps[1])
|
||||||
|
{
|
||||||
|
light.MainLamp = LightLamp.Yellow.ToString();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
light.MainLamp = LightLamp.Red.ToString();
|
||||||
|
}
|
||||||
|
if (lamps[3])
|
||||||
|
{
|
||||||
|
light.SubLamp = LightLamp.Green.ToString();
|
||||||
|
}
|
||||||
|
else if (lamps[4])
|
||||||
|
{
|
||||||
|
light.SubLamp = LightLamp.Yellow.ToString();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
light.SubLamp = LightLamp.Red.ToString();
|
||||||
|
}
|
||||||
|
return light;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -204,6 +204,7 @@
|
|||||||
<Compile Include="Models\AccountBindingModels.cs" />
|
<Compile Include="Models\AccountBindingModels.cs" />
|
||||||
<Compile Include="Models\AccountViewModels.cs" />
|
<Compile Include="Models\AccountViewModels.cs" />
|
||||||
<Compile Include="Models\IdentityModels.cs" />
|
<Compile Include="Models\IdentityModels.cs" />
|
||||||
|
<Compile Include="Models\Lamp.cs" />
|
||||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||||
<Compile Include="Providers\ApplicationOAuthProvider.cs" />
|
<Compile Include="Providers\ApplicationOAuthProvider.cs" />
|
||||||
<Compile Include="Results\ChallengeResult.cs" />
|
<Compile Include="Results\ChallengeResult.cs" />
|
||||||
@@ -237,6 +238,7 @@
|
|||||||
<Content Include="Areas\HelpPage\Views\Help\DisplayTemplates\CollectionModelDescription.cshtml" />
|
<Content Include="Areas\HelpPage\Views\Help\DisplayTemplates\CollectionModelDescription.cshtml" />
|
||||||
<Content Include="Areas\HelpPage\Views\Help\DisplayTemplates\ApiGroup.cshtml" />
|
<Content Include="Areas\HelpPage\Views\Help\DisplayTemplates\ApiGroup.cshtml" />
|
||||||
<Content Include="Areas\HelpPage\Views\Help\Api.cshtml" />
|
<Content Include="Areas\HelpPage\Views\Help\Api.cshtml" />
|
||||||
|
<None Include="Properties\PublishProfiles\CrossLamp.pubxml" />
|
||||||
<None Include="Scripts\jquery-1.10.2.intellisense.js" />
|
<None Include="Scripts\jquery-1.10.2.intellisense.js" />
|
||||||
<Content Include="Scripts\jquery-1.10.2.js" />
|
<Content Include="Scripts\jquery-1.10.2.js" />
|
||||||
<Content Include="Scripts\jquery-1.10.2.min.js" />
|
<Content Include="Scripts\jquery-1.10.2.min.js" />
|
||||||
@@ -248,7 +250,9 @@
|
|||||||
<Content Include="Scripts\modernizr-2.6.2.js" />
|
<Content Include="Scripts\modernizr-2.6.2.js" />
|
||||||
<Content Include="Scripts\respond.js" />
|
<Content Include="Scripts\respond.js" />
|
||||||
<Content Include="Scripts\respond.min.js" />
|
<Content Include="Scripts\respond.min.js" />
|
||||||
<Content Include="Web.config" />
|
<Content Include="Web.config">
|
||||||
|
<SubType>Designer</SubType>
|
||||||
|
</Content>
|
||||||
<Content Include="Web.Debug.config">
|
<Content Include="Web.Debug.config">
|
||||||
<DependentUpon>Web.config</DependentUpon>
|
<DependentUpon>Web.config</DependentUpon>
|
||||||
</Content>
|
</Content>
|
||||||
|
|||||||
26
Modbus.Net/CrossLampControl.WebApi/Models/Lamp.cs
Normal file
26
Modbus.Net/CrossLampControl.WebApi/Models/Lamp.cs
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Web;
|
||||||
|
|
||||||
|
public enum LightLamp{Red,Yellow,Green}
|
||||||
|
namespace CrossLampControl.WebApi.Models
|
||||||
|
{
|
||||||
|
public class Lamp
|
||||||
|
{
|
||||||
|
public string MainLamp { get; set; }
|
||||||
|
public string SubLamp { get; set; }
|
||||||
|
|
||||||
|
public Lamp()
|
||||||
|
{
|
||||||
|
MainLamp = LightLamp.Red.ToString();
|
||||||
|
SubLamp = LightLamp.Red.ToString();
|
||||||
|
}
|
||||||
|
|
||||||
|
public Lamp(LightLamp mLamp, LightLamp sLamp)
|
||||||
|
{
|
||||||
|
MainLamp = mLamp.ToString();
|
||||||
|
SubLamp = sLamp.ToString();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<!--
|
||||||
|
您 Web 项目的发布/打包进程将使用此文件。您可以通过编辑此 MSBuild 文件
|
||||||
|
来自定义该进程的行为。若要了解与此相关的详细信息,请访问 http://go.microsoft.com/fwlink/?LinkID=208121。
|
||||||
|
-->
|
||||||
|
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||||
|
<PropertyGroup>
|
||||||
|
<WebPublishMethod>FileSystem</WebPublishMethod>
|
||||||
|
<LastUsedBuildConfiguration>Release</LastUsedBuildConfiguration>
|
||||||
|
<LastUsedPlatform>Any CPU</LastUsedPlatform>
|
||||||
|
<SiteUrlToLaunchAfterPublish />
|
||||||
|
<LaunchSiteAfterPublish>True</LaunchSiteAfterPublish>
|
||||||
|
<ExcludeApp_Data>False</ExcludeApp_Data>
|
||||||
|
<publishUrl>d:\CrossLamp</publishUrl>
|
||||||
|
<DeleteExistingFiles>False</DeleteExistingFiles>
|
||||||
|
</PropertyGroup>
|
||||||
|
</Project>
|
||||||
Reference in New Issue
Block a user