Jump to content


Photo
- - - - -

Serial Port Read


  • Please log in to reply
11 replies to this topic

#1 acalbear

acalbear

    Cocooner

  • Registered
  • PipPip
  • 36 posts

Posted 06 June 2008 - 01:20 AM

I recently acquired an x-10 RF receiver (W800). I am attempting to utilize the receiver to connect to wireless motion and door contacts to act as triggers for firing other functions or to bind to home objects.

I have set up a custom device and connected to the serial port for which the w800 is attached. Using port spy I can see that the receiver and premise are indeed receiving data whenever I open and close a wireless contact device. At this point, i am just trying to have premise read the serial port data but with no success. When I chose RXmode text, I can see SYMBOLS in the RxTEXTLINE box. However, I am unable to read the data to a register which in turn I will use in a logic script.

Any tips on how i can read this data to find out what the serial port is spitting out such that I can use it in a script. Port Spy apparently displays hex but I am not sure how I will embed this in a script.

Any help is appreciated.

Thanks.
ACB

#2 JimSpr

JimSpr

    Cocooner

  • Registered
  • PipPip
  • 26 posts

Posted 06 June 2008 - 01:45 AM

There will be a class created for your custom device in modules (i.e. Modules/Default/Classes/DeviceName). You can go there and add scripts, properties, etc to do what you want.

For instance, go to your class in modules, right-click and select "New|Script|Property Change". Select the "All" tab and pick the RxTextLine property. Add script to do whatever you want.

--jim

#3 123

123

    Cocoonut

  • Registered
  • PipPipPipPip
  • 2170 posts
  • Location:Montreal, QC
  • Experience:average
  • Software:Premise
  • Hardware:Elk M1

Posted 06 June 2008 - 12:12 PM

Try using Text_Listener. It is a super-simple serial port listener ... it receives data from the serial port and then writes it to a property and to the debug console.

It is called "Text" listener because it assumes the incoming data is text-based and ends with a carriage-return or line-feed (or some other common line terminator).

If the incoming data is in binary-format, you'll need to use a different technique. You don't read the incoming data from the RXTextLine buffer but from RXBinaryData ... and you have to do a little housekeeping with the binary-data buffer. Check out PFiedlander's Omnistat module here. It provides a nice example of handling binary data via a serial port. If you want to examine the Omnistat's communications protocol, check this post.

The Omnistat module polls the thermosat every 15 seconds. Look in "ClassContructor" and you'll find "system.Timer" ... I don't believe you need this for the W800.

Edited by 123, 06 June 2008 - 02:45 PM.


#4 BLH

BLH

    Dedicated Cocooner

  • Registered
  • PipPipPip
  • 798 posts
  • Location:South East CT.
  • Experience:average
  • Hardware:ISY-99
  • Tech:X10-PLC, X10-RF, INSTEON

Posted 06 June 2008 - 06:04 PM

Have you looked at the WGL web site? The W800 page has a few links on it like the serial data outputted when a signal is received.
http://www.wgldesigns.com/w800.html

#5 acalbear

acalbear

    Cocooner

  • Registered
  • PipPip
  • 36 posts

Posted 08 June 2008 - 11:03 AM

Being a hobbyist instead of a programmer puts me at a disadvantage so pardon my basic commentary. JimSpr - I discovered the new class and was attempting to write a script as you had suggested. The problem I had and hence my original post is that I do not know exactly how the data is coming across. When I place code to capture the data from the RxTextLine and watched the variable nothing would appear. Another potential issue is that I have bad code.

According to Port Spy I am definitely getting a signal. Here it is directly from Port Spy:

(Hitting the test Button)
09 06 84 7B
09 06 84 7B
09 06 84 7B
09 06 84 7B
09 06 84 7B
09 06 04 FB
09 06 04 FB
09 06 04 FB
09 06 04 FB
09 06 04 FB

(Closing the contact)
09 06 84 7B
09 06 84 7B
09 06 84 7B
09 06 84 7A
09 06 84 7B

(Opening the contact)

09 06 04 FB
09 06 04 FB
09 06 04 FB
09 06 04 FB
09 06 04 FB

As an aside - I think it sends the same code multiple times to ensure the receiver gets the code. I find that if I restrict the transmition from the DS10, I get different lines instead of the consistency noted above.

