public ConnectThread(BluetoothChatService chatService, BluetoothDevice device, bool secure)
			{
			    this.chatService = chatService;
			    mmDevice = device;
				BluetoothSocket tmp = null;
				mSocketType = secure ? "Secure" : "Insecure";

				// Get a BluetoothSocket for a connection with the
				// given BluetoothDevice
				try
				{
					if (secure)
					{
						tmp = device.CreateRfcommSocketToServiceRecord(MY_UUID_SECURE);
					}
					else
					{
						tmp = device.CreateInsecureRfcommSocketToServiceRecord(MY_UUID_INSECURE);
					}
				}
				catch (IOException e)
				{
					Log.E(TAG, "Socket Type: " + mSocketType + "create() failed", e);
				}
				mmSocket = tmp;
			}
예제 #2
0
        public string PrintInvSumm(BluetoothSocket mmSocket,BluetoothDevice mmDevice,DateTime printDate1,DateTime printDate2)
        {
            msg = "";
            Stream mmOutputStream;
            try {
                UUID uuid = UUID.FromString ("00001101-0000-1000-8000-00805F9B34FB");
                mmSocket = mmDevice.CreateInsecureRfcommSocketToServiceRecord (uuid);
                if (mmSocket == null) {
                    msg = "Error creating sockect";
                    return msg;
                }
                if (mmDevice.BondState == Bond.Bonded) {
                    mmSocket.Connect ();
                    Thread.Sleep (300);
                    mmOutputStream = mmSocket.OutputStream;
                    byte[] charfont;
                    if (apara.PaperSize == "58mm") {
                        charfont = new Byte[] { 27, 33, 1 }; //Char font 9x17
                        mmOutputStream.Write (charfont, 0, charfont.Length);
                    }

                    if (apara.PaperSize == "80mm") {
                        charfont = new Byte[] { 27, 33, 0 }; //Char font 12x24
                        mmOutputStream.Write (charfont, 0, charfont.Length);
                    }

                    string text = GetInvoiceSumm (printDate1, printDate2);
                    //byte[] cc = ASCIIEncoding.ASCII.GetBytes(text);

                    byte[] cc = Encoding.GetEncoding ("GB18030").GetBytes (text);
                    int rem;
                    int result = Math.DivRem (cc.Length, 2048, out rem);
                    int pos = 0;
                    for (int line = 0; line < result; line++) {
                        IsStreamCanWrite (mmOutputStream);
                        mmOutputStream.Write (cc, pos, 2048);
                        pos += 2048;
                    }
                    if (rem > 0)
                        mmOutputStream.Write (cc, pos, rem);

                    //mmOutputStream.Write (cc, 0, cc.Length);
                    Thread.Sleep (3000);
                    mmOutputStream.Flush ();
                    mmOutputStream.Close ();
                    mmSocket.Close ();
                }

            } catch (Exception ex) {
                msg = ex.Message;
            }

            return msg;
        }
예제 #3
0
        //Bluetooth Printer -Mini Bluetooth Printer
        public void BluetoothMiniTest(BluetoothSocket mmSocket,BluetoothDevice mmDevice)
        {
            msg = "";
            Stream mmOutputStream;
            //TextView txtv = FindViewById<TextView> (Resource.Id.textView2);
            try {
                UUID uuid = UUID.FromString ("00001101-0000-1000-8000-00805F9B34FB");

                mmSocket = mmDevice.CreateInsecureRfcommSocketToServiceRecord (uuid);
                if (mmSocket == null) {
                    msg =  "Error creating sockect";
                    return;
                }
                if (mmDevice.BondState == Bond.Bonded) {
                    TrytoConnect(mmSocket);

                    Thread.Sleep (300);
                    mmOutputStream = mmSocket.OutputStream;
                    byte[] charfont;
                    charfont = new Byte[] { 27, 64 }; //Char font 9x17
                    mmOutputStream.Write(charfont, 0, charfont.Length);
                    if (apara.PaperSize=="58mm")
                    {
                        charfont = new Byte[] { 27, 33, 1 }; //Char font 9x17
                        mmOutputStream.Write(charfont, 0, charfont.Length);
                    }
                    if (apara.PaperSize=="80mm")
                    {
                        charfont = new Byte[] { 27, 33, 0 }; //Char font 12x24
                        mmOutputStream.Write(charfont, 0, charfont.Length);
                    }
                    charfont = new Byte[] { 28, 38 };
                    mmOutputStream.Write(charfont, 0, charfont.Length);
                    string test = "";
                    PrintCompHeader (ref test);
                    test = test+"\n\n\n\n\n";
                    byte[] cc = Encoding.GetEncoding("GB18030").GetBytes(test);
                    mmOutputStream.Write (cc,0, cc.Length);
                    Thread.Sleep (300);
                    charfont = new Byte[] { 28, 46 };
                    mmOutputStream.Write(charfont, 0, charfont.Length);
                    mmOutputStream.Close ();
                    mmSocket.Close ();
                    msg ="Printing....";
                } else {
                    msg= "Device not connected";

                }
            } catch (Exception ex) {
                msg = ex.Message;
            }
        }
