修复写字符串BUG

This commit is contained in:
anerx 2025-03-20 21:54:41 +08:00
parent 4251b781f9
commit 87f53c8949
2 changed files with 4 additions and 4 deletions

View File

@ -2,8 +2,8 @@ namespace Seyounth.Core.Extensions;
public static class DateTimeExtensions
{
public static int ToTimestamp(this DateTime dateTime)
public static long ToTimestamp(this DateTime dateTime)
{
return (int)new DateTimeOffset(dateTime).ToUnixTimeSeconds();
return new DateTimeOffset(dateTime).ToUnixTimeMilliseconds();
}
}

View File

@ -79,8 +79,8 @@ public class McPlc(string host, int port, Mitsubishi.McFrame type)
// 将字符串使用 ASCII 编码转换为字节数组
byte[] bytes = System.Text.Encoding.ASCII.GetBytes(value);
// 确保字节数组长度为 10
byte[] fixedLengthBytes = new byte[fixedLength];
Array.Copy(bytes, fixedLengthBytes, Math.Min(bytes.Length, fixedLength));
byte[] fixedLengthBytes = new byte[fixedLength*2];
Array.Copy(bytes, fixedLengthBytes, Math.Min(bytes.Length, fixedLength*2));
// 调用 WriteBytesAsync 方法写入字节数组
await WriteBytesAsync(address, fixedLengthBytes);
}