Files
Modbus.Net/Modbus.Net/ModBus.Net/FBox/FBoxUtility.cs
2015-12-25 16:31:11 +08:00

85 lines
2.7 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ModBus.Net.FBox
{
public enum FBoxType
{
AddressSync = 0,
CommunicationTagSync = 1
}
public class FBoxUtility :BaseUtility
{
private FBoxType _fboxType;
private SignalRSigninMsg SigninMsg { get; set; }
public string LocalSequence { get; set; }
protected IEnumerable<CommunicationUnit> CommunicationUnits { get; set; }
public FBoxType ConnectionType
{
get
{
return _fboxType;
}
set
{
_fboxType = value;
switch (_fboxType)
{
case FBoxType.AddressSync:
{
throw new NotImplementedException();
}
case FBoxType.CommunicationTagSync:
{
Wrapper = new FBoxSignalRProtocal(ConnectionString, LocalSequence, SigninMsg);
break;
}
}
}
}
public FBoxUtility(FBoxType fBoxType, string connectionString, string localSequence, IEnumerable<CommunicationUnit> communicationUnits, SignalRSigninMsg msg)
{
ConnectionString = connectionString;
LocalSequence = localSequence;
CommunicationUnits = communicationUnits.AsEnumerable();
SigninMsg = msg;
ConnectionType = fBoxType;
AddressTranslator = new AddressTranslatorFBox();
}
public override void SetConnectionType(int connectionType)
{
ConnectionType = (FBoxType) connectionType;
}
protected override async Task<byte[]> GetDatasAsync(byte belongAddress, byte masterAddress, string startAddress, int getByteCount)
{
try
{
var readRequestFBoxInputStruct = new ReadRequestFBoxInputStruct(startAddress, (ushort)getByteCount, AddressTranslator);
var readRequestSimenseOutputStruct =
(ReadRequestFBoxOutputStruct)await
Wrapper.SendReceiveAsync(Wrapper[typeof(ReadRequestFBoxProtocal)], readRequestFBoxInputStruct);
return readRequestSimenseOutputStruct.GetValue;
}
catch (Exception)
{
return null;
}
}
public override Task<bool> SetDatasAsync(byte belongAddress, byte masterAddress, string startAddress, object[] setContents)
{
throw new NotImplementedException();
}
}
}