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:
if Serial1.Open then
Serial1.Baud = 9600
Serial1.Bits = Serial.Bits8
Serial1.Stop = Serial.StopBits1
Serial1.Parity = Serial.ParityNone
Serial1.XON = true
NO ERROR BUT NOTHING PRINT!
Can you help me?
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 Are you sure that the printer is using XON flow control? If its not then nothing would get sent at all I dont 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 dont know…
Set the baud and other settings before you open the port, not afterwards. The way youve got it now there is no indication if the port actually opened or not. It wont 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. Ive never actually used the ability to open a port by path like that, so I dont know if it has other gotchas. In the past Ive 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 youre getting from that system.SerialPort( path) command is actually there or if its 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 its 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