Click here to Skip to main content
15,867,704 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
I have created a software to print with 450 dymo, but with 550 dymo I need a software in c#..do you have some example that I can see?

My code:

using DymoSDK.Implementations;
using Microsoft.Win32;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;

namespace WPFSDKSample.ViewModels
{
    public class MainViewModel : BaseViewModel
    {
        #region Commands
        private ICommand _openFileCommand;
        public ICommand OpenFileCommand
        {
            get { return _openFileCommand = _openFileCommand ?? new CommandHandler(() => OpenFileAction(), true); }
        }

        private ICommand _printLabelCommand;
        public ICommand PrintLabelCommand
        {
            get { return _printLabelCommand = _printLabelCommand ?? new CommandHandler(() => PrintLabelAction(), true); }
        }

        private ICommand _updateLabelCommand;
        public ICommand UpdateLabelCommand
        {
            get { return _updateLabelCommand = _updateLabelCommand ?? new CommandHandler(() => UpdateValueAction(), true); }
        }

        private ICommand _updatePreviewCommand;
        public ICommand UpdatePreviewCommand
        {
            get { return _updatePreviewCommand = _updatePreviewCommand ?? new CommandHandler(() => UpdatePreviewAction(), true); }
        }



        #endregion

        #region Props
        IEnumerable<DymoSDK.Interfaces.IPrinter> _printers;

        public IEnumerable<DymoSDK.Interfaces.IPrinter> Printers
        {
            get
            {
                if (_printers == null)
                    _printers = new List<DymoSDK.Interfaces.IPrinter>();
                return _printers;
            }
            set
            {
                _printers = value;
                NotifyPropertyChanged("Printers");
            }
        }

        public int PrintersFound
        {
            get { return Printers.Count(); }
        }

        string _fileName;
        public string FileName
        {
            get
            {
                if (string.IsNullOrEmpty(_fileName))
                    return "No file selected";

                return _fileName;
            }
            set
            {
                _fileName = value;
                NotifyPropertyChanged("FileName");
            }
        }

        private BitmapImage _imageSourcePreview;

        public BitmapImage ImageSourcePreview
        {
            get { return _imageSourcePreview; }
            set
            {
                _imageSourcePreview = value;
                NotifyPropertyChanged("ImageSourcePreview");
            }
        }


        List<DymoSDK.Interfaces.ILabelObject> _labelObjects;
        public List<DymoSDK.Interfaces.ILabelObject> LabelObjects
        {
            get
            {
                if (_labelObjects == null)
                    _labelObjects = new List<DymoSDK.Interfaces.ILabelObject>();
                return _labelObjects;
            }
            set
            {
                _labelObjects = value;
                NotifyPropertyChanged("LabelObjects");
            }
        }

        private DymoSDK.Interfaces.ILabelObject _selectedLabelObject;
        public DymoSDK.Interfaces.ILabelObject SelectedLabelObject
        {
            get { return _selectedLabelObject; }
            set
            {
                _selectedLabelObject = value;
                NotifyPropertyChanged("SelectedLabelObject");
            }
        }

        private string _objectValue;
        public string ObjectValue
        {
            get { return _objectValue; }
            set
            {
                _objectValue = value;
                NotifyPropertyChanged("ObjectValue");
            }
        }


        DymoSDK.Interfaces.IPrinter _selectedPrinter;
        public DymoSDK.Interfaces.IPrinter SelectedPrinter
        {
            get { return _selectedPrinter; }
            set
            {
                _selectedPrinter = value;
                NotifyPropertyChanged("SelectedPrinter");
                DisplayConsumableInformation();
            }
        }

        List<string> _twinTurboRolls;
        public List<string> TwinTurboRolls
        {
            get
            {
                if (_twinTurboRolls == null)
                    _twinTurboRolls = new List<string>();
                return _twinTurboRolls;
            }
            set
            {
                _twinTurboRolls = value;
                NotifyPropertyChanged("TwinTurboRolls");
            }
        }

        private string _selectedRoll;
        public string SelectedRoll
        {
            get { return _selectedRoll; }
            set
            {
                _selectedRoll = value;
                NotifyPropertyChanged("SelectedRoll");
            }
        }

        private string _consumableInfoText;
        public string ConsumableInfoText
        {
            get { return _consumableInfoText; }
            set
            {
                _consumableInfoText = value;
                NotifyPropertyChanged("ConsumableInfoText");
            }
        }

        private bool _showConsumableInfo;
        public bool ShowConsumableInfo
        {
            get { return _showConsumableInfo; }
            set
            {
                _showConsumableInfo = value;
                NotifyPropertyChanged("ShowConsumableInfo");
            }
        }
        #endregion

        DymoSDK.Interfaces.IDymoLabel dymoSDKLabel;


