Premise RS232 Programming Question

Motorola Premise

etc6849

Senior Member
I have an a/v receiver that sends in hex 00 when power is lost or restored. When Premise receives this 00 in hex, it interprets it as a zero length string, ie "".

If I am already using text mode for rs232 commands that are received, how do I check for this 00 in hex?

I tried using something like:

if this.rxTextLine = chr(0) then
...
end if

However this did not detect the hex 00... also tried it with chr(int(&h0)).

Any suggestions? It would be very useful to detect when power is restored to my A/V equip following an outage and this seems like a way to do this.
 
and if you use hexa mode ?
do you have informations in case "RxBinaryData" ?

I use rs232 to received a watchdog from an audio/video matrix ("02 53 53 53 03 ") and I have no problems

Jean-Michel Rendu
 
Thanks for the reply!

I wish I could use binary mode, but all the other commands are ascii and work fine under textmode :lol: I believe in premise you can only use binary or text mode, but never both within the same driver? I actually have never used binarymode before though. Pic shows the selection between binary and text...
 

Attachments

  • binary_mode_select.JPG
    binary_mode_select.JPG
    39.4 KB · Views: 46
I have an a/v receiver that sends in hex 00 when power is lost or restored. When Premise receives this 00 in hex, it interprets it as a zero length string, ie "".
The attached image shows that, by default, hex 00 (NUL) is considered to be a line-terminator when operating in text-mode. When Premise receives a solitary NUL, it considers it to be a zero-length string.

You could try removing NUL from the RxTextLineTerminators property but I doubt it would be beneficial. The UPS A/V Receiver would have to transmit a NUL followed by a legitimate line-terminator (CR or LF) before it would be interpreted as a string.

If you are certain that the UPS A/V Receiver transmits a NUL character exclusively for a power lost/restored event, then you can simply use this fact to your advantage. Have your driver interpret a received zero-length string as an indicator of a power lost/restored event.

Your last resort is to convert your text-mode driver to operate in binary-mode. That'd be a shame because 99.9% of the UPS's A/V Receiver's transmissions can be handled in text-mode.

Operating in binary-mode means your driver scans each byte in the receive-buffer until it finds a line-terminator. It must save the scanned bytes to a working-buffer and then purge them from the receive-buffer. Basically, you do all the grunt work that text-mode does for you ... except you gain the ability to examine each byte.

For an example of operating in binary-mode, have a look at the Home Electronics IRA driver.


PS
I noticed in your previous post that you have set RxTextLineTerminators to hex 1A (SUB). Is that a valid line-terminator for the UPS's A/V Receiver's command protocol?
 

Attachments

  • RxTextLineTerminators.png
    RxTextLineTerminators.png
    4.5 KB · Views: 3
The 1A is for an Onkyo receiver driver... To make things more confusing, this post is about an undocumented power feature of the onkyo receiver, not the UPS (that's a different post). It appears the Onkyo receiver sends 00 as hex upon a power outage and upon return from a power outage.

I'll try removing the null again, but I think I tried that before.

As for the APC UPS (see post under hardware section): I'm not sure what line terminators to use (been using the 0D 0A 00). I'm going to call APC, but it looks like they didn't release the rs232 protocol publicly. It also looks like I sent the UPS something it didn't like because it quit responding after I finally got it to work by sending Y to start smart mode... If I had a fully programming guide, I think it would be easy to build an APC Smart UPS driver for Premise, but I'll have to put it on hold until I get back home this weekend to reset the UPS.
 
123, I just saw your updates to your post. Thanks for the clarifications :)

I think I finally get the differences between rxtextmode and rxbinarymode now...

One thought that comes to mind is port splitting the real com port off into two virtual ports. One virtual port would be tied to the existing Onkyo driver in text mode, the other to a new power outage driver that monitors in binary mode for 00.

