usb to serial (rs232) convert on Mac OS (el capitan)

Hello
I have un usb to serial (rs232) convert on Mac OS (el capitan)

I connect a serial printer
from terminal with command “cat test.txt > /dev/cu.usbserial” the printer print the text file
In Xojo with this code:

serial1.SerialPort=system.SerialPort("/dev/cu.usbserial")
serial1.Reset
serial1.Close

if Serial1.Open then
Serial1.Baud = 9600
Serial1.Bits = Serial.Bits8
Serial1.Stop = Serial.StopBits1
Serial1.Parity = Serial.ParityNone
Serial1.XON = true
end if

serial1.Write(“hello”)
serial1.Close

NO ERROR BUT NOTHING PRINT!
Can you help me?

This thread might help or give you some ideas: https://forum.xojo.com/26945-el-capitan-and-usb-communication-issue

the fact that you can use it from the command line like that would seem to indicate to me that the low level drivers are working to communicate with the device. I would try a couple of things.

Eliminate the simple and obvious stuff first :wink: Are you sure that the printer is using XON flow control? If it’s not then nothing would get sent at all I don’t think. I would disable that to test with first. And verify the baud rate and other settings. What baud and other settings are used when you just cat that file to the dev entry? I don’t know…

Set the baud and other settings before you open the port, not afterwards. The way you’ve got it now there is no indication if the port actually opened or not. It won’t set any of the settings and the write commands will happily just do nothing if the open failed. Move your open command after you setup the port settings and do some indication of success or failure of it. I’ve never actually used the ability to open a port by path like that, so I don’t know if it has other gotchas. In the past I’ve always walked over the array of available ports to find the one with the name I wanted, which in your case would be “cu.usbserial” or more likely it would be “tty.usbserial” so you might want to experiment with that too. Check to see if the port you’re getting from that system.SerialPort( path) command is actually there or if it’s just returning nil.

Most serial interfaces create 2 dev entries and I always use the tty one when I do this and that usually works. Does this printer create a /dev/tty.usbserial entry also? If so try using that one.

if it’s a line printer then it might be waiting for a line ending character? Is there a newline/carriage return at the end of your test file? You could try writing (“hello” + EndOfLine.unix) and see if that makes it write the line.

Many devices that talk over regular serial use the DTR line to power the opti isolators that do the line level shifting internally so you might try turning on the DTR line like Serial1.DTR = true

Lastly, while I doubt it will make any difference, it might be worth the effort to add a Serial1.xmitWait before you close it so that