Cyclic messages

The free CAN Software API (Application Programming Interface) for Windows®

Cyclic messages

Postby danis_rom » Fri 5. Aug 2011, 07:44

Hello,

it is possible to send cyclic messages not only setting a software timer that repeat its self? I mean there is a way to be sure that the cycle period for example has exactly 100ms cycle time? Like a hardware trigger on the card. I use PCAN USB.

Thank you,

Daniel
danis_rom
 
Posts: 5
Joined: Mon 11. Jul 2011, 17:12

Re: Cyclic messages

Postby M.Maidhof » Fri 5. Aug 2011, 09:23

Hello Daniel,

with the PCANBasic API you have to use a timer (or better multimediatimer) to generate periodical messages. We do not off a direct hardware trigger for that feature. However, when you use the API of the canapi2.dll which will be available when purchasing the PCAN-Developer package, it will be possible to use a timestamp in CAN_Write(). Than all messages with future timestamps will be stored in the driver, and will be transmitted by the driver than, without having the application trigger the exact transmit time. The application only has to fill that buffer again from time to time.

On the other hand, when you need to send 100ms cyclic message with PCANBasic it will be no problem to realize that with a multimediatimer.

best regards

Michael
User avatar
M.Maidhof
Support
Support
 
Posts: 217
Joined: Wed 22. Sep 2010, 14:00
Location: Darmstadt, Germany

Re: Cyclic messages

Postby marbeia » Thu 1. Mar 2012, 10:29

Hello,

I need to send a 3ms cyclic sync message (COBID 0x80 DATA -).
How can I implement that through my .net 4 application?
I already try using timers but they are not accurate.
The best result I have is with a thread. It run accuratly for some sec. but it randomly jump 1ms. And my Can network hardware have to receive a stable cycle time. I think the problem come from Windows thread gestion.

Is there a way for the PCAN-USB interface to fire a cyclic event or send a cyclic sync message ?

Best regards
MA
marbeia
 
Posts: 2
Joined: Thu 1. Mar 2012, 10:09

Re: Cyclic messages

Postby K.Wagner » Thu 1. Mar 2012, 11:37

Hello marbeia,

as Michael said, to gain on accuracy you need to use high performance timers or multimedia timers (Wiki: HPET. The good news is that with both of them one can achieve a precise resolution of 1 ms. The bad news is that they are not implemented within the .Net Framework, so you have to import the functions/structures related to those timers and do the calculations yourself, but that is not that difficult :P.

Multimedia Timers: Here you will find information about the multimedia timers. You will see a list of all structures and functions that you probably need to marshal in order to use them from a .Net environment. After you have understood this, you can try to parse the items yourself or search for it in the internet.

High-Performance Timers: Here you will find information about the high-performance timers. Even better, you will find here already an example, which includes the marshaling of the two needed functions and their use. Just a remark, this document is intended for Windows-CE, but the functions and the way to handle with them is the same. The main different is the DLL in which the functions are included. The functions for Windows CE are included in the library "Coredll.dll", and for Windows Desktop are in "Kernel32.dll"

I hope this information helps you to go forward with your project.
Best regards,
Keneth
User avatar
K.Wagner
Software Development
Software Development
 
Posts: 134
Joined: Wed 22. Sep 2010, 13:36
Location: Darmstadt, Germany

Re: Cyclic messages

Postby marbeia » Thu 1. Mar 2012, 18:02

Hi K.wagner,

Thanks for your answer, i'll try to use these timers and let you know if it work.
marbeia
 
Posts: 2
Joined: Thu 1. Mar 2012, 10:09


Return to PCAN-Basic