Custom WIN Program for Teensy

Status
Not open for further replies.

GiGiUK

Active member
Hi All

Does anyone know if its possible to create a custom Windows program that can 1. Read analog inputs, 2.write to the Teensy EEPROM??

Ive searched but havent found anything. It wod seem a bit odd if you cant do this?

Thanks in advance.
 
You write a Windows program to send commands to Teensy and you write a Teensy program to read the Windows commands and react accordingly.
 
Hi

I have made some progress. I have managed to write a basic C# program that will turn ON and OFF pin 13 LED on a Teensy 3.5 using the USB Type: Serial. Its a breakthrough, I'm really happy with myself ha ha.
However, because I'm building a midi project I need my C# program to work when I program Teensy using the USB Type: Serial + Midi in the Teensy Duino platform and currently it doesn't work. Can anyone help me out with this?

TEENSY Code:
Code:
void setup() {
  Serial.begin(9600);
  pinMode(13, OUTPUT);
}

void loop() {

if (Serial.available()){
  int state = Serial.parseInt();
if (state == 1){
  digitalWrite(13, HIGH);
  Serial.println("Command completed LED turned ON");
}
if (state == 2){
  digitalWrite(13, LOW);
  Serial.println("Command completed LED turned OFF");
}
}

C# Win Application:

Code:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.IO.Ports;


namespace WindowsFormsApp1
{
    public partial class Form1 : Form
    {
        private SerialPort myport;
        
        public Form1()
        {
            InitializeComponent();
            init();
            
        }

        private void ON_btn_Click(object sender, EventArgs e)
        {
            myport.WriteLine("1");

            ON_btn.Enabled = false;
            OFF_btn.Enabled = true;
        }

        private void init()
        {
            try
            {
                myport = new SerialPort();
                //myport.BaudRate = 9600;
                myport.PortName = "COM5";
                myport.Open();
            }
            catch (Exception)
            {
                MessageBox.Show("Error!!");
            }

            //
            ON_btn.Enabled = true;
            OFF_btn.Enabled = false;

        }

        private void OFF_btn_Click(object sender, EventArgs e)
        {
            myport.WriteLine("2");

            ON_btn.Enabled = true;
            OFF_btn.Enabled = false;
        }
    }
}
 
Hi

I have made some progress. I have managed to write a basic C# program that will turn ON and OFF pin 13 LED on a Teensy 3.5 using the USB Type: Serial. Its a breakthrough, I'm really happy with myself ha ha.
However, because I'm building a midi project I need my C# program to work when I program Teensy using the USB Type: Serial + Midi in the Teensy Duino platform and currently it doesn't work. Can anyone help me out with this?

TEENSY Code:
...
C# Win Application:
...

Nice it worked ... to start ...

Quick glance and not sure what "it doesn't work" means?

Has the COM# changed perhaps and it isn't at the coded "COM5"?
 
I have a teensy sketch which uses MIDI and Serial. When it is running, it uses COM13 (plus there's a "Teensy MIDI" MIDI port as well). But if I run a program which only uses Serial, that uses COM9.
If you hard-code your C# program to use COM5 for just Serial, it should probably be looking for a different COM port when you compile it for Serial+MIDI.

Pete
 
O defragster, you little beauty and I'm a muppet. COM port changed to COM14...........pfff.

It seems that after I program the Teensy, it automatically changes COM port, seems bizarre to me.
 
When the USB TYPE changes it becomes a NEW device and gets a NEW COM# association.
Glad that got it to working!
 
it automatically changes COM port, seems bizarre to me.

Windows tries to associate a unique COM port number with each USB serial device you own. They're assigned in the order you plug them in. If you and your friend own the same 3 devices, and you plug device A in first, it becomes COM3 on your PC. Then if you plug in device B, it becomes COM4, and device C becomes COM5. The idea is if you unplug then all then reconnect 1 or more, say device C only, it (should) always show up as COM5.

If your friend with the same 3 devices plugs in device C first, it becomes COM3 on their machine. That association between the USB descriptor info which uniquely identifies that particular device and which COM port it always gets assigned is stored in your local Windows Registry.

You might expect Teensy would always get the same COM port number. And it should, on the same PC with the same Windows Registry info, but only when all the USB identification remains identical. If you change Tools > USB Type to cause Teensy to implement a different set of interfaces, or if you edit usb_desc.h & usb_desc.c, as far as Windows can tell you have just plugged in a completely different USB device. Windows can't know it's physically the same Teensy, and it most certainly should not guess any such thing. The USB descriptor info says it is now something else. As far as Windows knows, you've just bought a completely different USB product.

Sadly, this process isn't flawless. I don't know if it's bugs in Windows or something gets corrupted in the Windows Registry, or a result of changes made to other devices causing conflicts, but we have occasionally seen cases where Windows gets rather confused about COM port number assignments. But those are the exception where things go wrong.

Windows is indeed supposed to assign a new COM port number when it sees a new unique USB device. When you change USB types or edit the descriptors, to Windows it's a completely different USB device.
 
Status
Not open for further replies.
Back
Top