Page 1 of 1

Serial device configuration question

Posted: Sun Aug 23, 2009 12:54 am
by dlmorgan999
I'm about to create a new serial device. The protocol for this devices requires all strings to start with a 02H and end with a 03H. The actual command text is all ASCII though. The only way I can think to do this is to specify all the commands as hex values for each of the ASCII characters. I suppose I could enter the 03H in the command terminator string but this still doesn't take care of the leading 02H. Does anyone have a better idea?

-- Dave

Re: Serial device configuration question

Posted: Sun Aug 23, 2009 4:39 am
by Richard Naninck
Funny, sounds very much like my Panasonic Projector setup.
Protocol being:

STX C1 C2 C3 : P1 P2 P3 P4 ETX
Where STX is 02H and ETX is 03H

Included below my script that handles the receive and send part. I stripped lots of Subs because of text length. However, if this is what you are looking for, I can send you the rest as well..

Good luck.

Code: Select all

Option Explicit
On Error Resume Next

Dim Action
Dim ActionReceive
Dim ReceivedData
Dim Status
Dim RxItem
Dim intSleep
Dim intWaveform


'-------------------------------------------------------
'- Main: Checks Received Data and Handles Send Data ----
'-------------------------------------------------------
RxItem      = ""
intSleep    = 0
intWaveform = 0
SetPropertyValue "Projector Status.Action Receive", "Waiting"

Do
	Sleep 1
	'ActionReceive gets set by a task that triggers on a change in ReceivedData
	'This is done to accept duplicates in ReceivedData for being able to get multiple of the same Power State updates
	ActionReceive = GetPropertyValue("Projector Status.Action Receive")
	If ActionReceive = "GetReceivedData" Then
		ReceivedData = GetPropertyValue("Projector.Received Data")
		Call Handle_ReceivedData(ReceivedData)
		SetpropertyValue "Projector Status.Action Receive", "Waiting"
		Sleep 100
	End If
		
	Action = GetPropertyValue("Projector Status.Action")
	If Action <> "Waiting" Then
		If Action <> "" Then
			Call Handle_SendData(Action)
		End If
		SetpropertyValue "Projector Status.Action", "Waiting"
		Sleep 100
	End If
Loop


'-------------------------------------------------------
'- Handle Received Data --------------------------------
'-------------------------------------------------------
Sub Handle_ReceivedData(Data)
Dim DataItem

	Status  = ""
	Data    = Left(Data, Len(Data) - 1)
	Data    = Right(Data, Len(Data) - 1)
		
	If RxItem <> "" Then
		Select Case RxItem
			Case "QPW": Call Rx_Power(Data)
			Case "QFZ": Call Rx_FreezeStatus(Data)
			Case "QIN": Call Rx_InputSource(Data)
			Case "QOT": Call Rx_SleepStatus(Data)
			Case "QPM": Call Rx_PictureModeStatus(Data)
			Case "QWM": Call Rx_WaveformStatus(Data)
		End Select
		Status = RxItem
		RxItem = ""
	Else
		DataItem = Split(Data, ":")
		Select Case DataItem(0)
			Case "POF", "PON": Call Rx_Power(Data)
			Case "OFZ": Call Rx_FreezeStatus(DataItem(1))
			Case "IIS": Call Rx_InputSource(DataItem(1))
			Case "OOT": Call Rx_SleepStatus(DataItem(1))
			Case "VPM": Call Rx_PictureModeStatus(DataItem(1))
			Case "OWM": Call Rx_WaveformStatus(DataItem(1))
			Case "ER401": Status = "Error: Incorrect command sent by computer"
		End Select
	End If
	
	SetPropertyValue "Projector Status.Status", Status & " - " & Data
End Sub


