USB Serial Device projects with Xojo

  1. 3 months ago

    I'm revisiting Xojo after trying it out briefly back in 2011.
    But it turned out not to be for me back then, for the particular project I was working on at the time.
    So forgive me if my Xojo knowledge is a bit out of date.

    I'm looking at starting a new Desktop project that requires communication with USB Serial devices.
    And using Apple's IO Kit Framework in my usual Xcode enviroment requires a lot of work for USB Serial devices.

    So I notice that Xojo provides the "Serial" and "SerialPort" classes in their Framework.
    So my question is how easy and reliable are these classes for this type of project ?

    As after reading some of the Xojo documentation, and trying some of the code examples.
    I'm finding that the example code snippets do not deliver what they advertise.

    For example, the documentation code snippet below.

    For i As Integer = 0 To System.SerialPortCount-1
      MsgBox(System.SerialPort(i).Name)
    Next

    Results in a Message Box with only one port name, which is not a USB Serial port, but a Bluetooth port name.
    Am I missing something simple ?
    Or are these Xojo Framework classes out of date with the latest operating systems ?

    I'm trying this stuff out on a iMac running Mac OS Sierra.

    Thanks in advance.

    Regards Mark

  2. Norman P

    Aug 10 Xojo Inc

    If a USB device has a driver that presents itself as a serial device (like an RS232 serial port literally) then you'll see it
    Thats where those classes focus
    If it has no such driver then you wont see it

    USB is "serial" in that its protocol is serial
    But after that the plethora of devices drivers etc require you to do a fair bit of work per device - like in Xcode - to talk to USB drivers etc
    Its great when vendors deliver those drivers
    It sucks to have to write for ones that dont regardless of tool set

    Worse USB isn't something you can just generically "support"

  3. Working on a Serial device project is not something I've tried before, but I'm looking for development tool that has classes that deal with the system level stuff in a simple fashion.

    So what your saying is that the above posted code, will only list the serial ports if a responsive device is attached.
    even though a shell command like "system_profiler -detailLevel basic SPUSBDataType" lists the serial ports.

  4. Norman P

    Aug 10 Xojo Inc

    If the device isn't effectively mimicking a RS232 port then no you wont be able to deal with it directly using JUST Xojo code
    There is a plugin from monkeybread that lets you deal with USB but I've not used it so I cant say whether it would be of use or not

    USB is not my favourite to deal with at a system level either :P
    Been there done that

  5. Douglas H

    Aug 10 Pre-Release Testers, Xojo Pro
    Edited 3 months ago

    @Mark D So what your saying is that the above posted code, will only list the serial ports if a responsive device is attached.
    even though a shell command like "system_profiler -detailLevel basic SPUSBDataType" lists the serial ports.

    Many years ago I used to interface to lots of serial port devices -- back when 9 pin (or even 25 pin) serial ports were common on motherboards. A "universal serial bus" is NOT the same as a "serial port" unless / until there is a device driver to allow the USB to act as a serial port.

    Remember the SP of SPUSBDataType stands for System Profiler, not Serial Port, so what you are asking for is a list of USB ports and NOT a list of serial ports.

    While I have not had to deal with serial ports since I switched to Xojo, my SWAG is that Xojo's System.SerialPortCount will only report physical serial ports, or virtual serial ports such as an internal modem (remember those?) or a USB port with a device driver presenting itself as a virtual serial port.

    When I first looked at doing my own USB communications instead of serial ports (many years ago, in another language) I quickly realized that calling USB "Universal" was an oxymoron.

    That said, I have left off using serial port communications MANY years ago now so I really have no experience with Xojo serial port support. However instead of using the system_profiler command to find serial ports, try this:

    ls /dev/{tty,cu}.*

    And see how that compares to the list from System.SerialPortCount

  6. OK Norman and Douglas, thanks for the help.

    I'm waiting for the particular device to be delivered at this point, but just reasearching alternatives to IO Kit.

    The Xojo serial classes do appear on the face of it to handle a lot of the system level stuff.
    But I wrongly assumed a method named "SerialPortCount", would simply return the number of ports available on the system.
    For sure I have a lot more reasearch to do before undertaking this project, which is an area like yourself I'm unfamiliar with.

    But the good news is that the device does have a FTDI chip for communication, and there is an old Windows app available for communicating with the device, but no Mac app, and I like a challenge
    So I shall have play around a bit more with the Xojo classes when the device arrives, and decide wether Xojo or the more familiar to me Xcode enviroment is the best choice of tool

  7. Douglas H

    Aug 10 Pre-Release Testers, Xojo Pro

    @Mark D The Xojo serial classes do appear on the face of it to handle a lot of the system level stuff.
    But I wrongly assumed a method named "SerialPortCount", would simply return the number of ports available on the system.

    No, you wrongly assumed that a USB port is a "serial port". They are not -- until a vendor device driver creates a virtual serial port interface.

    If there was an old Windows app which worked with the device over USB, then the vendor had a device driver available for that version of Windows. Which is NOT to say they still have a device driver which works with 64-bit windows.

    I had done USB communications to devices under 32-bit Windows, then the vendor did NOT make 64-bit device drivers and I was up the proverbial creek.

  8. I now understand that a USB port does not represent itself as a serial port until a device driver presents itself as such.
    And I'm not sure if the Windows software available is a 32 or 64 bit app, as I don't have a Windows PC to check it out.

    All I know is that the device manufacturer has a Windows app available for the device, but I have no intention of going back to a Windows PC, so I shall have a play around with the device Via Terminal, to see what might be achievable via a custom UI Mac app.

  9. Douglas H

    Aug 10 Pre-Release Testers, Xojo Pro

    Does this device use a USB cable to attach to the computer, or a serial cable? Serial cables will have either a 9 pin or 25 pin D-shell connector. (These look similar to a VGA cable, which has a 15-pin D-shell connector with 3 rows of pins instead of 2 rows).

    If it uses a USB cable, this is NOT the same as "serial port" communications. If they were, it would have made my life soooo much simpler back in the day...

  10. I'm an old bloke too, so I know what a traditional serial port looks like.
    This particular device has a USB cable interface, so I'm not even sure if Xojo's serial classes will be suitable.

  11. Edited 3 months ago

    Mark,
    You mention that the device has an FTDI chip for the USB interface, and that you still have not received it. If it has an FTDI chip, then it is very very likely it will present itself as a standard COM (communication) serial port. But it will only do that once you plug it in and it is recognized by the OS. In other words, when you ran the example you were trying, the USB Serial COM port of the device will not show up if is not connected to the MAC/PC. So may be that is where you are stuck; you are expecting Xojo to lookup a COM port which is not there because there is no FTDI device connected to the MAC/PC USB port (it will only show up when you plug the actual device).

  12. Hi Langue

    Yeah I realise now that the above posted cose example would require the device to be plugged in, and present itself as a serial device.
    I can't be specific about the device itself, as it's one of those hush hush equipment installation contracts, that you can't talk about with your family or friends, or indeed strangers on the internet.
    The devices are not readily available to anyone, or indeed is the Windows software.
    But I've not found anything that can be done on a Windows PC, that can't also be done on a Mac.

    The equipment supplier is providing hand held programmers, and access to there software.
    But the hand held programmers only provide about 75% of the device programming capabilities of the software.

    It's inevitable that I will have to use a Windows PC for this initial contract work, or infect my Mac with the Windows virus via Bootcamp or some other VM software.

    But when I get my hands on some of the equipment, I shall be playing around with some code to see if a Mac app could be created to emulate what the Windows software does.
    Not because I have to, but because I like a challenge.

    At this point I'm simply looking for a framework or library, that does some of the work for me, and was trying to get a handle on what Xojo could offer in this area.
    But I apprciate that until I plug the device in, I don't know what weapon of choce would be best suited for my challenge.

    Regards Mark

  13. Richard W

    Aug 11 Pre-Release Testers, Xojo Pro

    So I notice that Xojo provides the "Serial" and "SerialPort" classes in their Framework.
    So my question is how easy and reliable are these classes for this type of project ?

    I would say that the serial support in Xojo is easy and reliable. I've been using it in macOS and Windows for our PLC programming software and our HMI communication application connecting to industrial equipment using various protocols. This stuff has to run 24/7 and it does using Xojo serial.

    Devices using the FTDI USB-Serial chip work very well and drivers are built into Windows 10 and macOS - plug it in and it just shows up as a serial port (or Windows COM port). We are considering using it in our own PLC hardware for a dedicated programming port.

  14. Mark C

    Aug 11 Pre-Release Testers, Xojo Pro Spain 35510

    I use, and have used for several years, FTDI USB serial cable in an ongoing project that is operating on MAC, pc, Linux and Raspberry Pi, all with the same code base, without changes, in the serial port section.
    It is very simple to use the Xojo classes and is very reliable.

    BUT, I am unable to use ANY serial device (as in RS232) on my MAC if the OS is later than 10.10.5 as apple have introduced some silly restrictions that have cause serial drivers from third parties to stop working en mass.

  15. Thanks Richard and Mark

    It's good to know that the Xojo Serial classes are reliable and easy to use, that's exactly what I was hoping to hear, as Apple's Frameworks are a real slog for this type of work, and so far I have not found any better alternative libraries that are suited to serial inteface projects on Mac.

    Bad news to here that Mac OS's after 10.10.5 are presenting problems with Serial communication projects, as both my iMac and MacBook are currently running 10.12.6. this is something that I was not wanting to here.

    It seems that over recent times Apple has made system level and hardware app programming stuff more restrictive in OSX, and even more impossable in iOS, where you need written permision from high level Apple executives and board members, to access iPhone hardware features like Blutooth and WiFi and plug in peripheral devices.

    After now having a better isea of whats required, I feel sure that I will try out the Xojo serial classes when I get the devices and equipment, And I feel it would be a good place to start, and offer a quicker route to a working project.
    As I've always liked the IDE and VB like language syntax, but never really found a project to try them both out properly.

    Thanks for all the advice folks.

  16. Robert L

    Aug 12 Pre-Release Testers, Xojo Pro

    As odd as this sounds, for recent projects where Serial is needed, I use a cheap raspberry pi as a serial proxy. Clients connect to the Pi over the LAN and then the Pi relays serial data between the LAN to the USB Serial cable to the serial device. For ~$30 you can circumvent any macOS limitations with USB serial drivers.

    You don't even need the latest Raspberry Pi. Even a first generation Raspberry Pi that might be collecting dust sitting on a shelf will work. (No Xojo app and related dependencies required). Google 'ser2net raspberry pi' for tutorials.

  17. Jean-Yves P

    Aug 12 Pre-Release Testers, Xojo Pro Europe (France, Besancon)

    you can even do this with an esp8266 instead of the Pi. it will cost you around $3 and will still be far too fast for what is needed.

or Sign Up to reply!