USB Input/output or other approaches

Hello, I have Haiku on my laptops (System 76, Dell and HP). All have a common fault, they have no serial or parallel ports that I can program to drive my own hardware designs.

Years ago there was a USB-PIO design shown, is it still available for Haiku? Or something like it? If so how would I access it in my programs?

Alternatively, I could try modifing a USB keyboard as an input but I don’t know the scan rate for keyboards so I don’t know how fast I can input data yet.

Also there are USB joysticks, do those work with Haiku yet? If yes I can buy one tomorrow, again do you know how fast the joystick is scanned in?

Lastly, looking at the USB updates there is something called a USB Sensor Hub, but so far the ones I found on the internet have a slow scan rate.

For my purposes I need to do 1000 samples per second, I don’t think the keyboard mod will work that fast, can anyone help point me in the right direction.

I thought that USB-Serial worked fine in Haiku – it’s only no good for KDL output.

I have a USB GameController (a.k.a Joystick) that works well, and I use a lot in Haiku, and another that doesn’t in the revision I’m using. It did once, and Adrien says he has fixed it in the current rev, but I haven’t yet been able to update to test it. The one that works is a Thrustmaster “Top Gun”, the one that doesn’t (ATM) is a Microsoft “Sidewinder Strategic Commander”.

No idea about scanning. I sort of assumed that (unlike an analog stick) the controller transmits events at its own rate. Plenty fast for anything I want to do (usually sending MIDI events to fluidsynth or csound).

There is no serial ports on my laptops, just USB, Ethernet, and Video (HDMI and/or VGA).

Yes, I know… You were talking about USB-Serial, and so am I. I assumed you were thinking of the USB<>Serial converters that are available. As far as I know they work fine in Haiku
.

No, I was talking Serial Serial - no USB. And by the way I got a USB to Serial adapter, I have not figured out how to use it under Haiku either.

If you have some pointers I would be grateful.

Thank you about the joy-stick, I will see if it is available at my local stores.

I am using serial and USB serial as well with Haiku, using Lazarus (so in Pascal). Works very nice,although in FPC two files have to be updated (posix). My programs use SynaSer (a bit adapted) and these updated posix files, to adress my own (well our companies) hardware.

