Can't open USB serial device
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller
-
- Livecode Opensource Backer
- Posts: 15
- Joined: Tue Apr 11, 2006 12:07 am
- Location: Weaverville, NC
Can't open USB serial device
I am trying to control a 3D printer from LC.
It is attached to my current model Mac Pro (10.14.2) through a USB connection.
I have several other programs that connect fine to the printer.
I attempted to connect to it with the following commands:
set the serialControlString to "BAUD=115200 PARITY=N DATA=8 STOP=1 to=on xon=off odsr=off octs=off dtr=off rts=off isdr=off"
open driver "/dev/tty.usbmodem207F376659521" for text update
This open command (with different COM address), works with a Windows PC.
However, on the Mac, it delays a few seconds, then up comes the spinning beachball. It is stuck forever and the only way to recover control is to unplug the USB cable from the printer.
I must be missing something that the Mac version of LC needs that is different than the PC version.
EDIT: Got it to connect. I changed the device address to:
"/dev/cu.usbmodem207F376659521"
EDIT2: On a second 3D printer, it did not appear to connect even with the /cu variant. It did actually open the device, but it turns out that the virtual serial DTR line is not being set according to the LC serialControlString setting for the MacOS version. I am looking for a way to set this from LC to update the serialControlString and send it to an already open device.
It is attached to my current model Mac Pro (10.14.2) through a USB connection.
I have several other programs that connect fine to the printer.
I attempted to connect to it with the following commands:
set the serialControlString to "BAUD=115200 PARITY=N DATA=8 STOP=1 to=on xon=off odsr=off octs=off dtr=off rts=off isdr=off"
open driver "/dev/tty.usbmodem207F376659521" for text update
This open command (with different COM address), works with a Windows PC.
However, on the Mac, it delays a few seconds, then up comes the spinning beachball. It is stuck forever and the only way to recover control is to unplug the USB cable from the printer.
I must be missing something that the Mac version of LC needs that is different than the PC version.
EDIT: Got it to connect. I changed the device address to:
"/dev/cu.usbmodem207F376659521"
EDIT2: On a second 3D printer, it did not appear to connect even with the /cu variant. It did actually open the device, but it turns out that the virtual serial DTR line is not being set according to the LC serialControlString setting for the MacOS version. I am looking for a way to set this from LC to update the serialControlString and send it to an already open device.
Last edited by see3d on Wed Feb 27, 2019 4:38 pm, edited 2 times in total.
-
- VIP Livecode Opensource Backer
- Posts: 7238
- Joined: Sat Apr 08, 2006 8:31 pm
- Location: Minneapolis MN
- Contact:
Re: Can't open USB serial device
I'm kind of surprised it works on windows, since LC doesn't yet have USB support officially. Apparently Windows is more flexible with its com ports.
LC had a poll some years ago about what features we would most like to see and I voted for USB but it didn't win.
LC had a poll some years ago about what features we would most like to see and I voted for USB but it didn't win.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com
HyperActive Software | http://www.hyperactivesw.com
-
- Livecode Opensource Backer
- Posts: 15
- Joined: Tue Apr 11, 2006 12:07 am
- Location: Weaverville, NC
Re: Can't open USB serial device
I am surprised by your response. The open driver command in the language dictionary states: "Use the open driver command to communicate with USB devices, devices attached to a serial port other than the modem and printer port, and other peripheral devices."
That looks like official USB support to me!
Re: Can't open USB serial device
Perhaps this part of it?
*Note, i'm not anywhere near an osx system at the moment, so have no way to test.Note: On Unix systems, devices can be addressed as part of the file system. This means that on such systems, the following two statements are equivalent:
Tip: Because OS X is based on Unix, you can use the open file command, as mentioned above, as a replacement for open driver on OS X systems.
-
- VIP Livecode Opensource Backer
- Posts: 7238
- Joined: Sat Apr 08, 2006 8:31 pm
- Location: Minneapolis MN
- Contact:
Re: Can't open USB serial device
Yeah, could be now, my info is getting old. I think Craig might know more, he works with connected peripherals. I'd try the "file" approach next, I think.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com
HyperActive Software | http://www.hyperactivesw.com
-
- Livecode Opensource Backer
- Posts: 15
- Joined: Tue Apr 11, 2006 12:07 am
- Location: Weaverville, NC
Re: Can't open USB serial device
Yes, I noticed that also. I tried both open driver and open file. They behave identically. I would have hoped that there would have been some sort of timeout or error message to get a hint of the problem, but it just hangs forever until the USB cable is unplugged. Using a non-existent device address does not result in a hang.
The only thing I can think of is it may be a permissions issue. I have not been able to pinpoint that and other programs don't have a problem connecting --unless it is an actual bug in LC (I hope not).
Re: Can't open USB serial device
Would be hard for me to say, as Jacque mentions, there are others far more involved with USB than I (I having no involvement).
-
- Livecode Opensource Backer
- Posts: 15
- Joined: Tue Apr 11, 2006 12:07 am
- Location: Weaverville, NC
Re: Can't open USB serial device
Got it to connect. I changed the device address to:
"/dev/cu.usbmodem207F376659521"
So a JavaScript program needed the /dev/tty... to connect and MacOS needed the /dev/cu... to connect. And don't get them mixed up or you are going nowhere!
"/dev/cu.usbmodem207F376659521"
So a JavaScript program needed the /dev/tty... to connect and MacOS needed the /dev/cu... to connect. And don't get them mixed up or you are going nowhere!
Re: Can't open USB serial device
Hi,
I think here is an explanation (at least for me):
PS: shamelessly copy-paste from somewhere...The idea is to supplement software in sharing a line between incoming and outgoing calls. The callin device (typically /dev/tty*) is used for incoming traffic. Any process trying to open it blocks within the open() call as long as DCD is not asserted by hardware (i.e. as long as the modem doesn't have a carrier). During this, the callout device (typically /dev/cu* -- cu stands for "calling unit") can be freely used. Opening /dev/cu* doesn't require DCD to be asserted and succeeds immediately. Once succeeded, the blocked open() on the callin device will be suspended, and cannot even complete when DCD is raised, until the cu device is closed again.
That way, you can have a getty listening on /dev/tty*, and can still use /dev/cu* without restrictions.
!
SUNNY-TDZ.COM doesn't belong to me since 2021.
To contact me, use the Private messages. Merci.
!
SUNNY-TDZ.COM doesn't belong to me since 2021.
To contact me, use the Private messages. Merci.
!
-
- Livecode Opensource Backer
- Posts: 15
- Joined: Tue Apr 11, 2006 12:07 am
- Location: Weaverville, NC
Re: Can't open USB serial device
Even though I got it to connect with the /dev/cu.usbmodem address, I could only write, but not read anything from another 3D printer. I found the root cause of why: Setting the serialControlString with dtr=on does not result in the dtr line being on. The default state is off and it stays off no matter what. While many other languages allow changing the state of these (virtual) lines, I can not find a way to do it in LC. The 3D printer will accept commands sent to it after it is open, and will send responses. It is just that the LC read from driver command ignores inputs unless the dtr state is asserted.
I can connect with LC, then make another connection with a terminal app that lets me change the dtr state, then disconnect. After that LC can fully communicate to the printer.
Is there a workaround in LC to control the dtr state after the open connection is made?
I can connect with LC, then make another connection with a terminal app that lets me change the dtr state, then disconnect. After that LC can fully communicate to the printer.
Is there a workaround in LC to control the dtr state after the open connection is made?
Re: Can't open USB serial device
Well, why not use shell(dictionary) to execute the cli and then connect to it? Alternately, if you have to connect to it with Lc first (not sure why), do that then use shell for the cli then disconnect/reconnect.
-
- Livecode Opensource Backer
- Posts: 15
- Joined: Tue Apr 11, 2006 12:07 am
- Location: Weaverville, NC
Re: Can't open USB serial device
I would love to use shell. I tried it for a day. Internet showed others could not get CLI to work either. There was no command that would work any better and no way I could find to toggle the DTR line. It seems this is a "feature" of MacOS, and many posts about it over the years. Mac Terminal app can connect to my printer and handles the DTR correctly, but it wants to own the device exclusively and won't make a 2nd connection if LC has already connected. If I were proficient at C programming, perhaps I could make an LC extension.
Re: Can't open USB serial device
Hmm, I don't know if you saw this comment (old dictionary) -
francois.chaplais@mines-paristech.fr 2009-09-01 at 08:55:22 wrote:Mac OS X note: the environment variables which are available in the shell function may not be the same as those available in the Terminal app. For instance, it may be necessary to update the $PATH variable to make some commands available to the shell function.
-
- Livecode Opensource Backer
- Posts: 9388
- Joined: Fri Feb 19, 2010 10:17 am
- Location: Bulgaria
Re: Can't open USB serial device
Cripes, that's a real case of lagging behind.since LC doesn't yet have USB support officially