Author Topic: Exception Reading from PLC with modbus TCP  (Read 940 times)

DanieLoche

  • Guest
Exception Reading from PLC with modbus TCP
« on: August 11, 2016, 06:32:40 AM »
Hello,

I'm having an issue using the Settings of my application to change the PLC Addresses for communication...

Here is attached a screenshot of the exception I got with the kind of line code concerned (also, Read with only the Address arguments raises the exception too)

On the other side, I use in Form load this kind of code, that seems to work:
Me.PilotLight8.PLCAddressValue = My.Settings.S151

In My.Settings are strings like "40001".

Note : I'm actually doing tests without PLC to see if everything turns ok with connection "issues". Hope that's not the problem... ^^


EDT: on the same subject, I noticed that with this configuration, a write() try slows a lot the application... takes about 2-3 seconds before going to the next step. Is that due to the wait of a timeout or is there another problem ?
« Last Edit: August 11, 2016, 08:45:26 AM by DanieLoche »

Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5271
    • View Profile
    • AdvancedHMI
Re: Exception Reading from PLC with modbus TCP
« Reply #1 on: August 11, 2016, 09:08:14 AM »
The -34 is a failed to connect error. When reading/writing via code, it is up to you to use Try-Catch block to handle exceptions.

The Write is delaying because it is a synchronous operation and holds the UI thread until the write fails on a timeout.

DanieLoche

  • Guest
Re: Exception Reading from PLC with modbus TCP
« Reply #2 on: August 11, 2016, 09:32:43 AM »
Okay thanks a lot. :)

Is it a good idea to put the Write instruction in a background worker so, or is this breaking how the driver works ?

Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5271
    • View Profile
    • AdvancedHMI
Re: Exception Reading from PLC with modbus TCP
« Reply #3 on: August 11, 2016, 09:40:03 AM »
You can use BeginWite for asynchronous writing, but it will then become up to you to ensure you don't overflow the buffer by writing faster than the device can process it.