@@ -549,18 +549,32 @@ public void ParseControlValueFromString(string myValue)
549
549
case TagDataType . S5Time :
550
550
case TagDataType . Time :
551
551
if ( myValueStrip . Contains ( "t#" ) || myValueStrip . Contains ( "s5t#" ) )
552
+ {
552
553
Controlvalue = Helper . GetTimespanFromS5TimeorTime ( myValue ) ;
554
+ }
553
555
else
554
- try { Controlvalue = TimeSpan . Parse ( myValue ) ; } catch ( Exception ) { }
556
+ {
557
+ TimeSpan ret ;
558
+ TimeSpan . TryParse ( myValue , out ret ) ;
559
+ Controlvalue = ret ;
560
+ }
555
561
break ;
556
562
case TagDataType . BCDWord :
557
563
case TagDataType . Int :
558
564
if ( myValueStrip . Contains ( "w#16#" ) || myValueStrip . Contains ( "dw#16#" ) )
565
+ {
559
566
Controlvalue = Convert . ToInt16 ( Helper . GetIntFromHexString ( myValue ) ) ;
567
+ }
560
568
else if ( myValue . StartsWith ( "2#" ) )
569
+ {
561
570
Controlvalue = Convert . ToInt16 ( Helper . GetIntFromBinString ( myValue ) ) ;
571
+ }
562
572
else
563
- try { Controlvalue = Int16 . Parse ( myValue ) ; } catch ( Exception ) { }
573
+ {
574
+ Int16 ret ;
575
+ Int16 . TryParse ( myValue , out ret ) ;
576
+ Controlvalue = ret ;
577
+ }
564
578
break ;
565
579
case TagDataType . BCDDWord :
566
580
case TagDataType . Dint :
@@ -569,40 +583,76 @@ public void ParseControlValueFromString(string myValue)
569
583
else if ( myValue . StartsWith ( "2#" ) )
570
584
Controlvalue = Convert . ToInt32 ( Helper . GetIntFromBinString ( myValue ) ) ;
571
585
else
572
- try { Controlvalue = Int32 . Parse ( myValue ) ; } catch ( Exception ) { }
586
+ try
587
+ {
588
+ if ( ! string . IsNullOrEmpty ( myValue ) )
589
+ Controlvalue = Int32 . Parse ( myValue ) ;
590
+ } catch ( Exception ) { }
573
591
break ;
574
592
case TagDataType . Byte :
575
593
if ( myValueStrip . Contains ( "w#16#" ) || myValueStrip . Contains ( "dw#16#" ) )
594
+ {
576
595
Controlvalue = Convert . ToByte ( Helper . GetIntFromHexString ( myValue ) ) ;
596
+ }
577
597
else if ( myValue . StartsWith ( "2#" ) )
598
+ {
578
599
Controlvalue = Convert . ToByte ( Helper . GetIntFromBinString ( myValue ) ) ;
600
+ }
579
601
else
580
- try { Controlvalue = Byte . Parse ( myValue ) ; } catch ( Exception ) { }
602
+ {
603
+ Byte ret ;
604
+ Byte . TryParse ( myValue , out ret ) ;
605
+ Controlvalue = ret ;
606
+ }
581
607
break ;
582
608
case TagDataType . BCDByte :
583
609
case TagDataType . SByte :
584
610
if ( myValueStrip . Contains ( "w#16#" ) || myValueStrip . Contains ( "dw#16#" ) )
611
+ {
585
612
Controlvalue = Convert . ToSByte ( Helper . GetIntFromHexString ( myValue ) ) ;
613
+ }
586
614
else if ( myValue . StartsWith ( "2#" ) )
615
+ {
587
616
Controlvalue = Convert . ToSByte ( Helper . GetIntFromBinString ( myValue ) ) ;
617
+ }
588
618
else
589
- try { Controlvalue = SByte . Parse ( myValue ) ; } catch ( Exception ) { }
619
+ {
620
+ SByte ret ;
621
+ SByte . TryParse ( myValue , out ret ) ;
622
+ Controlvalue = ret ;
623
+ }
590
624
break ;
591
625
case TagDataType . Word :
592
626
if ( myValueStrip . Contains ( "w#16#" ) || myValueStrip . Contains ( "dw#16#" ) )
627
+ {
593
628
Controlvalue = Convert . ToUInt16 ( Helper . GetIntFromHexString ( myValue ) ) ;
629
+ }
594
630
else if ( myValue . StartsWith ( "2#" ) )
631
+ {
595
632
Controlvalue = Convert . ToUInt16 ( Helper . GetIntFromBinString ( myValue ) ) ;
633
+ }
596
634
else
597
- try { Controlvalue = UInt16 . Parse ( myValue ) ; } catch ( Exception ) { }
635
+ {
636
+ UInt16 ret ;
637
+ UInt16 . TryParse ( myValue , out ret ) ;
638
+ Controlvalue = ret ;
639
+ }
598
640
break ;
599
641
case TagDataType . Dword :
600
642
if ( myValueStrip . Contains ( "w#16#" ) || myValueStrip . Contains ( "dw#16#" ) )
643
+ {
601
644
Controlvalue = Convert . ToUInt32 ( Helper . GetIntFromHexString ( myValue ) ) ;
645
+ }
602
646
else if ( myValue . StartsWith ( "2#" ) )
647
+ {
603
648
Controlvalue = Convert . ToUInt32 ( Helper . GetIntFromBinString ( myValue ) ) ;
649
+ }
604
650
else
605
- try { Controlvalue = UInt32 . Parse ( myValue ) ; } catch ( Exception ) { }
651
+ {
652
+ UInt32 ret ;
653
+ UInt32 . TryParse ( myValue , out ret ) ;
654
+ Controlvalue = ret ;
655
+ }
606
656
break ;
607
657
case TagDataType . Bool :
608
658
if ( myValue == "1" )
@@ -632,7 +682,8 @@ public void ParseControlValueFromString(string myValue)
632
682
else if ( ! string . IsNullOrEmpty ( myValue ) )
633
683
try
634
684
{
635
- Controlvalue = DateTime . Parse ( myValue ) ;
685
+ if ( ! string . IsNullOrEmpty ( myValue ) )
686
+ Controlvalue = DateTime . Parse ( myValue ) ;
636
687
}
637
688
catch ( Exception ) { }
638
689
break ;
0 commit comments