本文整理汇总了C#中TrionicCANLib.CAN.CANMessage.getData方法的典型用法代码示例。如果您正苦于以下问题:C# CANMessage.getData方法的具体用法?C# CANMessage.getData怎么用?C# CANMessage.getData使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TrionicCANLib.CAN.CANMessage
的用法示例。
在下文中一共展示了CANMessage.getData方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: handleMessage
public override void handleMessage(CANMessage a_message)
{
lock (m_canMessage)
{
if (a_message.getID() == m_waitMsgID)
{
m_canMessage.setData(a_message.getData());
m_canMessage.setFlags(a_message.getFlags());
m_canMessage.setID(a_message.getID());
m_canMessage.setLength(a_message.getLength());
m_canMessage.setTimeStamp(a_message.getTimeStamp());
messageReceived = true;
m_resetEvent.Set();
}
}
}
示例2: MarryCIMAndECU
private bool MarryCIMAndECU()
{
//0000000000633B02
CANMessage msg = new CANMessage(0x245, 0, 8);
ulong cmd = 0x0000000000633B02;
msg.setData(cmd);
m_canListener.setupWaitMessage(0x645);
if (!canUsbDevice.sendMessage(msg))
{
CastInfoEvent("Couldn't send message", ActivityType.ConvertingFile);
return false;
}
int waitMsgCount = 0;
while (waitMsgCount < 10)
{
CANMessage ECMresponse = new CANMessage();
ECMresponse = m_canListener.waitMessage(timeoutP2ct);
ulong rxdata = ECMresponse.getData();
// response might be 00000000783B7F03 for some time
// final result should be 0000000000637B02
if (getCanData(rxdata, 1) == 0x7B && getCanData(rxdata, 2) == 0x63)
{
return true;
}
else if (getCanData(rxdata, 1) == 0x7F && getCanData(rxdata, 2) == 0x3B && getCanData(rxdata, 3) == 0x78)
{
CastInfoEvent("Waiting for marry process to complete between CIM and car", ActivityType.ConvertingFile);
}
waitMsgCount++;
}
return false;
}
示例3: handleMessage
public override void handleMessage(CANMessage a_message)
{
if (_queue == null)
{
_queue = new CANMessage[16];
_receiveMessageIndex = 0;
_readMessageIndex = 0;
}
// add the message to a queue for later processing ...
// the queue is a ringbuffer for CANMessage objects.
// X objects are supported
// we need a receive and a read pointer for this to work properly
messageReceived = false;
//_queue[_receiveMessageIndex] = a_message;
_queue[_receiveMessageIndex] = new CANMessage();
_queue[_receiveMessageIndex].setData(a_message.getData());
_queue[_receiveMessageIndex].setID(a_message.getID());
_queue[_receiveMessageIndex].setLength(a_message.getLength());
_receiveMessageIndex++;
if(_receiveMessageIndex > _queue.Length - 1) _receiveMessageIndex = 0; // make it circular
//DetermineSize();
/*
lock (m_canMessage)
{
if (a_message.getID() == m_waitMsgID)
{
m_canMessage = a_message;
messageReceived = true;
}
}
if (messageReceived)
{
m_resetEvent.Set();
}*/
}
示例4: readMessages
/// <summary>
/// readMessages is the "run" method of this class. It reads all incomming messages
/// and publishes them to registered ICANListeners.
/// </summary>
public void readMessages()
{
int readResult = 0;
Lawicel.CANUSB.CANMsg r_canMsg = new Lawicel.CANUSB.CANMsg();
CANMessage canMessage = new CANMessage();
Console.WriteLine("readMessages started");
while (true)
{
lock (m_synchObject)
{
if (m_endThread)
{
Console.WriteLine("readMessages ended");
return;
}
}
readResult = Lawicel.CANUSB.canusb_Read(m_deviceHandle, out r_canMsg);
if (readResult == Lawicel.CANUSB.ERROR_CANUSB_OK)
{
if (acceptMessageId(r_canMsg.id))
{
canMessage.setID(r_canMsg.id);
canMessage.setLength(r_canMsg.len);
canMessage.setTimeStamp(r_canMsg.timestamp);
canMessage.setFlags(r_canMsg.flags);
canMessage.setData(r_canMsg.data);
lock (m_listeners)
{
AddToCanTrace(string.Format("RX: {0} {1}", canMessage.getID().ToString("X3"), canMessage.getData().ToString("X16")));
foreach (ICANListener listener in m_listeners)
{
listener.handleMessage(canMessage);
}
}
}
}
else if (readResult == Lawicel.CANUSB.ERROR_CANUSB_NO_MESSAGE)
{
Thread.Sleep(1);
}
}
}
示例5: sendMessageDevice
/// <summary>
/// sendMessage send a CANMessage.
/// </summary>
/// <param name="a_message">A CANMessage.</param>
/// <returns>true on success, othewise false.</returns>
protected override bool sendMessageDevice(CANMessage a_message)
{
Lawicel.CANUSB.CANMsg msg = new Lawicel.CANUSB.CANMsg();
msg.id = a_message.getID();
msg.len = a_message.getLength();
msg.flags = a_message.getFlags();
msg.data = a_message.getData();
int writeResult;
writeResult = Lawicel.CANUSB.canusb_Write(m_deviceHandle, ref msg);
if (writeResult == Lawicel.CANUSB.ERROR_CANUSB_OK)
{
return true;
}
else
{
logger.Debug("tx failed writeResult: " + writeResult);
return false;
}
}
示例6: success
//---------------------------------------------------------------------------------------------
/**
Sends a 11 bit CAN data frame.
@param msg CAN message
@return success (true/false)
*/
protected override bool sendMessageDevice(CANMessage msg)
{
try
{
caCombiAdapter.caCANFrame frame;
frame.id = msg.getID();
frame.length = msg.getLength();
frame.data = msg.getData();
frame.is_extended = 0;
frame.is_remote = 0;
combi.CAN_SendMessage(ref frame);
return true;
}
catch (Exception e)
{
logger.Debug("tx failed with Exception.Message: " + e.Message);
return false;
}
}
示例7: handleMessage
public override void handleMessage(CANMessage a_message)
{
if (_queue == null)
{
_queue = new CANMessage[32];
_receiveMessageIndex = 0;
_readMessageIndex = 0;
}
// add the message to a queue for later processing ...
// the queue is a ringbuffer for CANMessage objects.
// X objects are supported
// we need a receive and a read pointer for this to work properly
messageReceived = false;
//_queue[_receiveMessageIndex] = a_message;
_queue[_receiveMessageIndex] = new CANMessage();
_queue[_receiveMessageIndex].setData(a_message.getData());
_queue[_receiveMessageIndex].setID(a_message.getID());
_queue[_receiveMessageIndex].setLength(a_message.getLength());
_receiveMessageIndex++;
if(_receiveMessageIndex > _queue.Length - 1) _receiveMessageIndex = 0; // make it circular
DetermineSize();
}
示例8: sendMessage
public override bool sendMessage(CANMessage a_message)
{
string sendString = "t";
sendString += a_message.getID().ToString("X3");
sendString += a_message.getLength().ToString("X1");
for (uint i = 0; i < a_message.getLength(); i++) // leave out the length field, the ELM chip assigns that for us
{
sendString += a_message.getCanData(i).ToString("X2");
}
sendString += "\r";
if (m_serialPort.IsOpen)
{
AddToCanTrace("TX: " + a_message.getID().ToString("X3") + " " + a_message.getLength().ToString("X1") + " " + a_message.getData().ToString("X16"));
m_serialPort.Write(sendString);
//Console.WriteLine("TX: " + sendString);
}
// bitrate = 38400bps -> 3840 bytes per second
// sending each byte will take 0.2 ms approx
//Thread.Sleep(a_message.getLength()); // sleep length ms
// Thread.Sleep(10);
Thread.Sleep(1);
return true; // remove after implementation
}
示例9: SendSecretCode2
private bool SendSecretCode2()
{
//44585349006EAE07
CANMessage msg = new CANMessage(0x7E0, 0, 8);
ulong cmd = 0x44585349006EAE07;
msg.setData(cmd);
m_canListener.setupWaitMessage(0x7E8);
if (!canUsbDevice.sendMessage(msg))
{
CastInfoEvent("Couldn't send message", ActivityType.ConvertingFile);
return false;
}
CANMessage ECMresponse = new CANMessage();
ECMresponse = m_canListener.waitMessage(timeoutP2ct);
ulong rxdata = ECMresponse.getData();
if (getCanData(rxdata, 1) == 0xEE && getCanData(rxdata, 2) == 0x6E)
{
return true;
}
return false;
}
示例10: SendRestoreT8
private bool SendRestoreT8()
{
CANMessage msg = new CANMessage(0x7E0, 0, 3);
// 02 1A 79 00 00 00 00 00
ulong cmd = 0x0000000000791A02;
msg.setData(cmd);
m_canListener.setupWaitMessage(0x7E8);
if (!canUsbDevice.sendMessage(msg))
{
CastInfoEvent("Couldn't send message", ActivityType.ConvertingFile);
// Do not return here want to wait for the response
}
CANMessage response = new CANMessage();
response = new CANMessage();
response = m_canListener.waitMessage(200);
ulong data = response.getData();
// 7E8 03 5A 79 01 00 00 00 00
if (getCanData(data, 0) == 0x03 && getCanData(data, 1) == 0x5A && getCanData(data, 2) == 0x79 && getCanData(data, 3) == 0x01)
{
return true;
}
return false;
}
示例11: SendrequestDownloadME96
private bool SendrequestDownloadME96(bool recoveryMode)
{
CANMessage msg = new CANMessage(0x7E0, 0, 7);
//05 34 00 01 E0 00 00 00
ulong cmd = 0x000000E001003405;
msg.setData(cmd);
m_canListener.setupWaitMessage(0x7E8);
if (!canUsbDevice.sendMessage(msg))
{
CastInfoEvent("Couldn't send message", ActivityType.ConvertingFile);
return false;
}
bool eraseDone = false;
int eraseCount = 0;
int waitCount = 0;
while (!eraseDone)
{
m_canListener.setupWaitMessage(0x7E8); // TEST ELM327 31082011
CANMessage response = new CANMessage();
response = m_canListener.waitMessage(500); // 1 seconds!
ulong data = response.getData();
if (data == 0)
{
m_canListener.setupWaitMessage(0x311); // TEST ELM327 31082011
response = new CANMessage();
response = m_canListener.waitMessage(500); // 1 seconds!
data = response.getData();
}
// response will be 03 7F 34 78 00 00 00 00 a couple of times while erasing
if (getCanData(data, 0) == 0x03 && getCanData(data, 1) == 0x7F && getCanData(data, 2) == 0x34 && getCanData(data, 3) == 0x78)
{
if (recoveryMode) BroadcastKeepAlive();
else SendKeepAlive();
eraseCount++;
string info = "Erasing FLASH";
for (int i = 0; i < eraseCount; i++) info += ".";
CastInfoEvent(info, ActivityType.ErasingFlash);
}
else if (getCanData(data, 0) == 0x01 && getCanData(data, 1) == 0x74)
{
if (recoveryMode) BroadcastKeepAlive();
else SendKeepAlive();
eraseDone = true;
return true;
}
else if (getCanData(data, 0) == 0x03 && getCanData(data, 1) == 0x7F && getCanData(data, 2) == 0x34 && getCanData(data, 3) == 0x11)
{
CastInfoEvent("Erase cannot be performed", ActivityType.ErasingFlash);
return false;
}
else
{
Console.WriteLine("Rx: " + data.ToString("X16"));
if (canUsbDevice is CANELM327Device)
{
if (recoveryMode) BroadcastKeepAlive();
else SendKeepAlive();
}
}
waitCount++;
if (waitCount > 35)
{
if (canUsbDevice is CANELM327Device)
{
CastInfoEvent("Erase completed", ActivityType.ErasingFlash);
// ELM327 seem to be unable to wait long enough for this response
// Instead we assume its finnished ok after 35 seconds
return true;
}
else
{
CastInfoEvent("Erase timed out after 35 seconds", ActivityType.ErasingFlash);
return false;
}
}
Thread.Sleep(m_sleepTime);
}
return true;
}
示例12: sendReadDataByLocalIdentifier
private byte[] sendReadDataByLocalIdentifier(int address, int length, out bool success)
{
// we send: 0040000000002106
// .. send: 06 21 80 00 00 00 00 00
success = false;
byte[] retData = new byte[length];
if (!canUsbDevice.isOpen()) return retData;
CANMessage msg = new CANMessage(0x7E0, 0, 7);
//Console.WriteLine("Reading " + address.ToString("X8") + " len: " + length.ToString("X2"));
ulong cmd = 0x0000000000002106; // always 2 bytes
ulong addressHigh = (uint)address & 0x0000000000FF0000;
addressHigh /= 0x10000;
ulong addressMiddle = (uint)address & 0x000000000000FF00;
addressMiddle /= 0x100;
ulong addressLow = (uint)address & 0x00000000000000FF;
ulong len = (ulong)length;
cmd |= (addressLow * 0x1000000000000);
cmd |= (addressMiddle * 0x10000000000);
cmd |= (addressHigh * 0x100000000);
cmd |= (len * 0x10000); // << 2 * 8
//Console.WriteLine("send: " + cmd.ToString("X16"));
/*cmd |= (ulong)(byte)(address & 0x000000FF) << 4 * 8;
cmd |= (ulong)(byte)((address & 0x0000FF00) >> 8) << 3 * 8;
cmd |= (ulong)(byte)((address & 0x00FF0000) >> 2 * 8) << 2 * 8;
cmd |= (ulong)(byte)((address & 0xFF000000) >> 3 * 8) << 8;*/
msg.setData(cmd);
m_canListener.setupWaitMessage(0x7E8);
msg.elmExpectedResponses = 19; //in 19 messages there are 0x82 = 130 bytes of data, bootloader requests 0x80 =128 each time
if (!canUsbDevice.sendMessage(msg))
{
logger.Debug("Couldn't send message");
}
// wait for max two messages to get rid of the alive ack message
CANMessage response = new CANMessage();
ulong data = 0;
response = new CANMessage();
response = m_canListener.waitMessage(timeoutP2ct);
data = response.getData();
if (getCanData(data, 0) == 0x7E)
{
logger.Debug("Got 0x7E message as response to 0x21, ReadDataByLocalIdentifier command");
success = false;
return retData;
}
else if (response.getData() == 0x00000000)
{
logger.Debug("Get blank response message to 0x21, ReadDataByLocalIdentifier");
success = false;
return retData;
}
else if (getCanData(data, 0) == 0x03 && getCanData(data, 1) == 0x7F && getCanData(data, 2) == 0x23)
{
// reason was 0x31
logger.Debug("No security access granted");
RequestSecurityAccess(0);
success = false;
return retData;
}
else if (getCanData(data, 2) != 0x61 && getCanData(data, 1) != 0x61)
{
if (data == 0x0000000000007E01)
{
// was a response to a KA.
}
logger.Debug("Incorrect response to 0x23, sendReadDataByLocalIdentifier. Byte 2 was " + getCanData(data, 2).ToString("X2"));
success = false;
return retData;
}
//TODO: Check whether we need more than 2 bytes of data and wait for that many records after sending an ACK
int rx_cnt = 0;
byte frameIndex = 0x21;
if (length > 4)
{
retData[rx_cnt++] = getCanData(data, 4);
retData[rx_cnt++] = getCanData(data, 5);
retData[rx_cnt++] = getCanData(data, 6);
retData[rx_cnt++] = getCanData(data, 7);
// in that case, we need more records from the ECU
// Thread.Sleep(1);
SendAckMessageT8(); // send ack to request more bytes
//Thread.Sleep(1);
// now we wait for the correct number of records to be received
int m_nrFrameToReceive = ((length - 4) / 7);
if ((len - 4) % 7 > 0) m_nrFrameToReceive++;
//AddToCanTrace("Number of frames: " + m_nrFrameToReceive.ToString());
while (m_nrFrameToReceive > 0)
{
// response = new CANMessage();
//response.setData(0);
//response.setID(0);
// m_canListener.setupWaitMessage(0x7E8);
response = m_canListener.waitMessage(timeoutP2ct);
data = response.getData();
//AddToCanTrace("frame " + frameIndex.ToString("X2") + ": " + data.ToString("X16"));
if (frameIndex != getCanData(data, 0))
//.........这里部分代码省略.........
示例13: sendReadCommandME96
//KWP2000 can read more than 6 bytes at a time.. but for now we are happy with this
private byte[] sendReadCommandME96(int address, int length, out bool success)
{
success = false;
byte[] retData = new byte[length];
if (!canUsbDevice.isOpen()) return retData;
CANMessage msg = new CANMessage(0x7E0, 0, 8);
//optimize reading speed for ELM
if (length <= 3)
msg.elmExpectedResponses = 1;
//Console.WriteLine("Reading " + address.ToString("X8") + " len: " + length.ToString("X2"));
ulong cmd = 0x0000000000002307; // always 2 bytes
ulong addressHigh = (uint)address & 0x0000000000FF0000;
addressHigh /= 0x10000;
ulong addressMiddle = (uint)address & 0x000000000000FF00;
addressMiddle /= 0x100;
ulong addressLow = (uint)address & 0x00000000000000FF;
ulong len = (ulong)length;
cmd |= (addressLow * 0x10000000000);
cmd |= (addressMiddle * 0x100000000);
cmd |= (addressHigh * 0x1000000);
cmd |= (len * 0x100000000000000);
//Console.WriteLine("send: " + cmd.ToString("X16"));
/*cmd |= (ulong)(byte)(address & 0x000000FF) << 4 * 8;
cmd |= (ulong)(byte)((address & 0x0000FF00) >> 8) << 3 * 8;
cmd |= (ulong)(byte)((address & 0x00FF0000) >> 2 * 8) << 2 * 8;
cmd |= (ulong)(byte)((address & 0xFF000000) >> 3 * 8) << 8;*/
msg.setData(cmd);
m_canListener.setupWaitMessage(0x7E8);
if (!canUsbDevice.sendMessage(msg))
{
logger.Debug("Couldn't send message");
}
// wait for max two messages to get rid of the alive ack message
CANMessage response = new CANMessage();
ulong data = 0;
response = new CANMessage();
response = m_canListener.waitMessage(timeoutP2ct);
data = response.getData();
if (getCanData(data, 0) == 0x7E)
{
logger.Debug("Got 0x7E message as response to 0x23, readMemoryByAddress command");
success = false;
return retData;
}
else if (response.getData() == 0x00000000)
{
logger.Debug("Get blank response message to 0x23, readMemoryByAddress");
success = false;
return retData;
}
else if (getCanData(data, 0) == 0x03 && getCanData(data, 1) == 0x7F && getCanData(data, 2) == 0x23 && getCanData(data, 3) == 0x31)
{
// reason was 0x31 RequestOutOfRange
// memory address is either: invalid, restricted, secure + ECU locked
// memory size: is greater than max
logger.Debug("RequestOutOfRange. No security access granted");
RequestSecurityAccess(0);
success = false;
return retData;
}
else if (getCanData(data, 0) == 0x03 && getCanData(data, 1) == 0x7F && getCanData(data, 2) == 0x23)
{
logger.Debug("readMemoryByAddress " + TranslateErrorCode(getCanData(data, 3)));
success = false;
return retData;
}
/*else if (getCanData(data, 0) != 0x10)
{
AddToCanTrace("Incorrect response message to 0x23, readMemoryByAddress. Byte 0 was " + getCanData(data, 0).ToString("X2"));
success = false;
return retData;
}
else if (getCanData(data, 1) != len + 4)
{
AddToCanTrace("Incorrect length data message to 0x23, readMemoryByAddress. Byte 1 was " + getCanData(data, 1).ToString("X2"));
success = false;
return retData;
}*/
else if (getCanData(data, 2) != 0x63 && getCanData(data, 1) != 0x63)
{
if (data == 0x0000000000007E01)
{
// was a response to a KA.
}
logger.Debug("Incorrect response to 0x23, readMemoryByAddress. Byte 2 was " + getCanData(data, 2).ToString("X2"));
success = false;
return retData;
}
//TODO: Check whether we need more than 2 bytes of data and wait for that many records after sending an ACK
int rx_cnt = 0;
byte frameIndex = 0x21;
if (length > 3)
{
retData[rx_cnt++] = getCanData(data, 7);
// in that case, we need more records from the ECU
//.........这里部分代码省略.........
示例14: RequestSecurityAccessCIM
private bool RequestSecurityAccessCIM(int millisecondsToWaitWithResponse)
{
int secondsToWait = millisecondsToWaitWithResponse / 1000;
ulong cmd = 0x0000000000012702; // request security access
CANMessage msg = new CANMessage(0x245, 0, 8);
msg.setData(cmd);
m_canListener.setupWaitMessage(0x645);
CastInfoEvent("Requesting security access to CIM", ActivityType.ConvertingFile);
if (!canUsbDevice.sendMessage(msg))
{
CastInfoEvent("Couldn't send message", ActivityType.ConvertingFile);
return false;
}
CANMessage response = new CANMessage();
response = m_canListener.waitMessage(timeoutP2ct);
//ulong data = response.getData();
Console.WriteLine("---" + response.getData().ToString("X16"));
if (response.getCanData(1) == 0x67)
{
if (response.getCanData(2) == 0x01)
{
CastInfoEvent("Got seed value from CIM", ActivityType.ConvertingFile);
while (secondsToWait > 0)
{
CastInfoEvent("Waiting for " + secondsToWait.ToString() + " seconds...", ActivityType.UploadingBootloader);
Thread.Sleep(1000);
SendKeepAlive();
secondsToWait--;
}
byte[] seed = new byte[2];
seed[0] = response.getCanData(3);
seed[1] = response.getCanData(4);
if (seed[0] == 0x00 && seed[1] == 0x00)
{
return true; // security access was already granted
}
else
{
SeedToKey s2k = new SeedToKey();
byte[] key = s2k.calculateKeyForCIM(seed);
CastInfoEvent("Security access CIM : Key (" + key[0].ToString("X2") + key[1].ToString("X2") + ") calculated from seed (" + seed[0].ToString("X2") + seed[1].ToString("X2") + ")", ActivityType.ConvertingFile);
ulong keydata = 0x0000000000022704;
ulong key1 = key[1];
key1 *= 0x100000000;
keydata ^= key1;
ulong key2 = key[0];
key2 *= 0x1000000;
keydata ^= key2;
msg = new CANMessage(0x245, 0, 8);
msg.setData(keydata);
m_canListener.setupWaitMessage(0x645);
if (!canUsbDevice.sendMessage(msg))
{
CastInfoEvent("Couldn't send message", ActivityType.ConvertingFile);
return false;
}
response = new CANMessage();
response = m_canListener.waitMessage(timeoutP2ct);
// is it ok or not
if (response.getCanData(1) == 0x67 && response.getCanData(2) == 0x02)
{
CastInfoEvent("Security access to CIM granted", ActivityType.ConvertingFile);
return true;
}
else if (response.getCanData(1) == 0x7F && response.getCanData(2) == 0x27)
{
CastInfoEvent("Error: " + TranslateErrorCode(response.getCanData(3)), ActivityType.ConvertingFile);
}
}
}
else if (response.getCanData(2) == 0x02)
{
CastInfoEvent("Security access to CIM granted", ActivityType.ConvertingFile);
return true;
}
}
else if (response.getCanData(1) == 0x7F && response.getCanData(2) == 0x27)
{
CastInfoEvent("Error: " + TranslateErrorCode(response.getCanData(3)), ActivityType.ConvertingFile);
}
return false;
}
示例15: requestDownload011
private bool requestDownload011()
{
CANMessage msg = new CANMessage(0x11, 0, 7);
ulong cmd = 0x0000000000003406;
msg.setData(cmd);
m_canListener.setupWaitMessage(0x311);
if (!canUsbDevice.sendMessage(msg))
{
CastInfoEvent("Couldn't send message", ActivityType.ConvertingFile);
return false;
}
CANMessage response = new CANMessage();
response = new CANMessage();
response = m_canListener.waitMessage(timeoutP2ct);
ulong data = response.getData();
//CastInfoEvent("rx requestDownload: " + data.ToString("X16"), ActivityType.UploadingBootloader);
if (getCanData(data, 0) != 0x01 || getCanData(data, 1) != 0x74)
{
return false;
}
return true;
}