Exemplo n.º 1
0
        public bool WriteCanMsg(uint ID, byte[] Msg)
        {
            //重试的次数
            int retrycnt = 0;



            if (_IsOpen)
            {
                try
                {
                    VCI_CAN_OBJ CanMsg = new VCI_CAN_OBJ();
                    CanMsg.ID         = Globals._NODE_ | ID;
                    CanMsg.SendType   = 0;          //0:正常发送 1:单次发送 2:自发自收 3:单次自发自收
                    CanMsg.RemoteFlag = 0;          //0:数据帧 1: 远程帧
                    CanMsg.ExternFlag = 0;          //0:标准帧 1:扩展帧

                    CanMsg.DataLen = (byte)Msg.Length;
                    CanMsg.Data    = new byte[8];
                    Array.Copy(Msg, CanMsg.Data, CanMsg.DataLen);


                    VCI_ERR_INFO   ErrorInfo = new VCI_ERR_INFO();
                    VCI_CAN_STATUS Vcs       = new VCI_CAN_STATUS();

                    do
                    {
                        if (ZLGBasic.VCI_Transmit(m_DevType, m_DevIndex, m_DevIndex, ref CanMsg, 1) == ZLGBasic.STATUS_OK)
                        {
                            return(true);
                        }
                        else
                        {
                            retrycnt++;

                            ZLGBasic.VCI_ReadErrInfo(m_DevType, m_DevIndex, m_CanIndex, ref ErrorInfo);

                            ZLGBasic.VCI_ReadCANStatus(m_DevType, m_DevIndex, m_CanIndex, ref Vcs);

                            //写总线异常日志


                            Thread.Sleep(10);
                        }
                    } while (retrycnt < 3);
                }
                catch (Exception ex)
                {
                    LogHelper.WriteLog(ex.Message);
                }
            }

            return(false);
        }
Exemplo n.º 2
0
 public static extern UInt32 VCI_ReadCANStatus(UInt32 DeviceType, UInt32 DeviceInd, UInt32 CANInd, ref VCI_CAN_STATUS pCANStatus);