'-------------------------------------------------------
'- Handle Send Data --------------------------------
'-------------------------------------------------------
Sub Handle_SendData(Action)
Dim Data

	Data = Split(Action, "^") 'Typical Data "Power^On"
	Select Case Data(0)
		Case "Power"      : Call Tx_Power(Data(1))
		Case "InputSource": Call Tx_InputSource(Data(1)) 'Data(1) = Source (CP1, CP2, HD1, HD2, HD3, SVD, VID, RG1)
		Case "Menu"       : Call Send_Data("OMN")
		Case "Enter"      : Call Send_Data("OEN")
		Case "Back"       : Call Send_Data("OBK")
		Case "Button"     : Call Tx_Button(Data(1))      'Data(1) = Up, Down, Left, Right
		Case "Lens"       : Call Send_Data("OLE")
		Case "Default"    : Call Send_Data("OST")
		Case "Freeze"     : Call Tx_Freeze(Data(1))      'Data(1) = On, Off
		Case "Sleep"      : Call Tx_Sleep(Data(1))       'Data(1) = 0 .. 7
		Case "Blank"      : Call Send_Data("OSH")
		Case "Picture"    : Call Send_Data("OVM")
		Case "Waveform"   : Call Tx_Waveform(Data(1))    'Data(1) = 0 .. 8
		Case "Aspect"     : Call Send_Data("VS1")
		Case "PictureMode": Call Tx_PictureMode(Data(1)) 'Data(1) = Normal, Dynamic, Color 1, Color 2, Cinema 1, Cinema 2, Cinema 3 
		Case "Refresh"    : SetPropertyValue "Projector Refresh Script.State", "Running"
	End Select
End Sub


'-------------------------------------------------------
'- Subs and Functions below are for Received Data ------
'-------------------------------------------------------
'- Power State -----------------------------------------
'-------------------------------------------------------
Sub Rx_Power(Data)

	Select Case Data
		Case "000", "POF": SetPropertyValue "Projector Status.Power", "Off"
		Case "001", "PON": SetPropertyValue "Projector Status.Power", "On"
		Case Else : SetPropertyValue "Projector Status.Power", "---"
	End Select
End Sub


'-------------------------------------------------------
'- Freeze Status ---------------------------------------
'-------------------------------------------------------
Sub Rx_FreezeStatus(Data)

	Select Case Data
		Case "0" : SetPropertyValue "Projector Status.Freeze", "Off"
		Case "1" : SetPropertyValue "Projector Status.Freeze", "On"
		Case Else: SetPropertyValue "Projector Status.Freeze", "---"
	End Select
End Sub




'-------------------------------------------------------
'- Subs and Functions below are for Send Data ----------
'-------------------------------------------------------
'- (01) Set Power --------------------------------------
'-------------------------------------------------------
Sub Tx_Power(Data)

	Select Case Data
		Case "On"    : Call Send_Data("PON")
		Case "Off"   : Call Send_Data("POF")
		Case "Status": RxItem = "QPW" : Call Send_Data("QPW")
		Case "Toggle": 
			If GetPropertyValue("Projector Status.Power") <> "Off" Then
				Call Send_Data("POF")
			Else
				Call Send_Data("PON")
			End If
	End Select
End Sub


'-------------------------------------------------------
'- Set Input Source ------------------------------------
'-------------------------------------------------------
Sub Tx_InputSource(Data)

	Select Case Data
		Case "CP1"   : Call Send_Data("IIS:CP1")
		Case "CP2"   : Call Send_Data("IIS:CP2")
		Case "HD1"   : Call Send_Data("IIS:HD1")
		Case "HD2"   : Call Send_Data("IIS:HD2")
		Case "HD3"   : Call Send_Data("IIS:HD3")
		Case "SVD"   : Call Send_Data("IIS:SVD")
		Case "VID"   : Call Send_Data("IIS:VID")
		Case "RG1"   : Call Send_Data("IIS:RG1")
		Case "Status": RxItem = "QIN" : Call Send_Data("QIN")
	End Select
	
	If RxItem = "" Then 'Freeze is reset to Off after switching the Input Source
		SetPropertyValue "Projector Status.Freeze", "Off"
	End If
End Sub


