using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using Srr110uLib;
using Srr1100U;
namespace WpfApplication1
{
public partial class MainWindow : Window
{
SrrReader uhf = new SrrReader ("com8");
private string cc2;
public MainWindow ()
{
InitializeComponent ();
}
private void button_Click (object sender, RoutedEventArgs e)
{
/* SsuControl ssr = new SsuControl ();
ssr.Init ("com8");
byte[] cc=null;*/
uhf.ConnDevice ();
uhf.Read (c);
}
void c (string i)
{
this.Dispatcher.Invoke (() => { listBox.Items.Add (i); });
uhf.CloseDevice ();
}
private void button1_Click (object sender, RoutedEventArgs e)
{
SsuControl cc = new SsuControl ();
cc.Init ("com8");
byte[] a = cc.ReadDate ();
cc.WriteDate (a);
foreach (byte i in a)
textBox.Text += i.ToString ("X2");
cc.Close ();
}
private void textBox1_TextChanged (object sender, TextChangedEventArgs e)
{
}
private void button2_Click (object sender, RoutedEventArgs e)
{
SsuControl aa = new SsuControl ();
aa.Init ("com8");
/*byte[] b = {“”原本是在这里输入0x01这些“” };*/
/*string cc = textBox1.Text.ToString ();
cc2 = "00000000";
cc = cc2.Substring (0, 8 - cc2.Length) + cc;
byte[] b = System.Text.Encoding.Default.GetBytes (cc);这里是从网上摘抄的*/
aa.WriteDate (b);
aa.Close();
}
private void textBox_TextChanged (object sender, TextChangedEventArgs e)
{
}
}
}
byte[] b = {原本是在这里输入0x01这些“};,然后读出来,现在我想启动之后,在textbox里面写,然后读写出来,怎么弄各位大咖
string s=textbox.Text.Replace(" ","");//去掉多余的空格
if(s.Length%2>0)
{
//不是偶数,不能转换
return;
}
byte[] b=new byte[s.Length/2];
for (int i=0;i<b.Length;i++)
{
string s1=s.Substring(i*2,2);
bool isbyte=byte.TryParse(s1,System.Globalization.NumberStyles.HexNumber,null,out b[i]);
//这里要再判断一下isbyte,如果输入的没法转换成16进制数,后面不要发送
}
0x01是啥
如果不用转义的话
先申请一个全局变量
string 存储写入的值="";
写的事件里
存储写入的值==this.textBox1.text;
读的事件里
this.textBox2.text=存储写入的值;