Exemplo n.º 1
0
        //// The method that implements the delegated functionality
        //事件處理方法
        private void Communication_ReceivedDataFunction(Object sender, EventArgs e)
        {
            // 判斷物件是否為 SerialPort_EventArgsClass_DataReceived 實體
            if (e is SerialPort_EventArgsClass_DataReceived)
            {
                // 將物件由 EventArgs 轉型 SerialPortClass_DataReceivedEventArgs
                SerialPort_EventArgsClass_DataReceived DataReceivedClass = e as SerialPort_EventArgsClass_DataReceived;


                //form1.SetText("L1 receivind data 1" + Environment.NewLine);
                //form1.SetText(HM_Utilitys.ByteArrayToHexString(DataReceivedClass.ReceivedBuffer) + Environment.NewLine);

                byte   ReceivedCommand;
                byte[] decoding_Parameter;
                bool   is_found = USB_CDC_Packet_Forming_and_Decoding.CMD_Decoding_For_Receiving(DataReceivedClass.ReceivedBuffer, out ReceivedCommand, out decoding_Parameter);
                if (is_found)
                {
                    Receiving_Data_UnPAcking_By_USBPacket(ReceivedCommand, decoding_Parameter);
                    //form1.SetText("L1 receivind data 2" + Environment.NewLine);
                    //form1.SetText(HM_Utilitys.ByteArrayToHexString(decoding_Parameter) + Environment.NewLine);
                    //USB_CDC_DataReceived_EventSendOut receivedEvent = new USB_CDC_DataReceived_EventSendOut(ReceivedCommand, decoding_Parameter);
                    //OnUSB_CDC_DataReceived_EventSendOut(receivedEvent);
                }
            }
        }
Exemplo n.º 2
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);
 }
Exemplo n.º 3
0
        private void Send_USB_TO_FATOOL_CMD_Data(byte Cmd, byte[] data)
        {
            if (!IsConnectionToFaDevice)
            {
                return;
            }

            byte[] TransmitData = USB_CDC_Packet_Forming_and_Decoding.CMD_Forming_For_Transmitting(Cmd, data);

            CommunicationPort.ComPortSendData(TransmitData);
        }
Exemplo n.º 4
0
        private bool DetectingDisconnection()
        {
            byte[] TransmitData = USB_CDC_Packet_Forming_and_Decoding.CMD_Forming_For_Transmitting((byte)USB_CDC_Cmd.Cmd_For_Connect_Detection, new byte[0]);

            if (!CommunicationPort.ComPortSendData(TransmitData))
            {
                //fail to send
                return(false);
            }
            else
            {
                //success to send
                return(true);
            }
        }
Exemplo n.º 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);
            }
        }
Exemplo n.º 6
0
        public bool USB_CDC_SendData_With_Packet(USB_CDC_Cmd cmd, byte[] sendingData)
        {
            byte[] TransmitData = USB_CDC_Packet_Forming_and_Decoding.CMD_Forming_For_Transmitting((byte)cmd, sendingData);



            if (cmd != USB_CDC_Cmd.Cmd_For_Connect_Detection)
            {
                //Information inforForm = new Information("L1 USB Sending Data");
                //inforForm.Show();
                //inforForm.infor_textBox.AppendText(HM_Utilitys.ByteArrayToHexString(TransmitData));
            }

            if (!CommunicationPort.ComPortSendData(TransmitData))
            {
                //fail to send
                return(false);
            }
            else
            {
                //success to send
                return(true);
            }
        }