コード例 #1
0
ファイル: SLMPFrame.cs プロジェクト: masakrow/SLMPClient
        public int SLMP_GetSLMPInfo(SLMP_INFO p, byte[] pucStream)
        {
            int    i            = 0;
            int    iIndex       = 0;
            int    iLength      = 0;
            uint   uiTempLength = 0;
            ushort usFrameType  = 0;

            if (p.Equals(null) || (pucStream == null))
            {
                return(SLMP_ERR_NG);
            }

            usFrameType = CONCAT_2BIN(pucStream[0], pucStream[1]);

            Debug.WriteLine(usFrameType.ToString());
            /*[ Response : Binary Mode, Single Transmission Type ]*/
            if (usFrameType == SLMP_FTYPE_BIN_RES_ST)
            {
                Debug.WriteLine("I'm in 1");
                iIndex       = SLMP_FTYPE_BIN_RES_ST_INDEX;
                uiTempLength = CONCAT_2BIN(pucStream[8], pucStream[7]);

                iLength = (int)(uiTempLength - uiHeaderLength[iIndex]);

                Debug.WriteLine("Lenght:" + iLength.ToString());
                if (iLength < 0)
                {
                    return(SLMP_ERR_NG);
                }
                else if (iLength > 0)
                {
                    p.pucData = new byte[iLength];
                    if (p.pucData == null)
                    {
                        return(SLMP_ERR_NG);
                    }
                }

                (p.usNetNumber)  = pucStream[2];
                (p.usNodeNumber) = pucStream[3];
                (p.usProcNumber) = CONCAT_2BIN(pucStream[5], pucStream[4]);
                (p.usDataLength) = (ushort)uiTempLength;
                (p.usEndCode)    = CONCAT_2BIN(pucStream[10], pucStream[9]);

                for (i = 0; i < iLength; i++)
                {
                    p.pucData[i] = pucStream[uiDataAddr[iIndex] + i];
                }
                return(SLMP_ERR_OK);
            }

            /*[ Response : Binary Mode, Multiple Transmission Type ]*/
            else if (usFrameType == SLMP_FTYPE_BIN_RES_MT)
            {
                Debug.WriteLine("I'm in 2");
                iIndex       = SLMP_FTYPE_BIN_RES_MT_INDEX;
                uiTempLength = CONCAT_2BIN(pucStream[12], pucStream[11]);

                iLength = (int)(uiTempLength - uiHeaderLength[iIndex]);
                if (iLength < 0)
                {
                    return(SLMP_ERR_NG);
                }
                else if (iLength > 0)
                {
                    if (p.pucData == null)
                    {
                        return(SLMP_ERR_NG);
                    }
                }

                (p.usSerialNumber) = CONCAT_2BIN(pucStream[3], pucStream[2]);
                (p.usNetNumber)    = pucStream[6];
                (p.usNodeNumber)   = pucStream[7];
                (p.usProcNumber)   = CONCAT_2BIN(pucStream[9], pucStream[8]);
                (p.usDataLength)   = (ushort)uiTempLength;
                (p.usEndCode)      = CONCAT_2BIN(pucStream[14], pucStream[13]);

                for (i = 0; i < iLength; i++)
                {
                    p.pucData[i] = pucStream[uiDataAddr[iIndex] + i];
                }
                return(SLMP_ERR_OK);
            }
            return(SLMP_ERR_NG);
        }
