Home AMX User Forum NetLinx Studio

How do I include a module?

Hey guys,

Trying to make a module out of the code here: http://www.ryanwright.com/automation/amx_cm11a_v1.0.txt

But I'm really confused. What do I need to do to be able to include this as a module and modify the X10_COMMAND string from my main source?

Thanks!

Dan

Comments

  • NMarkRobertsNMarkRoberts Posts: 455
    Create a module called eg mX10Comms, give it this header, and put the code in it:
    module_name = 'mX10Comms' (
      dev RS232_2, (* The physical device the X10 is attached to *)
      dev vControl) (* The virtual device to which commands are sent *)
    

    Remove the define_device from the code and add:
    define_event
    
    data_event[vControl]                                               
    {
    string:
      {
      X10_COMMAND = data.text
      }
    }
    

    put the corresponding module definition in your mainline:
    define_device
    
    dX10 = 5001:whatever (* The physical device the X10 is attached to *)
    vX10 = 33001:1:1  (* The virtual device via which commands are sent to the X10 module *)
    
    define_module 'mX10Comms' modX10Comms  (
      dX10,
      vX10)
    

    In your external code send a command like so:
    send_string vX10,'Command'
    

    You will probably want to send commands from inside a control module rather than from the mainline so put vX10 in the header of the control module too.

    I think that answers your question but the module definitely isn't how I would code it.

    The code was written for Axcess not NetLinx. It still mostly works in NetLinx but it is designed to be an include in a single mainline rather than a module. That's why, for instance, all the variables begin with X10_ which is unnecessary if you are in a module called X10, but necessary if you are sharing code space with a bunch of other includes.

    That's also why everything is in define_start and define_program when NetLinx conventions put almost everything in the define_event while the actual code lives in define_functions.

    The SET BAUD command needs to be in the online event of the physical device and will not work otherwise.

    I would also add some sort of a command queue. I think that as the code stands, if you send the module three commands in a row, the first will get sent to the unit, the second will be delayed while the module waits for the reply to the first, and the third will overwrite the second causing it to be lost.

    I would also consider adding modest WAITs to the define_program code chunks.

    (NB above code uncompiled and untested.)
  • dmurray14dmurray14 Posts: 80
    Wow, thanks - I had no idea it was that hard. I may just start from scratch, it will be a good exercise for me.

    Thanks,
    Dan
  • NMarkRobertsNMarkRoberts Posts: 455
    It's only hard the first time.

    (Did I really just write that?)
Sign In or Register to comment.