Exemplo n.º 1
0
        }//private void port_DataReceived(object sender, SerialDataReceivedEventArgs e)

        // The method which fires the Event
        private void OnSerialPort_DataReceived_EventSendOut(SerialPort_EventArgsClass_DataReceived e)
        {
            if (SerialPort_DataReceived_EventSendOut != null)
            {
                SerialPort_DataReceived_EventSendOut(this, e);    // 觸發SerialPort_DataReceived_EventSendOut 事件
            }
        }
Exemplo n.º 2
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.º 3
0
        private void port_DataReceived(object sender, SerialDataReceivedEventArgs e)
        {
            // If the com port has been closed, do nothing
            if (!gSerialComPort.IsOpen)
            {
                return;
            }


            // Obtain the number of bytes waiting in the port's buffer
            int readbytes = gSerialComPort.BytesToRead;

            if (readbytes > 0)
            {
                // Create a byte array buffer to hold the incoming data
                byte[] buffer = new byte[readbytes];
                // Read the data from the port and store it in our buffer
                gSerialComPort.Read(buffer, 0, readbytes);

                //form1.SetText("Deiver UART received Data" + Environment.NewLine);
                //form1.SetText(HM_Utilitys.ByteArrayToHexString(buffer) + Environment.NewLine);
                //Information inforForm = new Information("Deiver UART received Data");
                //inforForm.Show();
                //inforForm.infor_textBox.AppendText("Length : " + readbytes + Environment.NewLine);
                //inforForm.infor_textBox.AppendText(HM_Utilitys.ByteArrayToHexString(buffer));


                // If anyone has subscribed, notify them
                SerialPort_EventArgsClass_DataReceived event_arg = new SerialPort_EventArgsClass_DataReceived(buffer);
                OnSerialPort_DataReceived_EventSendOut(event_arg);
            }
        }//private void port_DataReceived(object sender, SerialDataReceivedEventArgs e)