How Do I use VB.Net S7ProSim to read Input image PLCSIM

Eric-Klaasen

Member
Join Date
Apr 2007
Location
Gorey
Posts
9
When I try to write a PIW to a simulated PLC in PLCSIM, I get a Data Type Error.
Code:
___________________________________________________________________
Sub WriteInputWordImage(ByVal lStartIndex As Long, ByVal vData As Integer)

Dim errInputWordImage As Long

errInputWordImage = AxS7ProSim1.WriteInputImage(lStartIndex, vData)

If errInputWordImage = S_OK Then

'MsgBox(MSG_OK, vbInformation, "S7ProSim Example")

Else

ShowError(errInputWordImage)

End If

End Sub
_________________________________________________________________
Can anyone help me?
The sample in the manuals specify that data type should be "variant", I tried "Object" but that did not work.
 
I just installed :Microsoft Visual Studio 2005
Version 8.0.50727.42 (RTM.050727-4200)
Microsoft .NET Framework
Version 2.0.50727

Installed Edition: VB Express

Microsoft Visual Basic 2005 76541-000-0000011-00124
Microsoft Visual Basic 2005,

Would that make a difference?
 
Eric-Klaasen said:
Would that make a difference?
.NET 1.1 had a bug that would not let variant types in COM objects work correctly.

It's most likely something with marshalling to the variant type. The variant is not a .NET type and may need to be handled a little differently.

Is the ActiveX control you are using available to where I can download it?
 
Archie,​
Thanks for your interrest.​
This is a quote from the softwate manual:​


S7ProSim is an ActiveX Control that provides programmatic access to the process simulation interface of S7ProSim is an ActiveX™ Control that provides programmatic access to the process simulation interface of S7-PLCSIM. This control may be used in any application that can accept ActiveX controls. You can use this control to attach a process simulation to S7-PLCSIM.

Attached is the OCX I needed to inport into VB to start.​
I don't think it will do anything without the S7PLCSIM software.
There are a number of other OCX files there as well, but I don't know what they are for.
 
Hello all,
I'm kind of interested in this thread because a co-worker and myself are working on a project involving a PC running a VB program communicating via rs-232 to a Master PLC that is set up on a modbus network with 6 other slave devices(3 PLCs and 3 HMIs). We are experiencing frequent "lockups" or "hangups" with the VB program (i.e. failure to send data to the PLC, or taking a long time to send that data). We're not quite sure if it is a bug in his program or if it is an issue with the PC. I don't have alot of info on the VB end of it because the coworker handled that part of the project while I did the PLC/HMI stuff. When I get more info on the VB version and things of that nature I'll post more.It's just weird because sometimes it runs smoothly and other times it hangs up quite frequently.
 
Eric

I downloaded the ActiveX to look at a few things with it. I am not getting the same error your are.(of course I may not be able to without S7PLCSIM).

When you "imported" the ActiveX, did you do so by Add Reference of the COM object? Doing it this way will let VB create the InterOp assembly and determine the marshalling needed which is generally the easiest way in most cases.

One thing I do see is the second parameter of the type Variant is marshalled to an object. I do believe the object must be an array.

The one thing I would try is to pass the method an array:


Sub WriteInputWordImage(ByVal lStartIndex As Long, ByVal vData() As Integer)

Dim errInputWordImage AsLong

errInputWordImage = AxS7ProSim1.WriteInputImage(lStartIndex, vData)

 
Got it to write now without error now, only the data is not accepted by the S7PLCSIM. I am sure that the address is ok, because if I change the address, I correctly get an error stating the address in not configuerd.
Maybe I should study the manual a bit more.
Any Ideas?

Thanks for your advise so far!
 
Eric,

Once you've crossed from VB to the Siemens world, you went out of my areas of expertise. Maybe some Siemens experts can chime in at this point.


ctilly,

From the sounds of your description, I'd say you have some bugs in the VB code. When a program locks up it generally means it is in an inifinite loop or a dead lock where one section of the code is waiting for another and vice versa.
One of the easy ways to help narrow the problem is to do a ctrl-alt-del when it locks up and go to Task Manger. Then see if the program is consuming an very high amount of CPU time (95%+), if so it is most likely an infinite loop. Keep in mind if this is the case, then the PC is not truly locked up, but very slow to respond to events such as keyboard or mouse clicks.
If you do the ctrl-alt-del and nothing happens within about 2-3 minutes, then it is a sign of the PC is locked up all together.
 
Archie,
Just to let you know, I implemented the program in Excel VBA.
It worked properly there. This is the code I used:
'__________________________________________________________________________
Sub WriteInputWordImage(lStartIndex, iData() As Integer)
Dim errInputWordImage As Long
Dim iWordIn As Integer
Dim errWriteInputPoint As Long
Dim lBitIndex As Long
Dim lByteIndex As Long
Dim vData
errInputWordImage = S7ProSim1.WriteInputImage(lStartIndex, iData)
If errInputWordImage = S_OK Then
Else
ShowError (errInputWordImage)
End If
End Sub
'________________________________________________________________________
 
Eric-Klaasen said:
Archie,
Just to let you know, I implemented the program in Excel VBA.
It worked properly there.

Eric

If the code works as an ActiveX, but not with a .NET wrapper brings one possibility to mind, the possibility of differences in variable representation in memory.

Just as a shot in the dark, I would try this in the .NET version:

Sub WriteInputWordImage(ByVal lStartIndex As Long, ByVal vData() As Int16)
 
Hi,

I have programmed my project with S7 and I want to test it.

Can anyone tell me what the steps are to run the whole thing?

seperately,
I tested my code in Prosim (check with PLCsim & VB6) and it works - it can read, and write.

also seperately,
I have tested my program in S7 with PLCsim.

I can't seem to get the three of the S7-PLCSim-Prosim work together. I know they can because accidentally I did it but then it never happen again.

Please can anyone just write out the steps here. It would be helpful.
 

Similar Topics

Hello I have a s7-1200 and I would like to read the tags present in this controller with my controllogix controller. The two controllers don't use...
Replies
5
Views
145
Hi, I am looking to migrate some of our Electronic Overloads off of a Troublesome Devicenet Segment. Is there any documentation confirming the...
Replies
5
Views
104
Hoping someone can give me some guidance or confirmation of what I need to do. We have a FactoryTalk SE program that I need to change the IP...
Replies
2
Views
92
Can we use a Simotion D455 ethernet port x127 as a gate, to access S7-1500 plc Tia Portal program ? In the Simatic manager, we used Netpro to do...
Replies
2
Views
87
"Hello! Good day! Excuse me, I have a question regarding the 1761-NET-ENI. RSLinx has already detected it but it's not connecting to the PLC...
Replies
4
Views
134
Back
Top Bottom