///******************************************************************************************************* ///NOMBRE_FUNCIÓN: serialPort1_DataReceived ///DESCRIPCIÓN: Evento para el serial del lector de barras ///PARÁMETROS: ///CREO: Hugo Enrique Ramírez Aguilera ///FECHA_CREO: 25-Noviembre-2014 ///MODIFICÓ: ///FECHA_MODIFICÓ: ///CAUSA_MODIFICACIÓN: ///******************************************************************************************************* private void serialPort1_DataReceived(object sender, SerialDataReceivedEventArgs e) { try { // se valida que no este en uso el torniquete if (Lector2) { if (string.IsNullOrEmpty(Codigo_Lector2)) { Txt_Serial.Text = Serial1.ReadLine(); } } } catch (Exception ex) { try { if (!System.IO.Directory.Exists("reportes")) { System.IO.Directory.CreateDirectory("reportes"); } System.IO.File.WriteAllText("reportes/ex-" + DateTime.Now.ToString("dd-MM-yyyy_HH_mm_ss") + ".txt", ex.Message + "\n"); } catch { } } finally { // borrar el campo de texto y asignar control activo Serial_1 = string.Empty; } }
///******************************************************************************************************* ///NOMBRE_FUNCIÓN: Frm_Ope_Accesos_FormClosing ///DESCRIPCIÓN: Cierra los seriales para el uso de los escaners ///PARÁMETROS: N/A ///CREO: Hugo Enrique Ramírez Aguilera ///FECHA_CREO: 24-Noviembre-2014 ///MODIFICÓ: ///FECHA_MODIFICÓ: ///CAUSA_MODIFICACIÓN: ///******************************************************************************************************* private void Frm_Ope_Accesos_FormClosing(object sender, FormClosingEventArgs e) { if (Serial1.IsOpen) { Serial1.Close(); } }
public void SetRunning(bool run, string name) { if (run) { if (!Serial1.IsOpen) { Serial1.PortName = name; Serial1.Open(); } } else { if (Serial1.IsOpen) { Serial1.Close(); } } }
public void CheckSerializationName() { var s1 = new Serial1 { ID = 1, Name = "serial1", Serial2 = new Serial2 { ID = 2, Name = "serial2", }, }; s1.Serial2.Serial1 = s1; // needed for attribute name to work during deserialization //KnownTypes.Register(typeof(Serial1), typeof(Serial2)); var clone = Serializer.Clone(s1); Assert.Equal(s1.ID, clone.ID); Assert.Equal(s1.Name, clone.Name); Assert.Equal(s1.Serial2.ID, clone.Serial2.ID); Assert.Equal(s1.Serial2.Name, clone.Serial2.Name); Assert.Equal(s1.Serial2.Serial1.ID, clone.Serial2.Serial1.ID); var ms = new MemoryStream(); var w = new Writer(new PrimitiveBinaryWriter(ms)); w.Write(s1); var csharp = w.GenerateCSharpCode("Generated"); var t1 = w.Objects.OfType <TypeData>().First(x => x.RuntimeType().Type == typeof(Serial1)); var t2 = w.Objects.OfType <TypeData>().First(x => x.RuntimeType().Type == typeof(Serial2)); Assert.Equal("635B7B87-A594-4130-8B1A-CB398357613D", t1.FullName); Assert.NotNull(t1.Members.Cast <IMember>().FirstOrDefault(x => x.Name == "Bobafet")); Assert.Null(t1.Members.Cast <IMember>().FirstOrDefault(x => x.Name == "Name")); Assert.Null(t1.Assembly); Assert.Equal("TEST-NAME", t2.FullName); Assert.Equal("TEST Assembly", t2.Assembly); Assert.NotNull(t2.Members.Cast <IMember>().FirstOrDefault(x => x.Name == "PID")); Assert.Null(t2.Members.Cast <IMember>().FirstOrDefault(x => x.Name == "ID")); }
public void CheckSerializationName() { var s1 = new Serial1 { ID = 1, Name = "serial1", Serial2 = new Serial2 { ID = 2, Name = "serial2", }, }; s1.Serial2.Serial1 = s1; // needed for attribute name to work during deserialization //KnownTypes.Register(typeof(Serial1), typeof(Serial2)); var clone = Serializer.Clone(s1); Assert.Equal(s1.ID, clone.ID); Assert.Equal(s1.Name, clone.Name); Assert.Equal(s1.Serial2.ID, clone.Serial2.ID); Assert.Equal(s1.Serial2.Name, clone.Serial2.Name); Assert.Equal(s1.Serial2.Serial1.ID, clone.Serial2.Serial1.ID); var ms = new MemoryStream(); var w = new ObjectWriter(new PrimitiveBinaryWriter(ms)); w.Write(s1); var csharp = w.Context.GenerateCSharpCode("Generated"); var t1 = w.Context.Objects.OfType <ReflectType>().First(x => x.Type == typeof(Serial1)); var t2 = w.Context.Objects.OfType <ReflectType>().First(x => x.Type == typeof(Serial2)); Assert.Equal(t1.TypeName, "TEST-NAME"); Assert.Equal(t1.AssemblyName, null); Assert.Equal(t2.TypeName, "TEST-NAME"); Assert.Equal(t2.AssemblyName, "TEST Assembly"); }
/// <summary> /// /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void Tmr_Torniquete1_Tick(object sender, EventArgs e) { try { if (!Serial1.IsOpen) { Serial1.Open(); } } catch (Exception ex) { try { if (!System.IO.Directory.Exists("reportes")) { System.IO.Directory.CreateDirectory("reportes"); } System.IO.File.WriteAllText("reportes/ex-" + DateTime.Now.ToString("dd-MM-yyyy_HH_mm_ss") + ".txt", ex.Message + "\n"); } catch { } } }
/// <summary> /// /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void Tmr_Torniquete2_Tick(object sender, EventArgs e) { try { Tmr_Torniquete2.Stop(); short DataValue = 0; Acceso_Museo.App_Code.Negocio.Cls_Ope_Accesos_Negocio Acceso_Negocio = new App_Code.Negocio.Cls_Ope_Accesos_Negocio(); MccDaq.ErrorInfo ULStat = DaqBoard.DIn(PortNum, out DataValue); int resul = DataValue & (1 << 1); if (resul != 0) { if (First_T2) { First_T2 = false; } else { short DataValue2 = 0; MccDaq.ErrorInfo ULStat2 = DaqBoard.DIn(PortNum, out DataValue2); int resul2 = DataValue2 & (1 << 3); if (resul2 != 0) { Acceso_Negocio.P_No_Acceso = Codigo_Lector2; Acceso_Negocio.P_Terminal_ID = "00001"; Acceso_Negocio.P_Estatus = "UTILIZADO"; Acceso_Negocio.P_Fecha_Hora_Acceso = DateTime.Now; Acceso_Negocio.Actualizar_Estatus_Acceso(); } } } else { if (!First_T2) { if (!Serial1.IsOpen) { Serial1.Open(); } Codigo_Lector2 = string.Empty; Codigo_Lector3 = string.Empty; First_T2 = true; Tmr_Torniquete2.Enabled = false; Lector2 = true; Serial1.DiscardInBuffer(); Serial1.DiscardOutBuffer(); } } Tmr_Torniquete2.Start(); } catch (Exception ex) { var d = ex.Message; } }
///******************************************************************************************************* ///NOMBRE_FUNCIÓN: Frm_Ope_Accesos_Load ///DESCRIPCIÓN: Habilitara los seriales para el uso de los escaners ///PARÁMETROS: N/A ///CREO: Hugo Enrique Ramírez Aguilera ///FECHA_CREO: 24-Noviembre-2014 ///MODIFICÓ: ///FECHA_MODIFICÓ: ///CAUSA_MODIFICACIÓN: ///******************************************************************************************************* private void Frm_Ope_Accesos_Load(object sender, EventArgs e) { Control.CheckForIllegalCrossThreadCalls = false; try { String X = PortNum.ToString(); DataTable Dt_Consulta = new DataTable(); string[] Aux = SerialPort.GetPortNames(); foreach (string Nombre_Puerto in SerialPort.GetPortNames()) { Dt_Consulta = Cls_Ayudante_Lector_Codigo.Consultar_Puerto(""); // torniquete 1 if (Dt_Consulta.Rows[0][Cat_Parametros_Lector_Codigo.Campo_Puerto].ToString() == Nombre_Puerto && Dt_Consulta.Rows[0][Cat_Parametros_Lector_Codigo.Campo_Salida].ToString() == "0") { Serial1.PortName = Nombre_Puerto; Serial1.BaudRate = 9600; Serial1.DataBits = 8; Serial1.Parity = Parity.None; Serial1.StopBits = StopBits.One; Serial1.Handshake = Handshake.None; try { if (!Serial1.IsOpen) { Serial1.Open(); if (!System.IO.Directory.Exists("reportes")) { System.IO.Directory.CreateDirectory("reportes"); } System.IO.File.WriteAllText("reportes/ex-" + DateTime.Now.ToString("dd-MM-yyyy_HH_mm_ss") + ".txt", "Serial Abierto\n"); } } catch (Exception ex) { try { if (!System.IO.Directory.Exists("reportes")) { System.IO.Directory.CreateDirectory("reportes"); } System.IO.File.WriteAllText("reportes/ex-" + DateTime.Now.ToString("dd-MM-yyyy_HH_mm_ss") + ".txt", ex.Message + "\n"); } catch { } return; } } } //PortType = clsDigitalIO.PORTIN; //NumPorts = DioProps.FindPortsOfType(DaqBoard, PortType, out ProgAbility, out PortNum, out NumBits, out FirstBit); //Rele = new Relevador(); //Rele.Activar_Relevador(); //Acceso_Museo.App_Code.Negocio.Cls_Ope_Accesos_Negocio Accesos = new App_Code.Negocio.Cls_Ope_Accesos_Negocio(); //Accesos.Consultar_Accesos_Apertura(); } catch (Exception ex) { MessageBox.Show(ex.Message); } }