Пример #1
0
        //public static ResourceManager rm = new ResourceManager("IncomUtility.StringsEng", Assembly.GetExecutingAssembly());
        //public static ResourceManager rm = new ResourceManager("IncomUtility.StringsChn", Assembly.GetExecutingAssembly());

        public static byte[] sendCommand(byte[] payload, ref ERROR_LIST error, int sleepTime)
        {
            if (!SerialPortIO.isPortOpen())
            {
                error = ERROR_LIST.ERROR_PORT_NOT_OPEN;
                if (isMessageboxWortk)
                {
                    //    MessageBox.Show("Incom is not connected");
                    MessageBox.Show(rm.GetString("NotConnected"));
                }
                return(null);
            }
            if (payload == null)
            {
                error = ERROR_LIST.ERROR_INPUT_DATA_NONE;
                return(null);
            }

            int retryCount = (int)Constants.retryCount;

            byte[] u8TXbuffer = null;
            byte[] u8RXbuffer = null;

            SerialPortIO.mutex.WaitOne();

            while (retryCount-- > 0)
            {
                SerialPortIO.flushIOBuffer();

                u8TXbuffer = buildCMDPacket((byte)PACKET_CONF.COMM_SYSTEM_MFG_PC,
                                            (byte)PACKET_CONF.COMM_SYSTEM_INCOM, payload, ref error);
                if (error != ERROR_LIST.ERROR_NONE)
                {
                    continue;
                }

                SerialPortIO.writePacket(ref u8TXbuffer, ref error);
                if (error != ERROR_LIST.ERROR_NONE)
                {
                    continue;
                }
                Thread.Sleep(sleepTime);

                u8RXbuffer = SerialPortIO.readPacket(ref error);
                if (error != ERROR_LIST.ERROR_NONE)
                {
                    continue;
                }

                error = validateRXPacket(u8RXbuffer);
                if (error == ERROR_LIST.ERROR_NONE)
                {
                    break;
                }
            }
            if (APP.APP_UI_CommLog.packetCheck == true)
            {
                MainWindow.winCommLog.setText(u8TXbuffer, u8RXbuffer);
            }

            SerialPortIO.flushIOBuffer();
            SerialPortIO.mutex.ReleaseMutex();

            return(u8RXbuffer);
        }