예제 #4
0
        public void BluetoothMiniCN(BluetoothSocket mmSocket,BluetoothDevice mmDevice,CNNote inv,CNNoteDtls[] list,int noofcopy )
        {
            msg = "";
            Stream mmOutputStream;
            try {
                UUID uuid = UUID.FromString ("00001101-0000-1000-8000-00805F9B34FB");

                mmSocket = mmDevice.CreateInsecureRfcommSocketToServiceRecord (uuid);
                if (mmSocket == null) {
                    msg =  "Error creating sockect";
                    return;
                }
                if (mmDevice.BondState == Bond.Bonded) {
                    TrytoConnect(mmSocket);
                    Thread.Sleep (300);
                    mmOutputStream = mmSocket.OutputStream;
                    byte[] charfont;
                    charfont = new Byte[] { 27, 64 }; //Char font 9x17
                    mmOutputStream.Write(charfont, 0, charfont.Length);
                    if (apara.PaperSize=="58mm")
                    {
                        charfont = new Byte[] { 27, 33, 1 }; //Char font 9x17
                        //charfont = new Byte[] { 27, 77, 1 }; //Char font 9x17
                        mmOutputStream.Write(charfont, 0, charfont.Length);
                    }

                    if (apara.PaperSize=="80mm")
                    {
                        charfont = new Byte[] { 27, 33, 0 }; //Char font 12x24
                        //charfont = new Byte[] { 27, 77, 1 }; //Char font 9x17
                        mmOutputStream.Write(charfont, 0, charfont.Length);
                    }
                    charfont = new Byte[] { 28, 38 };
                    mmOutputStream.Write(charfont, 0, charfont.Length);
                    //charfont = new Byte[] { 28, 67,0,48 };
                    //mmOutputStream.Write(charfont, 0, charfont.Length);
                    string test = "";
                    double invTtlAmt =0;
                    double invTtlTax =0;
                    bool IsfoundInvoice =PrintCNInvoice(inv,ref test,ref invTtlAmt,ref invTtlTax );
                    if (!IsfoundInvoice){
                        PrintCompHeader (ref test);
                        PrintCustomer (ref test,inv.custcode);
                    }
                    PrintCNHeader (ref test,inv);
                    string dline="";
                    double ttlAmt =0;
                    double ttltax =0;
                    int count =0;
                    foreach(CNNoteDtls itm in list)
                    {
                        count+=1;
                        dline =dline+PrintCNDetail (itm,count);
                        ttlAmt = ttlAmt+ itm.netamount;
                        ttltax = ttltax+itm.tax;
                    }
                    test += dline;
                    PrintTotal (ref test,ttlAmt,ttltax);

                    PrintCNTaxSumm(ref test,list );
                    PrintFooter (ref test);
                    if (IsfoundInvoice)
                    {
                        test += "\nTHANK YOU\n\n";
                        PrintTotal (ref test,ttlAmt, ttltax, invTtlAmt,invTtlTax);
                        test += "n\n\n\n\n\n\n\n";
                    }else test += "\nTHANK YOUn\n\n\n\n\n\n\n";

                    //byte[] cc =ASCIIEncoding.ASCII.GetBytes(test);
                    byte[] cc = Encoding.GetEncoding("GB18030").GetBytes(test);
                    int bLen= cc.Length;

                    for (int i=0; i<noofcopy;i++)
                    {
                        int rem;
                        int result =Math.DivRem(cc.Length, 2048, out rem);
                        int pos =0;
                        for(int line= 0;line<result;line++)
                        {
                            IsStreamCanWrite (mmOutputStream);
                            mmOutputStream.Write (cc, pos, 2048);
                            pos += 2048;
                        }
                        if (rem >0)
                            mmOutputStream.Write (cc, pos, rem);
                        //mmOutputStream.BeginWrite(cc,0,cc.Length,
                        //mmOutputStream.Write (cc, 0, cc.Length);
                        Thread.Sleep (3000);
                        //mmOutputStream.Flush ();
                    }
                    Thread.Sleep (300);
                    mmOutputStream.Close ();
                    //mmInputStream.Close();
                    mmSocket.Close ();
                    msg ="Printing....";
                } else {
                    //txtv.Text = "Device not connected";
                    msg= "Device not connected";
                }

            } catch (Exception ex) {
                msg = ex.Message;
            }

            //	return msg;
        }
