Simple Serial Plugin - just to use for debugging
| Author |
Message |
|
dmeeker@mac.com
Joined: Aug 26, 2011 Posts: 73
|
 Re: Simple Serial Plugin - just to use for debugging
Thanks for that input Jim. Last night I came to the same conclusion. I had also tried separating those with commas, thinking that would work (after checking out another project where this was the used), but that also failed.
Then I realized that I probably wasn't sending the string properly and that it was going over the wire as just an ASCII string.
Let me know what your thoughts are. I don't want to go in and start hacking around as there may be a more elegant solution than what I'd come up with. Maybe even a way when entering in the string to send to include a checkbox or something that sets a variable on whether it not to run a conversion on the string.
I don't know.
Thanks again for being so helpful.
Dave
|
| Sat Nov 26, 2011 9:46 am |
|
 |
|
dmeeker@mac.com
Joined: Aug 26, 2011 Posts: 73
|
 Re: Simple Serial Plugin - just to use for debugging
I came across this and can't believe that this is the case: http://www.daniweb.com/software-develop ... eads/68078Could it really be that hard (or impossible ?) I then found this post, which seems more promising. http://eli.thegreenplace.net/2009/08/20 ... in-python/Dave
|
| Sat Nov 26, 2011 9:52 am |
|
 |
|
yergeyj
Joined: Dec 29, 2004 Posts: 239
|
 Re: Simple Serial Plugin - just to use for debugging
Dave,
The second one is closer to what you need. If you look at the EasyDAQ plugin code you'll see they send a lot of these type of commands.
I'll try to figure an easy way to add a "feature" to the Simple Serial plugin to send raw hex code, but it won't be for a few days, as I have family visiting this weekend.
Jim
|
| Sat Nov 26, 2011 10:07 am |
|
 |
|
dmeeker@mac.com
Joined: Aug 26, 2011 Posts: 73
|
 Re: Simple Serial Plugin - just to use for debugging
Thanks Jim! I certainly don't expect you to do this stuff while you are enjoying the family  Should you happen to take a look at this when you free up, I found something that might help make things easier. http://www.daniweb.com/software-develop ... ads/372287I think we could use the functions hexlify() and unhexlify() in module binascii to do this. I started looking at the plugin code, and it might be as simple as checking the string that was entered to see if it is hex, and then using hexify(command). Just thought I'd share. I don't think I am about to start making a hack job out of this (which I surely would), but that might be a much faster way for you to implement things, should you decide to do so (god willing!) Thanks again. Dave
|
| Sat Nov 26, 2011 4:15 pm |
|
 |
|
dfiedler
Joined: Mar 19, 2006 Posts: 56
|
 Re: Simple Serial Plugin - just to use for debugging
yergeyj wrote:I did not add any decoding or other response-from-serial handling, as everyone has their own serial device, with different possible response possibilities, for example, ongoing two-way communication or send-receive only. That said, you can update the response from your serial port to an Indigo variable every time a response is received, by modifying the last section of the serialdevice.py file: - Code: Select all
### Log response - this plugin does not parse or do anything with the response, but it's still called decodeResponse. ### May have more than one item in response string, even if sending command def decodeResponse(self, devId, responseString, commDirection): stringLen = len(responseString) indigo.server.log("Response from serial device: " + responseString + ", of length " + str(stringLen) + " characters") ## Just add the following line to have the response update "your" Indigo variable. indigo.variable.updateValue("YourVar", responseString)
Hope this helps, Jim
This was very helpful. But at this point your response from the serial device is initiated by a command sent to the device. In my case and perhaps in the general case the device initiates by itself and sends a serial command. It would be perhaps helpful to all if you could log to the indigo.server.log at the appropriate location serial strings coming from the serial device that were initiated by the device and not as a response. In my case with Serial Bridge I was doing this in a script so I get a whole line: repeat until singleCharVal is 13 set singleCharVal to read byte from source connectionName set myLine to myLine & (ASCII character of singleCharVal) end repeat Then if we can put myLine into indigo.server.log It would be best if this would all be added to your plugin as commented code. Then I can take it from there and parse the line and issue commands as needed. Thanks, Richard
|
| Sat Nov 26, 2011 6:52 pm |
|
 |
|
yergeyj
Joined: Dec 29, 2004 Posts: 239
|
 Re: Simple Serial Plugin - just to use for debugging
