Starting Out with CAN_USB

This forum covers issues concerning multiple software products.

Starting Out with CAN_USB

Postby docwat » Mon 15. Feb 2016, 06:58

Hi,

I am wishing to use the CAN-USB device simply to receive Normal CAN MESSAGES from ID 700 to ID 7FF (Feeder Nodes) in the first instance to accommodate the output from multiple animal feed weighers.(Baud Rate 125k)

Our current product simply uses an ASCII Command Sequence to communicate using a virtual comport.(USB_TIN during development)however I am looking at the comprehensive Peak range of devices to satisfy the distributed product worldwide.

Keneth Wagner's PCANBASIC provisions are superb and comprehensive. They will enable me to develop a highly effective solution for my application which will probably use WLAN TCPIP.

Currently I am using Lazarus as my Win 8.1/32 IDE. I would welcome some starting guidance from someone with experience in Peak Device application.

My proposed program is:

1) Load the .DLL into Windows\ system 32
2) Select a subset of declarations from the PCANBASIC to meet the requirements of the device.
3) Select a subset of functions and procedures from UNIT1.pas.

I need to replace a single Unit in my Weighing Product which works with USBTin and I think the above program should achieve this with the added reference Unit - cut down to size.

I think this should work with Lazarus.

Presumably once configured the CAN_USB device retains its SETUP in EEPROM and can operate on a basic send and receive message routine.

I notice that there is no mention of the ID mask in PCANBASIC and I assume the firmware in the CAN_USB device simply uses the start and end ID specs to implement the mask.

I would welcome any comment as to whether I am going about things the right way !

Many thanks,

Docwat (Edinburgh-Scotland)
docwat
 
Posts: 12
Joined: Sun 14. Feb 2016, 23:52

Re: Starting Out with CAN_USB

Postby U.Wilhelm » Mon 15. Feb 2016, 09:22

Lazarus is a open source IDE for the free Pascal implementation. We never used this programming language with our Interface DLL (PCAN Basic) but in prinzipel it should work. Find attached a non OO Pascal header file. We offer samples for Delphi so you could use this samples to start.
Filter setting is easy - simply read the online help you will find all info in the Windows CHM file.If you use only 11Bit CAN Ids /STD, our software Filter could so that only IDs from 0x700 to 0x7FF will be received - the rest will be deleted and will not be in the incomming queue of your software.
You first use the CAN_SetValue with the Parameter PCAN_FILTER_CLOSE. After that no CAN ID will be received. Now you call the CAN_FilterMessages with the from - to Values , often as you need. In your project simply one time: CAN_FilterMessages(PCAN_BUSx, 0x700, 0x7ff, PCAN_MESSAGE_STANDARD)
Attachments
PCANBasicNotOO.pas
PCANBasic for older Pascal - not OO
(27.96 KiB) Downloaded 260 times
--------------------------------
PEAK-System Technik
Technical Support Team
support@peak-system.com
-------------------------------
User avatar
U.Wilhelm
Sales & Support
Sales & Support
 
Posts: 1004
Joined: Fri 10. Sep 2010, 18:34
Location: Darmstadt

Re: Starting Out with CAN_USB

Postby docwat » Mon 15. Feb 2016, 17:45

Very Many thanks Wilhelm,

As I expected, some experimentation is required with Lazarus. It is almost identical to Delphi 7 which I could not get to run under WIN8.1. I expect contacting the DLL may present issues and I am not sure that THREADs are identical in Free Pascal. Nevertheless I think connecting with the DLL should be possible and if I can run the procs and functions provided by the DLL it should be workable. I will load the DLL and see whether it will respond to Lazarus Free Pascal code.

This submission was my introduction to the Peak System forum and your response was entirely helpful at this stage.

Greatly appreciated,

Docwat.
docwat
 
Posts: 12
Joined: Sun 14. Feb 2016, 23:52

Re: Starting Out with CAN_USB

Postby docwat » Mon 15. Feb 2016, 18:50

Hi Wilhelm,

Just to let you know the Not00 header file compiles without error under Lazarus. This looks hopeful !

I will work on this project over the next few days and keep you informed as it unfolds.

Vielen Dank,

Docwat
docwat
 
Posts: 12
Joined: Sun 14. Feb 2016, 23:52

Re: Starting Out with CAN_USB

Postby docwat » Wed 17. Feb 2016, 15:55

Hi Uwe,

