private void Receiving_Data_UnPAcking_By_USBPacket(byte Usb_Cmd, byte[] Usb_Data) { DSG_Current_ADC = 0; CHG_Current_ADC = 0; VBAT_ADC = 0; VBAT_mV_To_ADC_Factor = 0.0f; DSG_mA_To_ADC_Factor = 0.0f; CHG_mA_To_ADC_Factor = 0.0f; //byte Usb_Cmd = ReceivedClass.USB_Cmd; //byte[] Usb_Data = (byte[])ReceivedClass.USB_ReceivedData.Clone(); SetText("Receiving_Data_ByEvent CMD : " + HM_Utilitys.ByteToHexString(Usb_Cmd) + Environment.NewLine); SetText("Receive_Data byte: " + HM_Utilitys.ByteArrayToHexString(Usb_Data) + Environment.NewLine); //LEV_One_Wire_Receiving_Packet_Decoding.Received_Data_Group group = LEV_One_Wire_Receiving_Packet_Decoding.Received_Data_Group.None; List <LEV_One_Wire_Receiving_Packet_Decoding.Received_Data_Group> outDataGroupList; List <byte[]> outDataList; if (Usb_Cmd == (byte)USB_CDC_Cmd.Cmd_UART_RS485_Receive_Data) { g_ReceivedUartDataList.AddRange(Usb_Data); SetText("Cmd_UART_RS485_Receive_Data byte: " + HM_Utilitys.ByteArrayToHexString(Usb_Data) + Environment.NewLine); SetText("Cmd_UART_RS485_Receive_Data List : " + HM_Utilitys.ByteArrayToHexString(g_ReceivedUartDataList.ToArray <byte>()) + Environment.NewLine); LEV_One_Wire_Receiving_Packet_Decoding.Packet_Decoding_To_Group_And_Clear_List(ref g_ReceivedUartDataList, out outDataGroupList, out outDataList); if ((outDataGroupList.Count >= 1) && (outDataGroupList.Count == outDataList.Count)) { for (int i = 0; i < outDataGroupList.Count; i++) { if (outDataGroupList[i] == LEV_One_Wire_Receiving_Packet_Decoding.Received_Data_Group.OneWire_SystemData_Group) { SetText("OneWire_SystemData_Group : " + Environment.NewLine); SetText("Group data : " + HM_Utilitys.ByteArrayToHexString(outDataList[i]) + Environment.NewLine); Set_OneWire_SystemData(outDataList[i]); } else if (outDataGroupList[i] == LEV_One_Wire_Receiving_Packet_Decoding.Received_Data_Group.OneWire_EEPROM_Group) { SetText("OneWire_EEPROM_Group : " + Environment.NewLine); SetText("Group data : " + HM_Utilitys.ByteArrayToHexString(outDataList[i]) + Environment.NewLine); Set_OneWire_EEPROMData(outDataList[i]); myUI_CalculationInformatio(VBAT_ADC, DSG_Current_ADC, CHG_Current_ADC, VBAT_mV_To_ADC_Factor, DSG_mA_To_ADC_Factor, CHG_mA_To_ADC_Factor); } else { SetText("[Fail] None OneWire_Data : " + outDataGroupList[i] + Environment.NewLine); SetText("Group data : " + HM_Utilitys.ByteArrayToHexString(outDataList[i]) + Environment.NewLine); } } } //if (outDataGroupList.Count >= 1) else { SetText("[Fail] OneWire_Data List Count Fail. " + Environment.NewLine); LEV_One_Wire_Receiving_Packet_Decoding.Packet_Decoding_To_Group_And_Clear_List(ref g_ReceivedUartDataList, out outDataGroupList, out outDataList); } } //if(Usb_Cmd == (byte)USB_CDC_Cmd.Cmd_UART_RS485_Receive_Data){ }//private void Receiving_Data_UnPAcking_By_USBPacket(byte Usb_Cmd, byte[] Usb_Data)
//// The method that implements the delegated functionality //事件處理方法 private void FaReceivedMessageChange(Object sender, EventArgs e) { // 判斷物件是否為 ComPortStatusUpdate_EventArgs 實體 if (e is SerialPortMessage_EventArgs) { // 將物件由 EventArgs 轉型 ComPortStatusUpdate_EventArgs SerialPortMessage_EventArgs msg = e as SerialPortMessage_EventArgs; Log(LogMsgType.Incoming, "[FaReceivedMessage] Msg Type: " + msg.MsgType + ", ConectedStatus: " + msg.ConectedStatus + Environment.NewLine); Log(LogMsgType.Incoming, "Com port information : " + msg.ComPortInformation + Environment.NewLine); if (msg.MsgType == MessageTypes.ConnectingStatus) { if (msg.ConectedStatus == ConnectingStatusTypes.Connected) { FA_Connection(); } else { FA_DisConnection(); } } if (msg.MsgType == MessageTypes.ReceiveData) { Log(LogMsgType.Incoming, "RX Packet: " + HM_Utilitys.ByteArrayToHexString(msg.ReceivedBuffer) + Environment.NewLine); byte ReceivedCommand; byte[] decoding_Parameter; bool is_found = USB_CDC_Packet_Forming_and_Decoding.CMD_Decoding_For_Receiving(msg.ReceivedBuffer, out ReceivedCommand, out decoding_Parameter); if (is_found) { Log(LogMsgType.Incoming, "rx cmd: " + HM_Utilitys.ByteToHexString(ReceivedCommand) + Environment.NewLine); Log(LogMsgType.Incoming, "rx data: " + HM_Utilitys.ByteArrayToHexString(decoding_Parameter) + Environment.NewLine); } else { Log(LogMsgType.Error, "received packet error. " + Environment.NewLine); } } } else { Log(LogMsgType.Incoming, "[FaReceivedMessage] Unknow Message ....." + Environment.NewLine); } }