Beispiel #1
0
        public bool WriteCanMsg(uint ID, byte[] Msg)
        {
            int retrycnt = 0;

            TPCANMsg CanMsg = new TPCANMsg();

            CanMsg.ID      = Globals._NODE_ | ID;
            CanMsg.MSGTYPE = TPCANMessageType.PCAN_MESSAGE_STANDARD;

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

            if (_IsOpen)
            {
                do
                {
                    if (PCANBasic.Write(PCANBasic.PCAN_USBBUS1, ref CanMsg) == TPCANStatus.PCAN_ERROR_OK)
                    {
                        return(true);
                    }
                    else
                    {
                        retrycnt++;
                        TPCANStatus Status = PCANBasic.GetStatus(PCANBasic.PCAN_USBBUS1);
                        //写总线异常日志


                        Thread.Sleep(10);
                    }
                } while (retrycnt < 3);
            }

            return(false);
        }
Beispiel #2
0
 public static extern TPCANStatus Write(
     [MarshalAs(UnmanagedType.U1)]
     TPCANHandle Channel,
     ref TPCANMsg MessageBuffer);
Beispiel #3
0
 private static extern TPCANStatus Read(
     [MarshalAs(UnmanagedType.U1)]
     TPCANHandle Channel,
     out TPCANMsg MessageBuffer,
     IntPtr bufferPointer);
Beispiel #4
0
 /// <summary>
 /// Reads a CAN message from the receive queue of a PCAN Channel
 /// </summary>
 /// <param name="Channel">The handle of a PCAN Channel</param>
 /// <param name="MessageBuffer">A TPCANMsg structure buffer to store the CAN message</param>
 /// <returns>A TPCANStatus error code</returns>
 public static TPCANStatus Read(
     TPCANHandle Channel,
     out TPCANMsg MessageBuffer)
 {
     return(Read(Channel, out MessageBuffer, IntPtr.Zero));
 }
Beispiel #5
0
 public static extern TPCANStatus Read(
     [MarshalAs(UnmanagedType.U1)]
     TPCANHandle Channel,
     out TPCANMsg MessageBuffer,
     out TPCANTimestamp TimestampBuffer);