It is necessary to work directly with the com port (cashcode bill acceptor), ubuntu 16.04 & php7.1

When you turn on the PC, when you first access the com port, the com port hangs when you try to read the response. I temporarily fly with the launch of a third-party program (which normally works with com ports), after it everything works as it should. I watched the source code of one of such programs, nothing beyond the natural happens there, no changes are made to the port configuration or anything like that.

for work with a com port

Helper for bill acceptor

Controller itself

  • modemmanager already demolished? - aleksandr barakin
  • speed on the port should be set - eri
  • @alexanderbarakin, modemmanager then where?) - slowdream
  • @eri, yes, of course. All settings are spelled out and checked by letter with those indicated in the source code of the work program. - slowdream
  • modemmanager can block interface files of serial devices. The logic of his work is this. and, worst of all, sporadically. If you are working with a serial device yourself, I would recommend to remove this package first. - aleksandr barakin

1 answer 1

In the source you can see that the fopen function is used to access the port - this is the usual reading from a file. It does not set connection parameters on the port. Also, I do not see any other function in the code to initialize the port.

When you start a third-party program - it first sets the speed and stop bits, flow control.

For correct operation, I recommend setting up the port before running php or using php before opening the port.

How to change the parameters of the serial port in Linux (c opennet)

Display current settings:

 stty -F /dev/ttyS0 -a setserial -g /dev/ttyS0 

Enabling Hardware flow control (RTS / CTS):

 stty -F /dev/ttyS0 crtscts 

Set port speed:

 stty -F /dev/ttyS0 9600 

Setting interrupt and UART type:

 setserial /dev/ttyS0 auto_irq skip_test autoconfig setserial /dev/ttyS0 irq 5 uart 16550A skip_test 
  • Apparently my mistake was that I considered the absence of the flag as β€œoff”, and the presence, as β€œon” of the mode, when in fact the β€œ-” sign plays a role here (crtscts and -crtscts for example). I'm right ? I compared the output of the port of the working port via the service and no, it turned out stty -F /dev/ttyS0 min 0 -hupcl -icrnl -ixon -isig -icanon -iexten -echo ignbrk noflsh -opost everything worked. - slowdream
  • presence means change, absence - leave as is - eri