C#實(shí)現(xiàn)串口調(diào)試工具_(dá)第1頁
C#實(shí)現(xiàn)串口調(diào)試工具_(dá)第2頁
C#實(shí)現(xiàn)串口調(diào)試工具_(dá)第3頁
C#實(shí)現(xiàn)串口調(diào)試工具_(dá)第4頁
C#實(shí)現(xiàn)串口調(diào)試工具_(dá)第5頁
已閱讀5頁,還剩2頁未讀, 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡介

第C#實(shí)現(xiàn)串口調(diào)試工具bytehi=arr[0],lo=arr[1];

returnConvert.ToString(isReversehi+lo*0x100:hi*0x100+lo,16).ToUpper().PadLeft(4,'0');

catch(Exceptionex){throw(ex);}

publicstaticstringByteToString(byte[]arr)

returnByteToString(arr,true);

catch(Exceptionex){throw(ex);}

#endregion

#regionStringToHexString

publicstaticstringStringToHexString(stringstr)

StringBuilders=newStringBuilder();

foreach(shortcinstr.ToCharArray())

s.Append(c.ToString("X4"));

returns.ToString();

#endregion

#regionStringToHexByte

privatestaticstringConvertChinese(stringstr)

StringBuilders=newStringBuilder();

foreach(shortcinstr.ToCharArray())

if(c=0||c=127)

s.Append(c.ToString("X4"));

else

s.Append((char)c);

returns.ToString();

privatestaticstringFilterChinese(stringstr)

StringBuilders=newStringBuilder();

foreach(shortcinstr.ToCharArray())

if(c0c127)

s.Append((char)c);

returns.ToString();

///summary

///字符串轉(zhuǎn)16進(jìn)制字符數(shù)組

////summary

///paramname="hex"/param

///returns/returns

publicstaticbyte[]StringToHexByte(stringstr)

returnStringToHexByte(str,false);

///summary

///字符串轉(zhuǎn)16進(jìn)制字符數(shù)組

////summary

///paramname="str"/param

///paramname="isFilterChinese"是否過濾掉中文字符/param

///returns/returns

publicstaticbyte[]StringToHexByte(stringstr,boolisFilterChinese)

stringhex=isFilterChineseFilterChinese(str):ConvertChinese(str);

//清除所有空格

hex=hex.Replace("","");

//若字符個數(shù)為奇數(shù),補(bǔ)一個0

hex+=hex.Length%2!=0"0":"";

byte[]result=newbyte[hex.Length/2];

for(inti=0,c=result.Length;ii++)

result[i]=Convert.ToByte(hex.Substring(i*2,2),16);

returnresult;

#endregion

}

WPF技術(shù)點(diǎn):

1.自定義樣式按鈕

Stylex:Key="CommonButtonBase"TargetType="{x:TypeButton}"

SetterProperty="BorderBrush"Value="Transparent"/

SetterProperty="BorderThickness"Value="0"/

SetterProperty="Foreground"Value="{DynamicResource{x:StaticSystemColors.ControlTextBrushKey}}"/

SetterProperty="HorizontalContentAlignment"Value="Center"/

SetterProperty="VerticalContentAlignment"Value="Center"/

SetterProperty="Padding"Value="1"/

SetterProperty="Cursor"Value="Hand"/

SetterProperty="Template"

Setter.Value

ControlTemplateTargetType="{x:TypeButton}"

Borderx:Name="border"BorderBrush="{TemplateBindingBorderBrush}"

CornerRadius="4"

BorderThickness="{TemplateBindingBorderThickness}"

Background="{TemplateBindingBackground}"

SnapsToDevicePixels="true"

ContentPresenterHorizontalAlignment="{TemplateBindingHorizontalContentAlignment}"

Margin="{TemplateBindingPadding}"RecognizesAccessKey="True"

SnapsToDevicePixels="{TemplateBindingSnapsToDevicePixels}"

VerticalAlignment="{TemplateBindingVerticalContentAlignment}"/

/Border

ControlTemplate.Triggers

TriggerProperty="IsEnabled"Value="False"

SetterProperty="Background"Value="#000000"/

SetterProperty="Opacity"Value="0.1"/

/Trigger

TriggerProperty="IsMouseOver"Value="true"

SetterProperty="Foreground"Value="#FFFF00"/

/Trigger

TriggerProperty="IsMouseOver"Value="false"

SetterProperty="Foreground"Value="White"/

/Trigger

/ControlTemplate.Triggers

/ControlTemplate

/Setter.Value

/Setter

/Style

StyleTargetType="{x:TypeButton}"x:Key="Btn0093EABase"BasedOn="{StaticResourceCommonButtonBase}"

SetterProperty="Background"Value="#0093EA"/

SetterProperty="Foreground"Value="White"/

SetterProperty="FontSize"Value="22"/

SetterProperty="Height"Value="40"/

SetterProperty="Margin"Value="5"/

/Style

2.轉(zhuǎn)換器用于綁定按鈕

publicclassFontConverters:IValueConverter

publicobjectConvert(objectvalue,TypetargetType,objectparameter,CultureInfoculture)

if(value!=nullbool.TryParse(value.ToString(),outboolresult))

if(result)

return"關(guān)閉串口";

return"打開串口";

publicobjectConvertBack(objectvalue,TypetargetType,objectparameter,CultureInfoculture)

thrownewNotImplementedException();

}

//用于綁定UI的顏色狀態(tài)顯示publicclassColorConverters:IValueConverter

publicobjectConvert(objectvalue,TypetargetType,objectparameter,CultureInfoculture)

if(value!=nullbool.TryParse(value.ToString(),outboolresult))

if(result)

returnnewSolidColorBrush((Color)System.Windows.Media.ColorConverter.ConvertFromString("#2E8B57"));

returnnewSolidColorBrush((Color)System.Windows.Media.ColorConverter.ConvertFromString("#FF6347"));

publicobjectConvertBack(objectvalue,TypetargetType,objectparameter,CultureInfoculture)

thrownewNotImplementedException();

}

3.引用字體

TextBlockText="#xe6e4;"Margin="20505"FontFamily="pack://application:,,,/Font/#iconfont"

Foreground="White"FontSize="30"VerticalAlignment="Center"/

4.綁定命令和元素

TextBlockText="端口:"/

ComboBoxGrid.Row="0"Grid.Column="2"SelectedItem="{BindingCurrentParameter.Port}"

ItemsSource="{BindingComParameterConfig.Port}"

TextBlockText="波特率:"/

ComboBoxGrid.Row="0"Grid.Column="2"SelectedItem="{BindingCurrentParameter.BaudRdate}"

ItemsSource="{BindingComParameterConfig.BaudRate}"

TextBlockText="數(shù)據(jù)位:"/

ComboBoxGrid.Row="0"Grid.Column="2"SelectedItem="{BindingCurrentParameter.DataBit}"

ItemsSource="{Binding

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論