PCANBasic Trace Problem
Posted: Fri 28. Jul 2023, 05:02
Hi,
I depended on the PcanBasic C# Sample tracefile to develop my own program and transfer the sample code to my application ,and the trace record success
but the trace file have issue ,depend on mine calculation of message interval ,when interval less than 0.2ms ,it would be recorded twice ,if more than 0.2 ms ,its Ok
so why recoded twice ?
as shown my code and trace file !
Thanks!
I depended on the PcanBasic C# Sample tracefile to develop my own program and transfer the sample code to my application ,and the trace record success
but the trace file have issue ,depend on mine calculation of message interval ,when interval less than 0.2ms ,it would be recorded twice ,if more than 0.2 ms ,its Ok
so why recoded twice ?
as shown my code and trace file !
Code: Select all
const bool IsFD = false;
const bool TraceFileSingle = true;
const bool TraceFileDate = true;
const bool TraceFileTime = true;
const bool TraceFileOverwrite = false;
const bool TraceFileDataLength = false;
const uint TraceFileSize = 30;
const string TracePath = "";
const int TimerInterval = 1;
private System.Timers.Timer m_Timer;
private bool StartTrace()
{
uint iStatus = PCANBasic.PCAN_PARAMETER_ON;
TPCANStatus stsResult = PCANBasic.SetValue(UDSApi.PUDS_USBBUS1, TPCANParameter.PCAN_TRACE_STATUS, ref iStatus, sizeof(int)); // We activate the tracing by setting the parameter.
if (stsResult != TPCANStatus.PCAN_ERROR_OK)
{
ShowStatus(stsResult);
return false;
}
return true;
}
private void SetTimer()
{
m_Timer = new System.Timers.Timer(TimerInterval);
m_Timer.Elapsed += OnTimedEvent; // Hook up the Elapsed event for the timer.
m_Timer.AutoReset = true;
m_Timer.Enabled = true;
}
private void OnTimedEvent(Object source, ElapsedEventArgs e)
{
ReadMessages();
}
private void ReadMessages()
{
// We read at least one time the queue looking for messages. If a message is found, we look again trying to
// find more. If the queue is empty or an error occurr, we get out from the dowhile statement.
TPCANStatus stsResult;
do
{
stsResult = IsFD ? PCANBasic.ReadFD(UDSApi.PUDS_USBBUS1, out TPCANMsgFD CANMsgFD) : PCANBasic.Read(UDSApi.PUDS_USBBUS1, out TPCANMsg CANMsg);
if (stsResult != TPCANStatus.PCAN_ERROR_OK && stsResult != TPCANStatus.PCAN_ERROR_QRCVEMPTY)
{
//ShowStatus(stsResult);
return;
}
} while ((!Convert.ToBoolean(stsResult & TPCANStatus.PCAN_ERROR_QRCVEMPTY)));
}