When i review the RxTextLine box within the properties of the new custom device I dont see ascii text as I would expect but rather I get characters like this }}.

I was expecting simple text because I was looking at an ELK post discussing how to connect with a WGL and it utilized a pretty simple methodology of waiting for text to come through the appropriate port and devising simple rules around the receiving of the text. I might be wrong with this assumption.

When I switch the RxMode properties of the custom device to use binary instead of text, I can see the RxBytesRemaining number increase which appears that it is receiving binary information.

So, can it be that it Premise can receive both Binary and text information from the W800 or is that not possible and it can only receive one or the other. If it can read text, shouldnt I be able to see it show up in the RxTextLine box within properties? Any help is appreciated or if even better - can someone develop a proper driver :-). I'd be more than happy to complete but need a starting point to grasp on to. Using this training wheels approach I was able to hack the UPB drivers for premise to read all new SAI switches and the HAI modules so I might be able to do that with the W800.

123 - I imported text_listener but am unable to figure out how to configure it. I also downloaded debug but seems that I am missing a configuration of some sort to actually use text_listener.

Thanks for all the assistance and information.

#6 JimSpr

JimSpr

    Cocooner

  • Registered
  • PipPip
  • 26 posts

Posted 08 June 2008 - 02:07 PM

OK, I misunderstood. Your device is binary, so you shouldn't be using RxTextLine. Clear the "RxMode" checkbox, which will set the device type to binary. (Note: You probably want to do this in the device's constructor, which you can add under the device class in the module.)

You should implement a property change script on the "OnNewData" property and then process all the data you find in "RxBinaryData", which is an array of bytes. Then set the "RxRemoveBytes" property to the number of bytes you processed. Note: A reason you might not process all the data is that the end of the buffer may contain an incomplete message, which you don't want to throw away as the remaining data will probably come shortly.

Hope this helps.
--jim

#7 123

123

    Cocoonut

  • Registered
  • PipPipPipPip
  • 2170 posts
  • Location:Montreal, QC
  • Experience:average
  • Software:Premise
  • Hardware:Elk M1

Posted 08 June 2008 - 04:13 PM

You've confirmed that the W800 transmits data in binary format. Let's forget about Text_Listener and focus on the Omnistat example because it handles binary data.
  • Use File > Import to import the omnistat.xdo.
  • In the Shortcut Bar, click Devices.
  • Right-click CustomDevices and select New > OmniStatDirect
You've now imported and installed the Omnistat driver.
  • In the Shortcut Bar, click Modules.
  • Find and navigate this path: Omnistat > Classes > OmnistatDirect
  • Click the "ClassConstructor" script.
ClassConstructor is executed when you install the driver ("instantiated the Omnistat object" in object-oriented lingo). Think of it as the initializer. Note what happens in the script, as per JimSpr's instructions, RxMode is set to 0 and several other properties are initialized in preparation for receiving data. It also contains "system.timer" that I mentioned you won't need for the W800.

Click the OnChangeNewData script. This is the one that does all of the real work. When new data arrives in RxBinaryData, OnChangeNewData is executed (remember, Premise is event-driven). In this script, the contents of RxBinaryData are assigned to a variable called "rawvalues" (the name here has no special meaning ... it was assigned by PFiedlander).

The next part becomes less generic and more specific to handling data received from an Omnistat thermostat. Basically the code is trying to match what it finds in rawvalues with some known and meaningful pattern of bytes corresponding to the Omnistat's operation. The important point is that once it finds a match for say 12 bytes of data it subtracts this amount from RxBinaryData by setting RxBytesRemoved to 12. Meaning if you received 12 bytes and made sense of 12, you subtract 12 from 12 and leave behind 0 bytes in RxBinaryData (i.e. you've emptied the buffer). This is just a long-winded version of what JimSpr explained ... :)

Use the Omnistat module as a guide ... your first goal should be simple like reading the incoming bytes and dumping them to the Debug Console.

Here are two good posts on the original forum. The first one explains binary-mode serial programming and the second contains a handy little function to convert binary data into human-readable characters (i.e. hexadecimal 10 will be displayed as "0A").

Let us know if you need more help.