dfiedler wrote: This was very helpful. But at this point your response from the serial device is initiated by a command sent to the device. In my case and perhaps in the general case the device initiates by itself and sends a serial command. It would be perhaps helpful to all if you could log to the indigo.server.log at the appropriate location serial strings coming from the serial device that were initiated by the device and not as a response.
In my case with Serial Bridge I was doing this in a script so I get a whole line:
repeat until singleCharVal is 13 set singleCharVal to read byte from source connectionName set myLine to myLine & (ASCII character of singleCharVal) end repeat
Then if we can put myLine into indigo.server.log
It would be best if this would all be added to your plugin as commented code. Then I can take it from there and parse the line and issue commands as needed.
Thanks, Richard
I think what you are looking for is already included, and commented, in the Simple Serial plugin, as part of the concurrentSerialThread portion of the serialdevice.py: - Code: Select all
############################################################################################## def concurrentSerialThread(self, devId, conn, commandQueue): try: self.plugin.debugLog("Starting concurrent serial communications.") while True:
################################################################################## # First, on each pass read/decode any commands from the serial device. self.readSerialBuffer(devId, conn)
################################################################################## # Next, send commands from those queued. # Use a copy of the queue to avoid confusion if added to while executing. # Check for command to terminate thread, and if present, raise exception to stop thread. # Clear commands executed here, but not any added while executing. Need to first # get fresh copy of device properties, in case any commands were added # while this thread was processing the working queue. while not commandQueue.empty(): lenQueue = commandQueue.qsize() self.plugin.debugLog("Queue has " + str(lenQueue) + " command(s) waiting.") command = commandQueue.get() if command == "stopconcurrentSerialThread": self.plugin.debugLog("Raising exception to stop concurrent thread.") raise self.StopThread self.plugin.debugLog("Processing command: " + command) self.sendSerialCmd(devId, conn, command) self.plugin.debugLog(command + " command completed.") commandQueue.task_done()
The self.readSerialBuffer section does what I believe you had in you AppleScripts? Jim
|
| Sat Nov 26, 2011 8:17 pm |
|
 |
|
yergeyj
Joined: Dec 29, 2004 Posts: 239
|
 Re: Simple Serial Plugin - just to use for debugging
