0% found this document useful (0 votes)
36 views

Protocol

Uploaded by

Waly AF
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
36 views

Protocol

Uploaded by

Waly AF
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 30

namespace Posicion.

Protocolos
{
using Data.Estructuras;
using Posicion;
using Posicion.Data;
using PuertoSerial;
using System;
using System.Collections.Generic;
using System.IO;
using System.Threading;

public class PosWayneLink : XPosicion


{
private int m_gnRealPosicion;
private ISerial m_Puerto;
private int m_ManijaNumero = 0;
private int m_TotalTipo = 0;
private bool m_DineroAproximado = false;
private double m_Pulsos = 0.0;
private bool m_Abierta = false;
private int m_Estado = 14;
private int m_Manija = 0;
private int m_FormatoDinero = 1;
private int m_FormatoVolumen = 4;
private int m_FormatoPpu = 1;
private int m_FormatoTDinero = 1;
private int m_FormatoTVolumen = 3;
private int m_NumeroDigitosTotales = 8;
private double m_VentaDinero = 0.0;
private double m_VentaVolumen = 0.0;
private double m_VentaPpu = 0.0;
private double[] m_TotalDinero = new double[7];
private double[] m_TotalVolumen = new double[7];
private double[] m_PpuActual = new double[7];
private int WAIT = 0xe10;
private int lnposicion;
private byte NS = 1;
private long genpoly;
private byte[] m_NSasASCII = new byte[2];
private byte[] m_TamASCII = new byte[4];
private byte[] m_CRC = new byte[5];
private int ContInactivo;

public bool AbrirPosicion()


{
Console.WriteLine("Abrir Bomba\n\n\t");
this.m_Abierta = false;
this.GetEstado();
if (this.m_Estado != 15)
{
int num = 0;
if (num >= 3)
{
return false;
}
Thread.Sleep(10);
Console.WriteLine("CONFIGURA PROTOCOLO 3");
for (num = 0; num < 3; num++)
{
Thread.Sleep(10);
if (this.ldata())
{
for (num = 0; num < 3; num++)
{
Thread.Sleep(10);
if (this.ltreport())
{
this.m_Abierta = true;
return true;
}
}
return false;
}
}
}
return false;
}

public bool Activar()


{
for (int i = 0; i < 5; i++)
{
Thread.Sleep(0x44);
if (this.lresume())
{
return true;
}
}
return false;
}

private long calc_crc(byte[] pch, int longitud)


{
long crc = 0L;
for (int i = 1; i < longitud; i++)
{
crc = this.calc_crc_byte((long) pch[i], crc);
}
return crc;
}

private long calc_crc_byte(long dado, long crc)


{
this.genpoly = 0xa001L;
dado = dado << 1;
for (int i = 0; i < 8; i++)
{
dado = dado >> 1;
crc = (((dado ^ crc) & 1L) != 1L) ? (crc >> 1) : ((crc >> 1) ^
this.genpoly);
}
return crc;
}

private POSESTADO ConvierteEstado(int est)


{
POSESTADO iNACTIVO = POSESTADO.INACTIVO;
switch (est)
{
case 0:
iNACTIVO = POSESTADO.ERROR;
break;

case 6:
iNACTIVO = POSESTADO.ESPERA;
break;

case 7:
iNACTIVO = POSESTADO.LISTO;
break;

case 8:
iNACTIVO = POSESTADO.AUTORIZADO;
break;

case 9:
iNACTIVO = POSESTADO.SURTIENDO;
break;

case 10:
iNACTIVO = POSESTADO.REPORTE;
break;

case 11:
iNACTIVO = POSESTADO.REPORTE;
break;

case 12:
iNACTIVO = POSESTADO.DETENIDO;
break;

case 13:
iNACTIVO = POSESTADO.DATOS;
break;

case 14:
iNACTIVO = POSESTADO.INICIO;
break;

case 15:
iNACTIVO = POSESTADO.INACTIVO;
break;

default:
break;
}
return iNACTIVO;
}

public bool Detener()


{
for (int i = 0; i < 5; i++)
{
Thread.Sleep(30);
this.lstop();
this.GetEstado();
if (((this.m_Estado == 6) | (this.m_Estado == 7)) | (this.m_Estado
== 12))
{
return true;
}
}
return false;
}

public bool escribirlog(byte[] Line, string tipo)


{
bool flag = true;
string str = "";
if (Line == null)
{
return false;
}
foreach (byte num in Line)
{
str = str + num.ToString("x") + " ";
}
try
{
if (!Directory.Exists(@"C:\Insepet\LogWayneLink"))
{
Directory.CreateDirectory(@"C:\Insepet\LogWayneLink");
}
}
catch (Exception exception)
{
flag = false;
Console.WriteLine("Error al generar el log del ibutton // " +
exception.GetType().Name);
}
if (flag)
{
StreamWriter writer =
File.AppendText(@"C:\Insepet\LogWayneLink\LogData.txt");
writer.Write("\r\n");
writer.Write(tipo + ": " + str);
writer.Close();
}
return flag;
}

public POSESTADO Estado()


{
int num = 0;
while (true)
{
while (true)
{
if (num >= 2)
{
this.m_Estado = 15;
return this.ConvierteEstado(this.m_Estado);
}
Thread.Sleep(5);
int num2 = this.lestado();
if (num2 != this.m_Estado)
{
Thread.Sleep(5);
if (num2 != this.lestado())
{
break;
}
}
if (num2 == 15)
{
break;
}
this.m_Estado = num2;
return this.ConvierteEstado(this.m_Estado);
}
num++;
}
}

public bool GetAbierta()


{
return this.m_Abierta;
}

private bool GetCrc(byte[] Estado, int Longitud)


{
bool flag = false;
try
{
string str = this.calc_crc(Estado, Longitud).ToString("00000");
int index = 0;
while (true)
{
if (index >= str.Length)
{
flag = true;
break;
}
this.m_CRC[index] = (byte) str[(str.Length - 1) - index];
index++;
}
}
catch
{
}
return flag;
}

public POSESTADO GetEstado()


{
return this.ConvierteEstado(this.m_Estado);
}

public int GetGrado()


{
return this.m_Manija;
}

private bool GetLongData(long Longitud)


{
bool flag = false;
try
{
string str = Longitud.ToString("0000");
int index = 0;
while (true)
{
if (index >= str.Length)
{
flag = true;
break;
}
this.m_TamASCII[index] = (byte) str[(str.Length - 1) - index];
index++;
}
}
catch
{
}
return flag;
}

private byte GetLRC(byte[] Estado)


{
byte num = Estado[0];
for (int i = 1; i < Estado.Length; i++)
{
num = (byte) (num ^ Estado[i]);
}
return num;
}

private bool GetNS()


{
bool flag = false;
try
{
if (this.NS == 100)
{
this.NS = 0;
}
string str = this.NS.ToString("00");
this.m_NSasASCII[0] = (byte) str[0];
this.m_NSasASCII[1] = (byte) str[1];
flag = true;
}
catch
{
}
return flag;
}

public int GetNumDigitoTotales()


{
return this.m_NumeroDigitosTotales;
}

public double GetPpu(int ngrado)


{
if ((ngrado <= 0) || (ngrado >= 7))
{
return 0.0;
}
return this.m_PpuActual[ngrado];
}

public double GetTotalDinero(int ngrado)


{
Console.WriteLine("************* GET TOTAL DINERO**************");
Console.WriteLine("************** GRADO = " + ngrado.ToString() + "
**************");
for (int i = 0; i < this.m_TotalDinero.Length; i++)
{
Console.WriteLine("total " + i.ToString() + " = " +
this.m_TotalDinero[i].ToString());
}
if ((ngrado <= 0) || (ngrado >= 7))
{
return 0.0;
}
return this.m_TotalDinero[ngrado];
}

public CPosTotales GetTotales()


{
CPosTotales totales = new CPosTotales();
for (int i = 1; i <= this.m_ManijaNumero; i++)
{
totales.SetTotalDinero(i, this.GetTotalDinero(i));
totales.SetTotalVolumen(i, this.GetTotalVolumen(i));
}
return totales;
}

public double GetTotalVolumen(int ngrado)


{
if ((ngrado <= 0) || (ngrado >= 7))
{
return 0.0;
}
return this.m_TotalVolumen[ngrado];
}

public double GetVentaDinero()


{
return this.m_VentaDinero;
}

public double GetVentaPpu()


{
return this.m_VentaPpu;
}

public double GetVentaVolumen()


{
return this.m_VentaVolumen;
}
public bool Grado()
{
Console.WriteLine("Get Manija");
for (int i = 1; i < 2; i++)
{
Thread.Sleep(10);
if (this.lextend())
{
return true;
}
}
return false;
}

private bool lauth(int tMan)


{
bool flag = false;
string str = this.lnposicion.ToString("00");
int longitud = 0x8d;
List<byte> list = new List<byte> {
(byte) str[0],
(byte) str[1],
(byte) tMan.ToString()[0]
};
this.m_Puerto.EscribirBuffer(this.lcomando(new byte[0], '0', '1'));
List<byte> list2 = new List<byte>();
int num2 = 0;
while (true)
{
if (num2 < longitud)
{
if (!this.m_Puerto.LeerByte(this.WAIT))
{
return false;
}
list2.Add(this.m_Puerto.ByteLeido);
if (this.m_Puerto.ByteLeido != 0x55)
{
num2++;
continue;
}
longitud = num2 + 1;
}
this.escribirlog(list2.ToArray(), "Rx");
if (!this.lcrc(list2.ToArray(), longitud))
{
return false;
}
if (!this.llcr(list2.ToArray(), longitud))
{
return false;
}
if ((list2[2] == 0x30) && (list2[3] == 0x30))
{
flag = true;
}
return flag;
}
}
private byte[] lcomando(byte[] Datos, char C, char S)
{
byte[] estado = new byte[] { 2, 0x31, (byte) C, (byte) S };
if (!this.GetNS())
{
return null;
}
if (!this.GetLongData((long) Datos.Length))
{
return null;
}
this.NS = (byte) (this.NS + 1);
estado[4] = this.m_NSasASCII[0];
estado[5] = this.m_NSasASCII[1];
estado[6] = this.m_TamASCII[3];
estado[7] = this.m_TamASCII[2];
estado[8] = this.m_TamASCII[1];
estado[9] = this.m_TamASCII[0];
for (int i = 0; i < Datos.Length; i++)
{
estado[i + 10] = Datos[i];
}
if (!this.GetCrc(estado, 10 + Datos.Length))
{
return null;
}
estado[10 + Datos.Length] = this.m_CRC[4];
estado[11 + Datos.Length] = this.m_CRC[3];
estado[12 + Datos.Length] = this.m_CRC[2];
estado[13 + Datos.Length] = this.m_CRC[1];
estado[14 + Datos.Length] = this.m_CRC[0];
estado[15 + Datos.Length] = 3;
estado[0x10 + Datos.Length] = 70;
this.escribirlog(estado, "Tx");
return estado;
}

private bool lcpreset(int tValor, int tTipo, int tGrado)


{
char ch;
char ch2;
bool flag = false;
string str = this.gnPosicion.ToString("00");
string str2 = "";
string str3 = tGrado.ToString("0");
int longitud = 0x8d;
List<byte> list = new List<byte> {
(byte) str[0],
(byte) str[1]
};
if (tTipo == 1)
{
str2 = tValor.ToString("0000");
list.Add((byte) str2[0]);
list.Add((byte) str2[1]);
list.Add((byte) str2[2]);
list.Add((byte) str2[3]);
ch = '0';
ch2 = '9';
}
else
{
str2 = tValor.ToString("000000");
list.Add((byte) str2[0]);
list.Add((byte) str2[1]);
list.Add((byte) str2[2]);
list.Add((byte) str2[3]);
list.Add((byte) str2[4]);
list.Add((byte) str2[5]);
list.Add(0x30);
list.Add(0x30);
ch = '0';
ch2 = '8';
}
list.Add((byte) str3[0]);
this.m_Puerto.EscribirBuffer(this.lcomando(list.ToArray(), ch, ch2));
List<byte> list2 = new List<byte>();
int num2 = 0;
while (true)
{
if (num2 < longitud)
{
if (!this.m_Puerto.LeerByte(this.WAIT))
{
return false;
}
list2.Add(this.m_Puerto.ByteLeido);
if (this.m_Puerto.ByteLeido != 0x55)
{
num2++;
continue;
}
longitud = num2 + 1;
}
this.escribirlog(list2.ToArray(), "Rx");
if (!this.lcrc(list2.ToArray(), longitud))
{
return false;
}
if (!this.llcr(list2.ToArray(), longitud))
{
return false;
}
if ((list2[2] == 0x30) && (list2[3] == 0x30))
{
flag = true;
}
return flag;
}
}

private bool lcrc(byte[] Estado, int Longitud)


{
return true;
}

private bool ldata()


{
return true;
}

private void ldleep68()


{
}

private int lest(int est, int i)


{
int num = 15;
switch (est)
{
case 0:
num = 15;
break;

case 1:
num = 14;
this.lsmodo(i);
break;

case 2:
num = 12;
break;

case 3:
num = 14;
this.lsconfig(i);
break;

case 4:
num = 6;
break;

case 5:
num = 7;
break;

case 6:
num = 8;
break;

case 7:
num = 9;
break;

case 8:
num = 10;
break;

case 9:
num = 9;
break;

case 10:
num = 10;
break;
case 11:
num = 10;
break;

case 13:
num = 13;
break;

case 14:
num = 14;
break;

case 15:
num = 15;
break;

default:
break;
}
return num;
}

private int lestado()


{
int[] numArray = new int[0x21];
int[] numArray2 = new int[0x21];
string str = this.lnposicion.ToString("00");
int longitud = 0x8d;
List<byte> list = new List<byte> {
(byte) str[0],
(byte) str[1]
};
this.m_Puerto.EscribirBuffer(this.lcomando(list.ToArray(), '2', '8'));
List<byte> list2 = new List<byte>();
int num3 = 0;
while (true)
{
if (num3 < longitud)
{
if (!this.m_Puerto.LeerByte(this.WAIT))
{
return 15;
}
list2.Add(this.m_Puerto.ByteLeido);
if (this.m_Puerto.ByteLeido != 0x55)
{
num3++;
continue;
}
longitud = num3 + 1;
}
this.escribirlog(list2.ToArray(), "Rx");
if (!this.lcrc(list2.ToArray(), longitud))
{
return 15;
}
if (!this.llcr(list2.ToArray(), longitud))
{
return 15;
}
if ((list2[2] == 0x30) && (list2[3] == 0x30))
{
int num4 = (list2[11] & 15) + ((list2[10] & 15) * 10);
for (int i = 1; i <= num4; i++)
{
numArray[i] = list2[((4 * i) + 1) + 10] & 15;
numArray2[i] = list2[((4 * i) + 4) + 10] & 15;
}
}
this.m_Manija = numArray2[this.lnposicion];
return this.lest(numArray[this.lnposicion], this.lnposicion);
}
}

private bool lextend()


{
Console.WriteLine("-------------------------------------------");
Console.WriteLine("************INICIA EXTEND******************");
bool flag = false;
string str = this.lnposicion.ToString("00");
int longitud = 0x8d;
List<byte> list = new List<byte> {
(byte) str[0],
(byte) str[1]
};
this.m_Puerto.EscribirBuffer(this.lcomando(list.ToArray(), '2', '8'));
List<byte> list2 = new List<byte>();
int num2 = 0;
while (true)
{
if (num2 < longitud)
{
if (!this.m_Puerto.LeerByte(this.WAIT))
{
Console.WriteLine("ERROR1");
return false;
}
list2.Add(this.m_Puerto.ByteLeido);
if (this.m_Puerto.ByteLeido != 0x55)
{
num2++;
continue;
}
longitud = num2 + 1;
}
this.escribirlog(list2.ToArray(), "Rx");
if (!this.lcrc(list2.ToArray(), longitud))
{
Console.WriteLine("ERROR2");
return false;
}
if (!this.llcr(list2.ToArray(), longitud))
{
Console.WriteLine("ERROR3");
return false;
}
if ((list2[2] == 0x30) && (list2[3] == 0x30))
{
int num3 = int.Parse(((char) list2[10]) + ((char) list2[11]));
Console.WriteLine("POSICIONES WAYNELINK " + num3.ToString());
int num4 = 1;
while (true)
{
if (num4 > num3)
{
flag = true;
break;
}
if (num4 == this.lnposicion)
{
Console.WriteLine("ENTRA A POSICIONES");
Console.WriteLine("MANIJA CADENA ====== " + list2[((4 *
num4) + 4) + 10].ToString("x"));
this.m_Manija = int.Parse(((char) list2[((4 * num4) +
4) + 10]));
Console.WriteLine("MANIJA ====== " +
this.m_Manija.ToString());
flag = true;
}
num4++;
}
}
return flag;
}
}

private bool liinicia()


{
return true;
}

private bool lilazo(int tNpos)


{
bool flag = false;
string str = tNpos.ToString("00");
int longitud = 0x8d;
List<byte> list = new List<byte> {
(byte) str[0],
(byte) str[1]
};
this.m_Puerto.EscribirBuffer(this.lcomando(list.ToArray(), '2', '3'));
List<byte> list2 = new List<byte>();
int num2 = 0;
while (true)
{
if (num2 < longitud)
{
if (!this.m_Puerto.LeerByte(this.WAIT))
{
return false;
}
list2.Add(this.m_Puerto.ByteLeido);
if (this.m_Puerto.ByteLeido != 0x55)
{
num2++;
continue;
}
longitud = num2 + 1;
}
this.escribirlog(list2.ToArray(), "Rx");
if (!this.lcrc(list2.ToArray(), longitud))
{
return false;
}
if (!this.llcr(list2.ToArray(), longitud))
{
return false;
}
if ((list2[2] == 0x30) && (list2[3] == 0x30))
{
flag = true;
}
return flag;
}
}

public void LimpiarMemoria()


{
}

private bool liposiciones(int tNpos)


{
bool flag = false;
string str = tNpos.ToString("00");
int longitud = 0x8d;
List<byte> list = new List<byte> {
(byte) str[0],
(byte) str[1]
};
this.m_Puerto.EscribirBuffer(this.lcomando(list.ToArray(), '0', '0'));
List<byte> list2 = new List<byte>();
int num2 = 0;
while (true)
{
if (num2 < longitud)
{
if (!this.m_Puerto.LeerByte(this.WAIT))
{
return false;
}
list2[num2] = this.m_Puerto.ByteLeido;
if (this.m_Puerto.ByteLeido != 0x55)
{
num2++;
continue;
}
longitud = num2 + 1;
}
this.escribirlog(list2.ToArray(), "Rx");
if (!this.lcrc(list2.ToArray(), longitud))
{
return false;
}
if (!this.llcr(list2.ToArray(), longitud))
{
return false;
}
if ((list2[2] == 0x30) && (list2[3] == 0x30))
{
flag = true;
}
return flag;
}
}

private bool llcr(byte[] Estado, int Longitud)


{
return true;
}

public bool llibre()


{
bool flag = false;
string str = this.lnposicion.ToString("00");
int longitud = 0x8d;
List<byte> list = new List<byte> {
(byte) str[0],
(byte) str[1]
};
this.m_Puerto.EscribirBuffer(this.lcomando(list.ToArray(), '0', '6'));
List<byte> list2 = new List<byte>();
Thread.Sleep(100);
int num2 = 0;
while (true)
{
if (num2 < longitud)
{
if (!this.m_Puerto.LeerByte(this.WAIT))
{
return false;
}
list2.Add(this.m_Puerto.ByteLeido);
if (this.m_Puerto.ByteLeido != 0x55)
{
num2++;
continue;
}
longitud = num2 + 1;
}
this.escribirlog(list2.ToArray(), "Rx");
if (!this.lcrc(list2.ToArray(), longitud))
{
return false;
}
if (!this.llcr(list2.ToArray(), longitud))
{
return false;
}
if ((list2[2] == 0x30) && (list2[3] == 0x30))
{
flag = true;
}
return flag;
}
}
private int lnum(int hex)
{
return (hex & 15);
}

private bool lreal()


{
bool flag = false;
string str = this.lnposicion.ToString("00");
int longitud = 0x8d;
List<byte> list = new List<byte> {
(byte) str[0],
(byte) str[1]
};
this.m_Puerto.EscribirBuffer(this.lcomando(list.ToArray(), '0', '5'));
List<byte> list2 = new List<byte>();
int num2 = 0;
while (true)
{
if (num2 < longitud)
{
if (!this.m_Puerto.LeerByte(this.WAIT))
{
return false;
}
list2.Add(this.m_Puerto.ByteLeido);
if (this.m_Puerto.ByteLeido != 0x55)
{
num2++;
continue;
}
longitud = num2 + 1;
}
this.escribirlog(list2.ToArray(), "Rx");
if (!this.lcrc(list2.ToArray(), longitud))
{
return false;
}
if (!this.llcr(list2.ToArray(), longitud))
{
return false;
}
if ((list2[2] == 0x30) && (list2[3] == 0x30))
{
byte local1 = list2[10];
this.m_FormatoVolumen = list2[0x11] & 15;
this.m_FormatoDinero = list2[0x18] & 15;
this.m_FormatoPpu = list2[0x1d] & 15;
this.m_Manija = list2[30] & 15;
this.m_VentaDinero = (double) (list2[0x17] & 15);
this.m_VentaDinero += (double) ((list2[0x16] & 15) * 10);
this.m_VentaDinero += (double) ((list2[0x15] & 15) * 100);
this.m_VentaDinero += (double) ((list2[20] & 15) * 0x3e8);
this.m_VentaDinero += (double) ((list2[0x13] & 15) * 0x2710);
this.m_VentaDinero += (double) ((list2[0x12] & 15) * 0x186a0);
this.m_VentaVolumen = (double) (list2[0x10] & 15);
this.m_VentaVolumen += (double) ((list2[15] & 15) * 10);
this.m_VentaVolumen += (double) ((list2[14] & 15) * 100);
this.m_VentaVolumen += (double) ((list2[13] & 15) * 0x3e8);
this.m_VentaVolumen += (double) ((list2[12] & 15) * 0x2710);
this.m_VentaVolumen += (double) ((list2[11] & 15) * 0x186a0);
this.m_VentaPpu = (double) (list2[0x1c] & 15);
this.m_VentaPpu += (double) ((list2[0x1b] & 15) * 10);
this.m_VentaPpu += (double) ((list2[0x1a] & 15) * 100);
this.m_VentaPpu += (double) ((list2[0x19] & 15) * 0x3e8);
this.m_VentaVolumen /= Math.Pow(10.0, (double)
this.m_FormatoVolumen);
this.m_VentaDinero /= Math.Pow(10.0, (double)
this.m_FormatoDinero);
this.m_VentaPpu /= Math.Pow(10.0, (double) this.m_FormatoPpu);
Console.WriteLine("/*/*/*/*/*/*/*/* DINERO 05 = " +
this.m_VentaDinero.ToString() + "*/*/*/*/*/*/*/*/*/*/");
flag = true;
}
return flag;
}
}

private bool lresume()


{
bool flag = false;
string str = this.lnposicion.ToString("00");
int longitud = 0x8d;
List<byte> list = new List<byte> {
(byte) str[0],
(byte) str[1]
};
this.m_Puerto.EscribirBuffer(this.lcomando(list.ToArray(), '1', '9'));
List<byte> list2 = new List<byte>();
int num2 = 0;
while (true)
{
if (num2 < longitud)
{
if (!this.m_Puerto.LeerByte(this.WAIT))
{
return false;
}
list2.Add(this.m_Puerto.ByteLeido);
if (this.m_Puerto.ByteLeido != 0x55)
{
num2++;
continue;
}
longitud = num2 + 1;
}
this.escribirlog(list2.ToArray(), "Rx");
if (!this.lcrc(list2.ToArray(), longitud))
{
return false;
}
if (!this.llcr(list2.ToArray(), longitud))
{
return false;
}
if ((list2[2] == 0x30) && (list2[3] == 0x30))
{
flag = true;
}
return flag;
}
}

public bool lsconfig(int tPs)


{
bool flag = false;
string str = tPs.ToString("00");
int longitud = 0x8d;
List<byte> list = new List<byte> {
(byte) str[0],
(byte) str[1]
};
this.m_Puerto.EscribirBuffer(this.lcomando(list.ToArray(), '1', '6'));
List<byte> list2 = new List<byte>();
int num2 = 0;
while (true)
{
if (num2 < longitud)
{
if (!this.m_Puerto.LeerByte(this.WAIT))
{
return false;
}
list2.Add(this.m_Puerto.ByteLeido);
if (this.m_Puerto.ByteLeido != 0x55)
{
num2++;
continue;
}
longitud = num2 + 1;
}
this.escribirlog(list2.ToArray(), "Rx");
if (!this.lcrc(list2.ToArray(), longitud))
{
return false;
}
if (!this.llcr(list2.ToArray(), longitud))
{
return false;
}
if ((list2[2] == 0x30) && (list2[3] == 0x30))
{
flag = true;
}
return flag;
}
}

private bool lsmodo(int ps)


{
bool flag = false;
string str = ps.ToString("00");
int longitud = 0x8d;
List<byte> list = new List<byte> {
(byte) str[0],
(byte) str[1],
2
};
this.m_Puerto.EscribirBuffer(this.lcomando(list.ToArray(), '2', '5'));
List<byte> list2 = new List<byte>();
int num2 = 0;
while (true)
{
if (num2 < longitud)
{
if (!this.m_Puerto.LeerByte(this.WAIT))
{
return false;
}
list2.Add(this.m_Puerto.ByteLeido);
if (this.m_Puerto.ByteLeido != 0x55)
{
num2++;
continue;
}
longitud = num2 + 1;
}
this.escribirlog(list2.ToArray(), "Rx");
if (!this.lcrc(list2.ToArray(), longitud))
{
return false;
}
if (!this.llcr(list2.ToArray(), longitud))
{
return false;
}
if ((list2[2] == 0x30) && (list2[3] == 0x30))
{
flag = true;
}
return flag;
}
}

private bool lsprecio(int tGrado, int tPpu)


{
bool flag = false;
string str = this.lnposicion.ToString("00");
int longitud = 0x8d;
List<byte> list = new List<byte> {
(byte) str[0],
(byte) str[1],
(byte) tGrado.ToString()[0]
};
string str2 = tPpu.ToString("0000");
list.Add((byte) str2[0]);
list.Add((byte) str2[1]);
list.Add((byte) str2[2]);
list.Add((byte) str2[3]);
this.m_Puerto.EscribirBuffer(this.lcomando(list.ToArray(), '2', '7'));
List<byte> list2 = new List<byte>();
int num2 = 0;
while (true)
{
if (num2 < longitud)
{
if (!this.m_Puerto.LeerByte(this.WAIT))
{
return false;
}
list2.Add(this.m_Puerto.ByteLeido);
if (this.m_Puerto.ByteLeido != 0x55)
{
num2++;
continue;
}
longitud = num2 + 1;
}
this.escribirlog(list2.ToArray(), "Rx");
if (!this.lcrc(list2.ToArray(), longitud))
{
return false;
}
if (!this.llcr(list2.ToArray(), longitud))
{
return false;
}
if ((list2[2] == 0x30) && (list2[3] == 0x30))
{
flag = true;
}
return flag;
}
}

public bool lsprotocolo(byte tProt)


{
bool flag = false;
string str = this.lnposicion.ToString("00");
int longitud = 0x8d;
List<byte> list = new List<byte> {
(byte) str[0],
(byte) str[1],
tProt
};
this.m_Puerto.EscribirBuffer(this.lcomando(list.ToArray(), '3', '1'));
List<byte> list2 = new List<byte>();
int num2 = 0;
while (true)
{
if (num2 < longitud)
{
if (!this.m_Puerto.LeerByte(this.WAIT))
{
return false;
}
list2.Add(this.m_Puerto.ByteLeido);
if (this.m_Puerto.ByteLeido != 0x55)
{
num2++;
continue;
}
longitud = num2 + 1;
}
this.escribirlog(list2.ToArray(), "Rx");
if (!this.lcrc(list2.ToArray(), longitud))
{
return false;
}
if (!this.llcr(list2.ToArray(), longitud))
{
return false;
}
if ((list2[2] == 0x30) && (list2[3] == 0x30))
{
flag = true;
}
return flag;
}
}

private bool lsreport()


{
bool flag = false;
string str = this.lnposicion.ToString("00");
int longitud = 0x8d;
List<byte> list = new List<byte> {
(byte) str[0],
(byte) str[1]
};
this.m_Puerto.EscribirBuffer(this.lcomando(list.ToArray(), '0', '3'));
List<byte> list2 = new List<byte>();
int num2 = 0;
while (true)
{
if (num2 < longitud)
{
if (!this.m_Puerto.LeerByte(this.WAIT))
{
return false;
}
list2.Add(this.m_Puerto.ByteLeido);
if (this.m_Puerto.ByteLeido != 0x55)
{
num2++;
continue;
}
longitud = num2 + 1;
}
this.escribirlog(list2.ToArray(), "Rx");
if (!this.lcrc(list2.ToArray(), longitud))
{
return false;
}
if (!this.llcr(list2.ToArray(), longitud))
{
return false;
}
if ((list2[2] == 0x30) && (list2[3] == 0x30))
{
byte local1 = list2[10];
this.m_VentaVolumen = (double) (list2[0x10] & 15);
this.m_VentaVolumen = ((double) ((list2[15] & 15) * 10)) +
this.m_VentaVolumen;
this.m_VentaVolumen = ((double) ((list2[14] & 15) * 100)) +
this.m_VentaVolumen;
this.m_VentaVolumen = ((double) ((list2[13] & 15) * 0x3e8)) +
this.m_VentaVolumen;
this.m_VentaVolumen = ((double) ((list2[12] & 15) * 0x2710)) +
this.m_VentaVolumen;
this.m_VentaVolumen = ((double) ((list2[11] & 15) * 0x186a0)) +
this.m_VentaVolumen;
this.m_VentaDinero = (double) (list2[0x18] & 15);
this.m_VentaDinero = ((double) ((list2[0x17] & 15) * 10)) +
this.m_VentaDinero;
this.m_VentaDinero = ((double) ((list2[0x16] & 15) * 100)) +
this.m_VentaDinero;
this.m_VentaDinero = ((double) ((list2[0x15] & 15) * 0x3e8)) +
this.m_VentaDinero;
this.m_VentaDinero = ((double) ((list2[20] & 15) * 0x2710)) +
this.m_VentaDinero;
this.m_VentaDinero = ((double) ((list2[0x13] & 15) * 0x186a0))
+ this.m_VentaDinero;
this.m_VentaDinero = ((double) ((list2[0x12] & 15) * 0xf4240))
+ this.m_VentaDinero;
this.m_VentaDinero = ((double) ((list2[0x11] & 15) * 0x989680))
+ this.m_VentaDinero;
this.m_VentaPpu = (double) (list2[0x1c] & 15);
this.m_VentaPpu = ((double) ((list2[0x1b] & 15) * 10)) +
this.m_VentaPpu;
this.m_VentaPpu = ((double) ((list2[0x1a] & 15) * 100)) +
this.m_VentaPpu;
this.m_VentaPpu = ((double) ((list2[0x19] & 15) * 0x3e8)) +
this.m_VentaPpu;
this.m_Manija = list2[30] & 15;
this.m_VentaVolumen /= Math.Pow(10.0, (double)
this.m_FormatoVolumen);
this.m_VentaDinero /= Math.Pow(10.0, (double)
this.m_FormatoDinero);
this.m_VentaPpu /= Math.Pow(10.0, (double) this.m_FormatoPpu);
this.m_VentaDinero /= 100.0;
Console.WriteLine("/*/*/*/*/*/*/*/* DINERO 03= " +
this.m_VentaDinero.ToString() + "*/*/*/*/*/*/*/*/*/*/");
flag = true;
}
return flag;
}
}

private bool lstop()


{
bool flag = false;
string str = this.lnposicion.ToString("00");
int longitud = 0x8d;
List<byte> list = new List<byte> {
(byte) str[0],
(byte) str[1]
};
this.m_Puerto.EscribirBuffer(this.lcomando(list.ToArray(), '1', '8'));
List<byte> list2 = new List<byte>();
int num2 = 0;
while (true)
{
if (num2 < longitud)
{
if (!this.m_Puerto.LeerByte(this.WAIT))
{
return false;
}
list2.Add(this.m_Puerto.ByteLeido);
if (this.m_Puerto.ByteLeido != 0x55)
{
num2++;
continue;
}
longitud = num2 + 1;
}
this.escribirlog(list2.ToArray(), "Rx");
if (!this.lcrc(list2.ToArray(), longitud))
{
return false;
}
if (!this.llcr(list2.ToArray(), longitud))
{
return false;
}
if ((list2[2] == 0x30) && (list2[3] == 0x30))
{
flag = true;
}
return flag;
}
}

private bool ltreport()


{
bool flag = false;
string str = this.lnposicion.ToString("00");
int longitud = 0x8d;
List<byte> list = new List<byte> {
(byte) str[0],
(byte) str[1]
};
this.m_Puerto.EscribirBuffer(this.lcomando(list.ToArray(), '1', '7'));
List<byte> list2 = new List<byte>();
Thread.Sleep(20);
int num2 = 0;
while (true)
{
if (num2 < longitud)
{
if (!this.m_Puerto.LeerByte(this.WAIT))
{
return false;
}
list2.Add(this.m_Puerto.ByteLeido);
if (this.m_Puerto.ByteLeido != 0x55)
{
num2++;
continue;
}
longitud = num2 + 1;
}
this.escribirlog(list2.ToArray(), "Rx");
if (!this.lcrc(list2.ToArray(), longitud))
{
return false;
}
if (!this.llcr(list2.ToArray(), longitud))
{
return false;
}
if ((list2[2] == 0x30) && (list2[3] == 0x30))
{
int num3 = list2[15] & 15;
this.m_FormatoPpu = list2[13] & 15;
this.m_FormatoDinero = list2[14] & 15;
this.m_FormatoVolumen = list2[0x11] & 15;
this.m_FormatoTDinero = list2[14] & 15;
this.m_FormatoTVolumen = list2[0x10] & 15;
int num4 = 0;
while (true)
{
if (num4 >= num3)
{
flag = true;
break;
}
this.m_PpuActual[num4 + 1] = (double) (list2[0x16 + (num4 *
0x1d)] & 15);
this.m_PpuActual[num4 + 1] = ((double) ((list2[0x15 + (num4
* 0x1d)] & 15) * 10)) + this.m_PpuActual[num4 + 1];
this.m_PpuActual[num4 + 1] = ((double) ((list2[20 + (num4 *
0x1d)] & 15) * 100)) + this.m_PpuActual[num4 + 1];
this.m_PpuActual[num4 + 1] = ((double) ((list2[0x13 + (num4
* 0x1d)] & 15) * 0x3e8)) + this.m_PpuActual[num4 + 1];
this.m_TotalVolumen[num4 + 1] = (double) (list2[0x22 +
(num4 * 0x1d)] & 15);
this.m_TotalVolumen[num4 + 1] = ((double) ((list2[0x21 +
(num4 * 0x1d)] & 15) * 10)) + this.m_TotalVolumen[num4 + 1];
this.m_TotalVolumen[num4 + 1] = ((double) ((list2[0x20 +
(num4 * 0x1d)] & 15) * 100)) + this.m_TotalVolumen[num4 + 1];
this.m_TotalVolumen[num4 + 1] = ((double) ((list2[0x1f +
(num4 * 0x1d)] & 15) * 0x3e8)) + this.m_TotalVolumen[num4 + 1];
this.m_TotalVolumen[num4 + 1] = ((double) ((list2[30 +
(num4 * 0x1d)] & 15) * 0x2710)) + this.m_TotalVolumen[num4 + 1];
this.m_TotalVolumen[num4 + 1] = ((double) ((list2[0x1d +
(num4 * 0x1d)] & 15) * 0x186a0)) + this.m_TotalVolumen[num4 + 1];
this.m_TotalVolumen[num4 + 1] = ((double) ((list2[0x1c +
(num4 * 0x1d)] & 15) * 0xf4240)) + this.m_TotalVolumen[num4 + 1];
this.m_TotalVolumen[num4 + 1] = ((double) ((list2[0x1b +
(num4 * 0x1d)] & 15) * 0x989680)) + this.m_TotalVolumen[num4 + 1];
this.m_TotalVolumen[num4 + 1] = ((double) ((list2[0x1a +
(num4 * 0x1d)] & 15) * 0x5f5e100)) + this.m_TotalVolumen[num4 + 1];
this.m_TotalVolumen[num4 + 1] = ((double) ((list2[0x19 +
(num4 * 0x1d)] & 15) * 0x3b9aca00)) + this.m_TotalVolumen[num4 + 1];
this.m_TotalVolumen[num4 + 1] = (((long) (list2[0x18 +
(num4 * 0x1d)] & 15)) * 0x2540be400L) + this.m_TotalVolumen[num4 + 1];
this.m_TotalVolumen[num4 + 1] = (((long) (list2[0x17 +
(num4 * 0x1d)] & 15)) * 0x174876e800L) + this.m_TotalVolumen[num4 + 1];
this.m_TotalDinero[num4 + 1] = (double) (list2[0x2e + (num4
* 0x1d)] & 15);
this.m_TotalDinero[num4 + 1] = ((double) ((list2[0x2d +
(num4 * 0x1d)] & 15) * 10)) + this.m_TotalDinero[num4 + 1];
this.m_TotalDinero[num4 + 1] = ((double) ((list2[0x2c +
(num4 * 0x1d)] & 15) * 100)) + this.m_TotalDinero[num4 + 1];
this.m_TotalDinero[num4 + 1] = ((double) ((list2[0x2b +
(num4 * 0x1d)] & 15) * 0x3e8)) + this.m_TotalDinero[num4 + 1];
this.m_TotalDinero[num4 + 1] = ((double) ((list2[0x2a +
(num4 * 0x1d)] & 15) * 0x2710)) + this.m_TotalDinero[num4 + 1];
this.m_TotalDinero[num4 + 1] = ((double) ((list2[0x29 +
(num4 * 0x1d)] & 15) * 0x186a0)) + this.m_TotalDinero[num4 + 1];
this.m_TotalDinero[num4 + 1] = ((double) ((list2[40 + (num4
* 0x1d)] & 15) * 0xf4240)) + this.m_TotalDinero[num4 + 1];
this.m_TotalDinero[num4 + 1] = ((double) ((list2[0x27 +
(num4 * 0x1d)] & 15) * 0x989680)) + this.m_TotalDinero[num4 + 1];
this.m_TotalDinero[num4 + 1] = ((double) ((list2[0x26 +
(num4 * 0x1d)] & 15) * 0x5f5e100)) + this.m_TotalDinero[num4 + 1];
this.m_TotalDinero[num4 + 1] = ((double) ((list2[0x25 +
(num4 * 0x1d)] & 15) * 0x3b9aca00)) + this.m_TotalDinero[num4 + 1];
this.m_TotalDinero[num4 + 1] = (((long) (list2[0x24 + (num4
* 0x1d)] & 15)) * 0x2540be400L) + this.m_TotalDinero[num4 + 1];
this.m_TotalDinero[num4 + 1] = (((long) (list2[0x23 + (num4
* 0x1d)] & 15)) * 0x174876e800L) + this.m_TotalDinero[num4 + 1];
Console.WriteLine("DINERO TOTAL VENTA SIN FORMATO = " +
this.m_TotalDinero[num4 + 1].ToString());
Console.WriteLine("VOLUMEN TOTAL VENTA SIN FORMATO = " +
this.m_TotalVolumen[num4 + 1].ToString());
this.m_PpuActual[num4 + 1] /= Math.Pow(10.0, (double)
this.m_FormatoPpu);
this.m_TotalVolumen[num4 + 1] /= Math.Pow(10.0, (double)
this.m_FormatoTVolumen);
this.m_TotalDinero[num4 + 1] /= Math.Pow(10.0, (double)
this.m_FormatoTDinero);
Console.WriteLine("DINERO TOTAL VENTA = " +
this.m_TotalDinero[num4 + 1].ToString());
Console.WriteLine("VOLUMEN TOTAL VENTA = " +
this.m_TotalVolumen[num4 + 1].ToString());
num4++;
}
}
return flag;
}
}

public void Pitar()


{
}

public bool Precio(int ngrado, double ppu)


{
double num = 0.0;
num = Math.Pow(10.0, (double) this.m_FormatoPpu);
int tPpu = 0;
tPpu = (int) (ppu * num);
for (int i = 0; i < 3; i++)
{
Thread.Sleep(0x44);
if (this.lsprecio(ngrado, tPpu))
{
for (i = 0; i < 3; i++)
{
Thread.Sleep(200);
if (this.ltreport())
{
double num4 = Math.Pow(10.0, (double)
this.m_FormatoPpu);
return (this.m_PpuActual[ngrado - 1] == (((double)
tPpu) / num4));
}
}
return false;
}
}
return false;
}

public bool Programar(double valord, POSPROGRAMACION tipo, int pgrado)


{
this.m_VentaDinero = 0.0;
this.m_VentaVolumen = 0.0;
int tValor = 0xf423f;
int tTipo = 2;
double num4 = Math.Pow(10.0, (double) this.m_FormatoDinero);
double num5 = Math.Pow(10.0, (double) this.m_FormatoVolumen);
if (tipo == POSPROGRAMACION.LLENO)
{
tTipo = 2;
tValor = 0xf423f;
}
if (tipo == POSPROGRAMACION.DINERO)
{
tTipo = 2;
tValor = (int) (valord * num4);
}
if (tipo == POSPROGRAMACION.VOLUMEN)
{
tTipo = 1;
tValor = (int) (valord * num5);
}
for (int i = 0; i < 1; i++)
{
Thread.Sleep(0x44);
if (this.lcpreset(tValor, tTipo, pgrado))
{
return true;
}
}
return false;
}

public bool RealVenta()


{
Console.WriteLine("Venta Real");
for (int i = 0; i < 4; i++)
{
Thread.Sleep(0x44);
if (this.lreal())
{
return true;
}
}
return false;
}

public void Reinicio()


{
}

public bool ReporteVenta()


{
Console.WriteLine("REPORTE VENTA WAYNE
LINNK!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
Thread.Sleep(0x7d0);
this.lsconfig(this.lnposicion);
int num = 0;
while (true)
{
if (num < 4)
{
Thread.Sleep(100);
if (!this.llibre())
{
Thread.Sleep(200);
num++;
continue;
}
}
for (num = 0; num < 4; num++)
{
Thread.Sleep(60);
if (this.lsreport())
{
num = 0;
while (true)
{
if (num < 4)
{
Thread.Sleep(100);
if (!this.ltreport())
{
num++;
continue;
}
}
for (num = 1; num <= 5; num++)
{
int num2 = this.lestado();
if ((num2 == 6) | (num2 == 7))
{
Thread.Sleep(0);
return true;
}
}
return false;
}
}
}
return false;
}
}

public void SetAbierta(bool abierta)


{
this.m_Abierta = abierta;
}

public void SetConfiguracion(PosConfiguracion tconfig)


{
this.m_Abierta = false;
this.lnposicion = tconfig.Direccion;
this.m_gnRealPosicion = tconfig.IdPosicion;
this.m_ManijaNumero = tconfig.GradoNumero;
this.m_FormatoDinero = tconfig.PuntoDinero;
this.m_FormatoVolumen = tconfig.PuntoVolumen;
this.m_FormatoPpu = tconfig.PuntoPrecio;
this.m_FormatoTDinero = tconfig.PuntoDinero;
this.m_FormatoTVolumen = tconfig.PuntoVolumen;
this.m_TotalTipo = tconfig.TotalesTipo;
this.m_DineroAproximado = tconfig.OpcionPantallaAproximada;
this.m_Pulsos = tconfig.UnidadPulsos;
}

public void SetPuerto(ISerial puerto)


{
this.m_Puerto = puerto;
}

public bool TotalVenta(int ngrado)


{
Console.WriteLine("Total de Venta");
for (int i = 0; i < 4; i++)
{
Thread.Sleep(200);
if (this.ltreport())
{
return true;
}
}
return false;
}

public int gnPosicion


{
get
{
return this.lnposicion;
}
set
{
this.lnposicion = value;
}
}

public int gnRealPosicion


{
get
{
return this.m_gnRealPosicion;
}
}

int XPosicion.WAIT
{
get
{
return this.WAIT;
}
set
{
this.WAIT = value;
}
}

public int ContadorInactivo


{
get
{
return this.ContInactivo;
}
set
{
this.ContInactivo = value;
}
}
}
}

You might also like