Home AMX User Forum AMX General Discussion
Options

IO impuls control

I need to control climates device that can recognize only impulse from IO ports, so for example if I want to turn FAN to speed 1 I need to send impulse like this

IO port 1
4 seconds closed, 1 second open, 1 second closed

Or if I want to set fan speed to speed 3 I need to send

IO port 1
4 seconds closed, 1 second open, 1 second closed, 1 second open, 1 second closed, 1 second open, 1 second closed


And for temperature I for example 24 I need to send


IO port 1
2 seconds closed, 1 second open and than 1 second closed and 1 second for 14 times (desired temperature - 10)


Also I need counter to see what desired temperature is.

I have written it like


DEFINE_DEVICE

dvPanel = 10001:1:0 //mali touch panel
dvIO = 5001:4:0 //IO portovi

DEFINE_CONSTANT
DEFINE_TYPE
DEFINE_VARIABLE
DEFINE_LATCHING
DEFINE_MUTUALLY_EXCLUSIVE
DEFINE_START

SET_PULSE_TIME (10)

CREATE_BUFFER dvPANEL,cPANEL_BUFFER


DEFINE_EVENT









BUTTON_EVENT[dvPanel,1] //TEMP 20 digress
{
PUSH:
{
ON[dvIO,1]
WAIT 20
OFF[dvIO,1]

WAIT 30
PULSE[dvIO,1]
WAIT 50
PULSE[dvIO,1]
WAIT 70
PULSE[dvIO,1]
WAIT 90
PULSE[dvIO,1]
WAIT 110
PULSE[dvIO,1]
WAIT 130
PULSE[dvIO,1]
WAIT 150
PULSE[dvIO,1]
WAIT 170
PULSE[dvIO,1]
WAIT 190
PULSE[dvIO,1]
WAIT 210
PULSE[dvIO,1]
}
}

BUTTON_EVENT[dvPanel,2]
{
PUSH:
{
ON[dvIO,1]
WAIT 40
OFF[dvIO,1]
WAIT 50
PULSE[dvIO,1]
WAIT 70
PULSE[dvIO,1]
WAIT 90
PULSE[dvIO,1]
}
}

BUTTON_EVENT[dvPanel,3]
{
PUSH:
{
ON[dvIO,1]
WAIT 40
OFF[dvIO,1]
WAIT 50
PULSE[dvIO,1]
WAIT 70
PULSE[dvIO,1]
}
}

BUTTON_EVENT[dvPanel,4]
{
PUSH:
{
ON[dvIO,1]
WAIT 40
OFF[dvIO,1]
WAIT 50
PULSE[dvIO,1]
}
}


Question is how to optimize code ?!

Comments

  • Options
    Wow, that's horrible! (Not your code)

    First, if it works, it might be best to leave it alone.

    Second, I would never write something like that - I would code something generalised. Give me a day or so (;^) and it would look real good. Fortunately, NetLinx already offers you something to do that - the timeline. Go look it up, and I wish you the best of luck.

    Third, it's not quite that simple. If I were to pick up your touchpanel and press a bunch of random buttons the result would, I presume, be ghastly, because everything would fire at once. So you need to address that issue with a queue, or better with a state monitor.

    Both have been extensively detailed on various fora.
  • Options
    VladaPUBVladaPUB Posts: 138
    I also have a feedback that is the same as command, but it will late for 30-90 seconds from command !

    I am new at programing, so any help is great :)
  • Options
    GSLogicGSLogic Posts: 562
    As Mark said: lookup TIMELINES in the Netlinx help, you'll use them all the time.
  • Options
    //if you start with this, the stuff is only executed if there is no switching cycle running
    BUTTON_EVENT[myTP, myBtn]
    {
    PUSH:
    {
    IF(!TIMELINE_ACTIVE(myTml))
    {
    // start the timeline, pulse the first relay
    }
    }
    }


    //here you pulse the following relays
    TIMELINE_EVENT[myTml]
    {
    read the help about the event handlers TIMELINE.REPETITION and TIMELINE.SEQUENCE.
    }
Sign In or Register to comment.