110,567
社区成员
发帖
与我相关
我的任务
分享
//选择连接的设备,USB口或 串口
public void ChooseDevice() {
//如果能读取机器的版本号,则不打开串口
Timer timerUSB = new Timer();//创建一个Timer控件,实时读取数据
timerUSB.Enabled = true;
timerUSB.Interval = 1000;
byte[] byteV = new byte[10];
int VRet = MiReader.GetVersionNum(byteV);//读取设备版本号
string strV = "";
for (int i = 0; i < byteV.Length; i++)
{
strV += string.Format("{0:x2}", byteV[i]);
}
if (strV == "7265616465722d73667a")
{
timerUSB.Tick += new System.EventHandler(timerUSB_Tick);
}
//读取串口设备数据
else
{
OpenSerialPort();
}
}
//USB口设备,循环读取设备数据
private void timerUSB_Tick(object sender, EventArgs e)
{
byte[] byteuid = new byte[8];
byte[] byteBuffer = new byte[8];
int nRet = MiReader.TYPEB_SFZSNR(26, 0, byteuid, byteBuffer);
if (nRet != 0)
{
}
else
{
string strText = "";
for (int i = 0; i < byteBuffer.Length; i++)
{
strText += string.Format("{0:x2}", byteBuffer[i]);
strText = strText.ToUpper();
}
SendMess(strText.ToString());
}
}