Exemplo n.º 1
0
        public override void WriteCommands(Stream stream, Encoding encoding, Project project)
        {
            int realX = this.CalculatePrintingX(this.Width, project);
            int realY = this.CalculatePrintingY(this.Height, project);

            UsbUtil.WriteCommand(stream, encoding, "X" + realX + ";" + realY + ";" + (realX + this.Width) + ";" + (realY + this.Height) + ";" + this.Thickness);
        }
Exemplo n.º 2
0
        private void CheckConnection()
        {
            if (this.Project.PortName == null)
            {
                pbConnectionStatus.Image = TicketPrinter.Properties.Resources.status_error;
                lblConnectionStatus.Text = "No connection set up.";
                this.isConnected         = false;
            }

            else if (this.connection == null)
            {
                // Try connecting
                string[]      portNames    = SerialPort.GetPortNames();
                List <string> portNameList = new List <string>(portNames);
                if (portNameList.Contains(this.Project.PortName))
                {
                    this.connection = new SerialPort(this.Project.PortName);
                    UsbUtil.PrepareSerialPort(this.connection);
                    TryEstablishConnection(false);
                }
                else
                {
                    pbConnectionStatus.Image = TicketPrinter.Properties.Resources.status_error;
                    lblConnectionStatus.Text = this.Project.PortName + " not connected. Check setup or cable";
                    this.isConnected         = false;
                }
            }
            else if (!this.connection.IsOpen)
            {
                TryEstablishConnection(true);
            }

            UpdateLayoutConnected();
        }
Exemplo n.º 3
0
 public virtual void WriteCommands(Stream stream, Encoding encoding, Project project)
 {
     UsbUtil.WriteCommand(stream, encoding, "G" + (project.XOffset + this.Position.X) + ";" + GetAlignmentChar(this.HorizontalAlignment));
     UsbUtil.WriteCommand(stream, encoding, "I" + (project.YOffset + this.Position.Y) + ";" + GetAlignmentChar(this.VerticalAlignment));
     UsbUtil.WriteCommand(stream, encoding, "R" + GetRotationDegrees(this.Rotation));
     if (this.SupportsHorizontalScaling())
     {
         UsbUtil.WriteCommand(stream, encoding, "D" + this.HorizontalScaling);
     }
 }
Exemplo n.º 4
0
        public override void WriteCommands(Stream stream, Encoding encoding, Project project)
        {
            int width  = this.LineDirection == Direction.Horizontal ? this.Length : 1;
            int height = this.LineDirection == Direction.Vertical ? this.Length : 1;

            int realX = this.CalculatePrintingX(width, project);
            int realY = this.CalculatePrintingY(height, project);

            Console.WriteLine(this.Thickness + ";" + this.LineDirection.ToString());

            UsbUtil.WriteCommand(stream, encoding, "X" + realX + ";" + realY + ";" + (realX + width) + ";" + (realY + height) + ";" + this.Thickness);
        }
Exemplo n.º 5
0
        private void btnPrintTicket_Click(object sender, EventArgs e)
        {
            if (!this.isConnected)
            {
                new PrinterNotConnectedDialog().ShowDialog();
                return;
            }

            PrintTicketsDialog dialog = new PrintTicketsDialog(Project, SelectedTicket);

            if (dialog.ShowDialog() != DialogResult.OK)
            {
                return;
            }

            Ticket ticket = dialog.SelectedTicket;
            int    amount = dialog.Amount;

            // Configuration
            UsbUtil.WriteCommand(this.connection.BaseStream, Encoding.Default, "k1;0");

            // Layout
            for (int i = 0; i < amount; i++)
            {
                using (MemoryStream stream = new MemoryStream())
                {
                    stream.WriteByte(UsbUtil.BeginLayout);
                    foreach (TicketItem item in ticket.Items)
                    {
                        item.WriteCommands(stream, Encoding.Default, Project);
                    }

                    stream.WriteByte(UsbUtil.EndLayout);
                    byte[] buffer = stream.GetBuffer();
                    this.connection.Write(buffer, 0, buffer.Length);
                    Console.WriteLine(ManualControlWindow.formatOutput(Encoding.Default.GetString(buffer)));
                    //stream.WriteTo(this.connection.BaseStream);
                }

                UsbUtil.WriteCommand(this.connection.BaseStream, Encoding.Default, "#1");
                this.Project.NextTicketNumber++;
            }

            isChanged = true;
            UpdateSaveButton();
            nudNewTicketNumber.Value = Project.NextTicketNumber;
            pnlTicketItems.Refresh();
        }
