@@ -27,6 +27,8 @@ static void Main(string[] args) {
27
27
Console . ReadLine ( ) ;
28
28
}
29
29
30
+ private static bool isProgressReadout = false ;
31
+
30
32
static void Scenario1 ( ) {
31
33
32
34
Task . Factory . StartNew ( async ( ) => {
@@ -46,76 +48,115 @@ static void Scenario1 () {
46
48
47
49
_ = Task . Factory . StartNew ( async ( ) => {
48
50
while ( true ) {
49
- Console . Title = $ "Polling Paused: { interf . PollingPaused } , Speed UP: { interf . BytesPerSecondUpstream } B/s, Speed DOWN: { interf . BytesPerSecondDownstream } B/s";
51
+ if ( isProgressReadout ) continue ;
52
+ Console . Title = $ "Polling Paused: { interf . PollingPaused } , " +
53
+ $ "Speed UP: { interf . BytesPerSecondUpstream } B/s, " +
54
+ $ "Speed DOWN: { interf . BytesPerSecondDownstream } B/s, " +
55
+ $ "Poll delay: { interf . PollerDelayMs } ms, " +
56
+ $ "Queued MSGs: { interf . QueuedMessages } ";
50
57
await Task . Delay ( 1000 ) ;
51
58
}
52
59
} ) ;
53
60
54
- await interf . ConnectAsync (
55
- ( plcinf ) => {
61
+ await interf . ConnectAsync ( ( plcinf ) => AfterConnect ( interf , registers ) ) ;
56
62
57
- //reading a value from the register collection
58
- Console . WriteLine ( $ "BitValue is: { registers . BitValue } ") ;
59
- Console . WriteLine ( $ "TestEnum is: { registers . TestEnum } ") ;
63
+ } ) ;
60
64
61
- //writing a value to the registers
62
- Task . Factory . StartNew ( async ( ) => {
65
+ }
63
66
64
- //set plc to run mode if not already
65
- await interf . SetOperationMode ( OPMode . Run ) ;
67
+ static void AfterConnect ( MewtocolInterface interf , TestRegisters registers ) {
66
68
69
+ //reading a value from the register collection
70
+ Console . WriteLine ( $ "BitValue is: { registers . BitValue } ") ;
71
+ Console . WriteLine ( $ "TestEnum is: { registers . TestEnum } ") ;
67
72
68
- int startAdress = 10000 ;
69
- int entryByteSize = 20 * 20 ;
73
+ _ = Task . Factory . StartNew ( async ( ) => {
70
74
71
- var bytes = await interf . ReadByteRange ( startAdress , entryByteSize ) ;
72
- Console . WriteLine ( $ "Bytes: { string . Join ( '-' , bytes ) } ") ;
75
+ while ( true ) {
73
76
74
- await Task . Delay ( 2000 ) ;
77
+ isProgressReadout = true ;
75
78
76
- await interf . SetRegisterAsync ( nameof ( registers . TestInt32 ) , 100 ) ;
79
+ await interf . ReadByteRange ( 1000 , 2000 , ( p ) => {
77
80
78
- //adds 10 each time the plc connects to the PLCs INT regíster
79
- interf . SetRegister ( nameof ( registers . TestInt16 ) , ( short ) ( registers . TestInt16 + 10 ) ) ;
80
- //adds 1 each time the plc connects to the PLCs DINT regíster
81
- interf . SetRegister ( nameof ( registers . TestInt32 ) , ( registers . TestInt32 + 1 ) ) ;
82
- //adds 11.11 each time the plc connects to the PLCs REAL regíster
83
- interf . SetRegister ( nameof ( registers . TestFloat32 ) , ( float ) ( registers . TestFloat32 + 11.11 ) ) ;
84
- //writes 'Hello' to the PLCs string register
85
- interf . SetRegister ( nameof ( registers . TestString2 ) , "Hello" ) ;
86
- //set the current second to the PLCs TIME register
87
- interf . SetRegister ( nameof ( registers . TestTime ) , TimeSpan . FromSeconds ( DateTime . Now . Second ) ) ;
81
+ var totSteps = 10 ;
82
+ var cSteps = totSteps * p ;
88
83
89
- //test pausing poller
84
+ string progBar = "" ;
85
+ for ( int i = 0 ; i < totSteps ; i ++ ) {
90
86
91
- bool pollerPaused = false ;
87
+ if ( i < ( int ) cSteps ) {
88
+ progBar += "⬛" ;
89
+ } else {
90
+ progBar += "⬜" ;
91
+ }
92
+
93
+ }
92
94
93
- while ( true ) {
95
+ Console . Title = $ "Prog read range: { ( p * 100 ) . ToString ( "N1" ) } % { progBar } Queued MSGs: { interf . QueuedMessages } " ;
94
96
95
- await Task . Delay ( 5000 ) ;
97
+ } ) ;
96
98
97
- pollerPaused = ! pollerPaused ;
99
+ isProgressReadout = false ;
98
100
99
- if ( pollerPaused ) {
100
- Console . WriteLine ( "Pausing poller" ) ;
101
- await interf . PausePollingAsync ( ) ;
102
- Console . WriteLine ( "Paused poller" ) ;
103
- } else {
104
- interf . ResumePolling ( ) ;
105
- Console . WriteLine ( "Resumed poller" ) ;
106
- }
101
+ await Task . Delay ( 3000 ) ;
107
102
108
- }
103
+ }
104
+
105
+ } ) ;
106
+
107
+ //writing a value to the registers
108
+ _ = Task . Factory . StartNew ( async ( ) => {
109
+
110
+ //set plc to run mode if not already
111
+ await interf . SetOperationMode ( OPMode . Run ) ;
112
+
113
+ int startAdress = 10000 ;
114
+ int entryByteSize = 20 * 20 ;
109
115
116
+ var bytes = await interf . ReadByteRange ( startAdress , entryByteSize ) ;
117
+ Console . WriteLine ( $ "Bytes: { string . Join ( '-' , bytes ) } ") ;
110
118
111
- } ) ;
119
+ await Task . Delay ( 2000 ) ;
112
120
121
+ await interf . SetRegisterAsync ( nameof ( registers . TestInt32 ) , 100 ) ;
122
+
123
+ //adds 10 each time the plc connects to the PLCs INT regíster
124
+ interf . SetRegister ( nameof ( registers . TestInt16 ) , ( short ) ( registers . TestInt16 + 10 ) ) ;
125
+ //adds 1 each time the plc connects to the PLCs DINT regíster
126
+ interf . SetRegister ( nameof ( registers . TestInt32 ) , ( registers . TestInt32 + 1 ) ) ;
127
+ //adds 11.11 each time the plc connects to the PLCs REAL regíster
128
+ interf . SetRegister ( nameof ( registers . TestFloat32 ) , ( float ) ( registers . TestFloat32 + 11.11 ) ) ;
129
+ //writes 'Hello' to the PLCs string register
130
+ interf . SetRegister ( nameof ( registers . TestString2 ) , "Hello" ) ;
131
+ //set the current second to the PLCs TIME register
132
+ interf . SetRegister ( nameof ( registers . TestTime ) , TimeSpan . FromSeconds ( DateTime . Now . Second ) ) ;
133
+
134
+ //test pausing poller
135
+
136
+ bool pollerPaused = false ;
137
+
138
+ while ( true ) {
139
+
140
+ await Task . Delay ( 5000 ) ;
141
+
142
+ pollerPaused = ! pollerPaused ;
143
+
144
+ if ( pollerPaused ) {
145
+ Console . WriteLine ( "Pausing poller" ) ;
146
+ await interf . PausePollingAsync ( ) ;
147
+ //interf.PollerDelayMs += 10;
148
+ Console . WriteLine ( "Paused poller" ) ;
149
+ } else {
150
+ interf . ResumePolling ( ) ;
151
+ Console . WriteLine ( "Resumed poller" ) ;
113
152
}
114
- ) ;
153
+
154
+ }
155
+
115
156
116
157
} ) ;
117
158
118
- }
159
+ }
119
160
120
161
static void Scenario2 ( ) {
121
162
0 commit comments