Decoding Bms Data


Hinse

Recommended Posts

Hi,
I am trying to connect a battery management system to DaqFactory to log battery data.

I have several questions to get the project to work satisfactorily.

First:
How do I use ReadUntil or another command to detect the end of the data stream the ends in 0x85 0xA8. This sows up as \133\168 on the Comm Monitor. (see below)

Second:
I would like to send a hex phrase to trigger the data from the BMS. The attached document specifies: 0xA8 0x85 0x00 0x00 0x00 0x00 0x00 0x13
The only way I could get it to work was by using decimal equivalents.

Third:
I would like to parse the returned data on the "\" character into an array of 85 values.



Sample from COMM Monitor window:
Tx: \168\133\000\000\000\000\000\019
Rx: \168\133\032\000\026\000\143\128\143\128\142\157\142\241\143\143\143\115\143\127\164\016\156\064\000\050\105\120\113\072\011\184\000\010
\000\200\000\100\160\040\167\248\101\144\000\030\000\040\019\136\003\232\000\065\000\055\001\183\001\001\000\000\000\000\001\084\000\112\066\096\001\073\151\000\009\057\008\124\000\000\000\000\000\100\000\000\000\060\133\168


Existing Code:
global string data

while(1)
   try
      
   device.COM14.Purge()
   
   device.COM14.Write(chr(168))
   device.COM14.Write(chr(133))
   device.COM14.Write(chr(0))
   device.COM14.Write(chr(0))
   device.COM14.Write(chr(0))
   device.COM14.Write(chr(0))
   device.COM14.Write(chr(0))
   device.COM14.Write(chr(19))
 
   data = device.COM14.ReadUntil(chr(168))
   
   v.Values = parse(data,-1,"\")
      
   catch()

   ? strLastError

   endcatch  

   delay(10)

endwhile

24SBMSCommunication Protocol.pdf

Link to comment
Share on other sites

1) you don't want to use ReadUntil().  According to your docs, the system will return 86 bytes, so just do read(86), then verify that the last two bytes are 0x85 and 0xA8:

 

2) you can do this in a single command using the chra() function:

 

device.com14.write(chra({0xa8, 0x85, 0x00, 0x00, 0x00, 0x00, 0x00, 0x13})

 

3) use the asca() function to do the opposite of chra().

 

The end result is something like this (without the loop, declaration and try/catch):

 

private datain

 

device.com14.purge()

device.com14.write(chra({0xa8, 0x85, 0x00, 0x00, 0x00, 0x00, 0x00, 0x13})

data = device.com14.read(86)
datain = asca(data)
if ((datain[84] != 0x85) || (datain[85] != 0xa8))
   ? "Invalid packet"
else
   // do whatever you want.  Datain is an array where each element is a byte number
endif
Link to comment
Share on other sites

  • 1 month later...

Hi,

 

I got the code to work to a point, the command goes out but the response is ignored by DaqFactory.

I can see the data come back on the monitor screen within 50ms, but the read command returns nothing.

 

What are your thoughts?

 

(screen grab attached)

post-8443-0-09323600-1379635542_thumb.jp

 

thank you,

Pierre

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.