Beispiel #1
0
        //New system here:
        //synchronous functions for background thread.

        void BmsUpdate(BatteryWriteDataStruct write_data)
        {
            BatteryReadDataStruct read_data = null;


            if (!String.IsNullOrEmpty(BmsComPort) && BmsCom.Open(BmsComPort))
            {
                try
                {
                    //usually throws a timeout if the FTDI part has power and is connected but 48V is off.
                    read_data = BmsCom.BmsUpdate(write_data);
                }
                catch (Exception ex)
                {
                    //we still need to close the comport if we left it open, so the next attempt works properly.
                    if (BmsCom.IsOpen())
                    {
                        BmsCom.Close();
                    }
                    throw ex; //rethrow, so the top catches it.
                }

                BmsCom.Close();
            }


            if (read_data != null)
            {
                BatteryReadData = read_data;
                Dispatcher.BeginInvoke((Action)(() => { BmsUpdateGui(); }));
            }
        }
        public BatteryReadDataStruct BmsUpdate(BatteryWriteDataStruct write_struct)
        {
            var write_data = write_struct.Serialize();

            byte[] rx_buffer = RoundTripCommand(write_data, BatteryReadDataStruct.Size, NormalCellTimeout);

            BatteryReadDataStruct read_data = BatteryReadDataStruct.Deserialize(rx_buffer);

            return(read_data);
        }