public bool StartLogging(string DirectoryForLogFile, bool MultipleFiles, bool TimestampName, UInt32 MaxMegabytes) { TPCANStatus stsResult; //result of call to PEAK UInt32 iBuffer; //Int buffer to send to peak logging = false; //true is logging turned on 9return value) if (Directory.Exists(DirectoryForLogFile)) { ConfigureTraceFile(DirectoryForLogFile, MultipleFiles, TimestampName, MaxMegabytes); } else { ConfigureTraceFile("", MultipleFiles, TimestampName, MaxMegabytes); AddMessage(Feedback, "Directory for trace file: " + DirectoryForLogFile + ", not set (doesn't exist), default is exe location."); } iBuffer = (uint)PCANBasic.PCAN_PARAMETER_ON; stsResult = PCANBasic.SetValue(PeakCANHandle, TPCANParameter.PCAN_TRACE_STATUS, ref iBuffer, sizeof(UInt32)); if (stsResult == TPCANStatus.PCAN_ERROR_OK) { AddMessage(Feedback, "Trace log on"); logging = true; } return(logging); }
/// <summary> /// Thread-Function used for reading PCAN-Basic messages /// </summary> private void CANReadThreadFunc() { UInt32 iBuffer; iBuffer = Convert.ToUInt32(ReceiveEvent.SafeWaitHandle.DangerousGetHandle().ToInt32()); // Sets the handle of the Receive-Event. LastOperationStatus = PCANBasic.SetValue(PeakCANHandle, TPCANParameter.PCAN_RECEIVE_EVENT, ref iBuffer, sizeof(UInt32)); if (LastOperationStatus != TPCANStatus.PCAN_ERROR_OK) { //throw new Exception(PeakCANStatusErrorString(LastOperationStatus)); } if (ControlForm != null) { while (RxMessages) { // Waiting for Receive-Event if (ReceiveEvent.WaitOne(50)) { // Process Receive-Event using .NET Invoke function // in order to interact with Winforms UI (calling the // function ReadMessage) if (RxMessages) //Double check reading is still required { ControlForm.Invoke(ReadDelegate); } } } } else { throw new Exception("No control form set."); } }
public bool StopLogging() { UInt32 iBuffer = (uint)PCANBasic.PCAN_PARAMETER_OFF; TPCANStatus stsResult = PCANBasic.SetValue(PeakCANHandle, TPCANParameter.PCAN_TRACE_STATUS, ref iBuffer, sizeof(UInt32)); if (stsResult == TPCANStatus.PCAN_ERROR_OK) { AddMessage(Feedback, "Trace log off"); logging = false; } return(logging); }
/// <summary> /// Configures the PCAN-Trace file for a PCAN-Basic Channel /// </summary> private void ConfigureTraceFile(string TraceDirectory, bool MultipleFiles, bool TimeStampName, UInt32 MaxMegabytes) { UInt32 iBuffer; TPCANStatus stsResult; // Configure the size of a trace file (max 100 MBs) stsResult = PCANBasic.SetValue(PeakCANHandle, TPCANParameter.PCAN_TRACE_SIZE, ref MaxMegabytes, sizeof(UInt32)); if (stsResult != TPCANStatus.PCAN_ERROR_OK) { AddMessage(Feedback, GetFormatedError(stsResult)); } //Configure trace location stsResult = PCANBasic.SetValue(PeakCANHandle, TPCANParameter.PCAN_TRACE_LOCATION, TraceDirectory, (uint)TraceDirectory.Length); if (stsResult != TPCANStatus.PCAN_ERROR_OK) { AddMessage(Feedback, GetFormatedError(stsResult)); } //Single or multiple files if (MultipleFiles) { iBuffer = PCANBasic.TRACE_FILE_SEGMENTED | PCANBasic.TRACE_FILE_OVERWRITE; } else { iBuffer = PCANBasic.TRACE_FILE_SINGLE | PCANBasic.TRACE_FILE_OVERWRITE; } if (TimeStampName) { iBuffer = iBuffer | PCANBasic.TRACE_FILE_DATE | PCANBasic.TRACE_FILE_TIME; } stsResult = PCANBasic.SetValue(PeakCANHandle, TPCANParameter.PCAN_TRACE_CONFIGURE, ref iBuffer, sizeof(UInt32)); if (stsResult != TPCANStatus.PCAN_ERROR_OK) { AddMessage(Feedback, GetFormatedError(stsResult)); } }
/// <summary> /// Set the identify setting for a PCAN USB device /// </summary> /// <param name="PCANUSBHandle">PCAN USB device handle</param> /// <param name="OnOff">identify on or off</param> /// <returns>true if setting was made correctly, else false if it failed</returns> public static bool SetIdentify(PCANHandle PCANUSBHandle, bool OnOff) { TPCANStatus dllRet = TPCANStatus.PCAN_ERROR_UNKNOWN; //Assume unknown state to start UInt32 iBuffer; //Passed to PCAN dll in GetValue call if (OnOff) { iBuffer = PCANBasic.PCAN_PARAMETER_ON; } else { iBuffer = PCANBasic.PCAN_PARAMETER_OFF; } dllRet = PCANBasic.SetValue(PCANUSBHandle, TPCANParameter.PCAN_CHANNEL_IDENTIFYING, ref iBuffer, sizeof(UInt32)); if (dllRet == TPCANStatus.PCAN_ERROR_OK) { return(true); } else { return(false); } }