Hopefully I don't need to do that though and I can build an APC driver :lol: I think such a driver would be useful to a lot of users as it would allow better management of UPS battery usage during an outage. If I'm successful in building an APC driver, I would rely on it alone to perform power management during an outage to extend battery life (ie an A/V receiver draws much less current in standby so it could be turned off, while the SYS server would stay on). Such a driver would also ensure items that may come on automatically following power restoration are sent an off command; these devices would not need to be connected to the UPS in any way. Many devices seem to return to their previous state following power restoration, so this would be a handy tool.
 
Here is the code I use with "RxText = true"on onNewData :


dim arr
arr = this.RxBinaryData
Dim I, S
For I = 1 To LenB(arr)
hexaCourant=Hex(AscB(MidB(arr, I, 1)))
if len(hexaCourant)<2 then
hexaCourant="0" & hexaCourant
end if
S = S & hexaCourant & " "
Next
this.RxRemoveBytes = LenB(arr)

select case S
case "02 53 53 53 03 "
this.dernierControl=now
end select

this.dernierRetour=now

If sysevent.newVal = True Then
For i = 0 To this.RxLinesRemaining
this.RxNextLine = True
Next
End If
 
A hybrid approach; now there's something I've never tried! Use Text-Mode but also scan the RxBinaryData buffer for a specific sequence of bytes.

I'll have to test this out with my LG TV ... all its commands are text strings delimited with CRLF except when powered down it sends a solitary NUL.
 
maybe you can give me some insight into getting the LG to respond...I know I have the command right ka 01 01CR for 'on'..I just haven't been able to get the thing to respond. Is there a special setup needed to get it going? Or is it supposed to out of the box?
 
maybe you can give me some insight into getting the LG to respond...I know I have the command right ka 01 01CR for 'on'..I just haven't been able to get the thing to respond. Is there a special setup needed to get it going? Or is it supposed to out of the box?

Not all LG models will turn on over RS-232. There is some info on this page. http://www.lgrs232.com/

Edited Link
 
The LG power on/off sounds exactly like what the Onkyo does on return from a power outage...

I haven't tried Jean-Michel's method yet. Hopefully this weekend I can find time.

Merci beacoup Jean-Michel!
 
Has anyone tried this?

I can't get it to work for my SmartUPS (see pic).

Normally, the UPS gives line terminators 0D and 0A. However, when it sends an alert, it gives no line terminators. This means OnChangeOnNewData will not be triggerd until RxNextLine is set; thus, the alerts will not be processed until line terminators are processed and set RxNextLine.

This poses a problem if you don't enable polling and still want alerts or want the alerts immediately when they are sent to the port. Any ideas on this? See the attached jpeg. The break points for OnChangeOnNewData are never triggered :( However, if I do enable polling, I can parse out the alerts as they come along for the ride with the polling results. My code currently works doing this, using a RegEx object.

I really can't justify using binary mode to capture these alerts so I'm not going to rewrite the SmartUPS driver. However, when I build a W800RF32 driver, it looks like I may want to use binarymode as I suspect it does not use line terminators; don't have it yet though, it's coming in the mail next week :)

FYI: Reading the help files for builder indicate this hybrid method should not work??
I'm very confused ;)
Information from the help file:
OnNewData - This property is set to true when new data comes in (when RxTextLine changes).
OnRxOverRun - Set to true when receive buffer is exceeded.
RxLinesRemaining - Number of lines remaining in the text receive buffer (only applicable in text receive mode).
RxNextLine - When set to true, populates RxTextLine with the next line in the text receive buffer (only applicable in text receive mode).
RxTextLine - Current line of received text data (only applicable in text receive mode).
RxBytesRemaining - Number of Bytes remaining in the binary receive buffer (only applicable in binary receive mode).
RxRemoveBytes - Number of Bytes to remove from RxBinaryData (only applicable in binary receive mode).
RxBinaryData - Current value of received binary data (only applicable in binary receive mode).
 

Attachments

  • onnewdata.JPG
    onnewdata.JPG
    50.6 KB · Views: 29
I still havent had success in getting Premise to control my LG via serial commands. The LG responds with the LG RS-232 utility, but not via Premise...can any of you LG guys id the settings I need to change in builder? Any tricks?
 
Back
Top