This is my first post so forgive me if I mess this up.
I am using ModbusTCP to communicate with an Arduino via Ethernet using mudbus.h. (The correct spelling) I can read and write bit values and read register values without any issues. But for some reason I cannot write data to a register.
I would like to read a text file and send the values to two registers when the program starts. These values represent offset values for two TOF sensors connected to the Arduino.
I am hoping to be able to use them to line up my two Y Axis stepper motor positions on my CNC gantry and use the offsets to allow for any mounting errors.
Private Sub MainForm_Load(sender As Object, e As EventArgs) Handles MyBase.Load
If My.Computer.FileSystem.FileExists("C:\axis_offsets.txt") Then
Dim reader As New System.IO.StreamReader("C:\axis_offsets.txt")
Dim MyValue1, MyValue2 As String
MyValue1 = reader.ReadLine()
Dim CurrentValueInt1 As Integer = CInt(MyValue1)
MyValue2 = reader.ReadLine()
Dim CurrentValueInt2 As Integer = CInt(MyValue2)
reader.Close()
ModbusTCPCom1.Write("40003", CurrentValueInt1)
ModbusTCPCom1.Write("40004", CurrentValueInt2)
Else
Dim writer As New System.IO.StreamWriter("C:\axis_offsets.txt", False)
writer.WriteLine(0)
writer.WriteLine(0)
writer.Close()
End If
End Sub
This button click code will not work either.
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
ModbusTCPCom1.Write("40003", 2)
ModbusTCPCom1.Write("40004", 2)
End Sub
If I could figure out a way to use an ESP8266 with AHMI, I'd give it a go. Save me the problem of storing offsets on my computer and saving them on the ESP8266.
I'm a recently retired Industrial Electrician (Canada) so maybe I'm just getting old and missed something simple?
Thank you for any help one of you can provide. It would be deeply appreciated.