private void Button3_Click(object sender, EventArgs e) { byte[] TrType = new byte[2]; byte[] VersionInfo = new byte[2]; byte ReaderType = 0; byte ScanTime = 0; byte dmaxfre = 0; byte dminfre = 0; byte powerdBm = 0; byte FreBand = 0; fCmdRet = StaticClassReaderB.GetReaderInformation(ref fComAdr, VersionInfo, ref ReaderType, TrType, ref dmaxfre, ref dminfre, ref powerdBm, ref ScanTime, frmcomportindex); if (fCmdRet == 0) { FreBand = Convert.ToByte(((dmaxfre & 0xc0) >> 4) | (dminfre >> 6)); switch (FreBand) { case 0: { fdminfre = 902.6 + (dminfre & 0x3F) * 0.4; fdmaxfre = 902.6 + (dmaxfre & 0x3F) * 0.4; } break; case 1: { fdminfre = 920.125 + (dminfre & 0x3F) * 0.25; fdmaxfre = 920.125 + (dmaxfre & 0x3F) * 0.25; } break; case 2: { fdminfre = 902.75 + (dminfre & 0x3F) * 0.5; fdmaxfre = 902.75 + (dmaxfre & 0x3F) * 0.5; } break; case 3: { fdminfre = 917.1 + (dminfre & 0x3F) * 0.2; fdmaxfre = 917.1 + (dmaxfre & 0x3F) * 0.2; } break; case 4: { fdminfre = 865.1 + (dminfre & 0x3F) * 0.2; fdmaxfre = 865.1 + (dmaxfre & 0x3F) * 0.2; } break; } } AddCmdLog("GetReaderInformation", "GetReaderInformation", fCmdRet); }
//获得读写器信息 private void Button3_Click(object sender, EventArgs e) { byte[] TrType = new byte[2]; byte[] VersionInfo = new byte[2]; byte ReaderType = 0; byte ScanTime = 0; byte dmaxfre = 0; byte dminfre = 0; byte powerdBm = 0; Edit_Version.Text = ""; Edit_ComAdr.Text = ""; Edit_scantime.Text = ""; Edit_Type.Text = ""; ISO180006B.Checked = false; EPCC1G2.Checked = false; Edit_powerdBm.Text = ""; fCmdRet = StaticClassReaderB.GetReaderInformation(ref fComAdr, VersionInfo, ref ReaderType, TrType, ref dmaxfre, ref dminfre, ref powerdBm, ref ScanTime, frmcomportindex); if (fCmdRet == 0) { Edit_Version.Text = Convert.ToString(VersionInfo[0], 10).PadLeft(2, '0') + "." + Convert.ToString(VersionInfo[1], 10).PadLeft(2, '0'); Edit_ComAdr.Text = Convert.ToString(fComAdr, 16).PadLeft(2, '0'); Edit_scantime.Text = Convert.ToString(ScanTime, 10).PadLeft(2, '0') + "*100ms"; Edit_powerdBm.Text = Convert.ToString(powerdBm, 10).PadLeft(2, '0'); if (ReaderType == 0x03) { Edit_Type.Text = ""; } if (ReaderType == 0x06) { Edit_Type.Text = ""; } if (ReaderType == 0x09) { Edit_Type.Text = "UHFReader18"; } if ((TrType[0] & 0x02) == 0x02) //第二个字节低第四位代表支持的协议“ISO/IEC 15693” { ISO180006B.Checked = true; EPCC1G2.Checked = true; } else { ISO180006B.Checked = false; EPCC1G2.Checked = false; } write_log("获得读写器信息"); } }
private bool GetReaderInfor() { byte[] verInfo = new byte[2]; byte[] trType = new byte[2]; byte readerType = 0; byte inventoryScanTime = 0; int fCmdRet = 0x30; fCmdRet = StaticClassReaderB.GetReaderInformation(ref this.comAddr, verInfo, ref readerType, trType, ref inventoryScanTime, this.readHandle); if (fCmdRet == 0) { return(true); } else { return(false); } }
public static bool OpenPort() { bool ComOpen = false; int port = 0; int openresult, i; openresult = 30; if (!_IsUseNet) { port = Convert.ToInt32(_Com.Substring(3, _Com.Length - 3)); } int fOpenComIndex = 0; for (i = 6; i >= 0; i--) { fBaud = Convert.ToByte(i); if (fBaud == 3) { continue; } if (!_IsUseNet) { openresult = StaticClassReaderB.OpenComPort(port, ref fComAdr, fBaud, ref frmcomportindex); } else { LBErrorLog.InsertFileLog("OpenPort:" + _NetIPAddress + "_" + _NetPort + "_" + Rate); openresult = StaticClassReaderB.OpenNetPort(_NetPort, _NetIPAddress, ref fComAdr, ref frmcomportindex); } fOpenComIndex = frmcomportindex; if (openresult == 0x35) { LBErrorLog.InsertFileLog("网口已打开"); ComOpen = true; } if (openresult == 0) { ComOpen = true; byte[] TrType = new byte[2]; byte[] VersionInfo = new byte[2]; byte ReaderType = 0; byte ScanTime = 0; byte dmaxfre = 0; byte dminfre = 0; byte powerdBm = 0; int fCmdRet = StaticClassReaderB.GetReaderInformation(ref fComAdr, VersionInfo, ref ReaderType, TrType, ref dmaxfre, ref dminfre, ref powerdBm, ref ScanTime, frmcomportindex); if ((fCmdRet == 0x35) || (fCmdRet == 0x30)) { ComOpen = false; StaticClassReaderB.CloseSpecComPort(frmcomportindex); LBErrorLog.InsertFileLog("CloseSpecComPort串口通讯错误"); } fCmdRet = StaticClassReaderB.SetPowerDbm(ref fComAdr, powerDbm, frmcomportindex);//设置功率 break; } else if (_IsUseNet) { break; } } if ((fOpenComIndex == -1) && (openresult == 0x30)) { LBErrorLog.InsertFileLog("串口通讯错误"); } return(ComOpen); }
private void btn_run_Click(object sender, EventArgs e) { int port = 0; int openresult, i; openresult = 30; string temp; Cursor = Cursors.WaitCursor; fComAdr = Convert.ToByte("FF", 16);//读写器地址 try { if (true) //Auto自动选择COM口 { fBaud = Convert.ToByte(3); //9600bps19200bps38400bps57600bps115200bps if (fBaud > 2) { fBaud = Convert.ToByte(fBaud + 2); } openresult = StaticClassReaderB.AutoOpenComPort(ref port, ref fComAdr, fBaud, ref frmcomportindex); fOpenComIndex = frmcomportindex; if (openresult == 0) { ComOpen = true; if ((fCmdRet == 0x35) | (fCmdRet == 0x30)) { MessageBox.Show("串口通讯错误", "信息提示"); StaticClassReaderB.CloseSpecComPort(frmcomportindex); ComOpen = false; } } } } finally { Cursor = Cursors.Default; } string com = ""; if ((fOpenComIndex != -1) & (openresult != 0X35) & (openresult != 0X30)) { com = Convert.ToString(fOpenComIndex); ComOpen = true; } if ((fOpenComIndex == -1) && (openresult == 0x30)) { MessageBox.Show("串口通讯错误", "信息提示"); } byte[] TrType = new byte[2]; byte[] VersionInfo = new byte[2]; byte ReaderType = 0; byte ScanTime = 0; byte dmaxfre = 0; byte dminfre = 0; byte powerdBm = 0; fCmdRet = StaticClassReaderB.GetReaderInformation(ref fComAdr, VersionInfo, ref ReaderType, TrType, ref dmaxfre, ref dminfre, ref powerdBm, ref ScanTime, frmcomportindex); //if ((ComboBox_AlreadyOpenCOM.Items.Count != 0) & (fOpenComIndex != -1) & (openresult != 0X35) & (openresult != 0X30) & (fCmdRet == 0)) if ((com != "") & (fOpenComIndex != -1) & (openresult != 0X35) & (openresult != 0X30) & (fCmdRet == 0)) { fComAdr = Convert.ToByte("00", 16); temp = "COM" + com; frmcomportindex = Convert.ToInt32(temp.Substring(3, temp.Length - 3)); } //RefreshStatus(); lbl_status.Text = startRun(0); //设置应答模式 th_read = new Thread(startRead); th_read.Start(); // 启动 //th_write = new Thread(startWrite); //startRead();//运行应答模式 }
private void GetReaderInformation() { byte[] TrType = new byte[2]; byte[] VersionInfo = new byte[2]; byte ReaderType = 0; byte ScanTime = 0; byte dmaxfre = 0; byte dminfre = 0; byte powerdBm = 0; byte FreBand = 0; fCmdRet = StaticClassReaderB.GetReaderInformation(ref fComAdr, VersionInfo, ref ReaderType, TrType, ref dmaxfre, ref dminfre, ref powerdBm, ref ScanTime, frmcomportindex); if (fCmdRet == 0) { FreBand = Convert.ToByte(((dmaxfre & 0xc0) >> 4) | (dminfre >> 6)); switch (FreBand) { case 0: { fdminfre = 902.6 + (dminfre & 0x3F) * 0.4; fdmaxfre = 902.6 + (dmaxfre & 0x3F) * 0.4; } break; case 1: { fdminfre = 920.125 + (dminfre & 0x3F) * 0.25; fdmaxfre = 920.125 + (dmaxfre & 0x3F) * 0.25; } break; case 2: { fdminfre = 902.75 + (dminfre & 0x3F) * 0.5; fdmaxfre = 902.75 + (dmaxfre & 0x3F) * 0.5; } break; case 3: { fdminfre = 917.1 + (dminfre & 0x3F) * 0.2; fdmaxfre = 917.1 + (dmaxfre & 0x3F) * 0.2; } break; case 4: { fdminfre = 865.1 + (dminfre & 0x3F) * 0.2; fdmaxfre = 865.1 + (dmaxfre & 0x3F) * 0.2; } break; } HelperLog.Info(Convert.ToString(fdminfre) + "MHz"); HelperLog.Info(Convert.ToString(fdmaxfre) + "MHz"); if (fdmaxfre != fdminfre) { if ((TrType[0] & 0x02) == 0x02) //第二个字节低第四位代表支持的协议“ISO/IEC 15693” { HelperLog.Info("EPCC1G2 ISO180006B True"); } else { HelperLog.Info("EPCC1G2 ISO180006B Fasle"); } } } HelperLog.Info("GetReaderInformation" + GetErrorCodeDesc(fCmdRet)); }
private void btn_open_Click(object sender, EventArgs e) { int port = 0; int openresult, i; openresult = 30; string temp; Cursor = Cursors.WaitCursor; if (Edit_CmdComAddr.Text == "") { Edit_CmdComAddr.Text = "FF"; } fComAdr = Convert.ToByte(Edit_CmdComAddr.Text, 16); // $FF; fComAdr = Convert.ToByte("FF", 16); try { if (ComboBox_COM.SelectedIndex == 0)//Auto { fBaud = Convert.ToByte(ComboBox_baud2.SelectedIndex); if (fBaud > 2) { fBaud = Convert.ToByte(fBaud + 2); } openresult = StaticClassReaderB.AutoOpenComPort(ref port, ref fComAdr, fBaud, ref frmcomportindex); fOpenComIndex = frmcomportindex; if (openresult == 0) { ComOpen = true; // Button3_Click(sender, e); //自动执行读取写卡器信息 //if (fBaud > 3) //{ // ComboBox_baud.SelectedIndex = Convert.ToInt32(fBaud - 2); //} //else //{ // ComboBox_baud.SelectedIndex = Convert.ToInt32(fBaud); //} //Button3_Click(sender, e); //自动执行读取写卡器信息 if ((fCmdRet == 0x35) | (fCmdRet == 0x30)) { MessageBox.Show("串口通讯错误", "信息提示"); StaticClassReaderB.CloseSpecComPort(frmcomportindex); ComOpen = false; } } } else { temp = ComboBox_COM.SelectedItem.ToString(); temp = temp.Trim(); port = Convert.ToInt32(temp.Substring(3, temp.Length - 3)); for (i = 6; i >= 0; i--) { fBaud = Convert.ToByte(i); if (fBaud == 3) { continue; } openresult = StaticClassReaderB.OpenComPort(port, ref fComAdr, fBaud, ref frmcomportindex); fOpenComIndex = frmcomportindex; if (openresult == 0x35) { MessageBox.Show("串口已打开", "信息提示"); return; } if (openresult == 0) { ComOpen = true; //Button3_Click(sender, e); //自动执行读取写卡器信息 //if (fBaud > 3) //{ // ComboBox_baud.SelectedIndex = Convert.ToInt32(fBaud - 2); //} //else //{ // ComboBox_baud.SelectedIndex = Convert.ToInt32(fBaud); //} if ((fCmdRet == 0x35) || (fCmdRet == 0x30)) { ComOpen = false; MessageBox.Show("串口通讯错误", "信息提示"); StaticClassReaderB.CloseSpecComPort(frmcomportindex); return; } //RefreshStatus(); break; } } } } finally { Cursor = Cursors.Default; } string com = ""; if ((fOpenComIndex != -1) & (openresult != 0X35) & (openresult != 0X30)) { //ComboBox_AlreadyOpenCOM.Items.Add("COM" + Convert.ToString(fOpenComIndex)); //ComboBox_AlreadyOpenCOM.SelectedIndex = ComboBox_AlreadyOpenCOM.SelectedIndex + 1; com = Convert.ToString(fOpenComIndex); //Button3.Enabled = true; //button20.Enabled = true; //Button5.Enabled = true; //Button1.Enabled = true; //button2.Enabled = true; //Button_WriteEPC_G2.Enabled = true; //Button_SetMultiReadProtect_G2.Enabled = true; //Button_RemoveReadProtect_G2.Enabled = true; //Button_CheckReadProtected_G2.Enabled = true; //button4.Enabled = true; //SpeedButton_Query_6B.Enabled = true; //button6.Enabled = true; //button8.Enabled = true; //button9.Enabled = true; //button12.Enabled = true; //button_OffsetTime.Enabled = true; //button_settigtime.Enabled = true; //button_gettigtime.Enabled = true; ComOpen = true; } if ((fOpenComIndex == -1) && (openresult == 0x30)) { MessageBox.Show("串口通讯错误", "信息提示"); } byte[] TrType = new byte[2]; byte[] VersionInfo = new byte[2]; byte ReaderType = 0; byte ScanTime = 0; byte dmaxfre = 0; byte dminfre = 0; byte powerdBm = 0; fCmdRet = StaticClassReaderB.GetReaderInformation(ref fComAdr, VersionInfo, ref ReaderType, TrType, ref dmaxfre, ref dminfre, ref powerdBm, ref ScanTime, frmcomportindex); //if ((ComboBox_AlreadyOpenCOM.Items.Count != 0) & (fOpenComIndex != -1) & (openresult != 0X35) & (openresult != 0X30) & (fCmdRet == 0)) if ((com != "") & (fOpenComIndex != -1) & (openresult != 0X35) & (openresult != 0X30) & (fCmdRet == 0)) { fComAdr = Convert.ToByte("00", 16); temp = "COM" + com; frmcomportindex = Convert.ToInt32(temp.Substring(3, temp.Length - 3)); } //RefreshStatus(); lbl_status.Text = startRun(1); timer1.Enabled = true;//主动模式 }
static void Main() { int ComPortName = 0; byte DevAddr = 0x00; byte ComBaudRate = 6; int DevHandle = 0; int ret; byte[] fPassWord = new byte[4]; byte[] TrType = new byte[2]; byte[] VersionInfo = new byte[2]; byte ReaderType = 0; byte ScanTime = 0; byte dmaxfre = 0; byte dminfre = 0; byte powerdBm = 0; byte AdrTID = 0; byte LenTID = 2; byte TIDFlag = 0; int CardNum = 0; int Totallen = 0; byte[] EPC = new byte[5000]; DateTime scanTime = DateTime.Now; //string tmp_str; Thread Thr_EndProgramm = new Thread(EndProgramm); Thr_EndProgramm.Start(); Console.WriteLine("***** VT UHF Tag Reader v0.1 *****"); Console.WriteLine(""); ret = StaticClassReaderB.AutoOpenComPort(ref ComPortName, ref DevAddr, ComBaudRate, ref DevHandle); if (ret != 0) { Console.WriteLine("Unable to detect a tag reader"); Console.Write("Error n°: "); Console.WriteLine(Convert.ToString(ret)); Console.WriteLine("Press any key to quit..."); //Console.ReadKey(); //return; } Console.WriteLine("Reader opened"); ret = StaticClassReaderB.GetReaderInformation(ref DevAddr, VersionInfo, ref ReaderType, TrType, ref dmaxfre, ref dminfre, ref powerdBm, ref ScanTime, DevHandle); if (ret != 0) { Console.Write("Error n°: "); Console.WriteLine(Convert.ToString(ret)); Console.WriteLine("Press any key to quit..."); //Console.ReadKey(); //return; } Console.Write("Reader version : "); Console.WriteLine(Convert.ToString(VersionInfo[0], 10).PadLeft(2, '0') + "." + Convert.ToString(VersionInfo[1], 10).PadLeft(2, '0')); Console.Write("Device adress : "); Console.WriteLine(Convert.ToString(DevAddr, 16).PadLeft(2, '0')); Console.Write("Reader power [dBm] : "); Console.WriteLine(Convert.ToString(powerdBm, 10).PadLeft(2, '0')); Console.Write("Scan time : "); Console.WriteLine(Convert.ToString(ScanTime, 10).PadLeft(2, '0') + "*100ms"); //FreBand = Convert.ToByte(((dmaxfre & 0xc0) >> 4) | (dminfre >> 6));*/ if (ret != 0) { Console.Write("Error n°: "); Console.WriteLine(Convert.ToString(ret)); Console.WriteLine("Press any key to quit..."); //Console.ReadKey(); //return; } do { ret = StaticClassReaderB.Inventory_G2(ref DevAddr, AdrTID, LenTID, TIDFlag, EPC, ref Totallen, ref CardNum, DevHandle); if (ret == 1) { byte[] daw = new byte[Totallen]; Array.Copy(EPC, daw, Totallen); StringBuilder sb = new StringBuilder(daw.Length * 3); foreach (byte b in daw) { sb.Append(Convert.ToString(b, 16).PadLeft(2, '0')); } Console.Write(DateTime.Now.TimeOfDay.ToString()); Console.Write(" "); Console.Write(CardNum); Console.Write(" "); Console.Write(Totallen); Console.Write(" "); //Console.WriteLine(sb.ToString().ToUpper()); Console.Write(Convert.ToString(EPC[0], 16)); Console.Write(Convert.ToString(EPC[1], 16)); Console.Write(Convert.ToString(EPC[2], 16)); Console.Write(Convert.ToString(EPC[3], 16)); Console.WriteLine(""); } Thread.Sleep(10); }while (chr.Key != ConsoleKey.C); Console.WriteLine("Press any key to quit..."); Console.ReadKey(); StaticClassReaderB.CloseComPort(); }