Serial TTL, USB Communication - Sending ASCII Strings

LiveCode is the premier environment for creating multi-platform solutions for all major operating systems - Windows, Mac OS X, Linux, the Web, Server environments and Mobile platforms. Brand new to LiveCode? Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

JimAnders
Posts: 1
Joined: Thu Jun 11, 2020 5:14 am

Serial TTL, USB Communication - Sending ASCII Strings

Post by JimAnders » Thu Jun 11, 2020 5:21 am

I am working on a project to attempt to use LiveCode application to control an automated assembly machine. This machine has a number of stepper motors, switches and a few sensors such as load cells and linear encoders. The goal is to have an accessible UI so that operators and technicians can update and extend the programming. My vision is that LiveCode would be an ideal candidate for this. The stepper motor controllers are reasonably intelligent and can accept communications via a serial TTY 9600 baud link including a daisy-chained serial connection, a USB link or even an I2C connection. Obviously, USB is attractive because it’s somewhat ubiquitous.

The serial commands that the stepper controllers understand use one of four formats: quick, 7-bit write,
32-bit write, and block read. These are encoded as sequences of bytes within TTL serial command packets. Should be straightforward.

The USB commands also use one of four formats: quick, 7-bit write, 32-bit write, and block read.

The stepper motor controller even has a Windows or Mac application to control the steppers for testing. You can set the various stepper parameters, etc. This works nicely over the USB connection to the controller. They also install as part of that app the underlying software that allows one to type stepper commands from the command line terminal window. Like this...

stepcmd --current 500 --position 1234 --pause-on-error

stepcmd --resume --position 200 --pause-on-error

So, with this software installed on the host computer, I am thinking IT SHOULD be easy to somehow get LiveCode to generate these ASCII strings and send them just like in the command line prompt.

I am a mechanical engineer who graduated in the 1980s so my programming skills are minimal. So, hopefully someone here can understand what I am trying to achieve and point me in the right direction. If someone has a solution, I would certainly love to hear more.

Regards,
Jim Anders

SparkOut
Posts: 2852
Joined: Sun Sep 23, 2007 4:58 pm

Re: Serial TTL, USB Communication - Sending ASCII Strings

Post by SparkOut » Thu Jun 11, 2020 7:39 am

What does the provided stepper controller software comprise, and is it complete (does it have all the options to be as functional as you need albeit without a gui)?
If you can do everything you need with the command line then the simple answer is yes, you could use LiveCode to be a gui wrapping the calls to shell out the commands.
If there is a dll in use for which the call specifications can be provided, it could also be possible to use LiveCode Builder to make a library to interact more directly, rather than by shell calls.
So there's hope, but it might need a lot of technical fizzmergibbens or shell calls with quotes and escapes to be worked out.
There's a number of examples on the forum, see maverickalex's efforts with shell calls to flight simulator terrain software, an old thread but still valid, viewtopic.php?f=18&t=2766 , or my journey with support on making LCB library to call a 3rd party dll, viewtopic.php?f=93&t=30429

mrcoollion
Posts: 720
Joined: Thu Sep 11, 2014 1:49 pm
Location: The Netherlands

Re: Serial TTL, USB Communication - Sending ASCII Strings

Post by mrcoollion » Thu Jun 11, 2020 9:49 am

