Ejemplo n.º 1
0
        public static byte[] CheckSumHEXString(string stringReadFrom)
        {
            string[] arrayBarcode = stringReadFrom.Split(new Char[] { (char)44 });
            byte[]   result       = new byte[0];
            for (int i = 0; i < arrayBarcode.Length; i++)
            {
                result = i == 0 ? IOCommon.StringToByteArrayFastest(arrayBarcode[i]) : IOCommon.XORBytes(result, IOCommon.StringToByteArrayFastest(arrayBarcode[i]));
            }

            return(result);
        }
Ejemplo n.º 2
0
        public void WritetoSerial(string stringToWrite, bool isHEXCommand)
        {
            try
            {
                //stringToWrite = stringToWrite.Replace(" ", "");

                stringToWrite = stringToWrite.Replace("/", "");
                //stringToWrite = stringToWrite.Replace(",", ""); //ZEBRA: DON'T REMOVE ','
                //stringToWrite = stringToWrite.Replace("-", "");
                stringToWrite = stringToWrite.Replace("##", "/");  //TO SEND '/' TO PRINTER
                stringToWrite = stringToWrite.Replace("#~$", "/"); //TO SEND '/' TO PRINTER


                if (this.serialPort.IsOpen)
                {
                    Byte[] arrayBytesWriteTo;

                    if (isHEXCommand)
                    {
                        arrayBytesWriteTo = IOCommon.HexStringToByteArray(stringToWrite);
                    }
                    else
                    {
                        arrayBytesWriteTo = Encoding.ASCII.GetBytes(stringToWrite);
                    }


                    this.serialPort.ReadExisting();      //Clear the port before send
                    this.readResultBuffer = new byte[0]; //Clear buffer before send
                    this.serialPort.Write(arrayBytesWriteTo, 0, arrayBytesWriteTo.Length);
                }
                else
                {
                    throw new System.InvalidOperationException("NMVN: Network stream cannot be written");
                }
            }
            catch (Exception exception)
            { throw exception; }



            //try //Nguyen thuy code send to serial cua SONG THAN
            //{
            //    stringHex = stringHex.Replace(" ", "");
            //    stringHex = stringHex.Replace("/", "");
            //    stringHex = stringHex.Replace(",", "");
            //    stringHex = stringHex.Replace("-", "");

            //    byte[] buff = GlobalStaticFunction.HexStringToByteArray(stringHex);

            //    if (this.serialPort.IsOpen)
            //    {
            //        this.serialPort.ReadExisting();//Clear the port before send
            //        this.readResultBuffer = new byte[0];//Clear buffer before send
            //        this.serialPort.Write(buff, 0, buff.Length);
            //    }
            //}
            //catch (Exception exception)
            //{
            //    this.MainStatus = exception.Message;
            //}
        }