2014-10-10 update 2
This commit is contained in:
@@ -12,12 +12,16 @@ namespace CrossLampControl.WebApi.Controllers
|
||||
{
|
||||
public class CrossLampController : ApiController
|
||||
{
|
||||
ModbusUtility _utility = new ModbusUtility("COM6", (int)ModbusType.Rtu);
|
||||
ModbusUtility _utility = new ModbusUtility((int)ModbusType.Rtu, "COM3");
|
||||
[HttpGet]
|
||||
public Lamp GetLamp()
|
||||
{
|
||||
Lamp light = new Lamp();
|
||||
bool[] lamps = _utility.GetCoils(2, "0", 6);
|
||||
byte[] lampsbyte = _utility.GetDatas(2, (byte)ModbusProtocalReadDataFunctionCode.ReadCoilStatus, "0", 6);
|
||||
bool[] lamps =
|
||||
ValueHelper.Instance.ObjectArrayToDestinationArray<bool>(
|
||||
ValueHelper.Instance.ByteArrayToObjectArray(lampsbyte,
|
||||
new KeyValuePair<Type, int>(typeof (bool), 6)));
|
||||
if (lamps[0])
|
||||
{
|
||||
light.MainLamp = LightLamp.Green.ToString();
|
||||
|
||||
Binary file not shown.
@@ -494,11 +494,14 @@ namespace ModBus.Net
|
||||
}
|
||||
case "System.Boolean":
|
||||
{
|
||||
|
||||
bool[] value = Instance.GetBits(contents, ref count);
|
||||
for (int j = 0; j < value.Length; j++)
|
||||
int k = translateUnit.Value - i < 8 ? translateUnit.Value - i : 8;
|
||||
for (int j = 0; j < k; j++)
|
||||
{
|
||||
translation.Add(value[j]);
|
||||
}
|
||||
i += 7;
|
||||
break;
|
||||
}
|
||||
default:
|
||||
|
||||
Reference in New Issue
Block a user