Windows comm port app to mimic centre off 3 way toggle switch? - Page 1
Forum section: electronics / projects

author: Chris Wilson
author_rank: Super Contributor
timestamp: February 27, 2019, 01:10:27 pm
content: I have a custom written (by someone else...) app to control a high power SSR remotely fom a proper PC comm port. I would like to be able to mimic the actions of a 3 way, centre off toggle switch that powers in either direction a DC motor powered variometer, from one or two other comm porst. The idea is to remotely control the device via Windows Remote desktop. Is there any commercial software to do this sort of thing or would it need another custom application please? Ideally something that would use one or two comm ports to say use the + and - keys to power a DC motor either way via perhaps a driver transistor as long as the key relevant was depressed from within the app?

author: TomS_
author_rank: Frequent Contributor
timestamp: February 27, 2019, 04:14:43 pm
content: Can the person who made the app not extend it to provide such functionality? It seems like something so incredibly basic, I would be surprised if they cant do it.

author: DDunfield
author_rank: Regular Contributor
timestamp: February 28, 2019, 02:47:33 am
content: Quote from: Chris Wilson on February 27, 2019, 01:10:27 pmAre you just controlling the drivers via the DTR and RTS lines from the COM port?You could rig up something with an H-bridge to power the motor in either direction, however I wouldn't use one signal to power one way, and the other to do the reverse, as that leads the possibility that they can both be turned on at once which would be basically a "short". I'd use one (say DTR) as an enable (motor ON/OFF), and the other (RTS) to select which half of the bridge to turn on (direction).So '+' activates the motor in one direction and '-' in the other? Is there on OFF key? or do you "step" through the three positions? eg:+ Turns it on forward- Turns it off- Turns it on backward+ Turns it off+ Turns it on forwardEither way it would be dead easy to write (5 mins as long as you don't need pretty graphics and click boxes - just accepting two or three keys would be very simple).Can you give more detail on what you want? If it is truly that simple, I would be happy to knock it out for you.DavePS: What happens when you close the program? - Windows will take over control of the COM port lines at that point, and may periodically toggle them checking for connected devices...It *WILL* toggle them when it boots!

author: Ian.M
author_rank: Super Contributor
timestamp: February 28, 2019, 08:28:43 am
content: I don't like hardware that, under a consumer OS, uses the control lines of a COM port directly to interface to mechanical or power electrical devices, because (as DDunfield just pointed out) it *will* glitch during bootup, and can glitch due to OS or third party program activity when the controlling application is closed. Under current MS OSes, even if you think you've disabled anything that messes with the port, any OS and some application updates can screw it up again by restoring default settings or re-enabling 3rd party daemons that search for connected serial devices.To avoid the issues with 'dumb 'interfaces, while still using a COM port, the easiest solution is to hang a smart controller off the port, that interprets commands sent as character strings over its serial interface. With a little care to avoid it 'jabbering' as soon as the port is opened in a way that looks like a legacy serial mouse, or in a way that gets it mis-identified as a 3rd party serial device, it will be robust against unwanted state changes during bootup, or when its control application is closed.'Dumb' COM port control line interfaces were enough trouble back in the Win9x era, and IMHO should have died with MSDOS. Even cost is no longer a significant justification with a multiplicity of MCUs available for less than a DE-9 back shell!If all you care about is that it looks like a COM port to Windows, then any Arduino could handle the hardware side of things, possibly with a H-bridge breakout or shield for the DC motor. If you *MUST* hang it off a real serial port, consider an Arduino Pro Mini (one of the few non-USB Arduinos) + a MAX3232 or similar RS2232 interface IC. The same controller can handle multiple motors and SSRs, and also check sensors (e.g. limit switches), off a single COM port.On the software side of things, talking to a serial device using 7 bit ASCII*, is trivial and interactive from a terminal program, generally reasonably straightforward using nearly any programming language or scripting tool, and is even possible using native commands from a console command line.* Under Windows, in some programming languages and scripting tools it can be difficult to transfer full 8 bit binary data, and that also makes it difficult to drive interactively from a terminal program, so there's a strong incentive to put in the extra work coding the controller to keep the protocol human readable.

author: DDunfield
author_rank: Regular Contributor
timestamp: February 28, 2019, 10:56:21 am
content: Quote from: Ian.M on February 28, 2019, 08:28:43 amExactly this. I woke up with the idea to log back in and make this point but you beat me to it!My suggestion is to use an STM32 "Blue pill" - dirt cheap on ebay/ali (<$3) and plenty of power/memory etc. I use them of all kinds of stuff. I program them "bare metal", but I'm pretty sure there is an Arduino setup for it if you prefer to go that way.Lots of advantages over COM port control lines:- Has LOTS of I/O lines, also SPI, I2C, UART, ADC and other peripherals (ie: lots of expansion capability without adding any more to windows).- Human readable interface.- No special windows software needed, talk to it with any TTY program.- Just as easy to control it from windows, linux, mac, etc. With an HC05 BT serial module you could even control it from a Phone/Tablet (I think not relevant to the OP's needs- Protection from host inadvertently poking your I/O bits. Powers up in a known/stable state. Can have it power up in "last" state if you need that.- Can require a password if you need security controlling the device etc.- Easy to implement guard timers (perhaps you don't want to leave the motor on for hours).- Can have "smarter" functions than just turning an I/O bit on or off if needed.- Easy to change/updateDave