TechJunki

MrPLC Member
  • Content count

    253
  • Joined

  • Last visited

Everything posted by TechJunki

  1. I recently downloaded the new Visual Basic 2005 Express version from Microsoft for FREE, yes I said free. I know I have seen quite a few posts about using OPC with with the newer .NET versions of VB. Being quite comfortable with VB6 and OPC i gave this a shot and have successfully compiled code for both SyncRead and AsyncRead operations. I have not yet looked into the write operations but thought I would post the code I have for everyones viewing pleasure.. If anyone has an older version of VB.. .NET 2003 or .NET 2002 I would be interested in knowing if this code is compatible. ++ Be sure to add the reference "Rockwell Software OPC Automation" ++ Imports RsiOPCAuto Public Class Form1 Public MyRsLinxOPCServer As RsiOPCAuto.OPCServer Public WithEvents LinxOPCGroup As RsiOPCAuto.OPCGroup Public LinxItem1 As RsiOPCAuto.OPCItem Public LinxItem2 As RsiOPCAuto.OPCItem Private Sub Form1_Load(ByVal sender As Object, ByVal e As EventArgs) Handles MyBase.Load Dim ItemCount As Short Dim TransID As Int64 Dim CancelID As Int64 Dim i As Integer 'Create Server MyRsLinxOPCServer = New RsiOPCAuto.OPCServer 'Connect to Server MyRsLinxOPCServer.Connect("RSLinx OPC Server") 'Add Group to Server LinxOPCGroup = MyRsLinxOPCServer.OPCGroups.Add("TestGroup") 'Group name can be anything you want it to be 'Set Group Active for Data Updates and Events LinxOPCGroup.IsActive = True 'Group Update Rate LinxOPCGroup.UpdateRate = 1000 LinxOPCGroup.IsSubscribed = True 'Add Items to Group, the specifier on the end Needs to be Unique for each Tag LinxItem1 = LinxOPCGroup.OPCItems.AddItem("[PLC_TOPIC]TAGE_NAME1,L10,C1", 1) LinxItem2 = LinxOPCGroup.OPCItems.AddItem("[PLC_TOPIC]TAGE_NAME2,L10,C1", 2) End Sub Private Sub SyncRead_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SyncRead.Click Dim ItemCount As Short Dim TransID As Int64 Dim CancelID As Int64 Dim i As Integer 'Get Number of Items in Group From Server ItemCount = LinxOPCGroup.OPCItems.Count 'Dim Arrays for SyncRead Dim SyncServerHandles(ItemCount) As Integer Dim SyncErrors As System.Array Dim SyncValues As System.Array 'Pass in the ServerHandles for the items For i = 1 To ItemCount SyncServerHandles(i) = LinxOPCGroup.OPCItems.Item(i).ServerHandle Next 'Read Items From Group LinxOPCGroup.SyncRead(1, ItemCount, SyncServerHandles, SyncValues, SyncErrors) Dim MyData As System.Array MyData = SyncValues End Sub Private Sub AsyncRead_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AsyncRead.Click Dim ItemCount As Short Dim TransID As Int64 Dim CancelID As Int64 Dim i As Integer 'Get Number of Items in Group From Server ItemCount = LinxOPCGroup.OPCItems.Count 'Dim Arrays for SyncRead Dim AsyncServerHandles(ItemCount) As Integer Dim AsyncErrors As System.Array Dim AsyncValues As System.Array 'Pass in the ServerHandles for the items For i = 1 To ItemCount AsyncServerHandles(i) = LinxOPCGroup.OPCItems.Item(i).ServerHandle Next 'Execute statement to Read Data from Group LinxOPCGroup.AsyncRead(ItemCount, AsyncServerHandles, AsyncErrors, TransID, CancelID) 'Call Sub When Read is Completed -- AddHandler (LinxOPCGroup.AsyncReadComplete), AddressOf LinxOPCGroup_AsyncReadComplete End Sub Private Sub LinxOPCGroup_AsyncReadComplete(ByVal TransactionID As Integer, ByVal NumItems As Integer, ByRef ClientHandles As System.Array, ByRef ItemValues As System.Array, ByRef Qualities As System.Array, ByRef TimeStamps As System.Array, ByRef Errors As System.Array) Handles LinxOPCGroup.AsyncReadComplete Dim MyData As System.Array MyData = ItemValues End Sub End Class Code.txt
  2. Module Module1 Public RsLinxOPCServer As OPCAutomation.OPCServer Public WithEvents LinxOPCGroup As OPCAutomation.OPCGroup Public Sub AddOPCTags(ByVal Tags, ByVal NumOfTags) Dim AddItemServerErrors As System.Array Dim TagName As String Dim i As Integer ' OPC Item related data Dim ItemServerHandles As System.Array Dim OPCItemIDs(NumOfTags) As String Dim ClientHandles(NumOfTags) As Int32 'Create Server RsLinxOPCServer = New OPCAutomation.OPCServer 'Connect to Server RsLinxOPCServer.Connect("RSLinx OPC Server") 'Add Group to Server LinxOPCGroup = RsLinxOPCServer.OPCGroups.Add("MyGroup") 'Set Group Active for Data Updates and Events LinxOPCGroup.IsActive = False 'Group Update Rate LinxOPCGroup.UpdateRate = 500 LinxOPCGroup.IsSubscribed = False 'Add Items to Group, the specifier on the end Needs to be Unique for each Tag 'Lengths of Arrays Can Not be longer than 100 Elements or RSLINX Will Error For i = 1 To 1 TagName = "" & "MyTagArray,L8,C1" OPCItemIDs(i) = TagName ClientHandles(i) = i Next ' Add Items to RsLinx Server LinxOPCGroup.OPCItems.AddItems(NumOfTags, OPCItemIDs, ClientHandles, ItemServerHandles, AddItemServerErrors) End Sub Public Sub SyncRead(ByVal Tags) Dim CurrentServerState As Integer Dim ItemCount As Short Dim i As Integer ' Get Number of Items in Group From Server ItemCount = LinxOPCGroup.OPCItems.Count ' Dim Arrays for SyncRead Dim SyncServerHandles(ItemCount) As Integer Dim SyncErrors As System.Array Dim SyncValues As System.Array Dim SyncQualities As Object Dim SyncTime As Object ' Pass in the ServerHandles for the items For i = 1 To ItemCount SyncServerHandles(i) = LinxOPCGroup.OPCItems.Item(i).ServerHandle Next ' Read Items From Group LinxOPCGroup.SyncRead(1, ItemCount, SyncServerHandles, SyncValues, SyncErrors, SyncQualities, SyncTime) ' Copy Data to MyData Globals.MyData = SyncValues 'Remove Groups RsLinxOPCServer.OPCGroups.RemoveAll() ' Disconnect OPC Server RsLinxOPCServer.Disconnect() End Sub End Module
  3. I have an old time set sapplication which works fine in the old RsiOPCAuto.dll but after upgrading to Linx 2.58 it appears this dll is no longer included, and is switching to using the OPC DA Automation Wrapper, anyway this new Wrapper does not like the old "write" data structure. I am attempting to create the data structrure here in this screenshot, this is the structure that is returned when I do a read of the data points. I can modify/write this structure back to the PLC but can not figure how to make it from scratch using a DIM or Array.CreateInstance Statement or any other method for that matter. System.Array ---->System.Array ---------->Integer(8) Anyone have any ideas?? Thanks in advance....
  4. Simple Encoder

    Thanks I'll take a look at the pdf..
  5. I have a winder application that I need to measure speed and yardage on the roll. Has anyone had any experience interfacing a simple encoder such as a pulse encoder in to a high speed counter module for the logix and measuring speed and yardage. The winder currently is just an AC motor with a manual speed control, no feedback whatsoever. But I do have a contrologix PLC available and empty slots to accomidate a specialty card if necessary. What is the recommended practice or what have the rest of you been using for this type of application. Encoder Type?? Logix Module?? Thanks for any info..
  6. Simple Encoder

    TW, do you have a sample of the periodic code you are using for your rate measurment you care to share as I am now beginning to implement this? Thanks for all the help with this.........
  7. iFix!

    You will need to use a Timer event to schedule the code to execute
  8. RSLinx DDE Comms Problem

    Glad you got it working... Sometimes better not to question if it works...
  9. RSLinx DDE Comms Problem

    That is really strange, I was able to reproduce the problem, with a nine in the first element of the array it will "bomb" out VB6. I found that changing the Declaration datatype in the "Write" sub to a Variant seems to eliminate the problem. I tryed a few other datatypes all with out any success, either same thing or it just plain old didn't work. Must have something to do with how VB stores and sends the data in its memory. Anyway by changing the following line I have gotten this to work with a "9" as the first element of the array. let me know if you have the same result.. Dim WriteValues() As Integer --> Dim WriteValues() As Variant
  10. RSLinx DDE Comms Problem

    You could try posting or e-mailing your project file and I could take a look at it to see if it acts the same on my end. Not sure why it won't work correctly.
  11. RSLinx DDE Comms Problem

    I doubt it has anything to do with the setup in linx... Are you adding the items something like this....here is the rest of the code to add the items
  12. RSLinx DDE Comms Problem

    For VB6...almost the same Public Sub SyncWrite() ' Dim Arrays for SyncWrite Dim SyncServerHandles() As Long Dim Values() As Variant Dim WriteData Dim SyncErrors() As Long Dim ItemCount As Integer Dim WriteValues() As Integer ' Get Number of Items in Group From Server ItemCount = LinxOPCGroup.OPCItems.Count ' Redim Arrays for Item Count ReDim SyncServerHandles(ItemCount) ReDim Values(ItemCount) ReDim WriteData(ItemCount) ' Write values 1 to 10 to N63:500 to N63:509 and N63:510 to N63:519 ReDim WriteValues(9) ' Fill with Data For i = 0 To 9 WriteValues(i) = i + 1 Next ' Copy Array Data WriteData(1) = WriteValues 'Data to First Item in Group -- [TopicName]N63:500,L10,C1 WriteData(2) = WriteValues 'Data to Second Item in Group -- [TopicName]N63:510,L10,C1 ' Pass in the ServerHandles and Values for the items active in Linx For i = 1 To ItemCount ' Pass in ServerHandles SyncServerHandles(i) = LinxOPCGroup.OPCItems.Item(i).ServerHandle ' Pass in ClientHandles Values(i) = WriteData(LinxOPCGroup.OPCItems.Item(i).ClientHandle) Next ' Write data to server LinxOPCGroup.SyncWrite ItemCount, SyncServerHandles, Values, SyncErrors End Sub
  13. iFix!

    Try This Private Sub GetUser() Dim sUserId As String Dim sUserName As String Dim sGroupName As String System.FixGetUserInfo sUserId, sUserName, sGroupName If sUserId = "" Then CurrentUser.Caption = "Security Not Enabled" Exit Sub End If If sUserId = "ADMIN" Then 'Do Soemthing Here Exit Sub End If End Sub
  14. Thanks BobLfoot for catching that, I put it together pretty quick. I see the COP does in fact support String datatypes, I figured there was a better way to move strings.
  15. I would either use structured text (this is a whole other story), or you can just use the CONCAT function and make Source A the string you want to move, Source B would just be an empty string, and the destination is where you want to move the Source to.
  16. There may be a better way.... but quickly combining fuzzy logic's code and b_calton's "rules" it would look something like this.
  17. Just type it into the word as you would any variable
  18. Have you looked at fuzzy logic's example.."Clock.zip" it has a "String Concatenate" function used to add in the Colon....?
  19. RSLinx DDE Comms Problem

    Are you using a Multi Dimension Array?? Unless I am missing something....? This address you are using is a length of 30 with a index of 30... OPCItemIDs(22) = "[TEST_PLC]N14:0,L30,C30" If you are only writing to a single array .. elements N14:0 to n14:29 then it should not be "C30" it SHOULD BE "C1".. like this... OPCItemIDs(22) = "[TEST_PLC]N14:0,L30,C1" This may be causing the strange results you are seeing. For reference I usually do my writes as follows. Note this is in VB.NET not sure what you are using, I also have in VB6 if you are using that. Public Sub SyncWrite() Dim ItemCount As Integer Dim i As Integer ' Get Number of Items in Group From Server ItemCount = LinxOPCGroup.OPCItems.Count ' Dim Arrays for SyncWrite Dim SyncServerHandles(ItemCount) As Integer Dim Values(ItemCount) As Object Dim WriteData(ItemCount) As Object Dim SyncErrors As System.Array = Nothing ' Write values 1 to 10 to N63:500 to N63:509 and N63:510 to N63:519 Dim WriteValues() As Short = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10} ' Copy Array Data to System Object WriteData(1) = WriteValues 'Data to First Item in Group -- [TopicName]N63:500,L10,C1 WriteData(2) = WriteValues 'Data to Second Item in Group -- [TopicName]N63:510,L10,C1 ' Pass in the ServerHandles and Values for the items active in Linx For i = 1 To ItemCount ' Pass in ServerHandles SyncServerHandles(i) = LinxOPCGroup.OPCItems.Item(i).ServerHandle ' Pass in ClientHandles Values(i) = WriteData(LinxOPCGroup.OPCItems.Item(i).ClientHandle) Next ' Write data to server LinxOPCGroup.SyncWrite(ItemCount, SyncServerHandles, Values, SyncErrors) End Sub
  20. RSLinx DDE Comms Problem

    The @IsPresent bit will not work on a SLC type CPU (have tried on a SLC 5/03 and always returns 0), or at least I have never been able to get it to work. This may also be true on the Micrologix 1100 your using.. It does however work "OK" on PLC-5 and Logix 5000 CPU's as previously stated. Is there an equivilent Status word to use for 500 series CPU's??
  21. rs500 online graphic

    There are many ways.... I would use VB.NET Studio
  22. RSView ME 4.0 bit masking

    If memory serves me correctly... to address bit 3 of the word you should be able to just specify the bit at the end of the word in the connections tab, for bit three it would be.. WORD123.3 EDIT: Have you tryed defining a Data Type other than default, you may want to try specifying this as an integer data type
  23. vb2005 and RSLinx OPC

    Your code in the screenshot is different then your posted code... This is a little confusing, however the code you posted should work. I would verify the Topic exists in Rslinx and check your OPC group diagnostics when running the code to see if the group is created. Then check your OPC Communication events in RSlinx this will give you a more specific error message on the problem. Both can be found under the DDE/OPC menu option in Linx.
  24. Looking for a way to display the description text of a certain tag on the screen of a PV+ terminal. Is there a way to format the tag address in a string display or text label to show the description of the tag that is set-up in RsView? Thanks for the help....
  25. does that mean that I can only access the data by using the register addresses Yes....