Exemple #1
0
        private static void OpenBatteryCommunicationChannel(int moduleID = 10)
        {
            strCurrentID = moduleID.ToString();
            moduleID     = moduleID - 1;

            checked
            {
                try
                {
                    boolFirstBalanceFlag = true;

                    if (paramcom.IsOpen)
                    {
                        paramcom.Close();
                    }
                    try
                    {
                        paramcom.Open(strCurrentCOM, 9600, 8, RS232.DataParity.Parity_Mark, RS232.DataStopBit.StopBit_1, 512);
                        paramcom.Write(paramBattery.Wakeup());
                        paramcom.Close();
                        paramcom.Open(strCurrentCOM, 115200, 8, RS232.DataParity.Parity_Mark, RS232.DataStopBit.StopBit_1, 512);
                    }
                    catch (Exception ex3)
                    {
                        WriteError("Incorrect com port selected!");
                        throw new Exception("Open communication port fail");
                    }
                    try
                    {
                        paramBattery.ADDRESS = moduleID;
                        paramcom.Write(paramBattery.ModelReadSend());
                        if (paramcom.Read(9) != -1 && paramBattery.ModelReadReturn(paramcom.InputStream))
                        {
                            strID = (int)Math.Round((double)strID + Convert.ToDouble((moduleID + 1).ToString()));
                            if (Convert.ToDouble(strCurrentID) == (double)strID)
                            {
                                m_model = paramBattery.MODEL;
                                paramcom.Close();
                            }
                            strID = 0;
                        }
                    }
                    catch (Exception ex5)
                    {
                        throw ex5;
                    }
                    switch (m_model)
                    {
                    case "U1-12XP Rev. 1":
                    case "U24-12XP Rev. 1":
                    case "U27-12XP Rev. 1":
                    case "U1-12XP Rev. 2":
                    case "U24-12XP Rev. 2":
                    case "U27-12XP Rev. 2":
                        strVoltNO = Convert.ToString(4);
                        break;

                    case "UEV-18XP Rev. 1":
                    case "UEV-18XP Rev. 2":
                        strVoltNO = Convert.ToString(6);
                        break;
                    }
                    paramBattery.MODE    = strVoltNO;
                    paramBattery.ADDRESS = moduleID;

                    if (paramBattery.HardwareRevision == 2)
                    {
                        try
                        {
                            paramcom.Open(strCurrentCOM, 9600, 8, RS232.DataParity.Parity_Mark, RS232.DataStopBit.StopBit_1, 512);
                        }
                        catch (Exception ex7)
                        {
                            throw new Exception("Open Communication Port Fail");
                        }
                    }
                    paramBattery.MODE = strVoltNO;
                    try
                    {
                        paramcom.Write(paramBattery.Wakeup());
                    }
                    catch (Exception ex)
                    {
                        //TODO log
                        throw new Exception("Wakeup Battery Fail");
                    }
                    paramcom.Close();
                    try
                    {
                        paramcom.Open(strCurrentCOM, 115200, 8, RS232.DataParity.Parity_Mark, RS232.DataStopBit.StopBit_1, 512);
                    }
                    catch (Exception ex11)
                    {
                        throw new Exception("Open communication port Fail");
                    }
                    try
                    {
                        Openbalancing(paramcom, paramBattery);
                    }
                    catch (Exception ex13)
                    {
                        throw new Exception("Pls check config:the Com port or ModuleID ");
                    }
                    paramcom.Write(paramBattery.ExitCalibrationMode());
                    paramBattery.MODE  = strVoltNO;
                    strErrorMessage    = "";
                    timer.Enabled      = true;
                    boolCommnucateflag = true;
                }
                catch (Exception ex15)
                {
                    paramcom.Close();
                    WriteError($"Exception: { ex15.Message }");
                }
                finally
                {
                }
            }
        }