




版權(quán)說(shuō)明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡(jiǎn)介
第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"是否過(guò)濾掉中文字符/param
///returns/returns
publicstaticbyte[]StringToHexByte(stringstr,boolisFilterChinese)
stringhex=isFilterChineseFilterChinese(str):ConvertChinese(str);
//清除所有空格
hex=hex.Replace("","");
//若字符個(gè)數(shù)為奇數(shù),補(bǔ)一個(gè)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"打開(kāi)串口";
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. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒(méi)有圖紙預(yù)覽就沒(méi)有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。
最新文檔
- 2025年地區(qū)事業(yè)單位招聘面試真題試卷:社會(huì)學(xué)與社會(huì)政策
- 2025年P(guān)ETS一級(jí)試卷:英語(yǔ)詞匯記憶技巧與方法
- 2025年耐高溫超輕硅酸鈣隔熱保濕材料項(xiàng)目立項(xiàng)申請(qǐng)報(bào)告
- 現(xiàn)任高管在職證明及職責(zé)描述(5篇)
- 2025年安全工程師考試模擬試卷:安全生產(chǎn)管理實(shí)務(wù)案例分析
- 2025年環(huán)保袋項(xiàng)目立項(xiàng)申請(qǐng)報(bào)告
- 農(nóng)民生物技術(shù)利用推廣合作協(xié)議
- 2025年全球石油市場(chǎng)供需分析及價(jià)格波動(dòng)對(duì)全球地緣政治影響報(bào)告
- 2025年定制木門(mén)項(xiàng)目立項(xiàng)申請(qǐng)報(bào)告模板
- 農(nóng)業(yè)生物技術(shù)助力種業(yè)高效生產(chǎn):2025年創(chuàng)新技術(shù)與應(yīng)用策略報(bào)告
- 職業(yè)技術(shù)學(xué)院旅游管理專(zhuān)業(yè)《景區(qū)服務(wù)與管理》課程標(biāo)準(zhǔn)
- 貨物暫存協(xié)議合同模板
- 中央企業(yè)合規(guī)管理系列指南
- 貴州省貴陽(yáng)市2025年中考語(yǔ)文一模試卷附參考答案
- 防汛防雷安全培訓(xùn)
- 鐵路項(xiàng)目施工管理制度
- 新疆維吾爾自治區(qū)2024年普通高校招生單列類(lèi)(選考外語(yǔ))高職(專(zhuān)科)批次投檔情況 (理工)
- 定向士官面試題及答案
- 食品行業(yè)質(zhì)量安全風(fēng)險(xiǎn)管理措施
- 四年級(jí)2025年小學(xué)語(yǔ)文下學(xué)期期末考試真題人教版
- 西安美術(shù)統(tǒng)考考題及答案
評(píng)論
0/150
提交評(píng)論