Home AMX User Forum NetLinx Studio

M2M and remote device control

Can anyone hook me up with some code examples of how to acheive this? There's really a dearth of practical examples on the website and in the manuals.

Comments

  • AMXJeffAMXJeff Posts: 450
    PatG wrote: »
    Can anyone hook me up with some code examples of how to acheive this? There's really a dearth of practical examples on the website and in the manuals.

    What are you exactly trying to do, not alot of information in your post... Thanks!
  • PatGPatG Posts: 42
    OK well simply put I have to open a connection to another master and then control a device with a specific D:P:S. I'm pretty sure I have to open a client to connect to this master, and that's fine, but once that's done I'm not sure how to start referncing that device for control, or if I should be referencing the client itself ( ie what device I'm sending commands to ). Or if indeed once the connection is made all I have to do is control the declared device.

    Thanks
  • AMXJeffAMXJeff Posts: 450
    PatG wrote: »
    OK well simply put I have to open a connection to another master and then control a device with a specific D:P:S. I'm pretty sure I have to open a client to connect to this master, and that's fine, but once that's done I'm not sure how to start referncing that device for control, or if I should be referencing the client itself ( ie what device I'm sending commands to ). Or if indeed once the connection is made all I have to do is control the declared device.

    Thanks

    Most the work of this feature is automatically handled for you. Master to Master communication is very simple for the programmer to implement. First you have to make sure both masters have different system numbers. By default the masters get shipped as system 1. You can have a system number from 1 - 65535. Once you set the masters system numbers, for the sake of this conversation we will say system 1 & 2. To link the masters together, you must put one of the masters IP address in the other master "URL LIST". So in other words, put systems 2 IP address in systems 1's URL LIST. You do not need to and should not put systems 1's IP address in systems 2 URL LIST, in other words you only need to do this in one of the masters. Once you do this, system 1 has access to all of the control points in system 2 and system 2 has access to all the control points to system 1. Now all you have to do is program normally. Netlinx Diagnostics is the tool you can use to set the system numbers plus populate the URL LISTS.
    // SYSTEM 1'S CODE
    DEFINE_DEVICE
    
    dvProjector1 = 5001:1:1 // Serial Port located in System 1
    dvProjector2 = 5001:1:2 // Serial Port located in System 2
    dvTP = 10001:1:1 // TP located in system 1
    
    DEFINE_EVENT
    
    BUTTON_EVENT[dvTP,1]
    {
         PUSH:
         {
              // THIS WILL GO OUT A SERIAL PORT ON SYSTEM 1
              SEND_STRING dvProjector1,'POWER=ON'
         }
    }
    
    BUTTON_EVENT[dvTP,2]
    {
         PUSH:
         {
              // THIS WILL GO OUT A SERIAL PORT ON SYSTEM 2
              SEND_STRING dvProjector2,'POWER=ON'
         }
    }
    
    
    
    DATA_EVENT[dvProjector1]
    {
         STRING:
         {
             // PARSE DATA FROM SERIAL PORT IN SYSTEM 1
         }
    }
    
    
    DATA_EVENT[dvProjector2]
    {
         STRING:
         {
             // PARSE DATA FROM SERIAL PORT IN SYSTEM 2
         }
    }
    
    
  • PatGPatG Posts: 42
    OK this looks great. So am I correct in assuming that

    ip_client_open(dvClient.PORT,<IP>,<port>,IP_TCP)

    will achieve the same thing as using the URL list in this situation? ( where I am opening the client in the controlling master )
  • viningvining Posts: 4,368
    No, that would just open a socket on both masters and you would then have to some how exchange event data where as M2M creates a socket connection and creates an open broadcast between all device in the URL list so that all events are shared between all URL list members. Or something like that.
  • AMXJeffAMXJeff Posts: 450
    vining wrote: »
    No, that would just open a socket on both masters and you would then have to some how exchange event data where as M2M creates a socket connection and creates an open broadcast between all device in the URL list so that all events are shared between all URL list members. Or something like that.


    If you must add to the URL list in code use this method.

    // Directions...

    ADD_URL_ENTRY
    This function adds a URL entry to the specified device. The function requires a pre-initialized URL_STRUCT that will be sent to the specified device.

    ADD_URL_ENTRY (DEV Device, URL_STRUCT Url)

    Parameters:

    Device - Device number of the device that stores the URL; typically the local Master (0:1:0).

    If you currently connected to another Master, you can use <0:1:system number of remote master>.

    Url - URL_STRUCT that will be programmed into the device

    Result:

    0: Success

    -1: Specified device is invalid or is not online

    -2: Time out occurred

    -3: Function is already actively adding a URL entry (i.e. busy)

    -4: Add failed

    Note that NetLinx will automatically set bit 5 of the Flags member of the URL_STRUCT structure.

    See GET_URL_LIST for a description of the URL_STRUCT structure.
  • PatGPatG Posts: 42
    OK I think I got it now thanks. Would an online: event for the master be an appropriate place for add_url_entry?
  • AMXJeffAMXJeff Posts: 450
    PatG wrote: »
    OK I think I got it now thanks. Would an online: event for the master be an appropriate place for add_url_entry?

    DEFINE_START SECTION WOULD WORK...
  • viningvining Posts: 4,368
    Is there a specific reason why you want to add another master to the URL list via code instead of using NS2>Diagnostics Tab>URL Listing.... and then just adding your other master's IP to the main master's list.

    FYI, is you use the ADD_URL_ENTRY (DEV Device, URL_STRUCT Url) system function that AMXJeff suggested that needs to be put in the code for the main master only and that doesn't need or require you to open a connection to your other master with an IP_CLIENT_OPEN or anything. Once the other master is in the URL list of the main master everything is taken care of for you. All you need to do is declare your devices in the masters that you want to run code in for those devices and then create event handlers.
Sign In or Register to comment.