111,125
社区成员
发帖
与我相关
我的任务
分享
//1.在madicine 项目中创建一个类的cs文件:CanMessage.cs
using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using System.Linq;
using System.Text;
using Peak.Can.Basic;//2.引用包含有结构体TPCANMSG初始定义的文件
using TPCANHandle = System.Byte;
namespace Madicine.CanMessage
{
class CanMessage
{
//实例化结构体TPANMSG
public const TPCANMsg getMessage = new TPCANMsg();
string idText = "00350000";
int msgLength = 8;
// We configurate the Message. The ID (max 0x1FF),
// Length of the Data, Message Type and die data
//
//下面的头两条信息出错,显示标题中的错误信息
getMessage.DATA = new byte[8] { 0x42, 0x01, 0, 0, 0, 0, 0, 0 };
getMessage.ID = Convert.ToUInt32(idText, 16);
getMessage.LEN = Convert.ToByte(msgLength);
getMessage.MSGTYPE = TPCANMessageType.PCAN_MESSAGE_EXTENDED;
}
}
public struct TPCANMsg
{
/// <summary>
/// 11/29-bit message identifier
/// </summary>
public uint ID;
/// <summary>
/// Type of the message
/// </summary>
[MarshalAs(UnmanagedType.U1)]
public TPCANMessageType MSGTYPE;
/// <summary>
/// Data Length Code of the message (0..8)
/// </summary>
public byte LEN;
/// <summary>
/// Data of the message (DATA[0]..DATA[7])
/// </summary>
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 8)]
public byte[] DATA;
}
namespace Madicine.CanMessage
{
class CanMessage
{
string idText = "00350000";
int msgLength = 8;
//实例化结构体TPANMSG
public const TPCANMsg getMessage = new TPCANMsg()
{
DATA = new byte[8] { 0x42, 0x01, 0, 0, 0, 0, 0, 0 },
ID = Convert.ToUInt32(idText, 16),
LEN = Convert.ToByte(msgLength),
MSGTYPE = TPCANMessageType.PCAN_MESSAGE_EXTENDED
};
// We configurate the Message. The ID (max 0x1FF),
// Length of the Data, Message Type and die data
//
}
}
class CanMessage
{
//实例化结构体TPANMSG
public const TPCANMsg getMessage = new TPCANMsg();
string idText = "00350000";
int msgLength = 8;
// We configurate the Message. The ID (max 0x1FF),
// Length of the Data, Message Type and die data
//
public CanMessage()
{
getMessage.DATA = new byte[8] { 0x42, 0x01, 0, 0, 0, 0, 0, 0 };
getMessage.ID = Convert.ToUInt32(idText, 16);
getMessage.LEN = Convert.ToByte(msgLength);
getMessage.MSGTYPE = TPCANMessageType.PCAN_MESSAGE_EXTENDED;
}
}