Exemplo n.º 6
0
        private void btnConnect_Click(object sender, EventArgs e)
        {
            port = new SerialPort(this.lbPortName.SelectedItem.ToString());
            UsbUtil.PrepareSerialPort(port);
            port.ReadTimeout   = 500;
            port.WriteTimeout  = 500;
            port.DataReceived += WriteReceivedData;
            port.PinChanged   += port_PinChanged;

            port.ErrorReceived         += port_ErrorReceived;
            port.WriteBufferSize        = 16;
            port.ReadBufferSize         = 14;
            port.ReceivedBytesThreshold = 1;
            port.Open();

            tbLog.Text = "[TicketPrinterTest] Connected to printer on port " + this.lbPortName.SelectedItem.ToString();
            updateConnectLayout();
        }
Exemplo n.º 7
0
 public override void WriteCommands(System.IO.Stream stream, Encoding encoding, Project project)
 {
     UsbUtil.WriteCommand(stream, encoding, "G0" + project.XOffset);
     UsbUtil.WriteCommand(stream, encoding, "I0" + project.YOffset);
     UsbUtil.WriteCommand(stream, encoding, this.Text);
 }
Exemplo n.º 8
0
 private void btnChooseMagazine_Click(object sender, EventArgs e)
 {
     UsbUtil.WriteCommand(this.connection.BaseStream, this.connection.Encoding, "y9;30;2;" + (int)(nudMagazine.Value - 1));
 }
Exemplo n.º 9
0
 private void btnReinitialise_Click(object sender, EventArgs e)
 {
     UsbUtil.WriteCommand(this.connection.BaseStream, Encoding.Default, "y9;30;0");
 }
Exemplo n.º 10
0
        public override void WriteCommands(System.IO.Stream stream, Encoding encoding, Project project)
        {
            /*string varName = this.GetVariableName();
             * if (varName != null)
             * {
             *  base.WriteCommands(stream, encoding, project);
             *  Util.WriteCommand(stream, encoding, "F" + this.TextSpacing);
             *  Util.WriteCommand(stream, encoding, "V" + varName);
             *  Util.WriteCommand(stream, encoding, "T" + GetCommandFontName(this.FontType, this.FontSize) + ";" + this.GetText(project));
             * }
             * else*/

            Point oldPos = this.Position;
            Font  f      = GetFont();

            string[] lines            = GetText(project).Split(new string[] { "\r\n" }, StringSplitOptions.None);
            int      cumulativeHeight = 0;

            foreach (string line in lines)
            {
                cumulativeHeight += (int)TextRenderer.MeasureText(line, f).Height;
            }
            cumulativeHeight += (int)(FontSize / 2 * (lines.Length - 1));

            // Fix starting position of 'inverse' printing directions
            if (Rotation == ItemRotation.R180)
            {
                if (HorizontalAlignment == Alignment.Begin)
                {
                    this.Position += new Size(0, cumulativeHeight);
                }
                else if (HorizontalAlignment == Alignment.Center)
                {
                    this.Position += new Size(0, cumulativeHeight / 2);
                }
            }
            else if (Rotation == ItemRotation.R90)
            {
                if (HorizontalAlignment == Alignment.Begin)
                {
                    this.Position += new Size(cumulativeHeight, 0);
                }
                else if (HorizontalAlignment == Alignment.Center)
                {
                    this.Position += new Size(cumulativeHeight / 2, 0);
                }
            }

            foreach (string line in lines)
            {
                if (line.Trim() != "")
                {
                    base.WriteCommands(stream, encoding, project);
                    UsbUtil.WriteCommand(stream, encoding, "F" + this.TextSpacing);
                    UsbUtil.WriteCommand(stream, encoding, "T" + GetCommandFontName(this.FontType, this.FontSize) + ";" + line);
                }
                switch (Rotation)
                {
                case ItemRotation.R0:
                    this.Position += new Size(0, (int)TextRenderer.MeasureText(line, f).Height + this.FontSize);
                    break;

                case ItemRotation.R180:
                    this.Position -= new Size(0, (int)TextRenderer.MeasureText(line, f).Height + this.FontSize);
                    break;

                case ItemRotation.R90:
                    this.Position -= new Size((int)TextRenderer.MeasureText(line, f).Height + this.FontSize, 0);
                    break;

                case ItemRotation.R270:
                    this.Position += new Size((int)TextRenderer.MeasureText(line, f).Height + this.FontSize, 0);
                    break;
                }
            }
            this.Position = oldPos;
        }