Exemplo n.º 1
0
        public unsafe byte GetDateTime(ref int iDay, ref int iMonth, ref int iYear, ref int iHour, ref int iMinute, ref int iSecond )
        {
            byte[] bDataToSend = new byte[150];
            CmdData cmdPackage = new CmdData();
            int iRet = 0;

            cmdPackage.bCmd = CommandPackgeDefs.CMD_GET_DATETIME;
            cmdPackage.bDest = 0x74;
            cmdPackage.bNumData = 1;
            cmdPackage.bStatus = 0;
            cmdPackage.bSession = 0;

            cmdPackage =  ProcessPackageToRead(cmdPackage);

            if(cmdPackage.bCmd == 0xFF )
            {
                return (byte)iRet;
            }

            iDay    = cmdPackage.bRXData[0];
            iMonth  = cmdPackage.bRXData[1];
            iYear   = cmdPackage.bRXData[2] + 2000;
            iHour   = cmdPackage.bRXData[3];
            iMinute = cmdPackage.bRXData[4];
            iSecond = cmdPackage.bRXData[5];

            return 0;
        }
Exemplo n.º 2
0
        unsafe CmdData ProcessPackageToRead(CmdData CmdPackage)
        {
            byte[] bData = new byte[256];
            int DataLen = 0;
            int DataSent = 0;
            int PackageOk = -1;

            DataLen = MakePackage(CmdPackage, ref bData);

            try
            {
                DataSent = udpClient.Send(bData, DataLen);
            }
            catch (Exception)
            {

                throw;
            }

            CmdPackage.bCmd = 0xFF;

            if (DataSent == DataLen)
            {
                try
                {
                    var remoteEndPoint = new IPEndPoint(IPAddress.Any, 0);
                    byte[] receivedResults = udpClient.Receive(ref remoteEndPoint);

                    if (receivedResults.Length > 7)
                    {
                        if ((receivedResults[0] == CommandPackgeDefs.HEADER) && (receivedResults[1] == CommandPackgeDefs.HEADER) && (receivedResults[receivedResults.Length - 1] == CommandPackgeDefs.ENDTRANS))
                        {

                            CmdPackage.bCmd      = receivedResults[3];
                            CmdPackage.bDest     = receivedResults[4];
                            CmdPackage.bNumData  = receivedResults[6];
                            CmdPackage.bStatus   = receivedResults[5];
                            CmdPackage.bSession  = receivedResults[2];

                            for (int i = 0; i < CmdPackage.bNumData; i++ )
                            {
                                CmdPackage.bRXData[i] = receivedResults[i + 7];
                            }

                            PackageOk = 0;
                        }
                    }

                }
                catch (Exception)
                {

                }

            }

            return CmdPackage;
        }
Exemplo n.º 3
0
        int ProcessPackageToSend( CmdData CmdPackage )
        {
            byte[] bData = new byte[256];
            int DataLen = 0;
            int DataSent = 0;
            int PackageOk = -1;

            DataLen = MakePackage(CmdPackage, ref bData);

            try
            {
               	DataSent = udpClient.Send(bData, DataLen);
            }
            catch (Exception)
            {

                throw;
            }

            if( DataSent == DataLen )
            {
                try
                {
                    var remoteEndPoint = new IPEndPoint(IPAddress.Any, 0);
                    byte[] receivedResults = udpClient.Receive(ref remoteEndPoint);

                    if(receivedResults.Length > 7)
                    {
                        if( ( receivedResults[0] == CommandPackgeDefs.HEADER) && ( receivedResults[1] == CommandPackgeDefs.HEADER)  && ( receivedResults[receivedResults.Length-1] == CommandPackgeDefs.ENDTRANS) )
                        {
                            PackageOk = 0;
                        }
                    }

                }
                catch (Exception)
                {

                }

            }

            return PackageOk;
        }
Exemplo n.º 4
0
        public unsafe byte SendRelayCommand(byte bRelay, byte bState)
        {
            byte[] bDataToSend = new byte[150];
            CmdData cmdPackage = new CmdData();
            int iRet = 0;

            cmdPackage.bCmd     = CommandPackgeDefs.CMD_RELAY_WRITE;
            cmdPackage.bDest    = 0x74;
            cmdPackage.bNumData = 2;
            cmdPackage.bStatus  = 0;
            cmdPackage.bSession = 0;
            cmdPackage.bRXData[0] = bRelay;
            cmdPackage.bRXData[1] = bState;

            iRet = ProcessPackageToSend(cmdPackage);

            return 0;
        }