in the following github url (https://github.com/trozware/rev_stacks)
Sarah Reichelt (company TrozWare https://troz.net/) posted her LiveCode Stacks. One of the stacks is a serial communication example (SerialTest.rev).
You might want to try this as a basis to start from.
I have no idea if anything works but this is what I came across that might help you.

Regards,

Paul

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9669
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: Serial TTL, USB Communication - Sending ASCII Strings

Post by dunbarx » Thu Jun 11, 2020 1:43 pm

Hi.

It may be useful to check out devices that I have used for years, "Service USB Plus" made by "Bonig und Kallenbach" in Germany:
https://bkohg.com/interfaces_e.html

These are easy and fun to use, though not cheap (about $450). They use the USB port and include a framework for LC. They include I/O gadgetry that can easily be configured to drive stepper motors. The advantage is that all of LC is available for the UI, as are the read and write commands. I have several of these running machines in my factory, and several more driving lighting effects in the world.

Craig

sphere
Posts: 1145
Joined: Sat Sep 27, 2014 10:32 am
Location: Earth, Except when i Jump

Re: Serial TTL, USB Communication - Sending ASCII Strings

Post by sphere » Fri Jun 12, 2020 10:40 am

dunbarx wrote:
Thu Jun 11, 2020 1:43 pm
It may be useful to check out devices that I have used for years, "Service USB Plus" made by "Bonig und Kallenbach" in Germany:
https://bkohg.com/interfaces_e.html
Craig
Thanks!
Wow, it's the first time i see a (hardware) company mention Revolution aka LC.
I'm testing with a single stepper motor on a raspberry using LC7.(only when i have time) The usage for which i use it is rather simple. It has to turn switches with 1 to 4 positions depending on the type. And do this for 6000 times as part of safety tests. With LC i have it running but moving the mouse interferes the motor. You can actually hear and see it. So it seems the mouse is treated as privileged or how should i call it. So here it could be better to have a serial connection to a separate board, instead of directly using th GPIO to command the stepperdriver.

Trying the same with a python script it runs smooth(i'm no python programmer, but now i have it that it can spin CW and CCW). I don't know how it will work when i manage to create a GUI for python.

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9669
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: Serial TTL, USB Communication - Sending ASCII Strings

Post by dunbarx » Fri Jun 12, 2020 2:05 pm

Hi.

Stepper motors are a specialty of the gadget I mentioned.

In one of my applications, I interrogate the gadget constantly to detect switch states. There is no noticeable "interference" between mouse actions and the process itself.

Do I assume that the stepper is connected directly to the shaft of a free running rotary switch? And the motor is commanded to rotate a specific amount to each switch position? I am sure that there would be no similar problem in your case.

I am not connected in any way with the manufacturer, but it sounds like the "Service USB Plus" of theirs is perfect for you.

Craig

SparkOut
Posts: 2852
Joined: Sun Sep 23, 2007 4:58 pm

Re: Serial TTL, USB Communication - Sending ASCII Strings

Post by SparkOut » Fri Jun 12, 2020 6:32 pm

Assuming running from a Mac :D

sphere
Posts: 1145
Joined: Sat Sep 27, 2014 10:32 am
Location: Earth, Except when i Jump

Re: Serial TTL, USB Communication - Sending ASCII Strings

Post by sphere » Fri Jun 12, 2020 9:18 pm

dunbarx wrote:
Fri Jun 12, 2020 2:05 pm
Do I assume that the stepper is connected directly to the shaft of a free running rotary switch? And the motor is commanded to rotate a specific amount to each switch position? I am sure that there would be no similar problem in your case.

I am not connected in any way with the manufacturer, but it sounds like the "Service USB Plus" of theirs is perfect for you.

Craig
Yes indeed, it's connected to the shaft of a rotary switch with 2 to 4 positions, and where the moment of switching is important. The shaft is rotated to the moment the switch wants to switch itself. So the moment of switching may not be done by force of the rotation. Also a rated current is running thru the switch (ac or dc depending on the type) to check if pitting is occuring.
I will check it out. We also had once a sample which had a few nice driver boards via usb and on that board a small motor driver board fitted exactly which embedded an A4998 motorstepperdriver which i'm using now too. Maybe i can find such board.

Thanks!

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9669
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: Serial TTL, USB Communication - Sending ASCII Strings

Post by dunbarx » Sat Jun 13, 2020 5:08 am

If I were doing this, I would not use a stepper, but rather an ordinary gear motor coupled to an absolute encoder, In this way, one only needs to rotate the motor until a specific encoder value was reached, and then stop. It would also be simple to know which direction to go to reach the desired position most directly, since one only need rotate to fixed angular "address" corresponding to the contact positions of the switch. In this way, the gadget I mentioned is perfect for the task. It can power the motor, all the while reading the encoder, and stop at the desired angle.
So the moment of switching may not be done by force of the rotation.
Do you mean over-rotation, caused by angular inertia? Steppers do not have this issue,
to check if pitting is occuring.
I am keen to know what this means, and how one might detect such an odd state of affairs

Craig

sphere
Posts: 1145
Joined: Sat Sep 27, 2014 10:32 am
Location: Earth, Except when i Jump

Re: Serial TTL, USB Communication - Sending ASCII Strings

Post by sphere » Sat Jun 13, 2020 5:48 pm

Thanks for the hint, that is something what i might check into, a motor with encoder. Maybe for this topic it is more precise or easier to handle.
Do you mean over-rotation, caused by angular inertia? Steppers do not have this issue,
Indeed, therefore i saw just with the few tests i did that it worked great for that. Every switch has it's angle of degrees where is should switch and with the stepper motor depending on the steps one can calculate how much steps it would be to the next position.
My first idea was to attach something mechanical to to shaft so when turning to the 1st position it would be detected via a switch which i could read with one of the GPIO ports.
I am keen to know what this means, and how one might detect such an odd state of affairs
it's the damaging which could occur on the contacts, one could see this when disassembled. But also the contacts could melt together which is also not allowed. This can happen when a switch is used for DC when it is actually only suitable for AC, as the material of the contacts is different. Of course there are also switches who are suitable for both. The contacts must get together in one click and may not dender(or how is that called exactly in english). Also the housing of the switch must stand heat which occurs, especially when switching so many times. Mostly the test consists of 50 times an overload(like 10% more current then rated) and after that the endurance of 6000 times at rated current.

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9669
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: Serial TTL, USB Communication - Sending ASCII Strings

Post by dunbarx » Sun Jun 14, 2020 1:57 am

What loads are these switches dealing with? I assumed "typical" electronic loads, that is, a max of a couple of amperes at 5-24 volts or so. In this world, gold plated contacts are common, AC/DC is not important, and switching cycles above 100,000 are common.

If you are switching real power, then certainly you will want to drive solid state relays connected to rugged contactors. But even here, since there is always an intermediate device upstream of the contractor, the switches can still be the usual type, inexpensive and rugged.

So, what are those loads?

Craig

sphere
Posts: 1145
Joined: Sat Sep 27, 2014 10:32 am
Location: Earth, Except when i Jump

Re: Serial TTL, USB Communication - Sending ASCII Strings

Post by sphere » Sun Jun 14, 2020 12:15 pm

These switches are mostly industrial types up 380Vac and different amps from 1 up to and above 32A. And they are not all gold plated. AC or DC is important, if you like it or not. and yes they might be capable of doing 100000 switches or more. The tests according certain IEC/UL standards is 50 overload and 6000 endurance.
Like these:
switch.jpeg
These switches are used for motors or fuse boxes, or other heavy stuff. And yes relays or other types could be used so a "lighter" switch can be used. I know. But adding relays add up massively to the costs of a product.
But if a manufacturer rates the switch at say 250Vac 10A then we will test accordingly. What we see are mostly prototype products, or products who need extended certification, or just a part of a product like in this case switches.

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9669
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: Serial TTL, USB Communication - Sending ASCII Strings

Post by dunbarx » Sun Jun 14, 2020 4:22 pm

OK.

Good luck with this. Let me know how it came out. The only thing I want to reiterate is that mouse movements do not affect the operation of the gadget I mentioned.

Craig

sphere
Posts: 1145
Joined: Sat Sep 27, 2014 10:32 am
Location: Earth, Except when i Jump

Re: Serial TTL, USB Communication - Sending ASCII Strings

Post by sphere » Sun Jun 14, 2020 7:52 pm

Thanks, will do.

Jerry

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9669
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: Serial TTL, USB Communication - Sending ASCII Strings

Post by dunbarx » Mon Jun 15, 2020 5:24 am

It seems to me that four high current solid state relays (and you now must indeed choose AC or DC) ought easily to replace the motor and four position switch. The software would be far simpler and easier to manage.

Did you ever consider this? Reputable high voltage 50 Amp SSR's can be had for $10-20. You would just need to turn one of four on as needed, directly. Many more cycles, much more reliable, no mechanics. I have never used a Raspberry Pi, but I am sure they must have four output channels somehow, and my gadget has much more than that.

Craig

Post Reply

Return to “Getting Started with LiveCode - Experienced Developers”