コード例 #1
0
ファイル: AdvCANIO.cs プロジェクト: wpmyj/AdvaMACSystem
    /*****************************************************************************
    *
    *	acCanRead
    *
    *	Purpose:
    *		Read can message.
    *
    *
    *	Arguments:
    *		msgRead           - managed buffer for read
    *		nReadCount			- msg number that unmanaged buffer can preserve
    *     pulNumberofRead   - real msgs have read
    *		ov				      - synchronization event
    *	Returns:
    *	=0	SUCCESS; or <0 failure
    *
    *****************************************************************************/
    public int acCanRead(AdvCan.canmsg_t[] msgRead, uint nReadCount, ref uint pulNumberofRead)
    {
        bool flag;
        int  nRet;
        uint i;

        if (nReadCount > MaxReadMsgNumber)
        {
            return(OPERATION_ERROR);
        }

        pulNumberofRead = 0;
        flag            = AdvCan.ReadFile(hDevice, orgReadBuf, nReadCount, ref pulNumberofRead, 0); //Read frame
        if (flag)
        {
            if (pulNumberofRead == 0)
            {
                nRet = TIME_OUT;
            }
            else
            {
                for (i = 0; i < pulNumberofRead; i++)
                {
                    msgRead[i] = (AdvCan.canmsg_t)(Marshal.PtrToStructure(new IntPtr(orgReadBuf.ToInt32() + AdvCan.CAN_MSG_LENGTH * i), typeof(AdvCan.canmsg_t)));
                }
                nRet = SUCCESS;
            }
        }
        else
        {
            nRet = OPERATION_ERROR;                                 //Package receiving error
        }
        return(nRet);
    }
コード例 #2
0
ファイル: AdvCANIO.cs プロジェクト: ChiFang/AGV_Sys
    /*****************************************************************************
    *
    *    acCanRead
    *
    *    Purpose:
    *        Read can message.
    *
    *
    *    Arguments:
    *        msgRead           - managed buffer for read
    *        nReadCount        - msg number that unmanaged buffer can preserve
    *        pulNumberofRead   - real msgs have read
    *
    *    Returns:
    *        =0 SUCCESS; or <0 failure
    *
    *****************************************************************************/
    public int acCanRead(AdvCan.canmsg_t[] msgRead, uint nReadCount, ref uint pulNumberofRead)
    {
        bool flag;
        int  nRet;
        uint i;

        if (nReadCount > MaxReadMsgNumber)
        {
            nReadCount = MaxReadMsgNumber;
        }
        pulNumberofRead = 0;
        flag            = AdvCan.ReadFile(hDevice, orgReadBuf, nReadCount, out pulNumberofRead, this.rxOvr.memPtr);
        if (flag)
        {
            if (pulNumberofRead == 0)
            {
                nRet = TIME_OUT;
            }
            else
            {
                for (i = 0; i < pulNumberofRead; i++)
                {
                    if (OS_TYPE == 8)
                    {
                        msgRead[i] = (AdvCan.canmsg_t)(Marshal.PtrToStructure(new IntPtr(orgReadBuf.ToInt64() + AdvCan.CAN_MSG_LENGTH * i), typeof(AdvCan.canmsg_t)));
                    }
                    else
                    {
                        msgRead[i] = (AdvCan.canmsg_t)(Marshal.PtrToStructure(new IntPtr(orgReadBuf.ToInt32() + AdvCan.CAN_MSG_LENGTH * i), typeof(AdvCan.canmsg_t)));
                    }
                }
                nRet = SUCCESS;
            }
        }
        else
        {
            if (AdvCan.GetOverlappedResult(hDevice, this.rxOvr.memPtr, out pulNumberofRead, true))
            {
                if (pulNumberofRead == 0)
                {
                    nRet = TIME_OUT;                              //Package receiving timeout
                }
                else
                {
                    for (i = 0; i < pulNumberofRead; i++)
                    {
                        if (OS_TYPE == 8)
                        {
                            msgRead[i] = (AdvCan.canmsg_t)(Marshal.PtrToStructure(new IntPtr(orgReadBuf.ToInt64() + AdvCan.CAN_MSG_LENGTH * i), typeof(AdvCan.canmsg_t)));
                        }
                        else
                        {
                            msgRead[i] = (AdvCan.canmsg_t)(Marshal.PtrToStructure(new IntPtr(orgReadBuf.ToInt32() + AdvCan.CAN_MSG_LENGTH * i), typeof(AdvCan.canmsg_t)));
                        }
                    }
                    nRet = SUCCESS;
                }
            }
            else
            {
                nRet = OPERATION_ERROR;                                   //Package receiving error
            }
        }
        return(nRet);
    }