Exemplo n.º 5
0
        public unsafe byte SetDateTime(int iDay, int iMonth, int iYear, int iHour,  int iMinute,  int iSecond)
        {
            byte[] bDataToSend = new byte[150];
            CmdData cmdPackage = new CmdData();
            int iRet = 0;

            cmdPackage.bCmd = CommandPackgeDefs.CMD_SET_DATETIME;
            cmdPackage.bDest = 0x74;
            cmdPackage.bNumData = 6;
            cmdPackage.bStatus = 0;
            cmdPackage.bSession = 0;

            cmdPackage.bRXData[0] = (byte)iDay;
            cmdPackage.bRXData[1] = (byte)iMonth;
            cmdPackage.bRXData[2] = (byte)(iYear - 2000);
            cmdPackage.bRXData[3] = (byte)iHour;
            cmdPackage.bRXData[4] = (byte)iMinute;
            cmdPackage.bRXData[5] = (byte)iSecond;

            iRet = ProcessPackageToSend(cmdPackage);

            if (iRet != 0)
            {
                return (byte)iRet;
            }

            return 0;
        }
Exemplo n.º 6
0
        public unsafe byte SendReadEventCommand(int Slot, ref int StartDay, ref int StartMonth, ref int StartYear, ref int StartHour, ref int StartMinute, ref int StartSecond, ref int StopHour, ref int StopMinute, ref int StopSecond, ref int Type, ref int Relay, ref byte WeekDays)
        {
            byte[] bDataToSend = new byte[150];
            CmdData cmdPackage = new CmdData();
            int iRet = 0;

            cmdPackage.bCmd = CommandPackgeDefs.CMD_GET_EVENT;
            cmdPackage.bDest = 0x74;
            cmdPackage.bNumData = 1;
            cmdPackage.bRXData[0] = (byte)Slot;

            cmdPackage = ProcessPackageToRead(cmdPackage);

            if (cmdPackage.bCmd != 0xFF)
            {
               // Slot                     =     (int)cmdPackage.bRXData[0];
                Type                     =     (int)cmdPackage.bRXData[1];
                Relay                    =     (int)cmdPackage.bRXData[2];
                StartDay                 =     (int)cmdPackage.bRXData[3];
                StartMonth               =     (int)cmdPackage.bRXData[4];
                StartYear                =     (int)cmdPackage.bRXData[5] + 2000;
                WeekDays                 =     cmdPackage.bRXData[6];
                StartHour                =     (int)cmdPackage.bRXData[7];
                StartMinute              =     (int)cmdPackage.bRXData[8];
                StartSecond              =     (int)cmdPackage.bRXData[9];
                StopHour                 =     (int)cmdPackage.bRXData[10];
                StopMinute               =     (int)cmdPackage.bRXData[11];
                StopSecond               =     (int)cmdPackage.bRXData[12];
            }

            /*
            cmdPackage.bStatus = 0;
            cmdPackage.bSession = 0;
            cmdPackage.bRXData[0] = (byte)Slot;
            cmdPackage.bRXData[1] = (byte)Type; //Type
            cmdPackage.bRXData[2] = (byte)Relay; //Relay
            cmdPackage.bRXData[3] = (byte)StartDate.Day;
            cmdPackage.bRXData[4] = (byte)StartDate.Month;
            cmdPackage.bRXData[5] = (byte)(StartDate.Year - 2000);
            cmdPackage.bRXData[6] = WeekDays;
            cmdPackage.bRXData[7] = (byte)StartDate.Hour;
            cmdPackage.bRXData[8] = (byte)StartDate.Minute;
            cmdPackage.bRXData[9] = (byte)StartDate.Second;
            cmdPackage.bRXData[10] = (byte)StopDate.Hour;
            cmdPackage.bRXData[11] = (byte)StopDate.Minute;
            cmdPackage.bRXData[12] = (byte)StopDate.Second;

            iRet = ProcessPackageToSend(cmdPackage);
            */

            return cmdPackage.bStatus;
        }
