@@ -32,29 +32,53 @@ public List<StatusBit>? StatusDevices
3232 OnPropertyChanged ( nameof ( StatusDevices ) ) ;
3333 }
3434 }
35+ public string DisplayHex
36+ {
37+ get => Hex . ToUpper ( ) ;
38+ set
39+ {
40+ hex = value ;
41+ }
42+ }
3543
36- public string HEX
44+ public string DisplayBytes
3745 {
38- get => hex . ToUpper ( ) ;
46+ get => $ "Status Bytes { Bytes } ";
47+ }
48+
49+ public string Hex
50+ {
51+ get => hex ;
3952 set
4053 {
4154 hex = value ;
42- OnPropertyChanged ( nameof ( HEX ) ) ;
55+ OnPropertyChanged ( nameof ( DisplayHex ) ) ;
4356 }
4457 }
4558
4659 public string Bytes
4760 {
48- get => $ "Status Bytes { bytes } " ;
61+ get => bytes ;
4962 set
5063 {
5164 bytes = value ;
52- OnPropertyChanged ( nameof ( Bytes ) ) ;
65+ OnPropertyChanged ( nameof ( DisplayBytes ) ) ;
5366 }
5467 }
5568
5669 public ICommand DecodeCommand => new RelayCommand ( execute : _ => StatusDevices = InitializeStatusDevice ( SelectedDevices , hex ) , canExecute : _ => hex ? . Length > 0 ) ;
5770
71+ public string DecodeToByte ( ref string hex )
72+ {
73+ Hex hexValue = new ( hex ) ;
74+
75+ hexValue . ReduceRange ( null , 127 ) ;
76+
77+ hex = Regex . Replace ( hexValue . ToString ( ) , ".{2}" , "$0 " ) . Trim ( ) ;
78+
79+ return Regex . Replace ( hexValue . ConvertToBinary ( ) , ".{8}" , "$0 " ) . Trim ( ) ;
80+ }
81+
5882 public void OnPropertyChanged ( string prop = "" )
5983 {
6084 PropertyChanged ? . Invoke ( this , new PropertyChangedEventArgs ( prop ) ) ;
@@ -71,41 +95,37 @@ public void OnPropertyChanged(string prop = "")
7195 {
7296 MessageBox . ShowMessage ( ex . Message , "Oops.." , MessageBoxButton . OK , MessageBoxImage . Error ) ;
7397
74- HEX = string . Empty ;
98+ Hex = string . Empty ;
7599 Bytes = string . Empty ;
76100
77101 return null ;
78102 }
79103 }
80104
81- public string DecodeToByte ( ref string hex )
105+ public List < string > SetStatusBytesAndHex ( IDeviceModels selectedDevices , string hex )
82106 {
83- Hex hexValue = new ( hex ) ;
107+ string bytes = DecodeToByte ( ref hex ) ;
84108
85- hexValue . ReduceRange ( null , 127 ) ;
109+ List < string > hexArray = hex . Split ( ' ' ) . ToList ( ) ;
110+ List < string > bytesArray = bytes . Split ( ' ' ) . ToList ( ) ;
86111
87- hex = Regex . Replace ( hexValue . ToString ( ) , ".{2}" , "$0 " ) . Trim ( ) ;
112+ if ( bytesArray . Count < selectedDevices . QuantityStatusByte )
113+ {
114+ throw new ArgumentException ( $ "For this group device quantity of byte must be minimum { selectedDevices . QuantityStatusByte } !") ;
115+ }
116+ else if ( bytesArray . Count > selectedDevices . QuantityStatusByte )
117+ {
118+ bytesArray . RemoveFrom ( selectedDevices . QuantityStatusByte ) ;
119+ hexArray . RemoveFrom ( selectedDevices . QuantityStatusByte ) ;
120+ }
88121
89- return Regex . Replace ( hexValue . ConvertToBinary ( ) , ".{8}" , "$0 " ) . Trim ( ) ;
90- }
122+ Bytes = string . Join ( " " , bytesArray ) ;
123+ Hex = string . Join ( " " , hexArray ) ;
91124
92- private static List < IDeviceModels > InitializeDevices ( ) => new List < IDeviceModels > ( )
93- {
94- new DeviceModels ( Datecs . Instance , 6 , Country . BG , new string [ ] { "DP-05" , "DP-25" , "DP-35" , "WP-50" , "DP-150" } ) ,
95- new DeviceModels ( Datecs . Instance , 6 , Country . BG , new string [ ] { "FP-800" , "FP-2000" , "FP-650" , "SK1-21F" , "SK1-31F" , "FMP-10" , "FP-700" } ) ,
96- new DeviceModels ( Datecs . Instance , 8 , Country . BG , new string [ ] { "DP-25X" , "DP-05C" , "WP-500X" , "WP-50X" , "FP-700X" , "FP-700XR" , "FMP-350Xv" , "FMP-55X" } ) ,
97- new DeviceModels ( Datecs . Instance , 8 , Country . RO ) ,
98- new DeviceModels ( Daisy . Instance , 6 , Country . BG ) ,
99- new DeviceModels ( Daisy . Instance , 6 , Country . KZ ) ,
100- new DeviceModels ( Eltrade . Instance , 6 , Country . BG ) ,
101- new DeviceModels ( Tremol . Instance , 7 , Country . BG ) ,
102- new DeviceModels ( Tremol . Instance , 6 , Country . KE , new string [ ] { "CU" , "M23" } ) ,
103- new DeviceModels ( Incotext . Instance , 4 , Country . KE ) ,
104- new DeviceModels ( Port . Instance , 8 , Country . RU , new string [ ] { "150" , "600" , "1000" } ) ,
105- new DeviceModels ( Port . Instance , 6 , Country . KZ , new string [ ] { "150" } ) ,
106- } ;
125+ return bytesArray ;
126+ }
107127
108- private List < StatusBit > SetStatusDevice ( IDeviceModels selectedDevices , List < string > bytesArray )
128+ public List < StatusBit > SetStatusDevice ( IDeviceModels selectedDevices , List < string > bytesArray )
109129 {
110130 List < StatusBit > status = new ( ) ;
111131 var manufacturer = selectedDevices . Manufacturer ;
@@ -118,29 +138,23 @@ private List<StatusBit> SetStatusDevice(IDeviceModels selectedDevices, List<stri
118138
119139 status . Add ( new StatusBit ( statusBit , keyValuePair . Value ) ) ;
120140 }
141+
121142 return status ;
122143 }
123144
124- private List < string > SetStatusBytesAndHex ( IDeviceModels selectedDevices , string hex )
125- {
126- string bytes = DecodeToByte ( ref hex ) ;
127-
128- List < string > hexArray = hex . Split ( ' ' ) . ToList ( ) ;
129- List < string > bytesArray = bytes . Split ( ' ' ) . ToList ( ) ;
130-
131- if ( bytesArray . Count < selectedDevices . QuantityStatusByte )
132- {
133- throw new ArgumentException ( $ "For this group device quantity of byte must be minimum { selectedDevices . QuantityStatusByte } !") ;
134- }
135- else if ( bytesArray . Count > selectedDevices . QuantityStatusByte )
145+ private static List < IDeviceModels > InitializeDevices ( ) => new List < IDeviceModels > ( )
136146 {
137- bytesArray . RemoveFrom ( selectedDevices . QuantityStatusByte ) ;
138- Bytes = string . Join ( " " , bytesArray ) ;
139-
140- hexArray . RemoveFrom ( selectedDevices . QuantityStatusByte ) ;
141- HEX = string . Join ( " " , hexArray ) ;
142- }
143-
144- return bytesArray ;
145- }
147+ new DeviceModels ( Datecs . Instance , 6 , Country . BG , new string [ ] { "DP-05" , "DP-25" , "DP-35" , "WP-50" , "DP-150" } ) ,
148+ new DeviceModels ( Datecs . Instance , 6 , Country . BG , new string [ ] { "FP-800" , "FP-2000" , "FP-650" , "SK1-21F" , "SK1-31F" , "FMP-10" , "FP-700" } ) ,
149+ new DeviceModels ( Datecs . Instance , 8 , Country . BG , new string [ ] { "DP-25X" , "DP-05C" , "WP-500X" , "WP-50X" , "FP-700X" , "FP-700XR" , "FMP-350Xv" , "FMP-55X" } ) ,
150+ new DeviceModels ( Datecs . Instance , 8 , Country . RO ) ,
151+ new DeviceModels ( Daisy . Instance , 6 , Country . BG ) ,
152+ new DeviceModels ( Daisy . Instance , 6 , Country . KZ ) ,
153+ new DeviceModels ( Eltrade . Instance , 6 , Country . BG ) ,
154+ new DeviceModels ( Tremol . Instance , 7 , Country . BG ) ,
155+ new DeviceModels ( Tremol . Instance , 6 , Country . KE , new string [ ] { "CU" , "M23" } ) ,
156+ new DeviceModels ( Incotext . Instance , 4 , Country . KE ) ,
157+ new DeviceModels ( Port . Instance , 8 , Country . RU , new string [ ] { "150" , "600" , "1000" } ) ,
158+ new DeviceModels ( Port . Instance , 6 , Country . KZ , new string [ ] { "150" } ) ,
159+ } ;
146160}
0 commit comments