        public MainViewModel()
        {
            DymoSDK.App.Init();
            dymoSDKLabel = DymoLabel.Instance;
            Printers = DymoPrinter.Instance.GetPrinters();
            TwinTurboRolls = new List<string>() { "Auto", "Left", "Right" };
        }
        /// <summary>
        /// Open a Dymo label file and load the content in the instance of the class
        /// Get the preview image of the label
        /// Get the list of object names
        /// </summary>
        private void OpenFileAction()
        {
            OpenFileDialog openFileDialog = new OpenFileDialog();
            openFileDialog.Filter = "DYMO files |*.label;*.dymo|All files|*.*";

            if (openFileDialog.ShowDialog() == true)
            {
                FileName = openFileDialog.FileName;
               // DymoSDK.App.Init();
                //Load label from file path
                dymoSDKLabel.LoadLabelFromFilePath(FileName);
                //Get image preview of the label
                dymoSDKLabel.GetPreviewLabel();
                //Load image preview in the control 
                ImageSourcePreview = LoadImage(dymoSDKLabel.Preview);
                //Get object names list
                LabelObjects = dymoSDKLabel.GetLabelObjects().ToList();
            }
        }
        /// <summary>
        /// Print the current loaded label using the selected printer name
        /// </summary>
        private void PrintLabelAction()
        {
            int copies = 1;
            if (SelectedPrinter != null)
            {
                //Send to print
                if (SelectedPrinter.Name.Contains("Twin Turbo"))
                {
                    int rollSel = SelectedRoll == "Auto" ? 0 : SelectedRoll == "Left" ? 1 : 2;
                    DymoPrinter.Instance.PrintLabel(dymoSDKLabel, SelectedPrinter.Name, copies, rollSelected: rollSel);
                }
                else
                    DymoPrinter.Instance.PrintLabel(dymoSDKLabel, SelectedPrinter.Name, copies);

                //If the label contains counter objects
                //Update counter object and preview to show the incresead value of the counter
                var counterObjs = dymoSDKLabel.GetLabelObjects().Where(w => w.Type == DymoSDK.Interfaces.TypeObject.CounterObject).ToList();
                if (counterObjs.Count > 0)
                {
                    foreach (var obj in counterObjs)
                        dymoSDKLabel.UpdateLabelObject(obj, copies.ToString());
                    UpdatePreviewAction();
                }
            }
        }
        /// <summary>
        /// Update the object value using the object name selected
        /// </summary>
        private void UpdateValueAction()
        {
            if (SelectedLabelObject != null)
            {
                //Update label object value
                dymoSDKLabel.UpdateLabelObject(SelectedLabelObject, ObjectValue);
                UpdatePreviewAction();
            }
        }
        /// <summary>
        /// Update the preview image of the label
        /// </summary>
        private void UpdatePreviewAction()
        {
            dymoSDKLabel.GetPreviewLabel();
            if (dymoSDKLabel != null)
                ImageSourcePreview = LoadImage(dymoSDKLabel.Preview);
        }
        /// <summary>
        /// Load the preview image label in the  image control
        /// </summary>
        /// <param name="array">Preview image content</param>
        /// <returns>Bitmap of the content</returns>
        private BitmapImage LoadImage(byte[] array)
        {
            using (var ms = new System.IO.MemoryStream(array))
            {
                var image = new BitmapImage();
                image.BeginInit();
                image.CacheOption = BitmapCacheOption.OnLoad;
                image.StreamSource = ms;
                image.EndInit();
                return image;
            }
        }

        private void DisplayConsumableInformation()
        {
            ConsumableInfoText = string.Empty;
            if(SelectedPrinter != null && DymoPrinter.Instance.Is550Printer(SelectedPrinter.DriverName))
            {
                //IMPORTANT: Get consumable information may return NULL when printer is connected to the machine
                // we recommend wait a few seconds to establish connection with printer.
                DymoSDK.Interfaces.IConsumableInfo550Printer cons = DymoPrinter.Instance.GetCurrentLabelInsertedIn550Printer(SelectedPrinter.Name);
                if(cons != null)
                {
                   ConsumableInfoText =  $"Status: {cons.RollStatus} \nConsumable: {cons.Name} \nLabels remaining: {cons.LabelsRemaining}";
                }
            }
        }

    }
}


What I have tried:

I tried to develop a program in c++
Posted
Updated 7-Feb-23 5:26am
v4
Comments
Richard MacCutchan 7-Feb-23 11:33am    
That code is C# not C++. And you have not asked a question.

The DYMO Developer SDK Support Blog[^] has some documentation for C#: Net Tag Search[^] plus they have a Github Repo[^] with full source code samples that you can download and run. Here is a link to the WPFSDKSample[^]

Here is a link to their Nuget Pavkage that you can use in your app: NuGet Gallery | DYMO.Connect.SDK 1.4.3.37[^]
 
Share this answer
 
v3
Comments
Member 14594285 7-Feb-23 9:00am    
I follow this link but there is java and visual basic, in c# I don't find libraries
Dave Kreskowiak 7-Feb-23 9:05am    
There is no VB.NET library separate from a C# library. If it works with VB.NET, it will also work with C# because the library targets the .NET Framework, not the language.
Member 14594285 7-Feb-23 9:10am    
I tried to follow this link:
DYMO Label Framework .NET Reference documentation

but page not found..
Member 14594285 7-Feb-23 9:12am    
Can I use WPF libraries?
Member 14594285 7-Feb-23 9:08am    
ok thanks, I don't know c# and I try to learn..I used always c++ but with this printer I must use c#..so I must download VB.NET libray
You should talk to the people who created it - Dymo[^] - they provide technical support and API's, and will know more about their product than we will. If they don't, then find another supplier and demand your money back!
 
Share this answer
 
Comments
Member 14594285 7-Feb-23 4:00am    
yes, I saw..but they use software to print labels, but I need a code to print in my software, I use c#..I created a code with c++ but I need help to write in c#..thanks
OriginalGriff 7-Feb-23 4:18am    
Did you check their online support page?
If wasn't hard to find the SDK: https://www.dymo.com/support?cfid=online-support-sdk

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900