Вход

Просмотр полной версии : Управление модулем вывода из Visual Basic NET (NModbus)



bkz
16.08.2016, 09:13
Подскажите в чём проблема. Два модуля подключены через COM порт, у модуля ввода 32 адрес, у модуля вывода - 16. Данные регистра с модуля ввода читаю свободно, но записать данные в модуль вывода не могу... Ошибка "Необработанное исключение типа "Modbus.SlaveException" в NModbus4.dll". Полный текст ошибки:

Выдано исключение типа "Modbus.SlaveException".
Function Code: 134
Exception Code: 1 - The function code received in the query is not an allowable action for the server (or slave). This may be because the function code is only applicable to newer devices, and was not implemented in the unit selected. It could also indicate that the server (or slave) is in the wrong state to process a request of this type, for example because it is unconfigured and is being asked to return register values.

Листинг программы:

Imports Modbus.Device
Imports System.IO

Public Class Form1

Public master As ModbusSerialMaster
Public serPort As Ports.SerialPort
Public zzz As UShort()

Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
serPort = New Ports.SerialPort("COM4", 115200, Ports.Parity.None, 8, Ports.StopBits.One)
master = ModbusSerialMaster.CreateRtu(serPort)
serPort.Open()
End Sub

Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
zzz = master.ReadHoldingRegisters(32, 100, 1)
Label1.Text = zzz(0)
End Sub

Private Sub Form1_FormClosed(sender As Object, e As FormClosedEventArgs) Handles MyBase.FormClosed
serPort.Close()
End Sub

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
master.WriteSingleRegister(16, 50, 1)
End Sub
End Class

Евгений Кислов
16.08.2016, 09:22
Используйте функцию Write Multiple Registers.