Exemplo n.º 7
0
        // public unsafe byte SendConfigEventCommand(byte bDia, byte bMes, byte bAno, byte bStartHora, byte bStartMinuto, byte bStartSegundo, byte bStopHora, byte bStopMinuto, byte bStopSegundo)
        public unsafe byte SendConfigEventCommand(DateTime StartDate, DateTime StopDate, int Type, int Relay, int Slot, byte WeekDays)
        {
            byte[] bDataToSend = new byte[150];
            CmdData cmdPackage = new CmdData();
            int iRet = 0;

            cmdPackage.bCmd = CommandPackgeDefs.CMD_SET_EVENT;
            cmdPackage.bDest = 0x74;
            cmdPackage.bNumData = 13;
            cmdPackage.bStatus = 0;
            cmdPackage.bSession = 0;
            cmdPackage.bRXData[0] = (byte)Slot;
            cmdPackage.bRXData[1] = (byte)Type; //Type
            cmdPackage.bRXData[2] = (byte)Relay; //Relay
            cmdPackage.bRXData[3] = (byte)StartDate.Day;
            cmdPackage.bRXData[4] = (byte)StartDate.Month;
            cmdPackage.bRXData[5] = (byte)(StartDate.Year - 2000);
            cmdPackage.bRXData[6] = WeekDays;
            cmdPackage.bRXData[7] = (byte)StartDate.Hour;
            cmdPackage.bRXData[8] = (byte)StartDate.Minute;
            cmdPackage.bRXData[9] = (byte)StartDate.Second;
            cmdPackage.bRXData[10] = (byte)StopDate.Hour;
            cmdPackage.bRXData[11] = (byte)StopDate.Minute;
            cmdPackage.bRXData[12] = (byte)StopDate.Second;

            iRet = ProcessPackageToSend(cmdPackage);

            return 0;
        }
Exemplo n.º 8
0
        public unsafe byte ReadRelayCommand(ref byte[] bRelayState)
        {
            byte bRet = 0xFF;

            byte[] bDataToSend = new byte[150];
            CmdData cmdPackage = new CmdData();

            cmdPackage.bCmd = CommandPackgeDefs.CMD_RELAY_READ;
            cmdPackage.bDest = 0x74;
            cmdPackage.bNumData = 1;
            cmdPackage.bStatus = 0;
            cmdPackage.bSession = 0;

            cmdPackage = ProcessPackageToRead(cmdPackage);

            if (cmdPackage.bCmd != 0xFF)
            {
                for (int i = 0; i < 8; i++ )
                {
                    bRelayState[i] = (byte)((cmdPackage.bRXData[0] >> i) & 0x01);
                }

                bRet = 0;
            }

            return bRet;
        }
Exemplo n.º 9
0
        public unsafe int MakePackage( CmdData CmdPackage, ref byte[] bData )
        {
            /*byte [] bData = new byte[128];*/
            int DataCount = 0;

            bData[0] = CommandPackgeDefs.HEADER;
            bData[1] = CommandPackgeDefs.HEADER;
            bData[2] = CmdPackage.bSession;
            bData[3] = CmdPackage.bCmd;
            bData[4] = CmdPackage.bDest;
            bData[5] = CmdPackage.bStatus;
            bData[6] = CmdPackage.bNumData;

            for (int i = 0; i < CmdPackage.bNumData; i++ )
            {
                DataCount = i+7;
                bData[DataCount] = CmdPackage.bRXData[i];
            }

            DataCount++;

            bData[DataCount++] = 0;

            bData[DataCount++] = CommandPackgeDefs.ENDTRANS;

            return DataCount;
        }
Exemplo n.º 10
0
        private void buttonSysInfo_Click(object sender, EventArgs e)
        {
            CmdData SerialData = new CmdData();
            byte[] bData = new byte[128];
            byte[] bRData = new byte[128];

            SerialData.bCmd = CommandPackgeDefs.CMD_GET_IP;
            SerialData.bNumData = 1;

            int numdata = UDPProt.MakePackage(SerialData, ref bData);

            try
            {
                Serial.PortName = comboBoxPorts.Text;
                Serial.Open();

                Serial.Write(bData, 0, numdata);
                System.Threading.Thread.Sleep(100);
                Serial.Read(bRData, 0, 13);
                Serial.Close();

                textBoxIP.Text = Convert.ToString(bRData[7]) + "." + Convert.ToString(bRData[8]) + "." + Convert.ToString(bRData[9]) + "." + Convert.ToString(bRData[10]);

            }
            catch (Exception)
            {
                Serial.Close();
                textBoxIP.Text = "Erro.";
            }
        }