本文整理汇总了C#中TrionicCANLib.CAN.CANMessage.getLength方法的典型用法代码示例。如果您正苦于以下问题:C# CANMessage.getLength方法的具体用法?C# CANMessage.getLength怎么用?C# CANMessage.getLength使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TrionicCANLib.CAN.CANMessage
的用法示例。
在下文中一共展示了CANMessage.getLength方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: GetELMRequest
/// <summary>
/// Creates valid request string for ELM device. Calculates data size and formats it automatically
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
private static string GetELMRequest(CANMessage msg)
{
ulong reversed = BitTools.ReverseOrder(msg.getData());
//var length = BitTools.GetDataSize(reversed);
return reversed.ToString("X16").Substring(0, msg.getLength() * 2);
}
示例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: sendMessage
/// <summary>
/// sendMessage send a CANMessage.
/// </summary>
/// <param name="a_message">A CANMessage.</param>
/// <returns>true on success, othewise false.</returns>
public override bool sendMessage(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;
AddToCanTrace("TX: " + msg.id.ToString("X4") + " " + msg.data.ToString("X16"));
writeResult = Lawicel.CANUSB.canusb_Write(m_deviceHandle, ref msg);
if (writeResult == Lawicel.CANUSB.ERROR_CANUSB_OK)
{
AddToCanTrace("Message sent successfully");
return true;
}
else
{
switch (writeResult)
{
case Lawicel.CANUSB.ERROR_CANUSB_COMMAND_SUBSYSTEM:
AddToCanTrace("Message failed to send: ERROR_CANUSB_COMMAND_SUBSYSTEM");
break;
case Lawicel.CANUSB.ERROR_CANUSB_INVALID_PARAM:
AddToCanTrace("Message failed to send: ERROR_CANUSB_INVALID_PARAM");
break;
case Lawicel.CANUSB.ERROR_CANUSB_NO_MESSAGE:
AddToCanTrace("Message failed to send: ERROR_CANUSB_NO_MESSAGE");
break;
case Lawicel.CANUSB.ERROR_CANUSB_NOT_OPEN:
AddToCanTrace("Message failed to send: ERROR_CANUSB_NOT_OPEN");
break;
case Lawicel.CANUSB.ERROR_CANUSB_OPEN_SUBSYSTEM:
AddToCanTrace("Message failed to send: ERROR_CANUSB_OPEN_SUBSYSTEM");
break;
case Lawicel.CANUSB.ERROR_CANUSB_TX_FIFO_FULL:
AddToCanTrace("Message failed to send: ERROR_CANUSB_TX_FIFO_FULL");
break;
default:
AddToCanTrace("Message failed to send: " + writeResult.ToString());
break;
}
return false;
}
}
示例5: success
//---------------------------------------------------------------------------------------------
/**
Sends a 11 bit CAN data frame.
@param msg CAN message
@return success (true/false)
*/
public override bool sendMessage(CANMessage msg)
{
this.AddToCanTrace("Sending message: " + msg.getID().ToString("X4") + " " + msg.getData().ToString("X16") + " " + msg.getLength().ToString("X2"));
try
{
Combi.caCombiAdapter.caCANFrame frame;
frame.id = msg.getID();
frame.length = msg.getLength();
frame.data = msg.getData();
frame.is_extended = 0;
frame.is_remote = 0;
this.combi.CAN_SendMessage(ref frame);
this.AddToCanTrace("Message sent successfully");
return true;
}
catch (Exception e)
{
this.AddToCanTrace("Message failed to send: " + e.Message);
return false;
}
}
示例6: 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;
}
}
示例7: sendMessage
/// <summary>
/// sendMessage send a CANMessage.
/// </summary>
/// <param name="a_message">A CANMessage.</param>
/// <returns>true on success, othewise false.</returns>
public override bool sendMessage(CANMessage a_message)
{
lock (lockObj)
{
while (interfaceBusy)
{
if (lastSentTimestamp < Environment.TickCount - timeoutWithoutReadyChar)
{
//Console.WriteLine("released");
break;
}
}
lastSentTimestamp = Environment.TickCount;
interfaceBusy = true;
//Console.WriteLine("set");
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();
if (m_serialPort.IsOpen)
{
//m_serialPort.Write("\r");
string txstring = "t";
txstring += msg.id.ToString("X3");
txstring += "8"; // always 8 bytes to transmit
for (int t = 0; t < 8; t++)
{
byte b = (byte)(((msg.data >> t * 8) & 0x0000000000000000FF));
txstring += b.ToString("X2");
}
txstring += "\r";
AddToCanTrace(string.Format("TX: {0} {1} {2}", a_message.getID().ToString("X3"), a_message.getData().ToString("X16"), txstring));
m_serialPort.Write(txstring);
return true;
}
}
return false;
}
示例8: 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;
}
}
示例9: success
//-------------------------------------------------------------------------
/**
Sends a 11 bit CAN data frame.
@param message CAN message
@return success (true/false)
*/
public override bool sendMessage(CANMessage message)
{
return MctAdapter_SendMessage(message.getID(), message.getLength(),
message.getData());
}
示例10: 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();
}
示例11: sendMessage
public override bool sendMessage(CANMessage a_message)
{
lock (lockObj)
{
sendDataSempahore.WaitOne(timeoutWithoutReadyChar);
interfaceBusy = true;
if (a_message.getID() != _ECUAddress)
{
_ECUAddress = a_message.getID();
string command = "ATSH" + a_message.getID().ToString("X3") + "\r";
SendControlMessage(command, false);
}
//check if it is beneficial to send ATR0 and ATR1 for ELM clones
if (!supports8ByteResponse)
{
if ((a_message.elmExpectedResponses == 0) != request0Responses)
{
if (a_message.elmExpectedResponses == 0)
{
SendControlMessage("ATR0\r", false);
request0Responses = true;
}
else
{
SendControlMessage("ATR1\r", false);
request0Responses = false;
}
}
}
lastSentCanMessage = a_message.Clone();
string sendString = GetELMRequest(a_message);
if (a_message.getLength() < 8 || supports8ByteResponse) //ELM 2.0 supports 8 bytes + response count, previous versions dont
{
//add expected responses, but this has to be one char only :(
if (a_message.elmExpectedResponses != -1 && a_message.elmExpectedResponses < 16)
sendString += " " + a_message.elmExpectedResponses.ToString("X1");
}
sendString += "\r";
if (m_serialPort.IsOpen)
{
lastSentTimestamp = Environment.TickCount;
WriteToSerialWithTrace(sendString);
AddToCanTrace(string.Format("TX: {0} {1}", a_message.getID().ToString("X3"), sendString));
}
return true; // remove after implementation
}
}
示例12: 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
}
示例13: readMessages
public void readMessages()
{
CANMessage canMessage = new CANMessage();
string rxMessage = string.Empty;
Console.WriteLine("readMessages started");
while (true)
{
lock (m_synchObject)
{
if (m_endThread)
{
Console.WriteLine("readMessages ended");
return;
}
}
try
{
if (m_serialPort.IsOpen)
{
do
{
rxMessage = m_serialPort.ReadLine();
rxMessage = rxMessage.Replace("\r", ""); // remove prompt characters... we don't need that stuff
rxMessage = rxMessage.Replace("\n", ""); // remove prompt characters... we don't need that stuff
} while (rxMessage.StartsWith("w") == false);
uint id = Convert.ToUInt32(rxMessage.Substring(1, 3), 16);
if (acceptMessageId(id))
{
canMessage.setID(id);
canMessage.setLength(8);
canMessage.setData(0x0000000000000000);
for (uint i = 0; i < 8; i++)
canMessage.setCanData(Convert.ToByte(rxMessage.Substring(5 + (2 * (int)i), 2), 16), i);
lock (m_listeners)
{
AddToCanTrace("RX: " + canMessage.getID().ToString("X3") + " " + canMessage.getLength().ToString("X1") + " " + canMessage.getData().ToString("X16"));
//Console.WriteLine("MSG: " + rxMessage);
foreach (ICANListener listener in m_listeners)
{
listener.handleMessage(canMessage);
}
}
}
}
}
catch (Exception)
{
Console.WriteLine("MSG: " + rxMessage);
}
}
}