Home AMX User Forum AMX General Discussion

Events Mirroring

Hello)

I have a newbie problem :)

There is a Virtual Device. I want the following:

PUSH(vdvButton) --> BUTTON_EVENT[vdv] ---> <Do something>

In vdv module I use DO_PUSH()/DO_RELEASE() for buttons and ON/OFF for channels, assuming buttons and channels can have IDs 1-255.

In mainline I write the following:

DEFINE_VARIABLE

INTEGER BtnCodes[255]

DEFINE START
// Filling BtnCodes array...
// for (i=1;i<-255; i++) BtnCodes=i

BUTTON_EVENT[vdv, BtnCodes]
{
PUSH:
{
Send_String 0, "'Button #',ITOA(BUTTON.INPUT.Channel),' PUSH'"
}
RELEASE:
{
Send_String 0, "'Button #',ITOA(BUTTON.INPUT.Channel),' RELEASE'"
}
}

But this Button_Event never activates. I expected DO_PUSH/RELEASE would generate BUTTON_EVENT with same button code as in DO_PUSH/RELEASE.

Thanks in advance.

Comments

  • Joe HebertJoe Hebert Posts: 2,159
    I"m not sure I'm following your question but it looks like the BtnCodes integer array has no length since you are initializing the array one element at a time. After your FOR loop try a SET_LENGTH_ARRAY(BtnCodes,255) and see if that gets you where you want to go.

    HTH
  • FovFov Posts: 26
    No way :(

    DEFINE_START

    for (cnt = 1; cnt<=255; cnt++)
    {
    BtnID[cnt]=cnt
    ChlID[cnt]=cnt
    }

    SET_LENGTH_ARRAY(BtnID, 255)
    SET_LENGTH_ARRAY(ChlID, 255)

    ...


    BUTTON_EVENT[vdvSCTPServer, BtnID]
    {
    PUSH:
    {
    SEND_STRING 0, "'[!] SCTP to Mainline: Button PUSH: #',ITOA(BUTTON.INPUT.CHANNEL)"
    }
    RELEASE:
    {
    SEND_STRING 0, "'[!] SCTP to Mainline: Button RELEASE: #',ITOA(BUTTON.INPUT.CHANNEL)"
    }
    }

    BUTTON_EVENT still never activates...
  • Joe HebertJoe Hebert Posts: 2,159
    Can you post more complete code on what you are trying to accomplish? Maybe it's just lack of sleep on my part but I don't understand what you're asking. Sorry.
  • FovFov Posts: 26
    Well, ok. Some more code :)

    A part of vdv Module Code

    MODULE_NAME='SCTP_Comm'( DEV vdvSCTPServer, DEV dvSCTPServer, INTEGER nSCTPPort)

    DATA_EVENT[dvSCTPServer]
    {
    STRING:
    {
    // Parsing DATA.TEXT to get Button ID to push/release
    DO_PUSH(vdvSCTPServer, Parsed_Button_ID)
    ...
    }
    }

    A part of Mainline Code

    BUTTON_EVENT[vdvSCTPServer, BtnID]
    {
    PUSH:
    {
    SEND_STRING 0, "'[!] SCTP to Mainline: Button PUSH: #',ITOA(BUTTON.INPUT.CHANNEL)"
    }
    RELEASE:
    {
    SEND_STRING 0, "'[!] SCTP to Mainline: Button RELEASE: #',ITOA(BUTTON.INPUT.CHANNEL)"
    }
    }

    I call DO_PUSH when i get DATA_EVENT(vdv): STRING. It "pushes" a button on a Virtual Device. I want feedback for this event in mainline :)
  • Joe HebertJoe Hebert Posts: 2,159
    What you are trying to do should work. I"m not sure offhand if the RELEASE will trigger after a DO_PUSH but the PUSH should. A few questions:

    1) How are the two DEVs defined?

    2) Do you know a STRING is coming in at dvSCTPServer? You can verify that by doing a send_string 0 in the STRING handler for dvSCTPServer

    3) How are you calculating Parsed_Button_ID? Are you sure it's an integer?
  • FovFov Posts: 26
    Should, but it doesn't :(
    Diag says, virtual Button actually pushes so the trouble is in mainline BUTTON_EVENT.

    Answers:

    1)
    DEFINE_DEVICE
    vdvSCTPServer = 34999:1:0
    dvSCTPServer = 0:2:0

    2) Sure thing.

    3) Absolutely sure.

    :)
  • filpeefilpee Posts: 64
    I just tried this out
    DEFINE_DEVICE
    dvDev = 0:12:1;
    vdvDev = 33009:1:1;
    
    DEFINE_MODULE 'Module' mdl(vdvDev, dvDev)
    
    DEFINE_EVENT
    button_event[vdvDev,1]
    {
    	push:
    	{
    		send_string 0,"'push'";
    	}
    	release:
    	{
    		send_string 0,"'release'";
    	}
    }
    

    in the module i have somewhere

    do_push(vdvDev,1);

    turn messages on and i see the result
    (0000132575) push
    (0000133072) release
  • filpeefilpee Posts: 64
    If you are saying that Diag is reporting the button press then there must be a problem with the way you have defined your button_event.


    fire up Diag again and check that your variable BtnID has what you are expecting.

    Enable Push message display so you can see whats going on.
  • Joe HebertJoe Hebert Posts: 2,159
    Hmm...I wrote a quick test program and it works fine for me. I get the push and release from the DO_PUSH in a module. I know that doesn't help you any but what you want to do should work.
  • FovFov Posts: 26
    Joe:

    Can I take a look at your code?)

    Filpee:

    The problem isn't to write BUTTON_EVENT(dv, StaticID), but BUTTON_EVENT(dv, Array_of_IDs) instead.
  • Joe HebertJoe Hebert Posts: 2,159
    Fov wrote: »
    Joe:

    Can I take a look at your code?)

    Main program code:
    DEFINE_DEVICE
    
    dvComm = 5001:1:0
    vdvTest = 33001:1:0
    
    DEFINE_START
    
    DEFINE_MODULE 'TestMod' mdlTest(vdvTest, dvComm)
    
    DEFINE_EVENT
    
    BUTTON_EVENT[vdvTest,1] {
    
       PUSH: {
          SEND_STRING 0, 'Got push in main program'
       }
       
       RELEASE: {
          SEND_STRING 0, 'Got release in main program'   
       }
    }
    
    

    Module code:
    MODULE_NAME='TestMod' (DEV vdvTest, DEV dvTest)
    
    DEFINE_EVENT
    
    DATA_EVENT[dvTest] {
    
       STRING: {
          SEND_STRING 0, 'Got string in module'
          DO_PUSH(vdvTest,1)
       }
    }
    

    Output when I use Emulate a Device and send a string to dvComm:
    Line      4 :: Got string in module - 04:36:43
    Line      5 :: Got push in main program - 04:36:43
    Line      6 :: Got release in main program - 04:36:43
    
  • FovFov Posts: 26
    Joe:

    BUTTON_EVENT with statically specified Button ID works for me, for you and for all.

    I virtually 'push/release' buttons on vdv. I assume it can have a maximum of 255 buttons.
    When I call DO_PUSH/RELEASE, I specify Button ID. I want only ONE BUTTON_EVENT in mainline that could process a PUSH/RELEASE of ANY of 255 virtual buttons :)
  • Joe HebertJoe Hebert Posts: 2,159
    OK, here it is with a button array. Works fine:

    Main program:
    DEFINE_DEVICE
    
    dvComm = 5001:1:0
    vdvTest = 33001:1:0
    
    DEFINE_CONSTANT
    
    INTEGER nSomeButtons[] = {11,12,13,14,15}
    
    DEFINE_START
    
    DEFINE_MODULE 'TestMod' mdlTest(vdvTest, dvComm)
    
    DEFINE_EVENT
    
    BUTTON_EVENT[vdvTest,nSomeButtons] {
    
       PUSH: {
          SEND_STRING 0, "'Got push for button ',ITOA(nSomeButtons[GET_LAST(nSomeButtons)]),' in main program'"
       }
       
       RELEASE: {
          SEND_STRING 0, "'Got release for button ',ITOA(nSomeButtons[GET_LAST(nSomeButtons)]),' in main program'"
       }
    }
    
    

    Module:
    MODULE_NAME='TestMod' (DEV vdvTest, DEV dvTest)
    
    DEFINE_EVENT
    
    DATA_EVENT[dvTest] {
    
       STRING: {
          SEND_STRING 0, 'Got string in module'
          DO_PUSH(vdvTest,11)
       }
    }
    
    

    Output when using Emulate a Device to send a string to dvComm
    Line      1 :: Got string in module - 04:59:13
    Line      2 :: Got push for button 11 in main program - 04:59:13
    Line      3 :: Got release for button 11 in main program - 04:59:14
    
    
  • FovFov Posts: 26
    Nice,

    INTEGER nSomeButtons[] = {11,12,13,14,15}

    But how to do the same thing with { 1, ... , 255 } ?
    Sure, I don't want to write scary things like { 1,2,3,4,5,6,7,8,9,10,11,12 ... 100,101,102,103... 255}

    When I try to fill array in loop, it doesn't work somehow :(
  • Joe HebertJoe Hebert Posts: 2,159
    Fov wrote: »
    Nice,

    INTEGER nSomeButtons[] = {11,12,13,14,15}

    But how to do the same thing with { 1, ... , 255 } ?
    Sure, I don't want to write scary things like { 1,2,3,4,5,6,7,8,9,10,11,12 ... 100,101,102,103... 255}

    When I try to fill array in loop, it doesn't work somehow :(
    I should have caught this before. You need to use REBUILD_EVENT() to rebuild the event table.

    Like this:
    DEFINE_VARIABLE
    
    INTEGER nSomeButtons[255]
    
    INTEGER x
    
    DEFINE_START
    
    FOR (x=1; x<=255; x++) {
       nSomeButtons[x] = x
    }
    SET_LENGTH_ARRAY(nSomeButtons,255)
    REBUILD_EVENT()
    
    
  • FovFov Posts: 26
    Yup :) That works :) Thanks a lot ^^
  • Joe HebertJoe Hebert Posts: 2,159
    Sure thing.

    As further explanation, the event table is built at compile time before your button array is initialized which is why the events weren't firing. That's why you need to use REBUILD_EVENT() so the event table can get reconstructed.

    Also if you want to use more than 255 buttons just use SET_VIRTUAL_CHANNEL() in the ONLINE handler for the virtual device. For example if you want 1000 buttons you can do this:

    SET_VIRTUAL_CHANNEL_COUNT(vdvSCTPServer,1000)

    Have fun.
  • FovFov Posts: 26
    Thanks for all :)
  • Almost got it.

    You almost got it. You want to use the REBUILD_EVENT() function.

    Here is an example from NetLinx Help.

    DEFINE_DEVICE

    dvTP = 10001:1:0

    DEFINE_VARIABLE

    INTEGER X // loop counter

    INTEGER nBTNS[4000]

    DEFINE_START

    FOR (X = 1; X <= 4000; X++)
    {
    nBtns[X] = X
    }

    // the braces below enclose a variable update and
    // rebuild_event statement in a single block

    {
    SET_LENGTH_ARRAY(nBtns,4000)
    REBUILD_EVENT()
    }

    BUTTON_EVENT[dvTP,nBtns]
    {
    PUSH:
    {
    // ...
    }
    }
    // end
  • FovFov Posts: 26
    I'm newbie in Netlinx. I didn't know such function exists :)
Sign In or Register to comment.