Author Topic: Failed to write value.. After upgrade from 399k to 399x  (Read 2142 times)

eci

  • Newbie
  • *
  • Posts: 19
    • View Profile
Failed to write value.. After upgrade from 399k to 399x
« on: April 12, 2021, 12:02:37 PM »
Hello,

I'm sure this is a simple fix that I'm overlooking.  I have upgraded my project from 399k to 399x.  I'm using visual studio 2017 and communicating with an AB SLC 5/03 using the SerialDF1forSLCMicroCom1 driver.  This project is for an oven controller.

Everything is working as far as I can tell except for inputting times.  I am using DigitalPanelMeter as the controls.  Temperature inputs using the Keypad work correctly.  Using the Keypad to input a time throws the error "Failed to write value. Input string was not in a correct format."

Time inputs have a KeypadScaleFactor involved that I believe is causing the error.  A KeypadScaleFactor of .01667 was used for version 399k (we input minutes into the HMI to send as seconds to the PLC).  I have also tried a scale factor of 60 (.01667 always seemed incorrect to me for the input, but it previously worked).

Could someone point me in the right direction?

Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5322
    • View Profile
    • AdvancedHMI
Re: Failed to write value.. After upgrade from 399k to 399x
« Reply #1 on: April 12, 2021, 02:48:09 PM »
This error comes from the DigitalPanelMeter. at line 356 in this code:
Code: [Select]
                    Try
                        '* V3.99y Beta 19 - added writing through subscriptionHandler for Tag Alias purposes
                        If KeypadScaleFactor = 1 Or KeypadScaleFactor = 0 Then
                            m_ComComponent.Write(m_PLCAddressKeypad, KeypadPopUp.Value)
                        Else
                            m_ComComponent.Write(m_PLCAddressKeypad, Convert.ToString(CDbl(KeypadPopUp.Value) / m_KeypadScaleFactor))
                        End If
                    Catch ex As Exception
                        System.Windows.Forms.MessageBox.Show("Failed to write value. " & ex.Message)
                    End Try

- In Solution Explorer, expand down the AdvancedHMIControls project
- Expand down the Controls folder
- Right Click DigitalPanelMeter.vb and select View Code
- Scroll down to line 361, which should be this  "m_ComComponent.Write(m_PLCAddressKeypad, Convert.ToString(CDbl(KeypadPopUp.Value) / m_KeypadScaleFactor))"
- Click to the left of it to add a break point. It will show up as a red circle
- Run the code and enter a value
- The program will stop at the break point
- Hover over KeypadPopUp.Value and KeypadPopUp.Value to see their current values. Post those values here

eci

  • Newbie
  • *
  • Posts: 19
    • View Profile
Re: Failed to write value.. After upgrade from 399k to 399x
« Reply #2 on: April 12, 2021, 03:31:22 PM »
Hello Archie,

My code is a bit different and it does not convert to a string.  I've attached some screen shots but below is the code in the version I have.
Code: [Select]
                    Try
                        If KeypadScaleFactor = 1 Or KeypadScaleFactor = 0 Then
                            m_ComComponent.Write(m_PLCAddressKeypad, KeypadPopUp.Value)
                        Else
                            Dim v As Double = CDbl(KeypadPopUp.Value)
                            Dim z As Double = v / m_KeypadScaleFactor
                            m_ComComponent.Write(m_PLCAddressKeypad, CDbl(KeypadPopUp.Value) / m_KeypadScaleFactor)
                        End If
                    Catch ex As Exception
                        System.Windows.Forms.MessageBox.Show("Failed to write value. " & ex.Message)
                    End Try

Thank you!


Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5322
    • View Profile
    • AdvancedHMI
Re: Failed to write value.. After upgrade from 399k to 399x
« Reply #3 on: April 12, 2021, 04:36:05 PM »
If you use F10 to step through that code, does it go to the exception? I'm wondering if that is the place the exception occurs.

eci

  • Newbie
  • *
  • Posts: 19
    • View Profile
Re: Failed to write value.. After upgrade from 399k to 399x
« Reply #4 on: April 12, 2021, 04:38:48 PM »
Below is what I have changed those lines of code to and it seems to work.  Do you seen any issue with it?  I only know enough programming to get myself into trouble.
Code: [Select]
                    Try
                        If KeypadScaleFactor = 1 Or KeypadScaleFactor = 0 Then
                            m_ComComponent.Write(m_PLCAddressKeypad, KeypadPopUp.Value)
                        Else
                            Dim v As Double = CDbl(KeypadPopUp.Value)
                            Dim z As Double = v / m_KeypadScaleFactor
                            'm_ComComponent.Write(m_PLCAddressKeypad, CDbl(KeypadPopUp.Value) / m_KeypadScaleFactor)
                            Dim c As Integer = Convert.ToInt16(z)
                            m_ComComponent.Write(m_PLCAddressKeypad, c)
                        End If
                    Catch ex As Exception
                        System.Windows.Forms.MessageBox.Show("Failed to write value. " & ex.Message)
                    End Try

