Hi AlphaFrog
Thanks again for your code, it works like a charm, just the way I needed it to work.
I have been trying to get this working for 2 weeks now.
You are an absolute star and have saved my bacon.
Must say that the introduction to vb has been rather taxing, but has left me with an eagerness to learn more.
And thats a wrap.
Sample code that may assist anyone trying to communicate to DELTA PLC, if there is anyone else trying other functions to read or write to a Delta PLC, I have other communication strings that may be of use.
Option Explicit
Private Sub Worksheet_Change(ByVal Target As Range)
Dim send_string$, NETComm1
NETComm1 = 7
If Target.Count > 1 Then Exit Sub
If Target.Value = "" Then Exit Sub
If Target.Column <> 3 Then Exit Sub 'column C
If Application.CountIf(Columns("C"), Target) = 1 Then
'Unique serial number
send_string$ = ":01050500FF00F6" 'Y0 ON
Else
'Duplicated Serial number
Target.ClearContents
send_string$ = ":01050506FF00F0" 'Y6 ON
End If
'send to plc
send_string$ = Send_To_PLC(Me.NETComm1, send_string$)
End Sub
'USE Function Code 0x05 Force ON Coil Device
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
Dim send_string$, NETComm1
NETComm1 = 7
If Target.Address = "$A$1" Then
send_string$ = ":01050500FF00F6" 'Y0 ON
End If
If Target.Address = "$A$2" Then
send_string$ = ":010505000000F5" 'Device number, device instruction, address value, number of address, checksum. Y0 OFF
End If
If Target.Address = "$A$4" Then
send_string$ = ":01050506FF00F0" 'Y6 ON
End If
If Target.Address = "$A$5" Then
send_string$ = ":010505060000EF" 'Y6 OFF
End If
'send to plc
send_string$ = Send_To_PLC(Me.NETComm1, send_string$)
End Sub
Public Function Send_To_PLC(ByVal objNETCOMM As NETComm, ByVal send_string$) As String
Dim Buffer$
send_string$ = Chr(&H3A) + send_string$ + Chr(&HD) + Chr(&HA)
If objNETCOMM.PortOpen = False Then objNETCOMM.PortOpen = True
objNETCOMM.Output = send_string$
Send_To_PLC = send_string$
Do
DoEvents
Buffer$ = Buffer$ & objNETCOMM.InputData
Loop Until InStr(Buffer$, vbCrLf)
objNETCOMM.PortOpen = False
End Function
Bookmarks