IR Pulsing Implementation
RicardoSiqueira
Posts: 373
I wonder how the experienced Netlinx programmers implement their IR pulsing duration for multiple devices. Is there a better way than changing the Pulse time all the time in code using the SET_PULSE_TIME? For example , I would like the pulse time for a DVD to be fixed always on 0.3s whenever an IR channel is pulsed on the DVD, a VCR to 0.4s and so on. Maybe in a DATA_EVENT. Usually I create an include file that itiliazes all my IR devices like this:
DATA_EVENT[dvDVD]
{
ONLINE: //IR device comes ONLINE
{
SEND_COMMAND dvDVD,'SET MODE IR'
SEND_COMMAND dvDVD,'CARON'
}
}
I would appreciate if anybody could share a piece of code that takes care of setting the PULSE_TIME to each IR device only once in code. I want to be able to use the PULSE command without having to use the SET_PULSE_TIME all the time.
DATA_EVENT[dvDVD]
{
ONLINE: //IR device comes ONLINE
{
SEND_COMMAND dvDVD,'SET MODE IR'
SEND_COMMAND dvDVD,'CARON'
}
}
I would appreciate if anybody could share a piece of code that takes care of setting the PULSE_TIME to each IR device only once in code. I want to be able to use the PULSE command without having to use the SET_PULSE_TIME all the time.
0
Comments
There are two "classes" of I/R codes for me: PULSE, and TOGGLE.
In the PULSE case, I don't care what the pulse time is, as long as it works. I've picked 0.2 seconds for a pulse time, and this works with all of my devices. I've had no need to change this for any of my devices.
In the TO case (i.e. volume, or channel up, or fast forward, or whatever), it's based on when the button is released, so the pulse time has no bearing (to the best of my knowledge, anyway).
Finally, I like to write my code to be data driven. Thus, very rarely do I pulse (or toggle) I/R signals via hardlined code. Instead, I generally pulse or toggle based on whatever I got from the panel.
In the case of Viewpoints (2-way), I use two devices. Device one is for PULSEd codes, device two is for TO codes. Whatever channel I get for a button, I turn around and PULSE (or TO) to whatever the current source device is. This means that, when setting up a new device, the panel entirely decides what code is sent to the audio/video device, and if it's PULSE or TO.
In the case of Moderos, I do something similar, but in this case, I use two ports on the same device. The modulo of the device (or port) by two == 0 means pulse, == 1 means toggle.
Hope this helps,
-- Jeff
Aparently there is a problem in the firmware for NI's (.118) where this can cause problems after a while in that the device will stop sending out IR. I've had to roll the firmware back to 115 to get rid of this problem.
While there is a logic to that and credit should go to AMX for sticking with it it pretty consistently, I am not a big fan of the distinction. After all PULSE does, like 'SP', send IR so one wonders why finding about one doesn't at least reveal the existence of the other.
Fred
DEFINE_CALL 'Pulse Device' (DEV aDevice, INTEGER aChannel)
{
SWITCH (aDevice)
{
CASE 8: SET_PULSE_TIME(.5)
CASE 9: SET_PULSE_TIME(.3)
}
PULSE[aDevice,aChannel]
}
In this example device 8 could be a VCR, device 9 could be a DVD player
in your Main Line or Button Events, instead of the traditional Pulse statements, just type:
Call 'Pulse Device' (dvDVD,2)
it's worked well with all IR devices i've used so far (various DVDs, TVs, VCR and Cable boxes)
the default is 5 (0.5 seconds i think) - and it is too long.
many devices get doubled up IR codes and repeat their functions with the default setting
i then use send_command device SP,IrCodeNumber
just set and forget - it worked for me
My own advice is stop using SET_PULSE_TIME and PULSE[IR, xx] altogether. Using SEND_COMMAND IR, "'CTON', xx" allows you to individually set the pulse timing per device when using the SP command. In turn, that lets you use the same code for multiple devices, and it lets you tweak the timing for devices that are sensitive either way.
DATA_EVENT[dvDSS1]
{
ONLINE:
{
SEND_COMMAND dvDSS1, "'CTON',2"
SEND_COMMAND dvDSS1, "'CTOF',2"
}
}
BUTTON_EVENT[dvTP1,31]
{
PUSH:
{
IF(![dvDSS1,255]) SEND_COMMAND dvDSS1, "'SP',9" //PWR
SEND_COMMAND dvDSS1, "'XCH123'"
}
}
I don't remember any mention of the "SP" command in any of the programming classes I took. So between the numerous mentions in this column, as well as the examples posted, I was able to learn a new technique instead of building my own stacking function.
Thanks
Use the "Stack Pulse" if you can. The benefit is that the Master does not need to manage the pulse duration. The IR device will do this. No need to manage a series of IR commands with Waits or a Timeline_Event.
Line 1 :: Input Status:Pushed [81:1:1] - Channel 26 - 10:34:47
Line 2 :: Command To [5001:9:1]-[SP+] - 10:34:47
Line 3 :: Command To [5001:9:1]-[SP$0A] - 10:34:47
Line 4 :: Command To [5001:9:1]-[SP$00] - 10:34:47
Line 5 :: Command To [5001:9:1]-[SP$06] - 10:34:47
Line 6 :: Command To [5001:9:1]-[SP>] - 10:34:47
Line 7 :: Command To [5001:9:1]-[SP$01] - 10:34:47
Line 8 :: Input Status:Released [81:1:1] - Channel 26 - 10:34:47
I normally see only three (but sometimes four) flashes from the IR port on the NI-3000 I've got. I'm assuming it's pulsing lines 3,4,5 and 7, though one will seem to drop out. I don't know why it's sending an "SP+" and "SP>", aside that 43 is an ASCII "+" and 62 is an ASCII ">". Does anyone have any ideas? Would the ITOA have anything to do with it? Here's the code I'm using - it's for a "Random Album" function on an Imerge S1000 (old piece of hardware.)
It looks like you may want to add 10 to your random numbers if you have the numbers at IR slots 10-19 as per standard IR files.
Moving on the the code: If I?m reading your logic correctly you want a random number between 01-99. It looks to me like you didn?t account for the IR code offset (the number 0 is IR code 10 ? the number 9 is IR code 19) And it also looks like any number divisible by 10 (evenly of course ) won?t ever be generated.
You really don?t need a while loop and you don?t need the conversions between ASCII and decimal. All you really need are two numbers.
There are many ways to accomplish the same thing but here is one way to send out random IR codes for the digits 01-99:
Hope this helps.
I'm making it a CHAR that way I can do a LEFT&RIGHT_STRING on the RANDOM_NUMBER that was just generated. Unless there's another way of extracting the first digit of a two digit decimal number, this is how I can see doing it. I did forget the offset of the IR codes, and did add 10 to the broken random number.
Anyway, it would certainly help if the right Imerge IR file was in the master. I guess I was more concerned with the + and the >. It LOOKS like it's only sending 5 of the 6 IR pulses. However, the first pulse looks different from the others. The 43 and 62 were copy and pasted from a WACI file, do you think this could make any difference? Plus, when looking at the pulses (43 & 62) in IREdit, the repeat count is "0", total repeat time, and first pulse times are all different from the other pulses. Could this make much difference?
Anyway, thanks for the help!
Hope this helps
OP
Now I think Immerge has a CCF file for Pronto's on their website which you can use to verify codes and what not.
Not sure if you're using Axcess or Netlinx but you can control the Unit via IP if you're using Netlinx.
Okay, here is one way:
Does that get you where you want to go? The reason you weren't seeing all the pulses in your original code is because sometimes your code was trying to send out IR code function 0...which doesn't exist. What you really wanted was function 10 which is 0.
--D
Much more straight forward then mine. To get a number between 1-30 you would have to change:
nRandomNum = RANDOM_NUMBER(29) + 1
To:
nRandomNum = RANDOM_NUMBER(30) + 1
In a Random_Number sequence from 1 to 30, the numbers 1 and 30 (the outside numbers) will show up around 16% LESS of the time than all the other numbers 2-29. The Randon_Number() method looks at the numbers on each side of the string of sequenced numbers to get a randomized number, since 1 and 30 are on the outside, they don't get looked at as often. There is a fix if anyone really needs to know but I don't want to bore you.
jjames ? I laughed at your new avatar. Been there done that many more times then I?d care to remember.
Yup, you're right. I don't use Randoms that much, and had forgotten it returns one less than the value passed.
;-)
--D
No - please, feel free to try and bore me.
- Chip
One of the problems is the algorithms look at the numbers next to each other not just at the individual number, by doing this the out-most numbers will get picked less often. IF YOU MUST - ONE FIX IS: to get a random number between 1 and 10, get a Random_Number on 1-12 and if 1 or 12 popup repeat the function until it?s between 2-11, then subtract one to get back to the original 1-10.
I know this is crazy and I don't do this for everyday random numbers, but I thought it was interesting. You should see what Casinos do to generate random numbers for their slots and video poker games. Casinos can't use the computer algorithms because the patterns could be detected by a super human and give them an advantage. I'd like to see that!
One episode had a programmer in charge of making sure the slot machine code was correct get mad that the agency he worked for cheated the public out of more than the cheaters they were fighting. He put a trojan in the software that spot checked the machine that would modify the code after it verified it.
After a while that wasn't enough money for him and Keno came out. He went into the operating system the keno code ran on and debuged how it's random number code worked (after all, someone had to code that). He found that given a set of numbers of one game gave him a 50% chance of guesing the next set of numbers. Adding in each following game's numbers increased his odds as his program narrowed down what part of the 'loop' the code was in. He hit all numbers correctly on his third game...
Related to the code, I'm not seeing anyone save the last random number generated. If you don't compare new vs old, your 'random' will be a 'repeat' every so often.
Kevin D.
This is because most computer us what is called a "seed" to start the random number process, the seed is the starting point for the randomization algorithm. That's why each computer will always get the same starting number.
As Kevin mentioned:
I also think it is more important to store the "so called" random numbers in a array so they don't repeat until all sequenced numbers have been picked. I use this in my random MP3 function.