コード例 #1
0
        /// <summary>
        /// TRANSMIT DATA AND GETTING RESPONSE
        /// </summary>
        /// <param name="handle">PCAN HANDLE</param>
        /// <param name="id">PCAN TRANSMIT ID</param>
        /// <param name="command">PCAN TRANSMIT DATA</param>
        /// <param name="timeout">TIMEOUT FOR RESPONSE</param>
        /// <returns></returns>
        public TPCANStatus TransmitNormal(TPCANHandle handle, string id, byte[] command, int timeout)
        {
            TPCANStatus stsResult;
            bool        getR  = false;
            FrameRW     frame = new FrameRW();

            Thread.Sleep(_delayTime);

            do
            {
                stsResult = frame.ReadFrame(handle);
            }while (stsResult == TPCANStatus.PCAN_ERROR_OK);

            this.Tx.Time   = DateTime.Now.TimeOfDay.ToString();
            this.Tx.ID     = id;
            this.Tx.Length = command.Length.ToString();
            this.Tx.Data   = BitConverter.ToString(command).Replace("-", " ");

            this._status = "Write";
            stsResult    = frame.WriteFrame(handle, id, command);

            if (stsResult == TPCANStatus.PCAN_ERROR_OK)
            {
                while (timeout > 0)
                {
                    Thread.Sleep(1);

                    this._status = "Read";
                    stsResult    = frame.ReadFrame(handle);

                    timeout--;

                    if (stsResult == TPCANStatus.PCAN_ERROR_OK || stsResult == TPCANStatus.PCAN_ERROR_RESPONSE)
                    {
                        this.Rx = frame.ReturnData;
                        getR    = true;

                        if (stsResult == TPCANStatus.PCAN_ERROR_RESPONSE)
                        {
                            break;
                        }
                    }
                    else if (stsResult == TPCANStatus.PCAN_ERROR_QRCVEMPTY)
                    {
                        if (getR)
                        {
                            stsResult = TPCANStatus.PCAN_ERROR_OK;
                            break;
                        }
                    }
                }
            }
            return(stsResult);
        }
コード例 #2
0
        /// <summary>
        /// TRANSMIT DATA WITHOUT GETTING RESPONSE
        /// </summary>
        /// <param name="handle">PCAN HANDLE</param>
        /// <param name="id">PCAN TRANSMIT ID</param>
        /// <param name="command">PCAN TRANSMIT DATA</param>
        /// <returns></returns>
        public TPCANStatus TransmitOnly(TPCANHandle handle, string id, byte[] command)
        {
            TPCANStatus stsResult;
            FrameRW     frame = new FrameRW();

            Thread.Sleep(_delayTime);

            this.Tx.Time   = DateTime.Now.TimeOfDay.ToString();
            this.Tx.ID     = id;
            this.Tx.Length = command.Length.ToString();
            this.Tx.Data   = BitConverter.ToString(command).Replace("-", " ");

            this._status = "Write";
            stsResult    = frame.WriteFrame(handle, id, command);

            return(stsResult);
        }