コード例 #2
0
ファイル: SLMPFrame.cs プロジェクト: masakrow/SLMPClient
        public int SLMP_MakePacketStream(ushort ulFrameType, SLMP_INFO p, byte [] pucStream)
        {
            int i       = 0;
            int iLength = 0;
            int iIndex  = 0;


            if (p.Equals(null) || pucStream == null)
            {
                return(SLMP_ERR_NG);
            }
            /*[ Request : Binary Mode, Single Transmission Type ]*/
            if (ulFrameType == SLMP_FTYPE_BIN_REQ_ST)
            {
                iIndex  = SLMP_FTYPE_BIN_REQ_ST_INDEX;
                iLength = p.usDataLength - uiHeaderLength[iIndex];
                if (iLength < 0)
                {
                    return(SLMP_ERR_NG);
                }
                else if (iLength > 0)
                {
                    if (p.pucData == null)
                    {
                        return(SLMP_ERR_NG);
                    }
                }
                pucStream[0]  = SHIFT_R8(SLMP_FTYPE_BIN_REQ_ST);
                pucStream[1]  = SHIFT_R0(SLMP_FTYPE_BIN_REQ_ST);
                pucStream[2]  = SHIFT_R0(SLMP_FTYPE_BIN_REQ_ST);
                pucStream[3]  = SHIFT_R0(p.usNodeNumber);
                pucStream[4]  = SHIFT_R0(p.usProcNumber);
                pucStream[5]  = SHIFT_R8(p.usProcNumber);
                pucStream[6]  = (byte)0x00;
                pucStream[7]  = SHIFT_R0(p.usDataLength);
                pucStream[8]  = SHIFT_R8(p.usDataLength);
                pucStream[9]  = SHIFT_R0(p.usTimer);
                pucStream[10] = SHIFT_R8(p.usTimer);
                pucStream[11] = SHIFT_R0(p.usCommand);
                pucStream[12] = SHIFT_R8(p.usCommand);
                pucStream[13] = SHIFT_R0(p.usSubCommand);
                pucStream[14] = SHIFT_R8(p.usSubCommand);
                for (i = 0; i < iLength; i++)
                {
                    pucStream[uiDataAddr[iIndex] + i] = p.pucData[i];
                }
                return(SLMP_ERR_OK);
            }
            /*[ Request : Binary Mode, Multiple Transmission Type ]*/
            else if (ulFrameType == SLMP_FTYPE_BIN_REQ_MT)
            {
                iIndex  = SLMP_FTYPE_BIN_REQ_MT_INDEX;
                iLength = (p.usDataLength) - uiHeaderLength[iIndex];
                if (iLength < 0)
                {
                    return(SLMP_ERR_NG);
                }
                else if (iLength > 0)
                {
                    if (p.pucData == null)
                    {
                        return(SLMP_ERR_NG);
                    }
                }

                pucStream[0]  = SHIFT_R8(SLMP_FTYPE_BIN_REQ_MT);
                pucStream[1]  = SHIFT_R0(SLMP_FTYPE_BIN_REQ_MT);
                pucStream[2]  = SHIFT_R0(p.usSerialNumber);
                pucStream[3]  = SHIFT_R8(p.usSerialNumber);
                pucStream[4]  = (byte)0x00;
                pucStream[5]  = (byte)0x00;
                pucStream[6]  = SHIFT_R0(p.usNetNumber);
                pucStream[7]  = SHIFT_R0(p.usNodeNumber);
                pucStream[8]  = SHIFT_R0(p.usProcNumber);
                pucStream[9]  = SHIFT_R8(p.usProcNumber);
                pucStream[10] = (byte)0x00;
                pucStream[11] = SHIFT_R0(p.usDataLength);
                pucStream[12] = SHIFT_R8(p.usDataLength);
                pucStream[13] = SHIFT_R0(p.usTimer);
                pucStream[14] = SHIFT_R8(p.usTimer);
                pucStream[15] = SHIFT_R0(p.usCommand);
                pucStream[16] = SHIFT_R8(p.usCommand);
                pucStream[17] = SHIFT_R0(p.usSubCommand);
                pucStream[18] = SHIFT_R8(p.usSubCommand);

                for (i = 0; i < iLength; i++)
                {
                    pucStream[uiDataAddr[iIndex] + i] = p.pucData[i];
                }
                return(SLMP_ERR_OK);
            }

            return(SLMP_ERR_NG);
        }