2015-10-23 update 1 fix a bug and add FBox Connection
This commit is contained in:
81
Modbus.Net/ModBus.Net/FBox/FBoxUtility.cs
Normal file
81
Modbus.Net/ModBus.Net/FBox/FBoxUtility.cs
Normal file
@@ -0,0 +1,81 @@
|
||||
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; }
|
||||
|
||||
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, SigninMsg);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public FBoxUtility(FBoxType fBoxType, string connectionString, IEnumerable<CommunicationUnit> communicationUnits, SignalRSigninMsg msg)
|
||||
{
|
||||
ConnectionString = connectionString;
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user