If you need USB to serial converter chips, I’d advice to use FTDI chips for that. Very nice, multi platform useable, and used in our companies for years (also today on Haiku connecting to my data aquisition hardware that has a hardware serial port, connected to Haiku via FTDI USB<>serial.

I did not test using serial ports (USB serial) directly in C/C++ within Haiku yet though.

Oh BTW: there is a library from FTDI to use digital I/O directly on those chips, in the form of a DLL. I never used that though. I don’t know if such a library exists for Linux or Haiku. In my case I just use a microcontroller with own firmware that reads/writes I/O ports, adressed using the RS232 connection.

If you’re interested, I’ve put together a zip file with SynaSer and termios updates for current Haiku and Lazarus/FPC:
http://www.rudolfs-place.nl/Haiku/Downloads/SerPort_updates_FPC_RudolfCornelissen.zip

USB to serial adapters would be the simplest thing indeed. Haiku supports FTDI, Prolific, and Silicon Labs chips, as well as anything implementing the standard USB ttyACM interface. Usage is through BSerialPort and you can do some tests with SerialConnect. The ports are in /dev/ports just like “real” serial ports.

Gamepads and USB joysticks work, through the BJoystick API. The device is indeed responsible for the rate at which you can get events, usually every 12.5ms or so.

For anything more specific (I/O ports and the like) you will probably want to use the USB Kit directly or use libusb. The latter is standard also on other OS for the same usage so anything that uses it should work fine (but there are known bugs). Using FT2232 chips or some of Cypress devices, this makes it easy to implement custom protocols.

Finally, the Arduino SDK is available, which is also an option and probably a good compromise between ease of use and flexibility.

1 Like

I would just like to mention that while original Arduinos work well under Haiku (tested by myself), the cheap clones don’t, because they use CH340 chip for USB connectivity, and our libs don’t support it yet.

Ah, right, forgot about WCH chips. Support shouldn’t be too hard to add. Can you make a bugreport about that?

Done.

First, thank you to all the people who have tried to help me.

I got the USB to Serial cable to work, it did not work when I tried it last year, but that could easier be my fault because of the wiring I used.

My first experiment suggest it is going at full baud rate of 3,000,000 bits per second (I could be wrong) but I know plan to build hardware to convert the serial stream to a parallel output.

To my surprise I could not find a simple TTL UART circuit that using Google. I remember they existed in my old PET days (yes, I am that old) but all I could find is software UARTs and some hardware designs that need the chips to be on a CPU bus.

I need a simple serial->parallel design that I can just stream bytes to for my needs. So I am designing one of my own. Assuming all goes well I should hope to get it working by next week.

Again, thank you for all the help, hope you are all doing well.

Well, I have a few problems making an TTL UART, I need an oscilloscope first. I was looking at buying a cheap one when I realize I have all the parts to make a cheap digital scope, so that is what I am doing first.

On the other hand I am find a use for all the electronic parts I have kicking around here.

A USB to Serial cable is usually a RS232 serial output with +/- differential signaling. That has an additional differential driver which you do not need if your end goal if parallel TTL. You want a USB to TTL Serial chip, or cable. That is what PulkoMandy was referring to

FT2232 chips are a good choice FT2232HQ - FTDI They can often be found already built into cables. Often used to program ESP32, Arduino, other microcontrollers.
Depending on the number of parallel outputs you need and the drive strength, FT2232 may fit your needs all by itself by configuring MPSE. If you need more than that provides, you can use any basic microcontroller like Arduino if you are comfortable programming. arduino.cc or, if you are more comfortable with a soldering iron, a shift register should get you as many parallel lines as you need. Chain serial out to serial in of additional chips if you need more than 8. https://www.onsemi.com/pub/Collateral/MC74HC595A-D.PDF

Why is everything so hard?

I designed a make a LED oscilloscope that works.

I got two different USB to RS-232 adapters. One that outputs TTL levels and an adapter for the other RS-232 output for TTL interfacing.

Using DIR I found the USB port is active at /dev/ports/usb0 by using a LED driven by an interface chip. The LED would flash is data was sent. Also I tried the Rx and Tx lines together and used the program “serialconnect” to confirm the data was sent okay.

Tried ‘dir > /dev/ports/usb0’ - worked okay.

Tried ‘dd if=/dev/zero of=/dev/ports/usb0’ - also worked okay.

How when I tried in a program:

fileHandle = fopen("/dev/ports/usb0", "w"); // Attempt to open usb port
if (!fileHandle || ferror(fileHandle)) {
       printf("Can not open RS-232 as a file:\n");
    } else {
       printf("Testing transmission on RS-232\n");
       for ( index=0; index<255; index++) { outputBuffer[index]=85; };
       fwrite(outputBuffer, sizeof(char), 128LL, fileHandle); // write 128 bytes.
       fclose(fileHandle); }
 return 0L; }

The file handle was created okay with no errors, but writes to the port did not work. Any suggestions?

Why don’t you use the BSerialPort API instead of writing directly to the file?

That is what I am working on trying to get operating right now.

I am using the serialIO from the haiku sources kit folder to try and get it to work.

Sorry, I am not that smart, it takes me some time to figure out what I am doing wrong. The code I am starting with is:

#include <SerialPort.h>
#include <stdio.h>
#include <string.h>

int main(int argc, char *argv[]) {
	BSerialPort port;
	if (argc < 2) {
		printf("usage: %s <port>\n", argv[0]);
		int32 portCount = port.CountDevices();
		printf("ports (%ld):\n", (long)portCount);
		char nameBuffer[B_OS_NAME_LENGTH];
		for (int32 i = 0; i < portCount; i++) {
			if (port.GetDeviceName(i, nameBuffer, sizeof(nameBuffer)) != B_OK) {
				printf("failed to retrieve name %ld\n", (long)i); continue; }
			printf("%s\n", nameBuffer); }
		return 1; }
	return 0; }

Well that will just list serial ports in the system.

You can refer to the Be Book:
https://www.haiku-os.org/legacy-docs/bebook/BSerialPort_Overview.html
https://www.haiku-os.org/legacy-docs/bebook/BSerialPort.html

Basically,

port.Open("/dev/ports/usb/0");
port.Read(buffer, length);
port.Write(buffer, length);

And then there are calls to configure the baudrate, flow control, etc.

Reading the port blocks your process until data is available.

1 Like

Yes, you are right it will only list ports. But so far it is not compiling, I am working step by step to find what I am doing wrong.

As it is for my own custom hardware I am willing to take my time. But I have to ask, where is the best place to publish diagrams of hardware designs for Haiku? In the old day I just zipped all my files together and released them on BeBits, but what is the best thing to do today?

We still have beshare, perhaps post the name of the zipfile once it’s ready. There is also a site called http://www.be.wildman-productions.org/ to upload to.