So far no problems with Lazarus. I am communicating with the PCAN_USB using the DLL so I can now explore the connection with our product CAN bus.

I have a substantial learning curve however your various sample progs will be of great assistance.

I can now close this conversation until I can return with any odd Lazarus problems which might help other Lazarus FPC
colleagues.

Noch einmal vielen dank

Docwat.
docwat
 
Posts: 12
Joined: Sun 14. Feb 2016, 23:52

Re: Starting Out with CAN_USB

Postby U.Wilhelm » Wed 17. Feb 2016, 22:05

Hi Dochwat,

many thanks for the feedback! Was it necessary to change the pascal header to use it with Lazarus?
Mabe this information is also usefull for other useres who want to use this free IDE with our CAN Interfaces.

Thank you and regards

Uwe
--------------------------------
PEAK-System Technik
Technical Support Team
support@peak-system.com
-------------------------------
User avatar
U.Wilhelm
Sales & Support
Sales & Support
 
Posts: 1004
Joined: Fri 10. Sep 2010, 18:34
Location: Darmstadt

Re: Starting Out with CAN_USB

Postby docwat » Fri 19. Feb 2016, 12:40

Hi Uwe,

I will report back in detail once I have converted my product to PEAK_USB. The PeakBasic Unit compiled without modification however the Lazarus components may have slightly different properties so I have not loaded Unit 1 but merely taken advantage of Kenet Wagner's extensive coding experience to use selected functions and procedures.

The only change which I have had to make is to use $XX instead of 0xXX.

At this stage the INITIALISATION , READ and WRITE processes are working perfectly and CANVIEW is proving very useful.

The inclusion of PEAK_USB is delightfully straightforward and of course removes my previous need to use a virtual serial port and ASCII commands. The DLL is a far more satisfactory solution. The FPC appart from the $XX change has not thrown up any problems.

Vielen Dank,

DocWat
docwat
 
Posts: 12
Joined: Sun 14. Feb 2016, 23:52

Re: Starting Out with CAN_USB

Postby docwat » Thu 25. Feb 2016, 13:12

Hi Uwe,

Ich bin dumm !

I have been using PCANBASICNot00 but wish to modify the UNIT1 Tform1.ReadMessage function. This calls TPCanBasic which is not declared in Not00.
.Read.

Can I simply add the Class Functions of CanBasic or should I simply load the CanBasic version which includes all the class declarations used by Unit1 ?

Typically:
class function TPCANBasic.ReadFD(Channel: TPCANHandle; var MessageBuffer: TPCANMsgFD; var TimestampBuffer: TPCANTimestampFD):TPCANStatus;
begin
Result:= CAN_ReadFD(Channel, MessageBuffer, @TimestampBuffer);
end;

I would like to take advantage of Kenet Wagner's comprehensive routines to read and write to my hardware system.

Vielen Dank,

Docwat
docwat
 
Posts: 12
Joined: Sun 14. Feb 2016, 23:52

Re: Starting Out with CAN_USB

Postby docwat » Thu 25. Feb 2016, 13:13

Hi Uwe,

Of course not using the FD Routine !

Vielen Dank,

Docwat
docwat
 
Posts: 12
Joined: Sun 14. Feb 2016, 23:52

Re: Starting Out with CAN_USB

Postby U.Wilhelm » Fri 26. Feb 2016, 08:59

My colleauge Keneth have add a class for C#, C++ and for Delphi to use the programmimg language specific OO functions. For C# he create a namespace called Peak.Can.Basic , in Borland Builder a class called PCANBasicClass::PCANBasicClass(), in C++ CLR a namespace called Peak.Can.Basic , for C++using MFC the calss PCANBasicClass::PCANBasicClass(), in VB.Net a namesapce called Peak.Can.Basic and for Delphi the unit PCANBasic (find in the the PCANBasic.pas file). But all based on the simple DLL Implementation which is not OO. If you take a look at the PCANBasic.h file, or the PCANBasicNotOO.pas you see the simple software API with the "raw" functions. If you want the OO Version you had to use the PCANBasic.pas and change it for work with Lazarus. I do not know Lazarus, so i am sorry i could help you in this problem.
--------------------------------
PEAK-System Technik
Technical Support Team
support@peak-system.com
-------------------------------
User avatar
U.Wilhelm
Sales & Support
Sales & Support
 
Posts: 1004
Joined: Fri 10. Sep 2010, 18:34
Location: Darmstadt

Next

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