'-------------------------------------------------------
'- Send Data to projector ------------------------------
'-------------------------------------------------------
Sub Send_Data(Data)

	SetPropertyValue "Projector.Send Data", Chr(2) & Data & Chr(3)
End Sub

I put some screenshots in as well. A bit over the top maybe, but now you got it all :wink:

Re: Serial device configuration question

Posted: Sun Aug 23, 2009 9:25 am
by dlmorgan999
Hi Richard,

Somehow I figured it would be you that would answer. :wink:

Coincidentally, it is for a new Panasonic Plasma TV that I just bought. As such I suspect the commands are exactly the same. If you wouldn't mind creating an export with all of the required components that would save me a bunch of time! :D

-- Dave

Re: Serial device configuration question

Posted: Sun Aug 23, 2009 3:29 pm
by Richard Naninck
Well since we share the same choice of hardware it figures.
Not sure what the protocol for a Plasma TV from panasonic looks like, but the setup should be the same. Even if more, less or different option are available, they should be easy to add.
Included the export. Hopefully I got it all. I didn't include the theme panel since that probably has too many dependencies and it wouldn't help you. I am not very good at creating exports and I will never run an import from somebody else since it adds stuff to the system in a different way I would want it too. You could just look at the screen shots and create your own devices and properties. Nice buy! I am very pleased with my Panasonic projector.

Re: Serial device configuration question

Posted: Mon Aug 24, 2009 9:35 pm
by Steve Horn
Dave, this is somewhat OT, but do you have or know of the discrete IR codes (Pronto format) for your Panasonic Plasma? I recently got a 42" Panasonic Plasma, and found some of the discrete codes (pwr on, off) at remotecentral.com. but I'm lacking the screen format (aspect ratio) codes (full, justified, zoom, H-fill).

Re: Serial device configuration question

Posted: Tue Aug 25, 2009 12:13 am
by dlmorgan999
Steve: I just got the Panasonic TV and since it supports RS-232 I never went hunting for IR codes. Sorry.

Richard: you are right about running imports. It didn't work as well as I would have liked (I made a backup first though). I *was* able to look inside the hbx file though and figure out what I needed to do. Thanks for the help!

-- Dave

Re: Serial device configuration question

Posted: Sun Jun 21, 2015 4:52 pm
by markd
OK, I know this is a big time zombie thread, but I am sooooo close... I am trying to set up control for an Extron matrix switch. It is a serial device that I want to send arbitrary commands to.
I followed Richard's plan here, right to the letter (I think ;-). My ICC looks like his, with Send Data for a name, and %1% for the data. In my serial device, I have a Send Data property. but when I set it (from a script, just like in the example) I get an error in the log-

Unable to find associated Command associated with Property and Value [Send Data.V8$]

My data is V8$, which is what I want to send out on the serial port.

What am I missing??

thanks

Markd

Re: Serial device configuration question

Posted: Sun Jun 21, 2015 5:06 pm
by Richard Naninck
watching a movie right now so really no clue if I am processing this zobie thread (2009 :o ) the right way but maybe this is what you are missing. The wildcard * attached to the property...

Re: Serial device configuration question

Posted: Sun Jun 21, 2015 6:39 pm
by markd
Thanks! Wow, that is obscure.... how the heck did you figure that out??
Still not working, but that error is gone. Back to studying...

Re: Serial device configuration question

Posted: Mon Jun 22, 2015 12:19 pm
by Richard Naninck
Been doing it like this since 2006. The wildcard binds the same way standard serial command words do. It is in the help files :D

Re: Serial device configuration question

Posted: Tue Jun 23, 2015 9:24 pm
by markd
Yup, now that you mention it, there it is! RTFM! ;-) I guess I was thrown off by the whole concept of assigning commands- wasn't what I was expecting. By the time I got my head around that, I was looking at the posts in the forums.

My setup is working now- not sure what changed, although I did kill HB and and reboot the whole computer, so maybe something there? Anyways, thanks for the help (as always)!

Markd