Merge branch 'iioter:master' into master

This commit is contained in:
AbdalaMask 2024-01-03 06:24:57 +02:00 committed by GitHub
commit 56f965ec76
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 20 additions and 4 deletions

View File

@ -81,7 +81,7 @@ namespace IoTGateway
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IOptionsMonitor<Configs> configs, DeviceService deviceService, ModbusSlaveService modbusSlaveService)
public void Configure(IApplicationBuilder app, IOptionsMonitor<Configs> configs)
{
IconFontsHelper.GenerateIconFont();
app.UseExceptionHandler(configs.CurrentValue.ErrorHandler);

View File

@ -631,7 +631,9 @@ namespace PLC.ModBusMaster
break;
case DataTypeEnum.Float:
var f = float.Parse(ioArg.Value.ToString());
ModBusDataConvert.SetReal(shortArray, 0, f);
var fValue = BitConverter.SingleToUInt32Bits(f);
shortArray[1] = (ushort)(fValue & 0xffff);
shortArray[0] = (ushort)(fValue >> 16 & 0xffff);
toWriteArray = ChangeBuffersOrder(shortArray, ioArg.EndianType);
await _master.WriteMultipleRegistersAsync(slaveAddress, address, toWriteArray);
break;

View File

@ -289,7 +289,8 @@ namespace Plugin
{
Address = deviceVariable.DeviceAddress,
Value = para.Value,
ValueType = deviceVariable.DataType
ValueType = deviceVariable.DataType,
EndianType = deviceVariable.EndianType
};
var writeResponse = Driver
.WriteAsync(e.RequestId, deviceVariable.Method, ioArgModel).Result;

View File

@ -1,6 +1,7 @@
using IoTGateway.DataAccess;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using WalkingTec.Mvvm.Core;
@ -11,8 +12,14 @@ namespace Plugin
public static DBTypeEnum DbType;
public static string connnectSetting;
public static Guid? VariableSelectDeviceId, ConfigSelectDeviceId;
public IoTBackgroundService(IConfiguration configRoot)
private readonly IHostApplicationLifetime _appLifeTime;
private readonly IServiceProvider _serviceProvider;
public IoTBackgroundService(IConfiguration configRoot, IHostApplicationLifetime appLifeTime, IServiceProvider serviceProvider)
{
_appLifeTime = appLifeTime;
_serviceProvider = serviceProvider;
var connnectSettings = new List<ConnnectSettingsModel>();
configRoot.Bind("Connections", connnectSettings);
connnectSetting = connnectSettings[0].Value;
@ -53,6 +60,7 @@ namespace Plugin
}
public override Task StartAsync(CancellationToken cancellationToken)
{
_appLifeTime.ApplicationStarted.Register(OnStarted);
return Task.CompletedTask;
}
@ -60,5 +68,10 @@ namespace Plugin
{
return Task.CompletedTask;
}
private void OnStarted()
{
_ = _serviceProvider.GetRequiredService<DeviceService>();
_ = _serviceProvider.GetRequiredService<ModbusSlaveService>();
}
}
}