Setting Baud rate to variable
undrtkr
Posts: 35
I'm writing code for a 60+ room roll out for a college. They want control of two different Elmo document cameras. These two models have different baud rates. My question is can I set a variable to a specific baud rate and insert that variable into the SET BAUD command. Here is the code I'm thinking of.
DEFINE_VARIABLE
PERSISTENT INTEGER nElmoBaudRate //Determines Baud Rate
DEFINE_START
SWITCH(cElmoModel)
{
CASE cElmo400: nElmoBaudRate = 4800
CASE cElmo4400: nElmoBaudRate = 9600
}
DATA_EVENT[dvElmo]
{
ONLINE:
{
SEND_COMMAND DATA.DEVICE,"'SET BAUD ',nElmoBaudRate,' N,8,1'"
}
}
DEFINE_VARIABLE
PERSISTENT INTEGER nElmoBaudRate //Determines Baud Rate
DEFINE_START
SWITCH(cElmoModel)
{
CASE cElmo400: nElmoBaudRate = 4800
CASE cElmo4400: nElmoBaudRate = 9600
}
DATA_EVENT[dvElmo]
{
ONLINE:
{
SEND_COMMAND DATA.DEVICE,"'SET BAUD ',nElmoBaudRate,' N,8,1'"
}
}
0
Comments
Jeff
The other thing you could do, just to use less variable memory is this
There's really no reason to overly complicate it by declaring a variable
J
one note on this statement. You almost never want to do a SET BAUD command in the startup section. In most cases the device is not even online at startup. It's best to put it in a DATA_EVENT in the ONLINE: section. That way the command doesn't get ignored. Any type of integrated master should be done this way. NI_X100 or whatever...
J
Otherwise you could just switch the baudrate according to a button press or something...
Hm, good point. The above example would make it simpler. The cElmoModel is a constant set to 1 or 2. The installer will have to set this constant to whatever model of Elmo is being used before they compile and upload to the processor. Thanks.
**Note, I haven't tested any of this and I don't speak Elmo, it just seemed like a fun idea so I wrote this in 5 minutes. If this turns out to be a stupid idea, sorry about it**
As long as you can actually query the Elmo to find out what its model number is, this should work. Otherwise you'd have to set a variable (nElmoBaud) to tell you what the baud rate was when you asked it a question and just ask it anything, and tell it to keep the baud that got you a response.
I'm not necessarily recommending you use this, but it seemed like a fun way to make it so the installer couldn't forget to set the constant.
J
On another note, has anyone ever tried anything like the little snippet I posted yesterday? Something that sends commands out at different baud rates until it finds one that works, then stores that rate in persistent memory? It seems in the abstract to me that it would work, but I'm not set up to test it. I'm intrigued by the concept, because I like being able to write code that works for multiple rooms.
J
It's also useful on those occasions when you have a client who just can't leave the equipment alone and gets into the settings menu and goofs things up.
It's a good idea.