Forum Rule: Always post complete source code & details to reproduce any issue!
Page 2 of 2 FirstFirst 1 2
Results 26 to 34 of 34

Thread: Implementing TeensyLoader into a C# app?

  1. #26
    Junior Member
    Join Date
    Sep 2021
    Posts
    6
    Hi,

    thank you for your help. I have a quastion about your new repo.

    Is there a quick way to read the COM port name?

    Code:
    foreach (var teensy in watcher.ConnectedTeensies)
    {
          portCOM_comboBox.Items.Add(teensy);
    }
    But this reads all data about connected teensy. I only need COM port number

  2. #27
    Senior Member
    Join Date
    Apr 2014
    Location
    Germany
    Posts
    1,651
    E.g.
    Code:
    foreach (var board in watcher.ConnectedTeensies.Where(t => t.Ports.Any())) //loop through all connected boards which expose at least one COM port
    {                                                                            
       foreach (var port in board.Ports) // loop through all COM ports of the current board                    
       {
           Console.WriteLine(port);
       }
    }
    The example takes care of the fact that not all Teensies expose a COM port and that a Teensy can expose up to 3 COM ports.

  3. #28
    Junior Member
    Join Date
    Sep 2021
    Posts
    6
    Thank you. Everything is working great!

  4. #29
    Junior Member
    Join Date
    Nov 2021
    Location
    UK
    Posts
    4
    Hello,
    Firstly, thank you, luni, for all the work with TeensySharp library. A great tool.
    I made my first app to update firmware on teensies using .NET framework and windows forms. The problem is that when the app is opened, the the PC grinds into the halt. Task manager showing "WMI Provider Host" and "System Interrupts" using all the the CPU.
    Am I doing something wrong? I am using pretty much the win forms example in the git repository.

    Code:
    var Watcher = new TeensyWatcher();
    var Board = PJRC_Board.Teensy_35;
    var FlashImage = SharpUploader.GetEmptyFlashImage(Board);
    
    OpenFileDialog v1 = new OpenFileDialog();
    v1.Filter = "hex files (*.hex)|*.hex|All files (*.*)|*.*";
    v1.FilterIndex = 0;
    
    if (v1.ShowDialog() == DialogResult.OK)
    {
             SharpHexParser.ParseStream(File.OpenText(v1.FileName), FlashImage);
             USB_Device Teensy = Watcher.ConnectedDevices.FirstOrDefault();
             SharpUploader.StartHalfKay(Teensy.Serialnumber);
             int result = SharpUploader.Upload(FlashImage, Board, Teensy.Serialnumber, reboot: true);
    }

  5. #30
    Senior Member
    Join Date
    Apr 2014
    Location
    Germany
    Posts
    1,651
    The code you showed does look normal, but of course it is only a tiny snippet. To double check I just tried the WinForms example and it runs without an issue. Can you upload your project somewhere (e.g. GitHub) so that I can have a closer look?

    Edit: Just realized that you are using the synchronous functions (I thought I disabled them..) You need to use the async versions as shown in the example.
    Edit2: Sorry for the crappy answers so far. It looks like you are using a very old version of the library which doesn't work since a change in the USB descriptors a year or so ago. You need to use the current version from GitHub. The API changed significantly. Here is the relevant code from the updated WinForm example (Upload button)

    Code:
    private async void btnUpload_Click(object sender, EventArgs e)
    {
        var teensy = lbTeensies.SelectedItem as ITeensy;
        if (teensy != null)
        {
            string filename = tbHexfile.Text;
            if (File.Exists(filename))
            {
                var progress = new Progress<int>(v => progressBar.Value = v);
                progressBar.Visible = true;
                var result = await teensy.UploadAsync(filename, progress);
                MessageBox.Show(result.ToString(), "Message", MessageBoxButtons.OK, MessageBoxIcon.Information);
                progressBar.Visible = false;
                progressBar.Value = 0;
             }
             else MessageBox.Show("File does not exist", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
       }
    }
    Last edited by luni; 12-04-2021 at 11:19 AM.

  6. #31
    Junior Member
    Join Date
    Nov 2021
    Location
    UK
    Posts
    4
    Thanks, luni for a quick reponse. I was using a nuget package. I will try the github one.

  7. #32
    Senior Member
    Join Date
    Apr 2014
    Location
    Germany
    Posts
    1,651
    Yes, I definitely need to update that nuget package....

  8. #33
    Junior Member
    Join Date
    Nov 2021
    Location
    UK
    Posts
    4
    Quote Originally Posted by luni View Post
    Yes, I definitely need to update that nuget package....
    I look forward to it. Getting github repository into my visual studio project seems to be outside my capabilities. I never managed to get along with github.

  9. #34
    Senior Member
    Join Date
    Apr 2014
    Location
    Germany
    Posts
    1,651
    Here you are https://www.nuget.org/packages/lunOp...ibTeensySharp/ Since the API is rather different from the old version I decided to rename the library to lunOptics.libTeensySharp. So, you need to uninstall the old package first if you still have it installed. Let me know if it works for you.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •