2
0

3 Commits 3c7f0fb803 ... 5848ffa219

Autor SHA1 Nachricht Datum
  法 王 5848ffa219 1、增加byte数组和数据相互转换方法 vor 1 Woche
  法 王 f3bc5befc8 1、更新说明 vor 1 Woche
  法 王 4583830fdd 1、增加Device数据库读取 vor 1 Woche

+ 61 - 0
SKMC.API/Common/CommonUtil.cs

@@ -112,6 +112,67 @@ namespace SKMC.Api.Common
             }
         }
 
+        /// <summary>
+        /// 自动根据字节长度,返回对应有符号数值类型
+        /// </summary>
+        public static object AutoConvertToValue(byte[] bytes)
+        {
+            if (bytes == null || bytes.Length == 0)
+                return 0;
+
+            switch(bytes.Length)
+            {
+                case 2:
+                    return BitConverter.ToInt16(bytes, 0);
+                case 4:
+                    return BitConverter.ToInt32(bytes, 0);
+                case 8:
+                    return BitConverter.ToInt64(bytes, 0);
+                default:
+                    return BitConverter.ToInt64(bytes, 0);
+            }
+        }
+
+        /// <summary>
+        /// 自动根据字节长度,返回对应无符号数值类型
+        /// </summary>
+        public static object AutoConvertToUnsignedValue(byte[] bytes)
+        {
+            if (bytes == null || bytes.Length == 0)
+                return 0;
+
+            switch (bytes.Length)
+            {
+                case 2:
+                    return BitConverter.ToUInt16(bytes, 0);
+                case 4:
+                    return BitConverter.ToUInt32(bytes, 0);
+                case 8:
+                    return BitConverter.ToUInt64(bytes, 0);
+                default:
+                    return BitConverter.ToUInt64(bytes, 0);
+            }
+        }
+
+        /// <summary>
+        /// 将 long 转为 固定长度的字节数组(小端)
+        /// 支持:1、2、4、8 字节
+        /// 不足自动补0,超长自动截断
+        /// </summary>
+        public static byte[] ToFixedBytes(long value, int fixedLength)
+        {
+            // 支持 1/2/4/8 字节
+            // 先转成标准8字节
+            byte[] bytes = BitConverter.GetBytes(value);
+            byte[] result = new byte[fixedLength];
+
+            // 取前面fixedLength 字节
+            int copyLen = Math.Min(bytes.Length, fixedLength);
+            Array.Copy(bytes, result, copyLen);
+
+            return result;
+        }
+
         /// <summary>
         /// Float类型変換
         /// </summary>

+ 6 - 0
SKMC.API/Common/DB/SqlSugarTool.cs

@@ -33,6 +33,12 @@ namespace SKMC.Api.Common.DB
         /// <returns></returns>
         public static SqlSugarClient GetRuntimeDB() => GetDB("DB_RUNDATA");
 
+        /// <summary>
+        /// 从硬件库文件获取数据库实例
+        /// </summary>
+        /// <returns></returns>
+        public static SqlSugarClient GetDeviceDB() => GetDB("DB_DEVICE");
+
         private static SqlSugarClient GetDB(string dbName)
         {
             SqlSugarClient db = new SqlSugarClient(new ConnectionConfig()

+ 14 - 0
SKMC.API/Machine/Config/MachineDeviceErrorStore.cs

@@ -0,0 +1,14 @@
+using Prism.Mvvm;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace SKMC.Api.Machine.Config
+{
+    public abstract class MachineDeviceErrorStore : BindableBase
+    {
+        public abstract string GetAxisErrorInfo(short axisNo);
+    }
+}

+ 4 - 4
SKMC.API/Motion/Driver/IMotionDriver.cs

@@ -351,8 +351,8 @@ namespace SKMC.Api.Motion.Driver
         /// 写入SDO数据
         /// </summary>
         /// <param name="motionSdo">Sdo对象</param>
-        /// <returns>读取的SDO数据长度</returns>
-        int ReadSdoData(MotionSdo motionSdo);
+        /// <returns>是否读取成功</returns>
+        short ReadSdoData(MotionSdo motionSdo);
 
         /// <summary>
         /// 初始化Pdo配置
@@ -371,8 +371,8 @@ namespace SKMC.Api.Motion.Driver
         /// 读取Pdo数据
         /// </summary>
         /// <param name="motionPdo">Pdo对象</param>
-        /// <returns>读取的PDO数据长度</returns>
-        int ReadPdoData(MotionPdo motionPdo);
+        /// <returns>是否读取成功</returns>
+        short ReadPdoData(MotionPdo motionPdo);
 
         /// <summary>
         /// 写入自定义数据码

+ 1 - 1
SKMC.API/Motion/Model/MotionSdo.cs

@@ -39,6 +39,6 @@ namespace SKMC.Api.Motion.Model
         /// <summary>
         /// 数值(10进制)
         /// </summary>
-        public int DataVal { get; set; }
+        public long DataVal { get; set; }
     }
 }

+ 1 - 0
SKMC.API/SKMC.API.csproj

@@ -131,6 +131,7 @@
     <Compile Include="Common\Tasks\Tasks.cs" />
     <Compile Include="Common\Tcp\TCPClient.cs" />
     <Compile Include="Common\Tcp\TcpClientBase.cs" />
+    <Compile Include="Machine\Config\MachineDeviceErrorStore.cs" />
     <Compile Include="Machine\Monitor\MachineLatchTask.cs" />
     <Compile Include="Machine\Monitor\MachineStateLatchMonitor.cs" />
     <Compile Include="Vision\SKV0\SKVisionClient.cs" />