예제 #5
0
        //Bluetooth Printer -Mini Bluetooth Printer
        public void BluetoothMini(BluetoothSocket mmSocket,BluetoothDevice mmDevice,Invoice inv,InvoiceDtls[] list,int noofcopy)
        {
            msg = "";
            Stream mmOutputStream;
            //TextView txtv = FindViewById<TextView> (Resource.Id.textView2);
            try {
                UUID uuid = UUID.FromString ("00001101-0000-1000-8000-00805F9B34FB");

                mmSocket = mmDevice.CreateInsecureRfcommSocketToServiceRecord (uuid);
                if (mmSocket == null) {
                    //txtv.Text = "Error creating sockect";
                    msg =  "Error creating sockect";
                    //errmsg.Append(msg);
                    return;
                }
                //txtv.Text = mmDevice.BondState.ToString ();
                if (mmDevice.BondState == Bond.Bonded) {
                    //errmsg.Append("Start to connect\n");

                    //mmSocket.Connect ();
                    TrytoConnect(mmSocket);

                    Thread.Sleep (300);
                    //mmInputStream = mmSocket.InputStream;
                    //errmsg.Append("connected\n");
                    mmOutputStream = mmSocket.OutputStream;
                    byte[] charfont;
                    charfont = new Byte[] { 27, 64 }; //Char font 9x17
                    mmOutputStream.Write(charfont, 0, charfont.Length);
                    if (apara.PaperSize=="58mm")
                    {
                        charfont = new Byte[] { 27, 33, 1 }; //Char font 9x17
                        //charfont = new Byte[] { 27, 77, 1 }; //Char font 9x17
                        mmOutputStream.Write(charfont, 0, charfont.Length);
                    }

                    if (apara.PaperSize=="80mm")
                    {
                        charfont = new Byte[] { 27, 33, 0 }; //Char font 12x24
                        //charfont = new Byte[] { 27, 77, 1 }; //Char font 9x17
                        mmOutputStream.Write(charfont, 0, charfont.Length);
                    }
                    charfont = new Byte[] { 28, 38 };
                    mmOutputStream.Write(charfont, 0, charfont.Length);
                    //charfont = new Byte[] { 28, 67,0,48 };
                //	mmOutputStream.Write(charfont, 0, charfont.Length);
                    //charfont = new Byte[] { 27, 82, 15 }; //Char font 9x17
                //	mmOutputStream.Write(charfont, 0, charfont.Length);
                    string test = "";
                    //errmsg.Append("Set printer\n");
                    PrintInvoice (inv, list, ref test);
                    //var encoding = Encoding.GetEncoding(936);
                    //byte[] source = Encoding.Unicode.GetBytes(text);
                    //byte[] converted = Encoding.Convert(Encoding.Unicode, encoding, source);
                    //errmsg.Append("Start Endcoidng\n");
                    byte[] cc = Encoding.GetEncoding("GB18030").GetBytes(test);
                    for (int i=0; i<noofcopy;i++)
                    {
                        int rem;
                        int result =Math.DivRem(cc.Length, 2048, out rem);
                        int pos =0;
                        for(int line= 0;line<result;line++)
                        {
                            IsStreamCanWrite (mmOutputStream);
                            mmOutputStream.Write (cc, pos, 2048);
                            pos += 2048;
                        }
                        if (rem >0)
                            mmOutputStream.Write (cc, pos, rem);
                        //mmOutputStream.BeginWrite(cc,0,cc.Length,
                        //mmOutputStream.Write (cc, 0, cc.Length);
                        Thread.Sleep (3000);
                        //mmOutputStream.Flush ();
                    }
                    Thread.Sleep (300);
                    charfont = new Byte[] { 28, 46 };
                    mmOutputStream.Write(charfont, 0, charfont.Length);
                    mmOutputStream.Close ();
                    //mmInputStream.Close();
                    mmSocket.Close ();
                    msg ="Printing....";
                } else {
                    //txtv.Text = "Device not connected";
                    msg= "Device not connected";
                    //errmsg.Append(msg);
                }
            } catch (Exception ex) {
                msg = ex.Message;
            }
        }
