@@ -47,6 +47,10 @@ class RelayCoilElm extends CircuitElm {
4747
4848 // time to switch in seconds
4949 double switchingTime ;
50+ // release time (0 = same as switchingTime). real relays typically
51+ // release faster than they engage because the spring force assists
52+ // the armature return.
53+ double releaseTime ;
5054 double switchingTimeOn , switchingTimeOff ;
5155 double lastTransition ;
5256
@@ -122,6 +126,8 @@ void dumpXml(Document doc, Element elem) {
122126 XMLSerializer .dumpAttr (elem , "cr" , coilR );
123127 XMLSerializer .dumpAttr (elem , "ofc" , offCurrent );
124128 XMLSerializer .dumpAttr (elem , "swt" , switchingTime );
129+ if (releaseTime > 0 )
130+ XMLSerializer .dumpAttr (elem , "rt" , releaseTime );
125131 XMLSerializer .dumpAttr (elem , "tp" , type );
126132 }
127133 void dumpXmlState (Document doc , Element elem ) {
@@ -137,6 +143,7 @@ void undumpXml(XMLDeserializer xml) {
137143 coilR = xml .parseDoubleAttr ("cr" , coilR );
138144 offCurrent = xml .parseDoubleAttr ("ofc" , offCurrent );
139145 switchingTime = xml .parseDoubleAttr ("swt" , switchingTime );
146+ releaseTime = xml .parseDoubleAttr ("rt" , 0 );
140147 type = xml .parseIntAttr ("tp" , type );
141148 coilCurrent = xml .parseDoubleAttr ("ci" , coilCurrent );
142149 state = xml .parseIntAttr ("st" , state );
@@ -272,14 +279,16 @@ void stamp() {
272279 // resistor from internal node to coil post 2
273280 sim .stampResistor (nodes [nCoil3 ], nodes [nCoil2 ], coilR );
274281
282+ double effectiveReleaseTime = (releaseTime > 0 ) ? releaseTime : switchingTime ;
275283 if (type == TYPE_ON_DELAY ) {
276284 switchingTimeOn = switchingTime ;
277285 switchingTimeOff = 0 ;
278286 } else if (type == TYPE_OFF_DELAY ) {
279287 switchingTimeOff = switchingTime ;
280288 switchingTimeOn = 0 ;
281289 } else {
282- switchingTimeOff = switchingTimeOn = switchingTime ;
290+ switchingTimeOn = switchingTime ;
291+ switchingTimeOff = effectiveReleaseTime ;
283292 }
284293 setSwitchPositions ();
285294 }
@@ -390,15 +399,21 @@ public EditInfo getEditInfo(int n) {
390399 return new EditInfo ("Coil Resistance (ohms)" , coilR , 0 , 0 );
391400 if (n == 5 )
392401 return new EditInfo ("Switching Time (s)" , switchingTime , 0 , 0 );
393- if (n == 6 )
402+ if (n == 6 && (type == TYPE_NORMAL || type == TYPE_LATCHING ))
403+ return new EditInfo ("Release Time (s)" , releaseTime > 0 ? releaseTime : switchingTime , 0 , 0 );
404+ int labelIdx = (type == TYPE_NORMAL || type == TYPE_LATCHING ) ? 7 : 6 ;
405+ if (n == labelIdx )
394406 return new EditInfo ("Label (for linking)" , label );
395407 return null ;
396408 }
397409
398410 public void setEditValue (int n , EditInfo ei ) {
399411 if (n == 0 ) {
412+ int oldType = type ;
400413 type = ei .choice .getSelectedIndex ();
401414 setPoints ();
415+ if (oldType != type )
416+ ei .newDialog = true ;
402417 }
403418 if (n == 1 && ei .value > 0 ) {
404419 inductance = ei .value ;
@@ -412,7 +427,10 @@ public void setEditValue(int n, EditInfo ei) {
412427 coilR = ei .value ;
413428 if (n == 5 && ei .value > 0 )
414429 switchingTime = ei .value ;
415- if (n == 6 )
430+ if (n == 6 && (type == TYPE_NORMAL || type == TYPE_LATCHING ) && ei .value > 0 )
431+ releaseTime = ei .value ;
432+ int labelIdx = (type == TYPE_NORMAL || type == TYPE_LATCHING ) ? 7 : 6 ;
433+ if (n == labelIdx )
416434 label = ei .textf .getText ();
417435 }
418436
0 commit comments