private void DM8120讀取2D() { if (InvokeRequired) { BeginInvoke((Action)DM8120讀取2D); } else { if (GlobalData.DM[DmTable.DM_8120CCD讀取2D碼].Equals("1")) { string readCode = readerAccessor.ExecCommand("LON", 8000); if (!string.IsNullOrEmpty(readCode)) { PLCcommand.PLC_Write(PLCcommand.Cmd_Mode.Mode_Write_Single, PLCcommand.PLC_IO.DM, DmTable.DM_8220CCD讀2D碼完成, 1, 0, null); lblText.Text = readCode; MessageBox.Show("讀取成功。"); } else { PLCcommand.PLC_Write(PLCcommand.Cmd_Mode.Mode_Write_Single, PLCcommand.PLC_IO.DM, DmTable.DM_8221CCD讀2D檔失敗, 1, 0, null); liveviewForm1.EndReceive(); MessageBox.Show("讀取錯誤,請檢查讀取器或材料是否有異常。"); } PLCcommand.PLC_Write(PLCcommand.Cmd_Mode.Mode_Write_Single, PLCcommand.PLC_IO.DM, DmTable.DM_8120CCD讀取2D碼, 0, 0, null); CCD讀取Tag = false; } } }
override public bool ReadBarcode(ref string message, int timeout, ref string errorMessage) { try { if (!Connected) { errorMessage = "Keyence尚未連線"; return(false); } else if (Error) { errorMessage = "Keyence Error中"; return(false); } else { triggering = true; message = reader.ExecCommand("LON", timeout); if (message == null || message == "") { if (reader.LastErrorInfo == ErrorCode.Closed) { Error = true; } errorMessage = String.Concat("讀取失敗, ErrorCode : ", reader.LastErrorInfo.ToString()); return(false); } else { return(true); } } } catch (Exception ex) { errorMessage = String.Concat("LON Exception : ", ex.ToString()); return(false); } }
/// <summary> /// 执行LON命令 /// </summary> public bool ExecCommandLon() { //ExecCommand("command")is for sending a command and getting a command response. string data = m_reader.ExecCommand("LON"); if (NewReaderDataEvent != null) { NewReaderDataEvent(data, m_index); return(true); } return(false); }
private void 條碼讀取器動作執行緒(object obj) { while (true) { // 讀檔 if (GlobalData.DM[DmTable.DM_8120CCD讀取2D碼].Equals("1")) { if (formStartModel.允許2D讀取Tag) { GlobalParameter.ReadContent = readerAccessor.ExecCommand("LON", 8000); if (string.IsNullOrEmpty(GlobalParameter.ReadContent)) { readerAccessor.ExecCommand("LOFF"); PLCMethod.WriteSingle(DmTable.DM_8221CCD讀2D檔失敗, 1); } else { PLCMethod.WriteSingle(DmTable.DM_8220CCD讀2D碼完成, 1); } } else { PLCMethod.WriteSingle(DmTable.DM_8220CCD讀2D碼完成, 1); } PLCMethod.WriteSingle(DmTable.DM_8120CCD讀取2D碼, 0); } Thread.Sleep(100); // 寫入 if (GlobalData.DM[DmTable.DM_81212D碼通知寫入].Equals("1")) { string xmlString = "<?xml version='1.0' encoding='UTF-8'?>" + "<COMMAND>" + "<COM_NUM>11</COM_NUM>" + "<INFORMATION>" + "<ID>" + GlobalParameter.ReadContent + "</ID>" + "</INFORMATION>" + "</COMMAND>"; socket.SendTimeout = 10000; socket.ReceiveTimeout = 5000; // 送出XML XmlDocument doc = new XmlDocument(); doc.InnerXml = xmlString; Byte[] sendBuf = Encoding.UTF8.GetBytes(doc.OuterXml); socket.Send(sendBuf, sendBuf.Length, SocketFlags.None); // 回傳XML Byte[] recvBuf = new Byte[0x40000]; for (Int32 i = 0; i < recvBuf.Length; i++) { recvBuf[i] = 0; } socket.Receive(recvBuf, 0, recvBuf.Length, SocketFlags.None); // 取得子節點參數,正確:"0"、錯誤:"1" XElement xmlroot = XElement.Parse(TypeMethod.FormtXmlDoc(Encoding.UTF8.GetString(recvBuf))); string error = ((XElement)(xmlroot.Element("ERROR"))).Value; int dm = (error == "0") ? DmTable.DM_82222D碼寫入完成 : DmTable.DM_82232D碼寫入失敗; PLCMethod.WriteSingle(dm, 1); // PLC:DM_81212D碼通知寫入,清空點位 PLCMethod.WriteSingle(DmTable.DM_81212D碼通知寫入, 0); } Thread.Sleep(100); } }
static void Main(string[] args) { ReaderAccessor m_reader = new ReaderAccessor(); ReaderSearcher m_searcher = new ReaderSearcher(); //LER ARGUMENTO try { string CodConfig = args[0].ToString(); string Ipconfig = args[1].ToString(); //string CodConfig = "123456"; //string Ipconfig = "192.168.100.1"; string codComparacao = CodConfig;//Codigo de comparação Console.WriteLine("Enviar codigo para camera: " + codComparacao); //CONECTAR COM A CAMERA try { //Stop liveview. // liveviewForm1.EndReceive(); //Set ip address of liveview. //liveviewForm1.IpAddress = Ipconfig; ////Start liveview. //liveviewForm1.BeginReceive(); ////Set ip address of ReaderAccessor. m_reader.IpAddress = Ipconfig; //Connect TCP/IP. m_reader.Connect((data) => { //Define received data actions here.Defined actions work asynchronously. //"ReceivedDataWrite" works when reading data was received. //BeginInvoke(new delegateUserControl(ReceivedDataWrite), Encoding.ASCII.GetString(data)); }); //TRANSFORMAR CODIGO E ENVIAR try { //transf string em hex codComparacao = toHex(CodConfig); // Mandar código de comparacao ReceivedDataWrite(m_reader.ExecCommand("WP,402," + codComparacao)); ReceivedDataWrite(m_reader.ExecCommand("SAVE")); Console.WriteLine(String.Format("Código enviado...")); } catch (Exception ex2) { Console.WriteLine(String.Format("Não foi possível enviar o código de comparação! Erro {0}/r/n", ex2.Message)); } } catch (Exception ex) { Console.WriteLine(String.Format("Falha na comunicação! Erro {0}/r/n", ex.Message)); } } catch { Console.WriteLine(String.Format("Não há argumento para alterar o código! Erro {0}/r/n")); } //FECHAR PORTA m_reader.CloseFtp(); //Console.Clear(); //Console.ReadKey(); }