diff --git a/ADP.sln b/ADP.sln index 9850756..35c3475 100644 --- a/ADP.sln +++ b/ADP.sln @@ -35,6 +35,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UpdateInfoMoudle", "UpdateI EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MonitorModule", "MonitorModule\MonitorModule.csproj", "{850A5BE8-0BC1-4D6A-8351-DD812C9C4427}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CAN驱动", "CAN驱动\CAN驱动.csproj", "{D1868672-0132-4B1A-A393-C2CF49A25E74}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -101,6 +103,10 @@ Global {850A5BE8-0BC1-4D6A-8351-DD812C9C4427}.Debug|Any CPU.Build.0 = Debug|Any CPU {850A5BE8-0BC1-4D6A-8351-DD812C9C4427}.Release|Any CPU.ActiveCfg = Release|Any CPU {850A5BE8-0BC1-4D6A-8351-DD812C9C4427}.Release|Any CPU.Build.0 = Release|Any CPU + {D1868672-0132-4B1A-A393-C2CF49A25E74}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {D1868672-0132-4B1A-A393-C2CF49A25E74}.Debug|Any CPU.Build.0 = Debug|Any CPU + {D1868672-0132-4B1A-A393-C2CF49A25E74}.Release|Any CPU.ActiveCfg = Release|Any CPU + {D1868672-0132-4B1A-A393-C2CF49A25E74}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/ADP/ADP.csproj b/ADP/ADP.csproj index e915270..876b4b7 100644 --- a/ADP/ADP.csproj +++ b/ADP/ADP.csproj @@ -9,6 +9,7 @@ + diff --git a/CAN驱动/CAN.cs b/CAN驱动/CAN.cs new file mode 100644 index 0000000..4056f0b --- /dev/null +++ b/CAN驱动/CAN.cs @@ -0,0 +1,417 @@ +using Common.Attributes; +using System.Collections.Generic; +using System.ComponentModel; +using System.Diagnostics; +using System.IO; +using System.Runtime.InteropServices; +using System.Text.Json; +using TSMaster; +namespace CAN驱动 +{ + [ADPCommand] + public class CAN + { + + public static event Action ConnectEvent; + public static event Action DisConnectEvent; + public static bool ConnectFlag { get; set; } = false; + + /// + /// 初始化CAN驱动 + /// + /// + /// + /// + [Browsable(false)] + public static int Init(string ProjectName, string? filePath = null) + { + if (string.IsNullOrEmpty(filePath)) + { + return TsMasterApi.initialize_lib_tsmaster(ProjectName); + } + else + { + return TsMasterApi.initialize_lib_tsmaster_with_project(ProjectName, Path.GetFullPath(filePath)); + } + } + + /// + /// 释放CAN驱动 + /// + [Browsable(false)] + public static void Release() + { + TsMasterApi.finalize_lib_tsmaster(); + } + + public static int obj = 0; + public static TCANFDQueueEvent_Win32 listener; + [Browsable(false)] + public static int RegisterListener(TCANFDQueueEvent_Win32 listenEvent) + { + listener = listenEvent; + var re = TsMasterApi.tsapp_register_event_canfd(ref obj, listener); + Debug.Assert(re == 0); + return re; + } + + [Browsable(false)] + public static int UnRegisterListener(TCANFDQueueEvent_Win32 listenEvent = null) + { + if (listenEvent is not null) + { + listener = listenEvent; + } + var re = TsMasterApi.tsapp_unregister_event_canfd(ref obj, listener); + Debug.Assert(re == 0); + return re; + } + + /// + /// 连接 + /// + /// + public static int Connect() + { + + var re = TsMasterApi.tsapp_connect(); + if (re == 0) + { + re = TsMasterApi.tscom_can_rbs_start(); + if (re == 0) + { + ConnectFlag = true; + Task.Run(() => ConnectEvent?.Invoke()); + } + else + { + Debug.WriteLine($"CAN_RBS启动失败,错误代码:{re}"); + } + } + else + { + Debug.WriteLine($"CAN连接失败,错误代码:{re}"); + return re; + } + return re; + } + + /// + /// 断开 + /// + /// + public static int DisConnect() + { + var re = TsMasterApi.tsapp_disconnect(); + //Debug.Assert(re == 0); + if (re == 0) + { + ConnectFlag = false; + Task.Run(() => DisConnectEvent?.Invoke()); + } + else + { + Debug.WriteLine($"断开CAN连接失败,错误代码:{re}"); + } + + + return re; + } + + /// + /// 加载DBC + /// + /// + /// + /// + /// + [Browsable(false)] + public static int LoadDBC(string filePath, int[] channel, out uint databaseID) + { + databaseID = 0; + + var re = TsMasterApi.tsdb_load_can_db(Path.GetFullPath(filePath), string.Join(",", channel), ref databaseID); + foreach (var item in channel) + { + DBCParse.parse(databaseID, item); + DBCParse.rbs_parse(databaseID, item); + } + + return re; + } + + /// + /// 卸载DBC + /// + /// + /// + [Browsable(false)] + public static int UnLoadDBC(uint? databaseID = null) + { + if (databaseID == null) + { + return TsMasterApi.tsdb_unload_can_dbs(); + } + else + { + return TsMasterApi.tsdb_unload_can_db(databaseID.Value); + } + } + + /// + /// 开始记录日志 + /// + /// + /// + public static int StartLogging(string filePath) + { + return TsMasterApi.tsapp_start_logging(Path.GetFullPath(filePath)); + } + + /// + /// 结束记录日志 + /// + /// + public static int StopLogging() + { + return TsMasterApi.tsapp_stop_logging(); + } + + /// + /// 弹出通道映射窗口 + /// + /// + /// + [Browsable(false)] + public static int ShowChannelMappingWindow(bool isWait = false) + { + return TsMasterApi.tsapp_show_tsmaster_window("Hardware", isWait); + } + + /// + /// 获取信号值 + /// + /// + /// + /// + /// + public static double GetSignalValue(byte channel, string AMsgName, string ASgnName) + { + double value = double.NaN; + var find = DBCParse.MsgDatabase[channel].First(s => s.msg_name == AMsgName); + var re = TsMasterApi.tsdb_get_signal_value_canfd(ref find.ACANFD, AMsgName, ASgnName, ref value); + + return value; + } + + /// + /// 获取信号值 + /// + /// + /// + /// + /// + /// + [Browsable(false)] + public static int GetSignalValue(byte channel, string AMsgName, string ASgnName, ref double value) + { + var find = DBCParse.MsgDatabase[channel].First(s => s.msg_name == AMsgName); + return TsMasterApi.tsdb_get_signal_value_canfd(ref find.ACANFD, AMsgName, ASgnName, ref value); + } + + /// + /// 获取信号值 + /// + /// + /// + /// + /// + /// + + [Browsable(false)] + public static int GetSignalValue(ref TLIBCANFD ACANFD, string AMsgName, string ASgnName, ref double value) + { + return TsMasterApi.tsdb_get_signal_value_canfd(ref ACANFD, AMsgName, ASgnName, ref value); + } + + /// + /// 设置信号值 + /// + /// + /// + /// + /// + /// + /// + /// + /// + public static int SetSignalValue(byte channel, string AMsgName, string ASgnName, double AValue, bool isSend = false, float sendPeriod = 0) + { + var find = DBCParse.MsgDatabase[channel].First(s => s.msg_name == AMsgName); + find.ACANFD.FIdxChn = channel; + var re = TsMasterApi.tsdb_set_signal_value_canfd(ref find.ACANFD, AMsgName, ASgnName, AValue); + Debug.Assert(re == 0); + if (re != 0) throw new Exception($"设置报文失败!返回代码{re}"); + if (re != 0) return re; + if (isSend) + { + if (sendPeriod == 0) + { + return TsMasterApi.tsapp_transmit_canfd_async(ref find.ACANFD); + } + else + { + return TsMasterApi.tsapp_add_cyclic_msg_canfd(ref find.ACANFD, sendPeriod); + } + } + return 0; + } + + + /// + /// 设置信号值 + /// + /// + /// + /// + /// + public static int SetSignalValue(APP_CHANNEL channel, string AMsgName, float sendPeriod = 0) + { + var find = DBCParse.MsgDatabase[(byte)channel].First(s => s.msg_name == AMsgName); + find.ACANFD.FIdxChn = (byte)channel; + if (sendPeriod == 0) + { + return TsMasterApi.tsapp_transmit_canfd_async(ref find.ACANFD); + } + else + { + return TsMasterApi.tsapp_add_cyclic_msg_canfd(ref find.ACANFD, sendPeriod); + } + } + + /// + /// 发送自定义报文 + /// + /// + [Browsable(false)] + public static int SetMsg(TLIBCANFD msg) + { + return TsMasterApi.tsapp_transmit_canfd_async(ref msg); + } + + /// + /// 设置报文 + /// + /// 通道 + /// DBC数据库ID + /// 报文数组 + public static void SetMsg(APP_CHANNEL channel, int ID, byte[] bytes) + { + var find = DBCParse.MsgDatabase[(byte)channel].FirstOrDefault(s => s.ACANFD.FIdentifier == ID); + if (find != null) + { + Array.Copy(bytes, 0, find.ACANFD.FData, 0, Math.Min(bytes.Length, find.ACANFD.FData.Length)); + } + } + + /// + /// 发送自定义报文 + /// + /// + /// + /// + /// + /// + /// + /// + /// + /// + /// + /// + /// + public static int SendMsg(APP_CHANNEL AIdxChn, int AID, bool AIsTx, bool AIsExt, + bool AIsRemote, byte ADLC, byte[] ADataArray, bool AIsFD = true, bool AIsBRS = false, + bool isUpdateDBCDatabase = false, float sendPeriod = 0) + { + var send = new TLIBCANFD + { + FIdxChn = (byte)AIdxChn, + FProperties = 0, + FIdentifier = AID, + FDLC = ADLC, + FTimeUS = 0uL, + FData = new byte[64], + FFDProperties = 0, + FIsTx = AIsTx, + FIsError = false, + FIsExt = AIsExt, + FIsRemote = AIsRemote, + FIsFD = AIsFD, + FIsBRS = AIsBRS + }; + int length = Math.Min(ADataArray.Length, 64); + Array.Copy(ADataArray, 0, send.FData, 0, length); + int re; + if (sendPeriod == 0) + { + re = TsMasterApi.tsapp_transmit_canfd_async(ref send); + } + else + { + re = TsMasterApi.tsapp_add_cyclic_msg_canfd(ref send, sendPeriod); + } + + if (isUpdateDBCDatabase) + { + var find = DBCParse.MsgDatabase[(byte)AIdxChn].FirstOrDefault(s => s.ACANFD.FIdentifier == send.FIdentifier); + if (find != null) + { + Array.Copy(send.FData, 0, find.ACANFD.FData, 0, Math.Min(ADataArray.Length, find.ACANFD.FData.Length)); + } + } + return re; + } + + /// + /// 添加循环发送报文 + /// + /// + /// + /// + /// + public static int AddCyclicMsg(byte channel, string AMsgName, float sendPeriod) + { + var find = DBCParse.MsgDatabase[channel].First(s => s.msg_name == AMsgName); + find.ACANFD.FIdxChn = channel; + return TsMasterApi.tsapp_add_cyclic_msg_canfd(ref find.ACANFD, sendPeriod); + } + + /// + /// 清除循环发送的报文 + /// + /// + public static int DeleteCyclicMsgs() + { + return TsMasterApi.tsapp_delete_cyclic_msgs(); + } + + /// + /// 获取错误提示 + /// + /// 错误代码 + /// + public static string GetErrorDescription(int errorCode) + { + IntPtr ADesc = IntPtr.Zero; + TsMasterApi.tsapp_get_error_description(errorCode, ref ADesc); + + if (ADesc == IntPtr.Zero) return $"未知错误代码: {errorCode}"; + + // 假设返回的是 ANSI 字符串(如 C 的 char*) + string? description = Marshal.PtrToStringAnsi(ADesc); + + return description ?? $"未知错误代码: {errorCode}"; + } + + } +} diff --git a/CAN驱动/CAN驱动.csproj b/CAN驱动/CAN驱动.csproj new file mode 100644 index 0000000..0a6e281 --- /dev/null +++ b/CAN驱动/CAN驱动.csproj @@ -0,0 +1,20 @@ + + + + net8.0 + enable + false + enable + + + + + + + + + ..\CanDriver\bin\Debug\net8.0\Interop.TSMasterAPI.dll + + + + diff --git a/CAN驱动/DBCParse.cs b/CAN驱动/DBCParse.cs new file mode 100644 index 0000000..47ab723 --- /dev/null +++ b/CAN驱动/DBCParse.cs @@ -0,0 +1,269 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Reflection; +using System.Runtime.InteropServices; +using System.Security.Cryptography; +using System.Text; +using System.Text.Json.Serialization; +using System.Threading.Tasks; +using TSMaster; + +namespace CAN驱动 +{ + public struct can_network + { + [JsonInclude] + public string network_name; + [JsonInclude] + public can_node[] can_nodes; + + } + public struct can_node + { + [JsonInclude] + public string node_name; + [JsonInclude] + public can_message[] tx_can_Messages; + [JsonInclude] + public can_message[] rx_can_Messages; + } + public struct can_message + { + [JsonInclude] + public string message_name; + [JsonInclude] + public string[] signals; + } + + public class _Msg_ + { + public int msg_type { get; set; } + public int msg_id { get; set; } + public int msg_cyclic { get; set; } + public byte msg_dlc { get; set; } + public string msg_name { get; set; } + public string[] signal_Name { get; set; } + public int msg_brs { get; set; } + public TLIBCANFD ACANFD; + } + public enum Msg_Type + { + CAN = 0, + CANFD = 1, + } + /// + /// DBC 文件信息类型枚举,用于指定 tsdb_get_can_db_info 查询的内容类型。 + /// + public enum DBCINFO + { + /// 网络名称 + NETWORK_Name = 0, + + /// CAN 报文总数 + CAN_MSG_COUNT = 11, + /// CAN FD 报文总数 + CANFD_MSG_COUNT = 12, + /// 节点总数 + NODE_COUNT = 14, + + /// 信号名称 + SIGNAL_NAME = 33, + + /// CAN 报文类型 + CAN_MSG_TYPE = 40, + /// CAN 报文 DLC(数据长度码) + CAN_MSG_DLC = 41, + /// CAN 报文 ID + CAN_MSG_ID = 42, + /// CAN 报文周期 + CAN_MSG_CYCLIC = 43, + /// CAN 报文名称 + CAN_MSG_NAME = 44, + /// CAN 报文信号数量 + CAN_MSG_SIGNAL_COUNT = 47, + /// CAN 报文信号名称索引 + CAN_MSG_SIGNAL_NAME_INDEX = 48, + + /// CAN FD 报文类型 + CANFD_MSG_TYPE = 60, + /// CAN FD 报文 DLC(数据长度码) + CANFD_MSG_DLC = 61, + /// CAN FD 报文 ID + CANFD_MSG_ID = 62, + /// CAN FD 报文周期 + CANFD_MSG_CYCLIC = 63, + /// CAN FD 报文名称 + CANFD_MSG_NAME = 64, + /// CAN FD 报文信号数量 + CANFD_MSG_SIGNAL_COUNT = 67, + /// CAN FD 报文信号名称索引 + CANFD_MSG_SIGNAL_NAME_INDEX = 68, + + /// 节点名称 + NODE_Name = 101, + /// 节点发送 CAN 报文数量 + NODE_TX_CAN_COUNT = 103, + /// 节点发送 CAN 报文索引 + NODE_TX_CAN_MESSAGE_INDEX = 104, + /// 节点接收 CAN 报文数量 + NODE_RX_CAN_COUNT = 105, + /// 节点接收 CAN 报文索引 + NODE_RX_CAN_MESSAGE_INDEX = 106, + /// 节点发送 CAN FD 报文数量 + NODE_TX_CANFD_COUNT = 107, + /// 节点发送 CAN FD 报文索引 + NODE_TX_CANFD_MESSAGE_INDEX = 108, + /// 节点接收 CAN FD 报文数量 + NODE_RX_CANFD_COUNT = 109, + /// 节点接收 CAN FD 报文索引 + NODE_RX_CANFD_MESSAGE_INDEX = 110, + } + + public class DBCParse + { + public static List> MsgDatabase { get; set; } = + [.. Enumerable.Range(0, 12).Select(_ => new List<_Msg_>())]; + public static can_network can_Network; + public static string tsdb_get_can_db_info(uint ADatabaseId, int AType, int AIndex, int ASubIndex) + { + nint tmpInt = new nint(); + int ret = TsMasterApi.tsdb_get_can_db_info(ADatabaseId, AType, AIndex, ASubIndex, ref tmpInt); + if (ret == 0) + { + return Marshal.PtrToStringAnsi(tmpInt) ?? ""; + } + else + return ""; + } + + public static void parse(uint Aid, int channel) + { + int CANcount = int.Parse(tsdb_get_can_db_info(Aid, (int)DBCINFO.CAN_MSG_COUNT, 0, 0)); + for (int i = 0; i < CANcount; i++) + { + _Msg_ temp = new _Msg_(); + temp.msg_type = int.Parse(tsdb_get_can_db_info(Aid, (int)DBCINFO.CAN_MSG_TYPE, i, 0)); + temp.msg_dlc = byte.Parse(tsdb_get_can_db_info(Aid, (int)DBCINFO.CAN_MSG_DLC, i, 0)); + temp.msg_id = int.Parse(tsdb_get_can_db_info(Aid, (int)DBCINFO.CAN_MSG_ID, i, 0)); + temp.msg_name = tsdb_get_can_db_info(Aid, (int)DBCINFO.CAN_MSG_NAME, i, 0); + temp.msg_cyclic = int.Parse(tsdb_get_can_db_info(Aid, (int)DBCINFO.CAN_MSG_CYCLIC, i, 0)); + temp.signal_Name = new string[int.Parse(tsdb_get_can_db_info(Aid, (int)DBCINFO.CAN_MSG_SIGNAL_COUNT, i, 0))]; + for (int signalcount = 0; signalcount < temp.signal_Name.Length; signalcount++) + { + temp.signal_Name[signalcount] = tsdb_get_can_db_info(Aid, (int)DBCINFO.SIGNAL_NAME, int.Parse(tsdb_get_can_db_info(Aid, (int)DBCINFO.CAN_MSG_SIGNAL_NAME_INDEX, i, signalcount)), 0); + } + temp.msg_brs = 0; + temp.ACANFD = new TLIBCANFD(APP_CHANNEL.CHN1, + temp.msg_id, + true, + temp.msg_type == 1 || temp.msg_type == 4 ? true : false, + false, temp.msg_dlc, + temp.msg_type < 2 ? false : true, + false); + MsgDatabase[channel].Add(temp); + + } + + CANcount = int.Parse(tsdb_get_can_db_info(Aid, (int)DBCINFO.CANFD_MSG_COUNT, 0, 0)); + for (int i = 0; i < CANcount; i++) + { + _Msg_ temp = new _Msg_(); + temp.msg_type = int.Parse(tsdb_get_can_db_info(Aid, (int)DBCINFO.CANFD_MSG_TYPE, i, 0)); + temp.msg_dlc = byte.Parse(tsdb_get_can_db_info(Aid, (int)DBCINFO.CANFD_MSG_DLC, i, 0)); + temp.msg_id = int.Parse(tsdb_get_can_db_info(Aid, (int)DBCINFO.CANFD_MSG_ID, i, 0)); + temp.msg_name = tsdb_get_can_db_info(Aid, (int)DBCINFO.CANFD_MSG_NAME, i, 0); + temp.msg_cyclic = int.Parse(tsdb_get_can_db_info(Aid, (int)DBCINFO.CANFD_MSG_CYCLIC, i, 0)); + temp.signal_Name = new string[int.Parse(tsdb_get_can_db_info(Aid, (int)DBCINFO.CANFD_MSG_SIGNAL_COUNT, i, 0))]; + for (int signalcount = 0; signalcount < temp.signal_Name.Length; signalcount++) + { + temp.signal_Name[signalcount] = tsdb_get_can_db_info(Aid, (int)DBCINFO.SIGNAL_NAME, int.Parse(tsdb_get_can_db_info(Aid, (int)DBCINFO.CANFD_MSG_SIGNAL_NAME_INDEX, i, signalcount)), 0); + } + temp.msg_brs = int.Parse(tsdb_get_can_db_info(Aid, 69, i, 0)); + temp.ACANFD = new TLIBCANFD(APP_CHANNEL.CHN1, temp.msg_id, true, temp.msg_type == 1 || temp.msg_type == 4 ? true : false, false, temp.msg_dlc, temp.msg_type < 2 ? false : true, temp.msg_brs == 1 ? true : false); + MsgDatabase[channel].Add(temp); + } + MsgDatabase[channel].Sort((a, b) => a.msg_id.CompareTo(b.msg_id)); + } + + public static void rbs_parse(uint AID, int channel) + { + can_Network = new can_network(); + can_Network.network_name = tsdb_get_can_db_info(AID, (int)DBCINFO.NETWORK_Name, 0, 0); + int Node_count = int.Parse(tsdb_get_can_db_info(AID, (int)DBCINFO.NODE_COUNT, 0, 0)); + can_Network.can_nodes = new can_node[Node_count]; + for (int i = 0; i < Node_count; i++) + { + can_Network.can_nodes[i].node_name = tsdb_get_can_db_info(AID, (int)DBCINFO.NODE_Name, i, 0); + int tx_can_count = int.Parse(tsdb_get_can_db_info(AID, (int)DBCINFO.NODE_TX_CAN_COUNT, i, 0)); + int tx_canfd_count = int.Parse(tsdb_get_can_db_info(AID, (int)DBCINFO.NODE_TX_CANFD_COUNT, i, 0)); + + int rx_can_count = int.Parse(tsdb_get_can_db_info(AID, (int)DBCINFO.NODE_RX_CAN_COUNT, i, 0)); + int rx_canfd_count = int.Parse(tsdb_get_can_db_info(AID, (int)DBCINFO.NODE_RX_CANFD_COUNT, i, 0)); + + //获取tx_can结构体 + can_Network.can_nodes[i].tx_can_Messages = new can_message[tx_can_count + tx_canfd_count]; + + can_Network.can_nodes[i].rx_can_Messages = new can_message[rx_can_count + rx_canfd_count]; + //获取报文名以及信号名 + //1 get can_message idnex + //2 get can message name + //3 get signal count + //4 get signal name + int tx_index = -1; + for (int tx_can = 0; tx_can < tx_can_count; tx_can++) + { + int can_message_idnex = int.Parse(tsdb_get_can_db_info(AID, (int)DBCINFO.NODE_TX_CAN_MESSAGE_INDEX, i, tx_can)); + can_Network.can_nodes[i].tx_can_Messages[tx_can].message_name = tsdb_get_can_db_info(AID, (int)DBCINFO.CAN_MSG_NAME, can_message_idnex, 0); + + can_Network.can_nodes[i].tx_can_Messages[tx_can].signals = new string[int.Parse(tsdb_get_can_db_info(AID, (int)DBCINFO.CAN_MSG_SIGNAL_COUNT, can_message_idnex, 0))]; + for (int signalcount = 0; signalcount < can_Network.can_nodes[i].tx_can_Messages[tx_can].signals.Length; signalcount++) + { + can_Network.can_nodes[i].tx_can_Messages[tx_can].signals[signalcount] = tsdb_get_can_db_info(AID, (int)DBCINFO.SIGNAL_NAME, int.Parse(tsdb_get_can_db_info(AID, (int)DBCINFO.CAN_MSG_SIGNAL_NAME_INDEX, can_message_idnex, signalcount)), 0); + } + + tx_index = tx_can; + } + for (int tx_can = 0; tx_can < tx_canfd_count; tx_can++, tx_index++) + { + int can_message_idnex = int.Parse(tsdb_get_can_db_info(AID, (int)DBCINFO.NODE_TX_CANFD_MESSAGE_INDEX, i, tx_can)); + can_Network.can_nodes[i].tx_can_Messages[tx_index + 1].message_name = tsdb_get_can_db_info(AID, (int)DBCINFO.CANFD_MSG_NAME, can_message_idnex, 0); + + can_Network.can_nodes[i].tx_can_Messages[tx_index + 1].signals = new string[int.Parse(tsdb_get_can_db_info(AID, (int)DBCINFO.CANFD_MSG_SIGNAL_COUNT, can_message_idnex, 0))]; + for (int signalcount = 0; signalcount < can_Network.can_nodes[i].tx_can_Messages[tx_index + 1].signals.Length; signalcount++) + { + can_Network.can_nodes[i].tx_can_Messages[tx_index + 1].signals[signalcount] = tsdb_get_can_db_info(AID, (int)DBCINFO.SIGNAL_NAME, int.Parse(tsdb_get_can_db_info(AID, (int)DBCINFO.CANFD_MSG_SIGNAL_NAME_INDEX, can_message_idnex, signalcount)), 0); + } + } + + int rx_index = -1; + for (int tx_can = 0; tx_can < rx_can_count; tx_can++) + { + int can_message_idnex = int.Parse(tsdb_get_can_db_info(AID, (int)DBCINFO.NODE_RX_CAN_MESSAGE_INDEX, i, tx_can)); + can_Network.can_nodes[i].rx_can_Messages[tx_can].message_name = tsdb_get_can_db_info(AID, (int)DBCINFO.CAN_MSG_NAME, can_message_idnex, 0); + + can_Network.can_nodes[i].rx_can_Messages[tx_can].signals = new string[int.Parse(tsdb_get_can_db_info(AID, (int)DBCINFO.CAN_MSG_SIGNAL_COUNT, can_message_idnex, 0))]; + for (int signalcount = 0; signalcount < can_Network.can_nodes[i].rx_can_Messages[tx_can].signals.Length; signalcount++) + { + can_Network.can_nodes[i].rx_can_Messages[tx_can].signals[signalcount] = tsdb_get_can_db_info(AID, (int)DBCINFO.SIGNAL_NAME, int.Parse(tsdb_get_can_db_info(AID, (int)DBCINFO.CAN_MSG_SIGNAL_NAME_INDEX, can_message_idnex, signalcount)), 0); + } + + rx_index = tx_can; + } + for (int tx_can = 0; tx_can < rx_canfd_count; tx_can++, rx_index++) + { + int can_message_idnex = int.Parse(tsdb_get_can_db_info(AID, (int)DBCINFO.NODE_RX_CANFD_MESSAGE_INDEX, i, tx_can)); + can_Network.can_nodes[i].rx_can_Messages[rx_index + 1].message_name = tsdb_get_can_db_info(AID, (int)DBCINFO.CANFD_MSG_NAME, can_message_idnex, 0); + + can_Network.can_nodes[i].rx_can_Messages[rx_index + 1].signals = new string[int.Parse(tsdb_get_can_db_info(AID, (int)DBCINFO.CANFD_MSG_SIGNAL_COUNT, can_message_idnex, 0))]; + for (int signalcount = 0; signalcount < can_Network.can_nodes[i].rx_can_Messages[rx_index + 1].signals.Length; signalcount++) + { + can_Network.can_nodes[i].rx_can_Messages[rx_index + 1].signals[signalcount] = tsdb_get_can_db_info(AID, (int)DBCINFO.SIGNAL_NAME, int.Parse(tsdb_get_can_db_info(AID, (int)DBCINFO.CANFD_MSG_SIGNAL_NAME_INDEX, can_message_idnex, signalcount)), 0); + } + } + } + } + } + + +} diff --git a/CAN驱动/Interop.TSMasterAPI.dll b/CAN驱动/Interop.TSMasterAPI.dll new file mode 100644 index 0000000..1d1400b Binary files /dev/null and b/CAN驱动/Interop.TSMasterAPI.dll differ diff --git a/CAN驱动/TSMaster.dll b/CAN驱动/TSMaster.dll new file mode 100644 index 0000000..a34dd33 Binary files /dev/null and b/CAN驱动/TSMaster.dll differ