Project

General

Profile

Bug #571

GenericIO - Incorrectly sending Address fields to device

Added by thechad almost 4 years ago. Updated over 3 years ago.

Status:
Closed
Priority:
Normal
Assignee:
-
Category:
-
Target version:
-
Start date:
05/03/2015
Due date:
% Done:

0%

Estimated time:
Resolution:

Description

Hi Folks,
It looks like there have been some bugs that have crept into GenericIO with the recent code changes (not sure what release this happened in).

Summary:
The code is not operating as I had designed it and is appending the address fields to the sent command.
This is not desired or required as the address (if needed) forms part of the command as entered by the user.
Code should be as follows:

'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
' called from devices module to send a command to serial/TCP interface
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Public Sub SendCommand(sAddress As String, sCmd As String)

  Dim sRawCmd As String

  ' Replace control characters in the string if present with actual values
  sRawCmd = Replace$(sCmd, "\\r", Chr$(13))
  sRawCmd = Replace$(sRawCmd, "\\n", Chr$(10))
  sRawCmd = sRawCmd & "\r\n"                                  '<---CORRECT code
'  sRawCmd = Replace$(sAddress, "|", "") & sRawCmd & "\r\n"    <---Incorrect code

The way it was designed was that you could send a command directly to the attached serial/TCP device by setting the "To Value" in "Action"/"Set Device".

eg. for this device ( which is an arduino that has 4 relays (R1, R2 R3 and R4))

You would create an Event Action that sends the required command string to the device.

Now this next BIT IS REALLY IMPORTANT!
Be sure to set only "Value1" as the other values will no be actually set/send out, only the DomotiGa internal value will be updated.
Value1 is special case as per this code in "Devices.module"

    ' Only do the SendCommand if it valueid and the device is switchable/dimmable
    If iValueNum = 1 And (rDevice!switchable Or rDevice!dimable) Then
      If Main.bDevicesDebug Then Main.WriteDebugLog("[Devices] Device '" & sDeviceName & "' is set as switchable or dimable, so call SendCommand() of plugin.")
      ' call plugin's sendcommand routine (if any)
      If Plugin.SendCommand(sPluginName, iInstance, sAddress, sValue, sDeviceName) Then
        ' TODO: remove if value control/feedback params are implemented
        ' until then this workaround is needed for some plugins
        Select sPluginName
          Case "GenericIO", "OpenZWave" 
            ' don't do valueupdate, these come back from devices

ie. the following will send the string "put_whatever_you_want_sent_here" to the device.

If say the serial/TCP command to turn relay 1 on was "R1:1", then you would have the following.

HOWEVER...some additional code has been added that requires the device to be either switchable or dimable.
You need to set the device to "Switchable" as the code in "Devices.module" now requires this...


    ' Only do the SendCommand if it valueid and the device is switchable/dimmable
<snip>
    Else
      If Main.bDevicesDebug Then Main.WriteDebugLog("[Devices] Device '" & sDeviceName & "' is not set as switchable or dimable, so only do a value update.")
      Devices.ValueUpdate(iDeviceId, iValueNum, sValue)

Also, the GenericIO.class has been setup to incorrectly add the address to the command.
This code will cause the following message to be incorrectly sent when you try to send just "R1:1"

2015/05/03 14:18:31 [GenericIO] SendCommand 'R1:1' to /dev/ttyUSB0 as 'R1=R2=R3=R4=R1:1'

When it should be ...
2015/05/03 14:18:31 [GenericIO] SendCommand 'R1:1' to /dev/ttyUSB0 as 'R1:1'

The corrected code in "GenericIO.class" is as follows.

'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
' called from devices module to send a command to serial/TCP interface
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Public Sub SendCommand(sAddress As String, sCmd As String)

  Dim sRawCmd As String

  ' Replace control characters in the string if present with actual values
  sRawCmd = Replace$(sCmd, "\\r", Chr$(13))
  sRawCmd = Replace$(sRawCmd, "\\n", Chr$(10))
  sRawCmd = sRawCmd & "\r\n"                                  '<---CORRECT code
'  sRawCmd = Replace$(sAddress, "|", "") & sRawCmd & "\r\n"    <---Incorrect code
genericio2.png (39 KB) genericio2.png thechad, 05/03/2015 07:48 AM
genericio1.png (45 KB) genericio1.png thechad, 05/03/2015 07:48 AM
genericio3.png (34.8 KB) genericio3.png thechad, 05/03/2015 07:48 AM
genericio4.png (33 KB) genericio4.png thechad, 05/03/2015 07:48 AM
2359
2360
2361
2362

History

#1 Updated by rdnzl almost 4 years ago

  • Status changed from New to Feedback

I have pushed you bugfix to the beta branch, thanks!

#2 Updated by thechad almost 4 years ago

Thanks for the quick fix Ron.

Sorry for the dumb question... but can you point me at the wiki entry for how I pull the beta branch?

#3 Updated by rdnzl almost 4 years ago

Have a peek here...
https://domotiga.nl/projects/domotiga/wiki/DomotiGa_Installation#DomotiGa

But you can ofcourse also only copy over the needed files, at this time there are no database changes done in the beta branch (but this changes over time of course)

#4 Updated by thechad almost 4 years ago

Tested the beta and working as expected.

Thanks!

#5 Updated by wwolkers over 3 years ago

  • Status changed from Feedback to Closed

Fixed in 1.0.022

Also available in: Atom PDF