Edited by 123, 08 June 2008 - 04:20 PM.


#8 123

123

    Cocoonut

  • Registered
  • PipPipPipPip
  • 2170 posts
  • Location:Montreal, QC
  • Experience:average
  • Software:Premise
  • Hardware:Elk M1

Posted 09 June 2008 - 09:52 AM

acalbear, did you try using Premise's existing MR26A driver with the WGL W800?

I'm curious to learn if this combination works a tiny bit or not at all. Theoretically, both devices receive and interpret the same wireless X10 codes so there *might* be interoperability.

The big difference is that the W800 receives X10 security codes. I noticed that the MR26A driver lets you set the received code. For example, a UR47a's Powertoggle button is assigned an address of "EEF0" and can be modified. Maybe by altering the codes, the existing MR26a driver can be tweaked to handle X10 security codes. It's a slim chance but worth a try before setting out to build a W800 driver.

BTW, I skimmed the source code for MisterHouse's W800 driver ... there's a fair amount of bit/byte twiddling involved! Commands are four bytes long. The 2nd and 4th bytes are simply complements of the first and third (for most but not all RF devices!) so the 1st and 3rd are the useful ones. Plus you need to swap the order of the bytes before processing them. Feh! Who comes up with this stuff?!?

#9 JimSpr

JimSpr

    Cocooner

  • Registered
  • PipPip
  • 26 posts

Posted 09 June 2008 - 10:38 AM

This won't work. The MR26a driver expects five byte packets and verifies the header/footer IIRC.

--jim

#10 123

123

    Cocoonut

  • Registered
  • PipPipPipPip
  • 2170 posts
  • Location:Montreal, QC
  • Experience:average
  • Software:Premise
  • Hardware:Elk M1

Posted 12 June 2008 - 11:07 AM

acalbear,

Here's the "skeleton" for a W800 driver. I used the same classes found in the MR26A and threw in one for the DS10A. It is hardly complete but should give you an idea of how these things are put together. It also lacks the all-important programming logic that makes it work but, hey, I didn't want to spoil your fun! :D

Import the XDO, go to Devices > CustomDevices, right-click and select New > W800. Right-click W800 and it will let you create sub-devices like a generic RF button, an HR12A palmPad, a DS10A, etc. Basically it is the same UI as the MR26A driver.

Attached Files



#11 acalbear

acalbear

    Cocooner

  • Registered
  • PipPip
  • 36 posts

Posted 13 June 2008 - 12:23 AM

Thanks guys for the leads. I am able to read the binary data from the comm port now. I now need to take the step of figuring out what the heck to do with that data and using the omni driver as an example. I re-found the link that had me believing that the W800 was sending text. As you may see, the video implies that it should be relatively straight forward to take incoming data and making use of it. Please take a look and provide thoughts.

http://www.cocoontech.com/w800rf32.htm

In the meantime, I will examine what 123 just sent. Thanks again.

ACB

acalbear,

Here's the "skeleton" for a W800 driver. I used the same classes found in the MR26A and threw in one for the DS10A. It is hardly complete but should give you an idea of how these things are put together. It also lacks the all-important programming logic that makes it work but, hey, I didn't want to spoil your fun! :P

Import the XDO, go to Devices > CustomDevices, right-click and select New > W800. Right-click W800 and it will let you create sub-devices like a generic RF button, an HR12A palmPad, a DS10A, etc. Basically it is the same UI as the MR26A driver.



#12 123

123

    Cocoonut

  • Registered
  • PipPipPipPip
  • 2170 posts
  • Location:Montreal, QC
  • Experience:average
  • Software:Premise
  • Hardware:Elk M1

Posted 13 June 2008 - 08:40 AM

I love demos with contradictions, they make you go "huh?"

1/3 of the way into the demo you see the "Secret Decoder Ring" program in action ... the command log lists a bunch of received commands and all are flagged as being "Unrecognized/Corrupt Packet" ... meanwhile the demo dialog exclaims "As you can see 2 different commands were received" ... huh? Maybe someone should explain that to the Decoder program because it marked all ten packets as "Unrecognized"!

Otherwise, it's a nice demo! :P

Edited by 123, 13 June 2008 - 08:40 AM.





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users