Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] LTIME is not translated properly #171

Merged
merged 5 commits into from
May 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -59,27 +59,43 @@ ApiPlcWriteRequest IWebApiPrimitive.PlcWriteRequestData
get
{
// TODO: review this casting to string... reason: there is some problem while creating request from long.
_plcWriteRequestData = WebApiConnector.CreateWriteRequest(Symbol, CyclicToWrite.Ticks.ToString(), _webApiConnector.DBName);
_plcWriteRequestData = WebApiConnector.CreateWriteRequest(Symbol, ToMicroSeconds(CyclicToWrite), _webApiConnector.DBName);
return _plcWriteRequestData;
}
}

/// <inheritdoc />
public void Read(string value)
public void Read(string result)
{
UpdateRead(TimeSpan.FromTicks(long.Parse(value)));
UpdateRead(TimeSpan.FromMilliseconds(ToMilliseconds(long.Parse(result))));
}


private long ToMilliseconds(long nanoseconds)
{
return nanoseconds / 1000000L;
}

private long ToNanoseconds(long nanoseconds)
{
return nanoseconds * 1000000L;
}

private string ToMicroSeconds(TimeSpan value)
{
return ToNanoseconds((long)value.TotalMilliseconds).ToString();
}

/// <inheritdoc />
public override async Task<TimeSpan> GetAsync()
{
return TimeSpan.FromTicks(long.Parse(await _webApiConnector.ReadAsync<string>(this)));
return TimeSpan.FromMilliseconds(ToMilliseconds(long.Parse(await _webApiConnector.ReadAsync<string>(this))));
}

/// <inheritdoc />
public override async Task<TimeSpan> SetAsync(TimeSpan value)
{
await _webApiConnector.WriteAsync(this, value.Ticks.ToString());
await _webApiConnector.WriteAsync(this, ToNanoseconds((long)value.TotalMilliseconds).ToString());
return value;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,12 @@ public OnlinerLTime(ITwinObject parent, string readableTail, string symbolTail)
/// <summary>
/// Gets the max value of <see cref="OnlinerLTime" />.
/// </summary>
public static TimeSpan MaxValue { get; } = TimeSpan.FromTicks(9223372036854775807 / 100);
public static TimeSpan MaxValue { get; } = TimeSpan.FromTicks(92233720368540000);

/// <summary>
/// Gets the min value of <see cref="OnlinerLTime" />.
/// </summary>
public static TimeSpan MinValue { get; } = TimeSpan.FromTicks(-9223372036854775808 / 100);
public static TimeSpan MinValue { get; } = TimeSpan.FromTicks(-92233720368540000);

/// <summary>
/// Gets the max value for this instance.
Expand Down
6 changes: 4 additions & 2 deletions src/AXSharp.connectors/tests/ax-test-project/src/program.st
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ PROGRAM MyProgram
mins.myREAL := REAL#-3.402823e+38 ;
mins.myLREAL := LREAL#-1.79769313486231e+308;
mins.myTIME := TIME#-106751d23h47m16s854ms;
mins.myLTIME := LTIME#-1067d12h28m40s368ms547us758ns;
mins.myLTIME := LTIME#-106751d23h47m16s854ms;
mins.myDATE := DATE#1970-01-01 ;
mins.myLDATE := LDATE#1970-01-01 ;
mins.myTIME_OF_DAY := TOD#0:0:0.0 ;
Expand Down Expand Up @@ -91,7 +91,9 @@ PROGRAM MyProgram
maxs.myREAL := REAL#+3.402823e+38 ;
maxs.myLREAL := LREAL#1.79769313486231e+308;
maxs.myTIME := TIME#106751d23h47m16s854ms;
maxs.myLTIME := LTIME#1067d12h28m40s368ms547us758ns;
maxs.myLTIME := LTIME#106751d23h47m16s854ms;
maxs.myLTIME := LTIME#106751d23h47m16s854ms;
// maxs.myLTIME := LTIME#1067d12h28m40s368ms547us758ns;
maxs.myDATE := DATE#2262-04-11 ;
maxs.myLDATE := LDATE#2262-04-11 ;
maxs.myTIME_OF_DAY := TOD#23:59:59.999000000 ;
Expand Down