how do i convert TPCANTimeStamp to a string

This forum covers issues concerning multiple software products.

how do i convert TPCANTimeStamp to a string

Postby TimK123 » Wed 28. Feb 2018, 16:50

I am writing a C# application using PCAN-BASIC API's. I need to print out as a string the value of the Timestamp that is received from the Read Function.

Code: Select all
TPCANTimestamp Ztime;
StreamWriter sw;

result = PCANBasic.Read(PCANBasic.PCAN_USBBUS1, out msg, out Ztime);

sw.WriteLine(Ztime.ToString());

I tried doing this and it wrote to my text file this string......... Peak.Can.Basic.TPCANTimestamp

I want the timestamp to display just as it does when I use view the trace using the PCANView tool.
Thanks,
Tim
Last edited by K.Wagner on Thu 1. Mar 2018, 10:04, edited 2 times in total.
Reason: Code tag including for better reading
TimK123
 
Posts: 1
Joined: Wed 28. Feb 2018, 16:37

Re: how do i convert TPCANTimeStamp to a string

Postby K.Wagner » Thu 1. Mar 2018, 10:03

Hello,

the text being printed is completely right, since you are printing a structure! Please note that the actual timestamp values are within the fields of the structure which are:

  • millis
  • millis_overflow
  • micros
For instance, you have to do something like this in order to show the elapsed milliseconds:
Code: Select all
result = PCANBasic.Read(PCANBasic.PCAN_USBBUS1, out msg, out Ztime);
sw.WriteLine(Ztime.millis.ToString());

Or convert the whole structure to microseconds and apply the scale you need/want, before printing the value. How to convert the TPCANTimestamp to microseconds, as well as the description of fields posted before, can be found within the help documentation of PCAN-Basic:
TPCANTimestamp.PNG
Help for structure TPCANTimestamp
TPCANTimestamp.PNG (25.6 KiB) Viewed 880 times
Best regards,
Keneth
K.Wagner
Software Development
Software Development
 
Posts: 682
Joined: Wed 22. Sep 2010, 12:36
Location: Darmstadt, Germany

Re: how do i convert TPCANTimeStamp to a string

Postby K.Wagner » Thu 1. Mar 2018, 10:14

By the way,

TimK123 wrote:I want the timestamp to display just as it does when I use view the trace using the PCANView tool.

For this, you just need to read the sample project for C#, and understand and copy the code. Just that easy...

PCB_Sample1.PNG
PCAN-Basic Sample UI
PCB_Sample1.PNG (21.59 KiB) Viewed 880 times
Best regards,
Keneth
K.Wagner
Software Development
Software Development
 
Posts: 682
Joined: Wed 22. Sep 2010, 12:36
Location: Darmstadt, Germany


Return to Software



This website uses cookies for analytics, for logins to the online shop and the forum, and for the handling of an order. By browsing this website you agree to the use of cookies. Detailed information on their use can be found in our privacy policy.

OKPrivacy Policy