Don,
I have pretty much the same plan. I replaced all Denon Amps with 2 Monoprice 6x6 amps. 12 zones independently controlled with 6 sources available. In the old installation I would request to turn on a device and status would change but I didn't always get result expected. For my new installation I plan to query the device for all information and set status accordingly.
Announcement
Collapse
No announcement yet.
Script to parse data returned from serial port - help needed
Collapse
X
-
Interesting... I'm doing something similar with my Denon amp. I trap for a specific device, say 'Volume' and if the incoming string contains the substring that identifies itself as volume, I set the device string and value to that. If it is something non numeric, like what imput I set the string to that and the value to a 1. When Homeseer starts up I have a script that quieries the receiver for the corresponding values. In my case a 'XM?<CR>' asks the amp what's up with all the XM stuff, and populate the devices with the results.
Leave a comment:
-
Got it working.
Substring() was the way to go. It appears the data is processed line by line as you had suggested. Not all responses will be this form so I have applied an If Then statement that checks length of string before I do anything with it. Seems to work.
Now for the coding of setting devices values based on what comes back. My goal is to always query the amps and use the real values to set data shown in HSTouch. This way I know for sure that the events happened as expected.
I will see how it goes. If you have a better idea please share.
Thanks for the help.
Leave a comment:
-
Originally posted by Dr_Crash View PostI finally got the response to hit the log exactly as shown. I guess you are saying I can then process each line as stand alone and shouldn't have a problem.
I'll give it a shot. You guys have been a huge help thus far.
Leave a comment:
-
I'm unsure what stage you are at in terms of getting this data into HomeSeer, if you have a script already running and these separate lines are coming into the HomeSeer log then it is likely that the strings are split by using the carriage return and line feed characters and that is running the callback script every time a new line of it applies (this is ideal because you can manipulate it in this script).
I'll give it a shot. You guys have been a huge help thus far.
Leave a comment:
-
Originally posted by Dr_Crash View Postmrhappy- I understand what you are saying. The problem is I don't exactly understand the response from the serial port. It is formatted exactly as the response was given in the first post. Is this considered to be streaming? In other words should I be thinking about processing data as if it were one string that looked like #>110001..... #>1200001... #>1300001...etc?
Each line contains information about power status for that zone, volume, bass, treble, source...I want to use this information to set correct values in HStouch and certain device indicators.
If not then it is not necessarily the end of the world, if all of that does arrive in one block and it does not have anything between the sets of data then you can use the String.Split function and split the strings on the basis of lets say the # character, from there you can fill an array with the data and then work on it to update devices etc.
Leave a comment:
-
mrhappy- I understand what you are saying. The problem is I don't exactly understand the response from the serial port. It is formatted exactly as the response was given in the first post. Is this considered to be streaming? In other words should I be thinking about processing data as if it were one string that looked like #>110001..... #>1200001... #>1300001...etc?
Each line contains information about power status for that zone, volume, bass, treble, source...I want to use this information to set correct values in HStouch and certain device indicators.
Leave a comment:
-
Originally posted by Dr_Crash View PostI will try substring().
I think I have a different problem as well. I am trying to figure out how to put each line of the response into a buffer. I have tried several ways with no luck. Pls keep in mind that I am a complete novice programmer and just keep trying different things. Any help would be appreciated.
Thanks,
Chris
Leave a comment:
-
Please note that I am also a paste and pray kind of guy...
This example might help you or just confuse you. Hope it helps
PHP Code:Public Class Form1
Private _SerialCommunicationThread As Thread
Private _DataQueue As Queue = Queue.Synchronized(New Queue())
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Me._SerialCommunicationThread = New Thread(AddressOf THREAD_SerialCommunication)
Me._SerialCommunicationThread.Priority = ThreadPriority.AboveNormal
Me._SerialCommunicationThread.Start()
TIMER_Main.Enabled = True
End Sub
Private Sub THREAD_SerialCommunication()
Try
Dim SerialPort As New SerialPort("COM1", 9600, Parity.None, 8, StopBits.One)
SerialPort.ReadTimeout = 1000
SerialPort.Open()
Dim Buffersize As Integer = 1024
Dim Buffer(Buffersize - 1) As Byte
Do
Dim DataRead = SerialPort.Read(Buffer, 0, Buffer.Length)
Dim BufferCut(DataRead - 1) As Byte
For i As Integer = 0 To BufferCut.Length - 1
Buffer(i) = BufferCut(i)
Next
Me._DataQueue.Enqueue(BufferCut)
Loop
Catch ex As Exception
MsgBox("An error has occured:" & vbCrLf & vbCrLf & ex.ToString)
End Try
End Sub
Private Sub TIMER_Main_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TIMER_Main.Tick
While Me._DataQueue.Count > 0
Dim Bytes = Me._DataQueue.Dequeue
Dim Text = Encoding.Default.GetString(Bytes)
RTF_Text.AppendText(Text)
End While
End Sub
End Class
Leave a comment:
-
I will try substring().
I think I have a different problem as well. I am trying to figure out how to put each line of the response into a buffer. I have tried several ways with no luck. Pls keep in mind that I am a complete novice programmer and just keep trying different things. Any help would be appreciated.
Thanks,
Chris
Leave a comment:
-
Whenever I do something like that I test the length of the string (if you absolutely know it is fixed) first, then possibly check the starting two characters are the #> characters before I started to manipulate it.
It is unlikely but just in case you only got a half string back from the device and then trying to get a substring failed, you can just use substring but you could also then check the component parts to make it valid. Like SubString(2,3) might be the amp zone you could then send that to a function to check if it is a valid zone (say 01 to 12 or whatever)...
You don't have to error check and you can probably get away with it but it depends on how critical your data is and whether you could live with it if it came up with an unexpected error and how you deal with that error.
Leave a comment:
-
Substring() will be your friend.
See for examples http://www.dotnetperls.com/substring-vbnet
Leave a comment:
-
Script to parse data returned from serial port - help needed
I am in need of assistance on how to parse data returned from serial port. I am using vb.net.
Command sent is "?10"
The response is:
#>1100010000200710100100
#>1200010000200710100100
#>1300010000200710100100
#>1400010000200710100100
#>1500010000200710100100
#>1600010000200710100100
I get a response with 6 strings. In each string each 2 digits mean something. For example on the first response #>110001....the 11 means Amp1 Zone 1. The 00 means something, the 01 means something...etc.
I need to parse all of this data into correct items for HS3. Any ideas?Tags: None
Leave a comment: