I'm writing a multithreaded app that uses libnodave as it's communication base to a PLC.
I have a couple of questions, that are maybe obvious to some, but this is the first time I'm trying something of this magnitude. I did use search, but did not get satisfactory results, that's why I'm posting here.
In the system we have decided to use "communication moments", that is: certain moments during the normal functioning of the machine, the PLC needs some data. My application gets this data from an oracle database, and reports it back.
The only drawback is, this processing and returning of data should be done as soon as possible. Sometimes throughput rates of around 100ms will have to be achieved. Mind, there are around 6 barcode scanners & 2 printers connected to the data interlink application.
Now what I've made of it so far:
I've split the PLC connections up in 3:
I have a System.Timer (threaded timer) that continuously reads data from a PLC. there is no way reading data should ever wait. (this is connection 1) (timer tickrate is 500ms, with time to spare)
Then I have another connection that is in charge of writing.
Finally I have one station that should always get priority in terms of processing. This is connection number 3 and is in charge of reading and writing for this station.
Now the problem is I get the occasional "Attempted to read or write protected memory. This is often an indication that other memory is corrupt".
I'm guessing this is a lock/synchronization problem?
The first implementation I did to make the multiple connections bit was 3 plcdaveConnection instances. Each connecting to the PLC (yep, 3 connections to the same PLC).
Didn't work in a stable fashion, so I copied the libnodave.dll twice and set up connections using a seperate dll each time just to try (hey, I'm desperate). Doesn't work like it should either…
Now the questions:
- Is the 1 DLL approach better or is using 3 the only way to make it work?
- Is the 1 DLL approach actually the same? I mean, does windows/libnodave do some things behind the scene's?
- I'm actually out of ideas for the high-speed station… I use locks when I read, and locks when I write (I lock on to the same object for both) and still it gives me the protected memory error. This makes me suspect that using 1 or more dll's or plcdaveconnection's doesn't make a difference when you're connecting to the same PLC.
Any advice, anyone?
Thanks in advance!
Alex
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I have
private static PlcConnectionInfo _plcCI;
private static S7Plc _plcCommunication1;
private static S7Plc1 _plcCommunication2;
private static S7Plc2 _plcCommunication3;
* 3 in my main application (each with different names of course)
PlcConnectionInfo and S7Plc are wrappers I made for a more object oriented-approach to use with libnodave,
connectioninfo is just a data collector that holds IP, network type etc.
S7Plc has a few functions: connect, disconnect, read, write, etc Each S7Plc has 1 static readonly object that functions as locker object for the read and write functions.
I use these as statics because they need to be accessible from other classes.
I am wondering if these 3 instances share the same connection in the background, or if all 3 of them use a different connection made by libnodave, Because I'm getting occasional accessviolation exceptions and I'm wondering if it's because I'm making lock errors, or if it's the connection that's being shared in the background, and thus would resemble me using
static S7Plc conn1;
static S7Plc conn2;
static S7Plc conn3;
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi,
I'm writing a multithreaded app that uses libnodave as it's communication base to a PLC.
I have a couple of questions, that are maybe obvious to some, but this is the first time I'm trying something of this magnitude. I did use search, but did not get satisfactory results, that's why I'm posting here.
In the system we have decided to use "communication moments", that is: certain moments during the normal functioning of the machine, the PLC needs some data. My application gets this data from an oracle database, and reports it back.
The only drawback is, this processing and returning of data should be done as soon as possible. Sometimes throughput rates of around 100ms will have to be achieved. Mind, there are around 6 barcode scanners & 2 printers connected to the data interlink application.
Now what I've made of it so far:
I've split the PLC connections up in 3:
I have a System.Timer (threaded timer) that continuously reads data from a PLC. there is no way reading data should ever wait. (this is connection 1) (timer tickrate is 500ms, with time to spare)
Then I have another connection that is in charge of writing.
Finally I have one station that should always get priority in terms of processing. This is connection number 3 and is in charge of reading and writing for this station.
Now the problem is I get the occasional "Attempted to read or write protected memory. This is often an indication that other memory is corrupt".
I'm guessing this is a lock/synchronization problem?
The first implementation I did to make the multiple connections bit was 3 plcdaveConnection instances. Each connecting to the PLC (yep, 3 connections to the same PLC).
Didn't work in a stable fashion, so I copied the libnodave.dll twice and set up connections using a seperate dll each time just to try (hey, I'm desperate). Doesn't work like it should either…
Now the questions:
- Is the 1 DLL approach better or is using 3 the only way to make it work?
- Is the 1 DLL approach actually the same? I mean, does windows/libnodave do some things behind the scene's?
- I'm actually out of ideas for the high-speed station… I use locks when I read, and locks when I write (I lock on to the same object for both) and still it gives me the protected memory error. This makes me suspect that using 1 or more dll's or plcdaveconnection's doesn't make a difference when you're connecting to the same PLC.
Any advice, anyone?
Thanks in advance!
Alex
Ok, let me rephrase a wee bit.
I have
private static PlcConnectionInfo _plcCI;
private static S7Plc _plcCommunication1;
private static S7Plc1 _plcCommunication2;
private static S7Plc2 _plcCommunication3;
* 3 in my main application (each with different names of course)
PlcConnectionInfo and S7Plc are wrappers I made for a more object oriented-approach to use with libnodave,
connectioninfo is just a data collector that holds IP, network type etc.
S7Plc has a few functions: connect, disconnect, read, write, etc Each S7Plc has 1 static readonly object that functions as locker object for the read and write functions.
I use these as statics because they need to be accessible from other classes.
I am wondering if these 3 instances share the same connection in the background, or if all 3 of them use a different connection made by libnodave, Because I'm getting occasional accessviolation exceptions and I'm wondering if it's because I'm making lock errors, or if it's the connection that's being shared in the background, and thus would resemble me using
static S7Plc conn1;
static S7Plc conn2;
static S7Plc conn3;
* 3 in my main application (each with different names of course) >> should be removed from previous post. I can't find the darn edit button…