<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[CAN message decoding - how is data returned?]]></title><description><![CDATA[<p dir="auto">Im trying to develop my code to interface with a SN65HVD230 CAN module. My device is a WiPy 3.0 with expansion board, and im using the callback to respond to messages as they come-in.</p>
<p dir="auto">I have read the CAN documentation: <a href="https://docs.pycom.io/firmwareapi/pycom/machine/can/" target="_blank" rel="noopener noreferrer nofollow">https://docs.pycom.io/firmwareapi/pycom/machine/can/</a> but I would like to be able to extract the engineering values from the returned messages.</p>
<p dir="auto">Im using a dictionary for my PGN attributes (engineering value,data bits, offset, scaling factor etc for the SPN's in the msg).<br />
Note: im working with extended identifier msgs intel byte order, unsigned integer 32 bit</p>
<p dir="auto">I struggling with knowing how to extract the data, partly because im not sure how its is returned.</p>
<p dir="auto">The documentation has a very basic example showing:</p>
<blockquote>
<blockquote>
<blockquote>
<p dir="auto">can.recv()<br />
(id=0x012, data=b'123', rtr=False, extended=False)</p>
</blockquote>
</blockquote>
</blockquote>
<p dir="auto">It looks as if the data sent for this msg was: can.send(id=12, data=bytes([1, 2, 3.............</p>
<p dir="auto">Is the data returned not in a sort of byte array?</p>
<p dir="auto">Im imaging I will need to: split out my relevant bytes, convert to integers, then sum in the correct order, then scale and apply offset.</p>
<p dir="auto">Also, im new to Python, so any hints or tips for woring with the returned data would be appreciated. Many thanks Jake</p>
]]></description><link>https://forum.pycom.io/topic/5948/can-message-decoding-how-is-data-returned</link><generator>RSS for Node</generator><lastBuildDate>Wed, 17 Jun 2026 22:00:43 GMT</lastBuildDate><atom:link href="https://forum.pycom.io/topic/5948.rss" rel="self" type="application/rss+xml"/><pubDate>Sat, 09 May 2020 11:41:42 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to CAN message decoding - how is data returned? on Sat, 09 May 2020 11:41:42 GMT]]></title><description><![CDATA[<p dir="auto">Im trying to develop my code to interface with a SN65HVD230 CAN module. My device is a WiPy 3.0 with expansion board, and im using the callback to respond to messages as they come-in.</p>
<p dir="auto">I have read the CAN documentation: <a href="https://docs.pycom.io/firmwareapi/pycom/machine/can/" target="_blank" rel="noopener noreferrer nofollow">https://docs.pycom.io/firmwareapi/pycom/machine/can/</a> but I would like to be able to extract the engineering values from the returned messages.</p>
<p dir="auto">Im using a dictionary for my PGN attributes (engineering value,data bits, offset, scaling factor etc for the SPN's in the msg).<br />
Note: im working with extended identifier msgs intel byte order, unsigned integer 32 bit</p>
<p dir="auto">I struggling with knowing how to extract the data, partly because im not sure how its is returned.</p>
<p dir="auto">The documentation has a very basic example showing:</p>
<blockquote>
<blockquote>
<blockquote>
<p dir="auto">can.recv()<br />
(id=0x012, data=b'123', rtr=False, extended=False)</p>
</blockquote>
</blockquote>
</blockquote>
<p dir="auto">It looks as if the data sent for this msg was: can.send(id=12, data=bytes([1, 2, 3.............</p>
<p dir="auto">Is the data returned not in a sort of byte array?</p>
<p dir="auto">Im imaging I will need to: split out my relevant bytes, convert to integers, then sum in the correct order, then scale and apply offset.</p>
<p dir="auto">Also, im new to Python, so any hints or tips for woring with the returned data would be appreciated. Many thanks Jake</p>
]]></description><link>https://forum.pycom.io/post/32634</link><guid isPermaLink="true">https://forum.pycom.io/post/32634</guid><dc:creator><![CDATA[JSmith]]></dc:creator><pubDate>Sat, 09 May 2020 11:41:42 GMT</pubDate></item><item><title><![CDATA[Reply to CAN message decoding - how is data returned? on Mon, 11 May 2020 04:18:21 GMT]]></title><description><![CDATA[<p dir="auto">I am pretty sure you can access the data by index:</p>
<pre><code>Frame = can.recv()
MyValue = Frame.data[0] + Frame.data[1] * 0x100
</code></pre>
<p dir="auto">Johan</p>
]]></description><link>https://forum.pycom.io/post/32659</link><guid isPermaLink="true">https://forum.pycom.io/post/32659</guid><dc:creator><![CDATA[johand]]></dc:creator><pubDate>Mon, 11 May 2020 04:18:21 GMT</pubDate></item><item><title><![CDATA[Reply to CAN message decoding - how is data returned? on Sun, 24 May 2020 21:10:20 GMT]]></title><description><![CDATA[<p dir="auto">To help others with this topic, the way I have extracted the engineering values is as per the below class method:</p>
<pre><code>def extract_value(self,data):
    bit_list = bin(int.from_bytes(data,&quot;little&quot;))[2:]
    packed_bit_str = zfill(bit_list,64)
    spn_relevant_str = packed_bit_str[(-1*(self.start_bit+self.msg_bits)):(-1*(self.start_bit))]
    self.engineering_value = ((int(spn_relevant_str, 2)) * self.scaling_factor) + self.offset
</code></pre>
<p dir="auto">I instantiate the class for each SPN, and for each PGN/msg the method is ran for all SPN's where the CAN ID matches the PGN ID.</p>
<p dir="auto">The reason for working in bits as opposed to bytes is that some messages dont take up a full byte or share bytes with other messages.</p>
<p dir="auto">I am new to Python and am in no way an experienced programmer, but though I would share my method since this didnt seem to be a commonly discussed topic.</p>
]]></description><link>https://forum.pycom.io/post/32836</link><guid isPermaLink="true">https://forum.pycom.io/post/32836</guid><dc:creator><![CDATA[JSmith]]></dc:creator><pubDate>Sun, 24 May 2020 21:10:20 GMT</pubDate></item></channel></rss>