/// <summary> /// Gets the devices connected to Edgeware (Printers and Antennas) /// </summary> /// <returns> /// A json string with the result { antenna: "Antena1", printer: "Printer 1"} /// or {} if no devices were found /// </returns> public String GetDevices() { autobuildHTK_client.Rivka.Api.PrintServiceClient PrintService = new autobuildHTK_client.Rivka.Api.PrintServiceClient(); autobuildHTK_client.Rivka.Api.AntennaClass[] antennasSource; string printer = ""; JObject devices = new JObject(); JArray antennas = new JArray(); try { antennasSource = PrintService.GetAntenna(); foreach (autobuildHTK_client.Rivka.Api.AntennaClass antenna in antennasSource) { JObject newAntena = new JObject(); newAntena.Add("model", antenna.Model); newAntena.Add("ip", antenna.IP); antennas.Add(newAntena); } } catch (Exception e) { } try { printer = PrintService.GetPrinter(); } catch (Exception e) { } devices.Add("antenna", antennas); if (printer != "") { devices.Add("printer", printer); } return(devices.ToString()); }
/// <summary> /// Scan and read an Antenna /// </summary> /// <param name="ip"> /// The IP address of the Antenna /// </param> /// <returns></returns> public String ScanAntenna(string ip) { autobuildHTK_client.Rivka.Api.PrintServiceClient PrintService = new autobuildHTK_client.Rivka.Api.PrintServiceClient(); string[] read = { }; //Try to read an Antenna try { read = PrintService.Read(ip); } catch (Exception e) { } return(JsonConvert.SerializeObject(read)); }
/// <summary> /// Send to print labels to an available printer and save in the sytem /// </summary> /// <param name="data"></param> /// <returns></returns> public String PrintLabel(String data)//String objid, String quantity, String location) { JArray jsondata = new JArray(); try { jsondata = JsonConvert.DeserializeObject <JArray>(data); } catch (Exception ex) { return(null); } String cadena = ""; String tipo = ""; JObject objcad = new JObject(); foreach (JObject row in jsondata) { int labels = 0; int quant = 0; String objid = ""; String objname = ""; String quantity = ""; String location = ""; String userid = ""; try { objid = row["objid"].ToString(); } catch (Exception ex) { } try { objname = row["objname"].ToString(); } catch (Exception ex) { } try { location = row["location"].ToString(); } catch (Exception ex) { } try { quantity = row["quantity"].ToString(); } catch (Exception ex) { } try { userid = row["userid"].ToString(); } catch (Exception ex) { } try { quant = Int16.Parse(quantity); } catch (Exception e) { } if (quant > 0 && objid != null && objid != "" && objid != "null") { // Try to send the information to the WebService try { autobuildHTK_client.Rivka.Api.PrintServiceClient PrintService = new autobuildHTK_client.Rivka.Api.PrintServiceClient(); string availablePrinter = ""; // Checks if there is an available printer try { availablePrinter = PrintService.GetPrinter(); if (availablePrinter != null && availablePrinter != "") { String newEPC = ""; JObject obj = new JObject(); bool conected = PrintService.Connect(availablePrinter); bool oLabel = PrintService.OpenLabel(); //Generate new EPCs newEPC = objectTable.getEPC(objid, quantity); obj = JsonConvert.DeserializeObject <JObject>(newEPC); string nextEPC = obj["nextEPC"].ToString(); bool sEPC = PrintService.SetEPC(nextEPC); int.TryParse(obj["quantity"].ToString(), out labels); bool print = PrintService.Print(availablePrinter, labels); PrintService.Disconnect(availablePrinter); PrintService.Close(); if (print == true) { saveObjects(objid, location, userid, objname, labels, obj["nextEPC"].ToString()); if (labels != quant) { cadena = "Enviado. Solo se imprimieron " + labels.ToString() + " etiquetas."; tipo = "warning"; } else { cadena = "Enviado Satisfactoriamente"; tipo = "success"; } bool ok = true; try { ok = RulesChecker.isValidToLocation(objid, location); } catch (Exception e) { } if (ok == false) { classNotifications.saveNotification("Rules", "Invalid", "Objetos se han movido a Ubicacion no valida"); // return "problem"; } } else { cadena = "Error en la Impresión"; tipo = "error"; } } else { cadena = "No Impresora Encontrada"; tipo = "error"; } } catch (Exception e) { tipo = "error"; cadena = "No Impresora Encontrada"; } } catch (Exception e) { tipo = "error"; cadena = "Error de comunicación, Intente nuevamente"; } } else { tipo = "error"; cadena = "Datos Incorrectos"; } } objcad["cadena"] = cadena; objcad["tipo"] = tipo; return(JsonConvert.SerializeObject(objcad)); }