miladel
Member
- Joined
- Aug 16, 2020
- Messages
- 14
- Programming Experience
- Beginner
Dear All,
In my project, I need to connect to S7 PLC and read data in cycles like every 100ms, then update variables and put them in Database. The app based on UWP and what I need to know is that how to use all the updated values from PLC in all of the code behinds,
what is the best method for my question?
here is a simple part of the code:
In the code I need to access to the value1 in all of the pages in my project and store it in SQL Database, Also it is necessary to keep connection alive while the app is running in background.
thanks in advance
In my project, I need to connect to S7 PLC and read data in cycles like every 100ms, then update variables and put them in Database. The app based on UWP and what I need to know is that how to use all the updated values from PLC in all of the code behinds,
what is the best method for my question?
here is a simple part of the code:
code in page1:
Plc plc = new Plc(CpuType.S7300, "192.168.0.10", 0, 2); // connection to PLC
DispatcherTimer dispatcherTimer; // Timer to work on cycle
public void DispatcherTimerSetup()
{
dispatcherTimer = new DispatcherTimer();
dispatcherTimer.Tick += dispatcherTimer_Tick;
dispatcherTimer.Interval = new TimeSpan(1000000);
dispatcherTimer.Start();
}
void dispatcherTimer_Tick(object sender, object e)
{
updateDb5();
}
private void Page_Loaded(object sender, RoutedEventArgs e)
{
plc.Open(); // start connection to PLC it could be starts with page load or a button
}
bool value1; // the value which is necessary to access in all pages
private void updateDb5()
{
var db5 = new Db5(); // DB5 in PLC
plc.ReadClass(db5, 5);
value1 = db5.oneSecBlink; // An example bool in PLC DB
}
In the code I need to access to the value1 in all of the pages in my project and store it in SQL Database, Also it is necessary to keep connection alive while the app is running in background.
thanks in advance