Hello.
I am trying to connect to the API using Excel VBA.
I am able to "Connect" to the API via TCP/IP using Excel VBA. However, I do not know how to send and receive a message.
##################
My questions
=========
Now that I am connected using TCP/IP,
1. Using Excel VBA, how do I send a message to TCP/IP, sample request
"HTX,@ES#,10,1,TESTREQUEST<CR><LF>"
2. Using Excel VBA, How do I retrieve or receive a response? Either in a text string, variable or into a Cell?
###################
I am able to do the following
1. Connect using PUTTY - TCP/IP (Telnet)
2. Address: 127.0.0.1, Port: 9100
Once connected in Putty, I can send the following message
"HTX,@ES#,10,1,TESTREQUEST<CR><LF>"
In Putty, I received the following Response
TESTREQUEST<CR><LF>,2023-04-17 04:38:48,4168.00,1,79263,4167.75,4168.00,2729085,0,0,C,
TESTREQUEST<CR><LF>,2023-04-17 04:38:48,4168.00,2,79265,4167.75,4168.00,2729085,0,0,C,
TESTREQUEST<CR><LF>,2023-04-17 04:38:48,4168.00,2,79267,4167.75,4168.00,2729085,0,0,C,
TESTREQUEST<CR><LF>,2023-04-17 04:38:48,4168.00,1,79268,4167.75,4168.00,2729085,0,0,C,
TESTREQUEST<CR><LF>,2023-04-17 04:38:48,4168.25,1,79269,4168.00,4168.25,2729086,0,0,C,
TESTREQUEST<CR><LF>,2023-04-17 04:39:00,4168.25,1,79270,4168.00,4168.25,2729087,0,0,C,
TESTREQUEST<CR><LF>,2023-04-17 04:39:00,4168.25,1,79271,4168.00,4168.25,2729087,0,0,C,
TESTREQUEST<CR><LF>,2023-04-17 04:39:00,4168.25,1,79272,4168.00,4168.25,2729088,0,0,C,
TESTREQUEST<CR><LF>,2023-04-17 04:39:00,4168.25,1,79273,4168.00,4168.25,2729088,0,0,C,
TESTREQUEST<CR><LF>,2023-04-17 04:39:00,4168.25,1,79274,4168.00,4168.25,2729088,0,0,C,
TESTREQUEST<CR><LF>,!ENDMSG!,
Over to EXCEL VBA
I downloaded the tool "Mobus activeX"
"
https://www.modbustools.com/modbus_activex.html"
The VBA code used is
Mbaxp1.Connection = TCP_IP '0 = TCP/IP
Mbaxp1.IPAddr1 = 127
Mbaxp1.IPAddr2 = 0
Mbaxp1.IPAddr3 = 0
Mbaxp1.IPAddr4 = 1
Mbaxp1.TCPIPPort = 9100
Mbaxp1.Timeout = 1000 ' Read timeout
Mbaxp1.ConnectTimeout = 2000 ' TCP/IP Connection timeout
Mbaxp1.LicenseKey ("xxxx-xxxx-xxxx-xxxx-xxxx-xxxx")
e = Mbaxp1.OpenConnection
e = Mbaxp1.GetLastError
If e = 0 Then
Cells(5, 2) = "Connection success"
I am able to connect, receiving the response e=0
My questions
=========
Now that I am connected using TCp?IP,
1. Using Excel VBA, how do I send a message to TCP/IP,
2. Using Excel VBA, How do I retrieve or receive a response? Either in a text string, variable or Cell?
Attached are my screen prints of Putty and Excel VBA.
Thank you in advance and any pointers or ideas will be greatly appreciated.
Thanks,
Megabite