Hi All,
Some time before I've used AdvancedHMI updated by Bryan Goose for Siemens PLC communication via Ethernet.
I was able to communicate with S7-1200 P.L.C. And able to get Read and Write all the variables data.
The problem starts when recently the customer changed the PLC program.
Originally the Bryan Goose Siemens Wrapper around AdvancedHMI using Libnodave had problems that it was unable to read Digital M bits after M0.0 i,e. from M0.0 to M0.7
I've tried and was able to update it and extend it from M0.0 to M2.7. But as I try to extend it further I'm unable to extend it. No error is thrown and it always shows 0. It is even unable to change the state.
The only problem is with writing of digital Tags.
I hope some1 might be able to help me with that...
'*********************************************************************************
'* Parse the address string and validate, if invalid, Return 0 in FileType
'* Convert the file type letter Type to the corresponding value
'* Reference page 7-18
'*********************************************************************************
Private RE1 As New Regex("(?i)^\s*(?<DataArea>([IQMTCSV]))(?<DataType>([BWD]))?(?<Offset>\d{1,4}).?(?<BitNumber>\d{1,3})?\s*$")
Private RE2 As New Regex("(?i)^\s*\w{2}?(?<DBDataBase>\d{1,4}).\w{2}(?<DataType>([BWD]))?(?<Offset>\d{1,4}).?(?<BitNumber>\d{1,3})?\s*$")
'Private RE2 As New Regex("(?i)^\s*(?<FileType>[SBN])(?<FileNumber>\d{1,3})(/(?<BitNumber>\d{1,4}))\s*$")
Private Function ParseAddress(ByVal DataAddress As String) As ParsedDataAddress
Dim result As New ParsedDataAddress
result.DataArea = 0 '* Let a 0 indicate an invalid address
result.BitNumber = 99 '* Let a 99 indicate no bit level requested
'*********************************
'* Try all match patterns
'*********************************
Dim mc As MatchCollection
If DataAddress.Chars(0) = "D" Then 'If address atarts with D then use the DB version of Match
mc = RE2.Matches(DataAddress)
result.DataArea = "D"
Else
mc = RE1.Matches(DataAddress)
result.DBDataBase = 1
End If
If mc.Count <= 0 Then
'mc = RE2.Matches(DataAddress)
'If mc.Count <= 0 Then
Return result
' End If
End If
'*******************************************************************
'* Keep the original address with the parsed values for later use
'*******************************************************************
result.PLCAddress = DataAddress
'*********************************************
'* Get elements extracted from match patterns
'*********************************************
If mc.Item(0).Groups("BitNumber").Length > 0 Then
result.BitNumber = mc.Item(0).Groups("BitNumber").ToString
End If
'* Was an element number specified?
If mc.Item(0).Groups("Offset").Length > 0 Then
result.Offset = mc.Item(0).Groups("Offset").ToString
End If
'* Get DataArea
If mc.Item(0).Groups("DataArea").Length > 0 Then
result.DataArea = mc.Item(0).Groups("DataArea").ToString
End If
'* Get DataType
If mc.Item(0).Groups("DataType").Length > 0 Then
result.DataType = mc.Item(0).Groups("DataType").ToString
End If
'* Get DataBase
If mc.Item(0).Groups("DBDataBase").Length > 0 Then
result.DBDataBase = Convert.ToInt16(mc.Item(0).Groups("DBDataBase").ToString)
End If
'**************************************************************************
'* Was a bit number higher than 15 specified along with an element number?
'** To let wrapper select bits from M0.0 to M2.7 [15 was replaced to 32 by MUSTAFA]
'**************************************************************************
If result.BitNumber > 32 And result.BitNumber < 99 Then
'* IO points can use higher bit numbers, so make sure it is not IO
If result.DataArea <> &H8B And result.DataArea <> &H8C Then
result.Offset += result.BitNumber >> 3
result.BitNumber = result.BitNumber Mod 8
End If
End If
Return result
End Function