Thank you again Archie

eci

  • Newbie
  • *
  • Posts: 19
    • View Profile
Re: Failed to write value.. After upgrade from 399k to 399x
« Reply #5 on: April 12, 2021, 04:44:28 PM »
It was throwing the exception at the write command right where you had me put the break point.  I don't think it liked the variable as a double.

Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5322
    • View Profile
    • AdvancedHMI
Re: Failed to write value.. After upgrade from 399k to 399x
« Reply #6 on: April 12, 2021, 04:53:11 PM »
With your change, if you write to a float register, it will round the value.

The part that I seem not be seeing is why z is calculated without and error, but when the same equation is used in the write method, it throws an error. This makes me think it is further in the driver where the error occurs.

eci

  • Newbie
  • *
  • Posts: 19
    • View Profile
Re: Failed to write value.. After upgrade from 399k to 399x
« Reply #7 on: April 12, 2021, 05:24:58 PM »
Thankfully rounding is just fine in my application.

I looked back at the DigitalPanelMeter code from the version 399k and it does use "m_ComComponent.Write(m_PLCAddressKeypad, CDbl(KeypadPopUp.Value) / m_KeypadScaleFactor)" so it probably is something to do with the driver.

Does my attached screen snip help at all?  I'm happy to play around with it if you'd like me to try different things.  The error is thrown before it attempts to write to the PLC so it should be easy to replicate.

Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5322
    • View Profile
    • AdvancedHMI
Re: Failed to write value.. After upgrade from 399k to 399x
« Reply #8 on: April 12, 2021, 05:55:14 PM »
Would you be able to try this in 3.99y Beta to see if it occurs in that version?

eci

  • Newbie
  • *
  • Posts: 19
    • View Profile
Re: Failed to write value.. After upgrade from 399k to 399x
« Reply #9 on: April 13, 2021, 09:08:45 AM »
It also occurs in 3.99y beta 38.  I am not sure how the drivers work, but this issue appears to be happening with all of the serial drivers.  The error is thrown before communication is attempted.

It only happens if the scale factor results in a decimal.

To replicate this all you need to do is put a DigitalPanelMeter on the main form of a fresh project, give it a Keypad scale factor of 2, keypad min 0 max 100, and send it to any of the SerialDF1 drivers with a PLCAddressKeypad of N17:1 for example.
Run the project, if you enter "4" into the keypad you'll get a "no response form PLC" error.  If you enter 5 you'll get a "input string was not in a correct format" error.

Vitor

  • Newbie
  • *
  • Posts: 20
    • View Profile
Re: Failed to write value.. After upgrade from 399k to 399x
« Reply #10 on: April 13, 2021, 03:02:09 PM »
It also occurs in 3.99y beta 38.  I am not sure how the drivers work, but this issue appears to be happening with all of the serial drivers.  The error is thrown before communication is attempted.

It only happens if the scale factor results in a decimal.

To replicate this all you need to do is put a DigitalPanelMeter on the main form of a fresh project, give it a Keypad scale factor of 2, keypad min 0 max 100, and send it to any of the SerialDF1 drivers with a PLCAddressKeypad of N17:1 for example.
Run the project, if you enter "4" into the keypad you'll get a "no response form PLC" error.  If you enter 5 you'll get a "input string was not in a correct format" error.

I have, some times ago with a Micrologix 1400, the same problem.
This tries to write a string with the decimal separator, be a coma or a point, to a integer element.
This its what i use to solve:

 m_ComComponent.Write(m_PLCAddressKeypad, CInt(CDbl(KeypadPopUp.Value) / m_KeypadScaleFactor))
« Last Edit: April 13, 2021, 03:05:54 PM by Vitor »

Godra

  • Hero Member
  • *****
  • Posts: 1447
    • View Profile
Re: Failed to write value.. After upgrade from 399k to 399x
« Reply #11 on: April 13, 2021, 09:41:22 PM »
I am not sure how accurate this code is but give it a try:

Code: [Select]
                    Try
                        If KeypadScaleFactor = 1 Or KeypadScaleFactor = 0 Then
                            m_ComComponent.Write(m_PLCAddressKeypad, KeypadPopUp.Value)
                        Else
                            Dim v As Double = CDbl(KeypadPopUp.Value)
                            Dim z As Double = v / m_KeypadScaleFactor
                            m_ComComponent.Write(m_PLCAddressKeypad, Convert.ToString(CInt(Math.Floor(z * Math.Pow(10.0F, CDbl(DecimalPosition))))))
                        End If
                    Catch ex As Exception
                        System.Windows.Forms.MessageBox.Show("Failed to write value. " & ex.Message)
                    End Try
« Last Edit: April 13, 2021, 09:55:56 PM by Godra »