Page 1 of 1

Mono linux and peak usb

Posted: Mon 15. Apr 2013, 12:10
by first_zyrex
Hello,

I am a c# developer, and i have a c# app for windows wich do a lot stuff on the can bus (with pcan usb).

Now i need also a app for linux programmed in c# wich do the same things.

I know about the mono stuff.
My app is already compiling.

But i have one problem.
How can i establish a connection the the pcan-usb with C# and linux.
Do some has some example??

BR

Re: Mono linux and peak usb

Posted: Mon 15. Apr 2013, 13:38
by M.Maidhof
Hello,

sorry, but at the moment we (PEAK) do not have any examples for C# and Linux.

regards

Michael

Re: Mono linux and peak usb

Posted: Mon 15. Apr 2013, 16:01
by first_zyrex
Do you think that in the next weeks you will have example for c# and linux?

May be you can take a look at the following code

Code: Select all

using TPCANHandle = System.Byte;
    
    [Flags]
    public enum PCANInitMessageType
    {
        Extended = 0x01,
        Standard = 0x00,
    }
    
    public static class PCANBasicLinux
    {        
        private const string PCAN_DLL = "/lib/libpcan.so.0.6";
        
        
        [DllImport(PCAN_DLL, EntryPoint = "LINUX_CAN_Open")]
        public static extern IntPtr CanOpen(
            [MarshalAs(UnmanagedType.BStr)]
            string deviceName,
            [MarshalAs(UnmanagedType.U4)]
            int nFlag);

        [DllImport(PCAN_DLL, EntryPoint = "CAN_Init")]
        public static extern int Init(
            IntPtr handle, 
            [MarshalAs(UnmanagedType.U2)]
            TPCANBaudrate Btr0Btr1, 
            [MarshalAs(UnmanagedType.I4)]
            PCANInitMessageType msgType);

        [DllImport(PCAN_DLL, EntryPoint = "CAN_Close")]
        public static extern int Close(IntPtr handle);

        [DllImport(PCAN_DLL, EntryPoint = "CAN_Status")]
        public static extern TPCANStatus GetStatus(IntPtr handle);


        [DllImport(PCAN_DLL, EntryPoint = "CAN_Read")]
        public static extern TPCANStatus Read(
            IntPtr hanlde,
            out TPCANMsg MessageBuffer);

        [DllImport(PCAN_DLL, EntryPoint = "CAN_Write")]
        public static extern TPCANStatus Write(
            IntPtr hanlde,
            ref TPCANMsg MessageBuffer);
  
        
        [DllImport(PCAN_DLL, EntryPoint = "nGetLastError")]
        public static extern int GetLastError();

    }
I try to access the pcan with the following paratmert

Code: Select all

 IntPtr ptr = PCANBasicLinux.CanOpen("/dev/pcan33", 0x02); 
but the ptr is still zero

but when i try "cat /dev/pcan33" i will see all canmessages on the bus

when i enter "cat /proc/pcan" in console i will get

Code: Select all

*------------- PEAK-System CAN interfaces (www.peak-system.com) -------------
*------------- Release_20130131_n (7.8.0) Apr 15 2013 11:05:31 --------------
*------------------------------- [mod] [usb] --------------------------------
*--------------------- 2 interfaces @ major 248 found -----------------------
*n -type- ndev --base-- irq --btr- --read-- --write- --irqs-- -errors- status
32    usb -NA- ffffffff 012 0x011c 00000091 00000000 00000095 00000000 0x0000
33    usb -NA- ffffffff 013 0x031c 00000000 00000000 0000005b 00000010 0x0000

Re: Mono linux and peak usb

Posted: Mon 15. Apr 2013, 19:49
by PEAK-Support
I do not understand on which LIB you like to implemnt the C# Interface? Please send us a short e-mail to support@peak-system.com and we could send you some Beta code for the PCAN-Basic for LINUX Implementation.

Re: Mono linux and peak usb

Posted: Fri 9. Jan 2015, 11:19
by hammer
Hi,

I'm developing a mono application (Linux c#) using peak systems device too.

There is any information, samples since then?

@first_zyrex: do you have som control class which could be used by me?

Thank you

Marc CG

Re: Mono linux and peak usb

Posted: Mon 12. Jan 2015, 11:52
by PEAK-Support
No, we do not offer any samples for MONO - please search on Linux Forums - this is the wrong Forum.
Our PCAN-Basic for Linux Package could be download from our Support Page. We only official support C++/Java and Python. It will be possible to run with all available programming languages, but we could not build samples for every languages.
Inside the package you have the complete source - so it will no problem to build your own C# header, or try to use the PCAN-Basic for Windows C# Header as template. If you have success, you could post the result here - maybe there are other users which find it usefull.

Re: Mono linux and peak usb

Posted: Tue 13. Jan 2015, 15:43
by hammer
Hi,

I Checked out the windows C# Example code and it helped me.

But I saw that it uses chardev to connect and disconnect. Do you have any c# sample code using netdev?

Which option would you recommend for a non continuous communication aplication?

Thanks

Marc CG

Re: Mono linux and peak usb

Posted: Wed 14. Jan 2015, 16:45
by PEAK-Support
In this Forum from PEAK-System, we only could do support for our own CAN Driver CharDev.
If you want support from the community driver NetDev, please post on a NetDev/SocketCAN related page.

Both drivers could be use for your application - but it´s your decission which you like to use...