Linux/USB approach

This forum covers PCAN-Linux and Linux development issues concerning our products

Linux/USB approach

Postby Christian » Tue 6. Sep 2011, 12:01

Hi,

I managed to compile and modprobe the kernel modules in preperation to access CAN via the USB converter (Ubuntu 2.6.38-11-generic). Unfortunately, I don't have one at hands yet. May I assume, that the output
Code: Select all
$ cat /proc/pcan
*------------ PEAK-Systems CAN interfaces (www.peak-system.com) -------------
*-------------------------- Release_20110728_n (7.3.0) ----------------------
*------------- [mod] [isa] [pci] [dng] [par] [usb] [pcc] [net] --------------
*--------------------- 0 interfaces @ major 249 found -----------------------
*n -type- ndev --base-- irq --btr- --read-- --write- --irqs-- -errors- status

will have an additional line, once I connect the converter (as seen in other posts here already)?

Further, the plan is to access the bus with a C compiled program. The output above is from netdev compilation, but chardev does also work that far. My C experience is a bit outdated. So, secondly, may I assume that chardev would be the easier choice to program open, read/write ... within C?
And finally, I investigated the code sample here, but it seems the termios.h headers are not on my system. Any idea of the package they should be in? (linux-headers are installed, but still ...)

Thank you very much & kind regards
Christian
Christian
 
Posts: 4
Joined: Tue 6. Sep 2011, 01:29

Re: Linux/USB approach

Postby U.Wilhelm » Tue 6. Sep 2011, 16:20

The test programms need installed “libpopt” and “libstdc++” with their header files (-dev variants)

so please call (Debian/Ubuntu):

Code: Select all
sudo apt-get install libpopt-dev
--------------------------------
PEAK-System Technik
Technical Support Team
support@peak-system.com
-------------------------------
U.Wilhelm
Sales & Support
Sales & Support
 
Posts: 388
Joined: Fri 10. Sep 2010, 19:34
Location: Darmstadt

Re: Linux/USB approach

Postby Christian » Mon 3. Oct 2011, 08:34

Thanks. As they were installed, I finally found the device being the problem.

I managed to read/write easily then. However, I now tried to use LINUX_CAN_Read_Timeout() when the compiler moaned, the TPCANRdMsg structure would not have the members ID, MSGTYPE etc. (or not named that way). I searched all the sources - at least I think so - but I did not find the definitions.

Where are the structures TPCANMsg and TPCANRdMsg defined, finally? Or, what are the differences in terms of their structure members?
Their definition seems not to be in libpcan.h and libpcan.c as expected. I would appreciate you could point me to them.

Thanks in advance
Christian
Christian
 
Posts: 4
Joined: Tue 6. Sep 2011, 01:29

Re: Linux/USB approach

Postby M.Maidhof » Tue 4. Oct 2011, 13:59

Hi,

please see pcan.h in the /driver directory.

best regards

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

Re: Linux/USB approach

Postby Christian » Mon 10. Oct 2011, 12:29

Hi,

Great! Thank you, this is exactly what I was looking for.

Sorry to bother, but here's another very noob question I desperately need some help with: How do I read/write/interprete negative values?

I'm on an Ubuntu working with gcc. I'm gradually approaching to move a servo, but then I noticed:
Fine to move it up 1mm with (just the data part in a daten[8] vector, value is 0x1676=5750):
Code: Select all
{0x00, 0x00, 0x76, 0x16, 0x00, 0x00, 0x00, 0x00}

But due to the interpretation I get this two complements thing (FFFFE98B) using negative values, which I neither know to handle nor how to work with [i.e. as printf("%i",0xFFFFE98B) does not give out a negative value]. :oops:

My idea is something like just handing over the integer interpretation, i.e.
Code: Select all
{0x00, 0x00, -118, -22, 0x00, 0x00, 0x00, 0x00}

but I don't dare so - an interpreted value too high will ruin the servo. And I still have no clue what negatives will look like coming from the bus or how to treat them if they all look like that.

I am fully aware this is miles off topic for you and feel very sorry about it, but I can't imagine anybody better to ask.

Thank you very much for your help & best regards
Christian
Christian
 
Posts: 4
Joined: Tue 6. Sep 2011, 01:29

Re: Linux/USB approach

Postby M.Maidhof » Mon 10. Oct 2011, 17:47

Hi,

yes, you are right...this is absolutely OFFTOPIC....

the highest bit will represent the sign of a variable, so depending of how many bits your variable have, you have to use a 8bit, 16bit or 32bit datatype and set the correct value into the CAN message.

Please see the following wiki page for more info: http://de.wikipedia.org/wiki/Zweierkomplement

example: -100 decimal:
8 bit: 0x9C
16 bit: 0xFF9C
32 bit: 0xFFFFFF9C

Take care, sometimes the byte order in CAN messages can be big or little endian:

http://de.wikipedia.org/wiki/Byte-Reihenfolge

this will confusing you totally now, but unfortunately thats the price you have to pay when you want to be a programmer.

regards

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

Re: Linux/USB approach

Postby Christian » Tue 11. Oct 2011, 09:31

Thank you, Michael.

Besides, I don't want to be a programmer - I just need this project as a solution. :)

Thanks again, take care
Christian
Christian
 
Posts: 4
Joined: Tue 6. Sep 2011, 01:29

Re: Linux/USB approach

Postby U.Wilhelm » Tue 18. Oct 2011, 08:49

Thread closed....
--------------------------------
PEAK-System Technik
Technical Support Team
support@peak-system.com
-------------------------------
U.Wilhelm
Sales & Support
Sales & Support
 
Posts: 388
Joined: Fri 10. Sep 2010, 19:34
Location: Darmstadt


Return to Linux



cron