CBus Driver Software - Issues

Discussion in 'General Discussion' started by John@DHW, Jul 4, 2005.

  1. John@DHW

    rhamer

    Joined:
    Aug 3, 2004
    Messages:
    673
    Likes Received:
    3
    Location:
    Melbourne, Australia
    Ok, I got the builder sample to work after a bit of fiddling around using the free version of Turbo C++

    I had to modify the sample project a little as the CSpin control dosen't seem to be supported.

    Cheers

    Rohan
     
    rhamer, Sep 23, 2006
    #21
  2. John@DHW

    Richo

    Joined:
    Jul 26, 2004
    Messages:
    1,257
    Likes Received:
    0
    Location:
    Adelaide
    That's great to hear.
     
    Richo, Sep 23, 2006
    #22
  3. John@DHW

    Mike_Izisys

    Joined:
    Oct 26, 2006
    Messages:
    1
    Likes Received:
    0
    Visual Basic connection

    Hi,

    So has anybody successfully implemented a program in VB (or any MS compiler) yet?

    I e-mailed CIS yesterday before I found this forum. This is the e-mail:

    *********************************************************

    I have downloaded the C-BUS Windows Driver. Is this compatible with Visual Basic?

    Thanks Mike

    *********************************************************

    Hi Mike,

    Thank you for your interest in C-Bus and choosing to use the C-Bus Module DLL.

    Yes, it is possible to use this with Visual Basic like any other DLL. You will need to make the appropriate references in your VB program to the functions you use and generate pointers to the callback and event functions that you register. There is nothing in the documentation as VB is not a language used here at CIS and we aren't in a position to offer support for that..

    The functions available are described in the Interface Specification document shipped with the DLL.

    Regards,

    Steve Dunn
    C-Bus Enabled Program Coordinator
     
    Mike_Izisys, Oct 26, 2006
    #23
  4. John@DHW

    rhamer

    Joined:
    Aug 3, 2004
    Messages:
    673
    Likes Received:
    3
    Location:
    Melbourne, Australia
    I couldn't get it to work with VB.NET, C# or C++ using the MS compilers.

    I have however got it working with borlands C++ compiler.

    I think somebody else here got it working with VB6, but I'm not 100% on that.

    Cheers

    Rohan
     
    rhamer, Oct 27, 2006
    #24
  5. John@DHW

    Richo

    Joined:
    Jul 26, 2004
    Messages:
    1,257
    Likes Received:
    0
    Location:
    Adelaide
    We do have all those compilers here and would love to sort this out one day. It is so hard to get justification for the time since the drivers are not an official product and just something Engineering did as a skunkwork project since we had the code.
     
    Richo, Oct 27, 2006
    #25
  6. John@DHW

    rhamer

    Joined:
    Aug 3, 2004
    Messages:
    673
    Likes Received:
    3
    Location:
    Melbourne, Australia
    Ok, so the world has turned a bit more and the good folk at CIS have now made the source code available for this.

    My end game is to build a DLL that will work in a .net application.

    Previously as discussed in this thread, I (and others) have been unable to get it to work in any MS environment, but I did get it to work in a Borland app.

    So firstly if anybody has already done this and would be kind enough to share the project, please let me know. Otherwise I'll have to call in all the favours from my MS C++ programming pals and see if we can get a working DLL that can be used in .net.

    Cheers

    Rohan
     
    rhamer, Dec 28, 2009
    #26
  7. John@DHW

    ashleigh Moderator

    Joined:
    Aug 4, 2004
    Messages:
    2,392
    Likes Received:
    24
    Location:
    Adelaide, South Australia
    Hi Rohan

    I suspect if you do whatever level of hackery is needed to interface to "unmanaged" code you might sort it out.

    The CORE problem with making calls to the DLL was that .net code runs threads. Lots of threads. All over the shop. And the DLL ***MUST*** be called only from a single thread.

    It looks like things like .net make a thread to process the pressing of a button control on a form, for example. Which is all fine and dandy but the main-line code is being belted by a regular timer.... hey presto - 2 threads running through the code.

    So - you need to understand the code and how it works. Remember, its designed for small embedded micros with a few K of code and RAM space. And this scales up to an operating system, until they day you play with threads.

    These days many modern run time systems have threads going on that you don't even know about - MS/.net is full of it. Borland / Embarcadero VCL to a much lesser extent (though watch out for Indy components - there are threads galore lurking there). And should you go playing in the land of some of the COM extensions / parts of windows / Win32 you will find a zillion threads being thrown off as well.
     
    ashleigh, Dec 29, 2009
    #27
  8. John@DHW

    rhamer

    Joined:
    Aug 3, 2004
    Messages:
    673
    Likes Received:
    3
    Location:
    Melbourne, Australia
    Thanks Ashleigh.

    I'll see if we cant wrap the code somehow in a critical section or channel it all through a single interface point to keep it single threaded.

    I don't know how all this will turn out, but I would think we should be able to make it go one way or another......fingers crossed.

    BTW with another hat on, we have talked about using this code to talk to a SIM on our newest product which runs an ARM processor. Does that sound reasonable?

    Cheers

    Rohan
     
    rhamer, Dec 29, 2009
    #28
  9. John@DHW

    ashleigh Moderator

    Joined:
    Aug 4, 2004
    Messages:
    2,392
    Likes Received:
    24
    Location:
    Adelaide, South Australia
    Running on an ARM - NOT A PROBLEM.

    Look in cbus_general.h and you will see definitions there for all sorts of compilers. We've used it on an ARM ourselves using the IAR compiler - so thats supported.

    If you do an ARM using (for example) GCC then the definitions may need update. If thats the case - in the spirit of open source, please contribute the changes back!

    (And check the cbus_config.h you use as well to make sure the relevant options and thingies are set right. It makes the difference between big/small, full featured, small featured, or bloated. There are LOTS of tweaks.)
     
    ashleigh, Dec 29, 2009
    #29
  10. John@DHW

    KevinH

    Joined:
    Aug 3, 2004
    Messages:
    171
    Likes Received:
    0
    Location:
    Yorkshire. UK
    Hi Rohan,

    Nice that you are working on .net compatibility - I do think the module code needs to support this as it is very prevalent. Please do keep us updated on any progress.

    Meanwhile I'm incorporating the code within my (Rabbit) embedded design - seems OK so far although I haven't yet got the time application ported.


    K
     
    Last edited by a moderator: Dec 30, 2009
    KevinH, Dec 30, 2009
    #30
  11. John@DHW

    rhamer

    Joined:
    Aug 3, 2004
    Messages:
    673
    Likes Received:
    3
    Location:
    Melbourne, Australia
    Funny you should say that, but the time application is confusing me a bit also.

    I havn't really had a good look, but it was the bit that I had trouble getting to compile.

    Cheers

    Rohan
     
    rhamer, Dec 30, 2009
    #31
  12. John@DHW

    ashleigh Moderator

    Joined:
    Aug 4, 2004
    Messages:
    2,392
    Likes Received:
    24
    Location:
    Adelaide, South Australia
    The time code is a PITA.

    Please please please read the instructions, read the code, set up the time/date mastering level correctly. IT IS VITALLY IMPORTANT YOU DO THIS RIGHT.

    Most devices you want to build will be time/date slaves. Set that up in the config and much of the ugly code will be conditionally sent to the bit bucket.

    Only EVER try and be a time./date master if you have a crystal locked real time clock, or an internet connection where you can use NTP with an external mechanism for doing so (and it then assumes you have a POSIX compliant run-time system where all the date/time conversion calls work in accordance with the standard.) If you don't understand what this means.... dont try and use it!
     
    ashleigh, Dec 31, 2009
    #32
  13. John@DHW

    rhamer

    Joined:
    Aug 3, 2004
    Messages:
    673
    Likes Received:
    3
    Location:
    Melbourne, Australia
    Sounds like good advice from an experienced player :)

    I am also now reading the Module Interface documentation, which I didn't realise what it was before.

    Thanks for your help so far which I know you are not obliged to provide.

    Cheers

    Rohan
     
    rhamer, Dec 31, 2009
    #33
  14. John@DHW

    rhamer

    Joined:
    Aug 3, 2004
    Messages:
    673
    Likes Received:
    3
    Location:
    Melbourne, Australia
    Hi Ashleigh,

    Any chance of getting CBus_comms.cpp & CBus_comms.h ;)

    And if your in a really good mood, the complete VC project as was used to build the DLL that was released (or was it built with Borland?) I know there is one in the zip file but I'm struggling to get it to build a dll that can be registered.

    Cheers

    Rohan
     
    rhamer, Dec 31, 2009
    #34
  15. John@DHW

    ashleigh Moderator

    Joined:
    Aug 4, 2004
    Messages:
    2,392
    Likes Received:
    24
    Location:
    Adelaide, South Australia
    cbus_comms.c and cbus_comms.h are in the Windows DLL folder.

    The original build of the DLL is done using Borland/Codegear/Embarcadero C++ Builder 2010, and the 2 files you need are "cbm.c" and "cbm.cbproj" - the latter being the project file, the former adding the definition of "DllEntryPoint" for the project.

    In the project, you need to add a symbol define which is used to make the entry points export into the DLL symbol table. You need to define the symbol "CBM_DLL" (to be anything). [This then, in cbus_general.h defines the symbol "dec_DLL" to be "__declspec(dllexport)" ]

    You also want to make sure that your compiler generates exported symbol names with and _ prefix instead of using mangled names.
     
    ashleigh, Jan 1, 2010
    #35
  16. John@DHW

    rhamer

    Joined:
    Aug 3, 2004
    Messages:
    673
    Likes Received:
    3
    Location:
    Melbourne, Australia
    I can't believe I missed that :eek: I used the stupid windows 7 search thing to search the whole directory and it returned nothing. I should have known better.

    Thanks, I'll work on this.

    Cheers

    Rohan
     
    rhamer, Jan 1, 2010
    #36
  17. John@DHW

    ashleigh Moderator

    Joined:
    Aug 4, 2004
    Messages:
    2,392
    Likes Received:
    24
    Location:
    Adelaide, South Australia
    Extract the whole archive.

    The build a DLL, the approach used has been to build from inside the "Windows DLL" folder, using a project containing cbus_comms.c, cbus_comms.h, cbm.c, and then "..\cbus.c", "..\cbus_lighting.c", etc etc etc.

    Then just build, and you're done.
     
    ashleigh, Jan 1, 2010
    #37
  18. John@DHW

    rhamer

    Joined:
    Aug 3, 2004
    Messages:
    673
    Likes Received:
    3
    Location:
    Melbourne, Australia
    Hmm.... I'm pretty confused now, and I think most of it is down to my level of understanding of C++ projects.

    I dont understand how I can work at the "Windows DLL" level as that only contains a Borland project file. I'm trying to setup a VS2005 project.

    Under that directory, in the "VisualC" directory there is a VC project which is what I have used as the basis of my project, but it seems to be incomplete. I have got it to build ok but what it builds is not a DLL that can be registered. It also does not seem to have any reference to CBM.c, which I have added but still no luck.

    So I don't really know where to go from here. If you tell me it's all there and I'm just not smart enough to understand, then that's ok and I'll get some "Expert" help. But I don't think I'm missing too much, it's just that I'm trying to use a compiler that has not been used before?

    Cheers

    Rohan

    And thanks for helping on your days off too.
     
    rhamer, Jan 1, 2010
    #38
  19. John@DHW

    ashleigh Moderator

    Joined:
    Aug 4, 2004
    Messages:
    2,392
    Likes Received:
    24
    Location:
    Adelaide, South Australia
    Ah. You have 2 choices there. Build against the DLL (you need to set a define, I can't remember what it is though, which declares in all the headers that they are DLL imports). Then you compile against the headers, and link specifying the DLL at link time. Then when you run the executable it will load the DLL, bind against it, and go.

    Alternatively, you can just compile against the entire source tree including the VS code. In which case you are building a complete stand alone executable.

    2 things to understand here;
    - ignore the .net-isms and treat/think/use everything in Win32 standard executable land.
    - read up on the different methods of referencing and linking against DLLs

    You also need to get your objective straight. If you want to build a program, that is completely stand-alone, you dont need to build the DLL first and then link against it. You can just build the program + the module source tree and it will be a single monolithic executable that "just goes".

    Inside Clipsal both approachs are used and the code supports all this. cbus_general.h shows the defines you need to make, which tells the directives in the headers that the compilation is:
    - For making a DLL
    - For referencing a DLL
    - For a monolithic exec where you don't care about a DLL (and this is the normal setup for embedded systems)
     
    ashleigh, Jan 1, 2010
    #39
  20. John@DHW

    rhamer

    Joined:
    Aug 3, 2004
    Messages:
    673
    Likes Received:
    3
    Location:
    Melbourne, Australia
    Ok, it probably would have made it easier if I explained from the beginning where I'm trying to go.

    I need to build the DLL as a COM object so I can import it into other environments/languages, specifically .NET languages.

    I need to be able to build it, so I can debug why the current Borland build won't work in .NET and make any changes that may be required.

    Assuming I get past that point, I then wish to create a project that runs as a service (in .NET) that imports the DLL and exposes the various functions via a socket interface.

    Then I can talk to it from another application (you probably guessed CQC) accross the network.

    Now I realise I can probably achieve the same result using C-Gate, but this appeals to me as it should be a more light weight solution, not require Java and allow me to control both ends.

    So where are we now. I guess you don't have a VC project that builds like the borland one, so I'm going to have to persist and get some help to build my own. Hopefully I'll be able to progress from there.

    As always any advice would be gratefully accepted.

    Cheers

    Rohan
     
    rhamer, Jan 1, 2010
    #40
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.