If you ever need to send some Optomux commands to a device from a SNAP PAC Controller, here’s a simple example I wrote the other day to flash some outputs in a repeating pattern.
Just import this chart into a strategy and use the Optomux protocol guide (form 1592) and you’ll be communicating with your Optomux device in no time! (I was using the built-in 485 serial connector on my SNAP-PAC-S2 in this example).
Or new LED Dimmer can communicate via Optomux, too.
FYI, the “repeating pattern” I mentioned in the example above I shamelessly borrowed from a TV show from my youth. Here’s how I implemented it using a bit shift right, then left…
// Do a scan pattern
nBitPattern = 0xC000; // to start: 1100 0000 0000 0000
for nIndex = 0 to 13 step 1 // we're going to shift this pattern over 14 times (don't want those 2 bits to fall off the end)
// LED pattern will look like this:
//1100000000000000 nIndex = 0
//0110000000000000 nIndex = 1
//0011000000000000 nIndex = 2
//0001100000000000 nIndex = 3
//0000110000000000 nIndex = 4
//0000011000000000 nIndex = 5
//0000001100000000 nIndex = 6
//0000000110000000 nIndex = 7
//0000000011000000 nIndex = 8
//0000000001100000 nIndex = 9
//0000000000110000 nIndex = 10
//0000000000011000 nIndex = 11
//0000000000001100 nIndex = 12
//0000000000000110 nIndex = 13
NumberToFormattedHexString(nBitPattern, 4, sPositions);
sOptomuxCommand = ">" + sAddress + "J" + sPositions + "??" + chr(13);
nCHResult = TransmitReceiveString(sOptomuxCommand, chSerial, sOptomuxResponse);
DelayMsec( nShiftDelayMS );
nBitPattern = nBitPattern >> 1; // shift our bit pattern by 1 bit to the right (as illustrated above)
next
for nIndex = 0 to 13 step 1 // we're going to shift back the other way
// LED pattern will look like this:
//0000000000000011 nIndex = 0
//0000000000000110 nIndex = 1
//0000000000001100 nIndex = 2
// ...
//0110000000000000 nIndex = 13
NumberToFormattedHexString(nBitPattern, 4, sPositions);
sOptomuxCommand = ">" + sAddress + "J" + sPositions + "??" + chr(13);
nCHResult = TransmitReceiveString(sOptomuxCommand, chSerial, sOptomuxResponse);
DelayMsec( nShiftDelayMS );
nBitPattern = nBitPattern << 1; // shift our bit pattern by 1 bit to the left
next
Just in case anyone needs a little Optomux code that’s specifically for our LED dimmer, here’s a simple example (just import this chart into a strategy)!