Example #1
0
 private void SendDataToUart_button_Click(object sender, EventArgs e)
 {
     if (SendDataToUart_textBox.Text == string.Empty)
     {
         return;
     }
     try
     {
         byte[] pre_data = HM_Utilitys.HexStringToByteArray(SendDataToUart_textBox.Text);
         Log(LogMsgType.Normal, HM_Utilitys.ByteArrayToHexString(pre_data) + Environment.NewLine);
         byte   cmd   = pre_data[0];
         byte[] data  = new byte[pre_data[1]];
         int    index = 0;
         for (int i = 2; i < pre_data.Length; i++)
         {
             data[index++] = pre_data[i];
         }
         Send_LEV_CMD_Data(cmd, data);
         //Send_USB_TO_FATOOL_CMD_Data(cmd, data);
     }
     //catch (FormatException)
     catch (Exception ex)
     {
         // Inform the user if the hex string was not properly formatted
         //Log(LogMsgType.Error, "Not properly formatted hex string: " + sendData_textBox.Text + "\n");
         Log(LogMsgType.Error, "Error: " + ex.ToString() + Environment.NewLine);
     }
 }
Example #2
0
        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)
Example #3
0
 private void Send_USB_TO_FATOOL_CMD_Data(byte Cmd, byte[] data)
 {
     if (!IsConnectionToFaDevice)
     {
         Log(LogMsgType.Error, "[Error] Could not send while Fa-Tool Device have not found." + Environment.NewLine);
         return;
     }
     byte[] TransmitData = USB_CDC_Packet_Forming_and_Decoding.CMD_Forming_For_Transmitting(Cmd, data);
     Log(LogMsgType.Outgoing, "Transmitting: " + HM_Utilitys.ByteArrayToHexString(TransmitData) + Environment.NewLine);
     FaConnect.ComPortSendData(TransmitData);
 }
Example #4
0
        private void Send_LEV_CMD_Data(byte Cmd, byte[] data)
        {
            if (!IsConnectionToFaDevice)
            {
                return;
            }


            byte[] levPacket = LEV_UART_Packet_Forming_and_Decoding.CMD_Forming_For_Transmitting(Cmd, data);
            Log(LogMsgType.Outgoing, "TransmittinglevPacket: " + HM_Utilitys.ByteArrayToHexString(levPacket) + Environment.NewLine);
            byte[] TransmitViaUart_As_Usb_Parameter = (byte[])levPacket.Clone();
            Send_USB_TO_FATOOL_CMD_Data((byte)USB_CDC_Cmd.Cmd_UART_RS485_Transmit_Data, TransmitViaUart_As_Usb_Parameter);
        }
Example #5
0
        //// 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);
            }
        }