예제 #6
0
        public void BluetoothPrint(BluetoothSocket mmSocket,BluetoothDevice mmDevice,string text,int noofcopy)
        {
            msg = "";
            Stream mmOutputStream;
            //TextView txtv = FindViewById<TextView> (Resource.Id.textView2);
            try {
                UUID uuid = UUID.FromString ("00001101-0000-1000-8000-00805F9B34FB");
                mmSocket = mmDevice.CreateInsecureRfcommSocketToServiceRecord (uuid);
                if (mmSocket == null) {
                    msg =  "Error creating sockect";
                    return;
                }
                if (mmDevice.BondState == Bond.Bonded) {
                    TrytoConnect(mmSocket);
                    Thread.Sleep (300);
                    mmOutputStream = mmSocket.OutputStream;
                    byte[] charfont;
                    charfont = new Byte[] { 27, 64 }; //Char font 9x17
                    mmOutputStream.Write(charfont, 0, charfont.Length);
                    if (apara.PaperSize=="58mm")
                    {
                        charfont = new Byte[] { 27, 33, 1 }; //Char font 9x17
                        mmOutputStream.Write(charfont, 0, charfont.Length);
                    }

                    if (apara.PaperSize=="80mm")
                    {
                        charfont = new Byte[] { 27, 33, 0 }; //Char font 12x24
                        mmOutputStream.Write(charfont, 0, charfont.Length);
                    }
                    charfont = new Byte[] { 28, 38 };
                    mmOutputStream.Write(charfont, 0, charfont.Length);
            //					charfont = new Byte[] { 28, 67,0,48 };
            //					mmOutputStream.Write(charfont, 0, charfont.Length);
                    byte[] cc = Encoding.GetEncoding("GB18030").GetBytes(text);
                    for (int i=0; i<noofcopy;i++)
                    {
                        int rem;
                        int result =Math.DivRem(cc.Length, 2048, out rem);
                        int pos =0;
                        for(int line= 0;line<result;line++)
                        {
                            IsStreamCanWrite (mmOutputStream);
                            mmOutputStream.Write (cc, pos, 2048);
                            pos += 2048;
                        }
                        if (rem >0)
                            mmOutputStream.Write (cc, pos, rem);
                        Thread.Sleep (3000);
                    }
                    Thread.Sleep (300);
                    charfont = new Byte[] { 28, 46 };
                    mmOutputStream.Write(charfont, 0, charfont.Length);
                    mmOutputStream.Close ();
                    mmSocket.Close ();
                    msg ="Printing....";
                } else {
                    msg= "Device not connected";
                }
            } catch (Exception ex) {
                msg = ex.Message;
            }
        }