dmeeker@mac.com wrote:Jim, Thanks for the quick response. So, in the text box where I designate what string to send over the port, I am typing: \x02\x00\x01\x0c\x01\x10 Did you mean that? (one single command) Or do you intend the \ to be line breaks? In any case, when I send this over the port, my log shows: Nov 25, 2011 8:53:45 AM Action Group Test - Query Zone Name copy Simple Serial Plugin Debug Queue has 1 command(s) waiting. Simple Serial Plugin Debug Processing command: \x02\x00\x01\x0c\x01\x10
Simple Serial Plugin Debug Sending command:\x02\x00\x01\x0c\x01\x10 . Simple Serial Plugin Response from serial device: , of length 0 characters Simple Serial Plugin Debug \x02\x00\x01\x0c\x01\x10 command completed.
Dave, Just for kicks, and because I can't test anything anymore with my pool (serial adaptor) off for the year, can you try sending the command as above, but enclosed in single quotes: '\x02\x00\x01\x0c\x01\x10' and let me know what happens? Otherwise, I think I'll reach out to Jay or Matt with a new post to get this solved - it's something easy in python that I'm missing. [BTW, i don't think the "hexify" command is the answer.] Thanks, Jim
|
| Sun Nov 27, 2011 9:00 am |
|
 |
|
dmeeker@mac.com
Joined: Aug 26, 2011 Posts: 73
|
 Re: Simple Serial Plugin - just to use for debugging
Jim, I sent the exact string: '\x02\x00\x01\x04\x16\x5B' No response. Here are the logs: Nov 27, 2011 1:14:32 PM Action Group Audio Test Simple Serial Plugin Debug Queue has 1 command(s) waiting. Simple Serial Plugin Debug Processing command: '\x02\x00\x01\x0c\x01\x10' Simple Serial Plugin Debug Sending command:'\x02\x00\x01\x0c\x01\x10' . Simple Serial Plugin Response from serial device: , of length 0 characters Simple Serial Plugin Debug '\x02\x00\x01\x0c\x01\x10' command completed.
|
| Sun Nov 27, 2011 1:13 pm |
|
 |
|
yergeyj
Joined: Dec 29, 2004 Posts: 239
|
 Re: Simple Serial Plugin - just to use for debugging
dmeeker@mac.com wrote:Jim, I sent the exact string: '\x02\x00\x01\x04\x16\x5B' No response. Here are the logs: Nov 27, 2011 1:14:32 PM Action Group Audio Test Simple Serial Plugin Debug Queue has 1 command(s) waiting. Simple Serial Plugin Debug Processing command: '\x02\x00\x01\x0c\x01\x10' Simple Serial Plugin Debug Sending command:'\x02\x00\x01\x0c\x01\x10' . Simple Serial Plugin Response from serial device: , of length 0 characters Simple Serial Plugin Debug '\x02\x00\x01\x0c\x01\x10' command completed.
OK. I made a separate post, and Matt replied with a good idea for how to handle this. I'll get to it as soon as possible, post an update, and send it to you. Jim
|
| Sun Nov 27, 2011 2:55 pm |
|
 |
|
yergeyj
Joined: Dec 29, 2004 Posts: 239
|
 Re: Simple Serial Plugin - just to use for debugging
NOTE: Version 0.9.1 posted 27-Nov-2011.
Although there is still a single action, it now has three variants, to allow text, binary or hexadecimal strings to be sent to the serial device, with the latter two entered as comma delimited strings.
Please send another PM if you would like the latest version of the plugin.
Jim
|
| Sun Nov 27, 2011 7:53 pm |
|
 |
|
dmeeker@mac.com
Joined: Aug 26, 2011 Posts: 73
|
 Re: Simple Serial Plugin - just to use for debugging
Jim, Thanks for the latest version of the plugin. I got it installed, and started playing around a bit. While I am not seeing the controller device (receiver of the rs232 commands) respond as I would expect it to, I did run a serial port sniffer and did see a bit of activity come back in my direction when I queried the name of the current mp3 that was playing on the device. Having said that, the simple commands (change audio zone, input source, volume, etc) still don't seem to be working. Going back to one of the simplest commands: Control Mute for an Audio Zone (Per the Docs they sent): Head(1 byte): 0x02 Reserved Byte(1 byte): 0x00 Zone Address(1 byte) : 0 through 16 Command(1 byte) 0x04 Data (1 byte): 0x1E (on) or 0x1f(Off) Example: Zone1 Mute On : 0x02 + 0x00 + 0x01 + 0x04 + 0x1E + Checksum Zone1 Mute Off : 0x02 + 0x00 + 0x01 + 0x04 + 0x1F + Checksum I took out the programmer calculator and added these values up to get the checksum. For the sake of this example, I am working with "mute off". The result was the following: Zone1 Mute Off : 0x02 + 0x00 + 0x01 + 0x04 + 0x1F + 0x26 Based on the back and forth we have had, I have converted this to the following: 02,00,01,04,1F,26 In the plugin, I have tried to both send this as HEX as well as Binary. My assumption is that HEX is what I want. In either case, I send the command, see the following in the logs, but the mute control doesn't do anything. Starting Up / Reloading Plugin Starting plugin "Simple Serial Plugin 0.9.1" (pid 3284) Plugin "Simple Serial Plugin" connected Plugin "Simple Serial Plugin 0.9.1" started Simple Serial Plugin Debug <<-- entering deviceStartComm, Device: SerialTest; ID=71425186, Type=simpleSerialCommunicator Simple Serial Plugin Debug Serial Port Name is /dev/cu.PL2303-00001004 Simple Serial Plugin Debug Serial Port Baud Rate is 38400 Simple Serial Plugin Debug Serial Port Parity is N Simple Serial Plugin Debug Serial Port Data Bits are 8 Simple Serial Plugin Debug Serial Port Stops Bits are 1 Simple Serial Plugin Debug Device name is SerialTest Simple Serial Plugin Debug Starting concurrent serial communications. Simple Serial Plugin Debug Started concurrent thread. Simple Serial Plugin Debug exiting deviceStartComm -->>
As HEX Nov 28, 2011 10:54:34 AM Action Group Unmute Kitchen Audio (Zone 1) Simple Serial Plugin Improper comma separated hexadecimal data?! Simple Serial Plugin Debug Queue has 1 command(s) waiting. Simple Serial Plugin Debug Processing command: Simple Serial Plugin Debug Sending command: Simple Serial Plugin Response from serial device: , of length 0 characters Simple Serial Plugin Debug As BinaryNov 28, 2011 11:04:52 AM Action Group Unmute Kitchen Audio (Zone 1) Simple Serial Plugin Improper comma separated binary data?! Simple Serial Plugin Debug Queue has 1 command(s) waiting. Simple Serial Plugin Debug Processing command: Simple Serial Plugin Debug Sending command: Simple Serial Plugin Response from serial device: , of length 0 characters Simple Serial Plugin Debug Because I am at work, I can only remote into the server at this point. Tonight, when I get home from work, I will sit down in front of one of these panels and try to send a bunch of different commands to see if I can get anything working. I can also try to "sniff" the serial port traffic to see what is going on. That's the latest. Dave
|
| Mon Nov 28, 2011 11:07 am |
|
 |
|
dmeeker@mac.com
Joined: Aug 26, 2011 Posts: 73
|
 Re: Simple Serial Plugin - just to use for debugging
Quick update... I realize what we have so far should "just work".
I asked one of the senior engineers on my team to take a look at the windows app that came with the multi-zone audio controller to see if he can figure out what (exactly) the messages that are being sent in their windows app look like.
It hit me that the documentation is pretty bad, so maybe they just left something out. I should know more by EOD.
dave
|
| Mon Nov 28, 2011 11:44 am |
|
 |
|
dmeeker@mac.com
Joined: Aug 26, 2011 Posts: 73
|
 Re: Simple Serial Plugin - just to use for debugging
One more note: I see the following in the logs. I am thinking that when someone in the house touches a control panel, the controller is sending a status update back over the port: Nov 28, 2011 1:12:09 PM Simple Serial Plugin Response from serial device:
Nov 28, 2011 1:15:30 PM Simple Serial Plugin Response from serial device:
Nov 28, 2011 1:19:07 PM Simple Serial Plugin Response from serial device:
Nov 28, 2011 1:22:00 PM Simple Serial Plugin Response from serial device:
Nov 28, 2011 1:23:25 PM Simple Serial Plugin Response from serial device:
|
| Mon Nov 28, 2011 1:25 pm |
|
 |
|
yergeyj
Joined: Dec 29, 2004 Posts: 239
|
 Re: Simple Serial Plugin - just to use for debugging
dmeeker@mac.com wrote:Jim, Based on the back and forth we have had, I have converted this to the following: 02,00,01,04,1F,26 In the plugin, I have tried to both send this as HEX as well as Binary. My assumption is that HEX is what I want. In either case, I send the command, see the following in the logs, but the mute control doesn't do anything. As HEX Nov 28, 2011 10:54:34 AM Action Group Unmute Kitchen Audio (Zone 1) Simple Serial Plugin Improper comma separated hexadecimal data?! Simple Serial Plugin Debug Queue has 1 command(s) waiting. Simple Serial Plugin Debug Processing command: Simple Serial Plugin Debug Sending command: Simple Serial Plugin Response from serial device: , of length 0 characters Simple Serial Plugin Debug Dave
Sorry Dave, Version 0.9.1 was not coded correctly to send the hex string. Should be fixed in v0.9.2. Jim
|
| Mon Nov 28, 2011 8:46 pm |
|
 |
|
yergeyj
Joined: Dec 29, 2004 Posts: 239
|
 Re: Simple Serial Plugin - just to use for debugging
dmeeker@mac.com wrote:One more note: I see the following in the logs. I am thinking that when someone in the house touches a control panel, the controller is sending a status update back over the port: Nov 28, 2011 1:12:09 PM Simple Serial Plugin Response from serial device:
Nov 28, 2011 1:15:30 PM Simple Serial Plugin Response from serial device:
Nov 28, 2011 1:19:07 PM Simple Serial Plugin Response from serial device:
Nov 28, 2011 1:22:00 PM Simple Serial Plugin Response from serial device:
Nov 28, 2011 1:23:25 PM Simple Serial Plugin Response from serial device:
Dave, You are correct, this implies there are strings being sent back from the device. I am presuming that because they are low-level hexadecimal, they cannot be presented in the log directly. I will try to set up a "decoder" that displays the response as text, binary or hexadecimal for the next version. Jim
|
| Mon Nov 28, 2011 8:59 pm |
|
|
Who is online |
Users browsing this forum: Majestic-12 [Bot] and 0 guests |
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot post attachments in this forum
|
|