Hi!I have a long experience in programming under Visual Basic, PHP, Javascript and microcontroller, but I'm absolutly newbie in bash script, so thanks in advance for your help!Anyway, I've a home server with Nas4Free (based on FreeBSD 9.2-RELEASE-p3 (kern.osreldate: 902001) ) and I'm trying to write a simple bash script that reads datas from serial port and write those datas to a text file. I've succeed in writing in a text file, but I've lot of problems with serial port!This is the configuration of the serial port: speed is 1200, 1 start bit '0', 7 bits per character, 1 parity even and 1 stop bitThis is the configuration I've tested for ttyu0.
![]()
How to read from a serial port in lua. Ask Question Asked 5 years, 3 months ago. Active 5 years, 3 months ago. Viewed 8k times 5. I'm new to lua and I'm trying to receive data from the port, ttyACM0, I can write to the port. Lua script read from serial port in OpenWRT. Read and Write to Serial Port with Lua on Windows. Lua module wrapping the Windows COMM port API. I have been working on a windows-specific wrapper for the COMM API. My hope is that this could satisfy one of the missing features identified for the Lua.
#!/bin/shkill -HUP 1stty -f /dev/ttyu0.init 1200 cs7 -parodd parenb -cstopb -icanon -iexten -ixon -ixoff -crtscts cread clocal echo -echoe echok -echoctlfor i in 1 2 3 4 5 6 7 8 9 10do# /bin/echo $iread ligne. Hi!So I made some progress. I've put two LEDs on the card to see if there is some activity on the serial port. Then I saw interesting things:- when the computer starts, LEDs are off.- when I send cat or read command on ttyu0, LEDs turn on and the computer is locked for about 5 minutes then I can use it again, as if there is a watchdog. But the process cat or ttyin is still running for about 2 minutes then disappears. When it disappears, LEDs turn off.I think that the problem comes from the way I read data from serial port; as the external source always send data without interrupt, maybe the command runs in a loop and waits for the end which doesn't exist!Maybe the solution should be running a command which reads only a few characters from ttyu0, but I can't find it.
Anybody have an idea?Thanks in advance. I am sorry, but I can't be bothered to read the whole thread. If I post something that you already know, I apologize.stty settings are valid only as long as process which set them runs. Once it dies, system reverts to default values.
![]()
I haven't used tty's under FreeBSD, but spent years connecting modems, terminal servers, terminals, serial printers, satellite receivers to Solaris and SCO machines. It was before Internet became widespread.The UNIX way to manipulate serial ports is to redirect scripts stdin or stdout or both to tty device, like:$ mySerialScript. I don't know what should you do.
I'd say you need both, read and write to device. There is a param in stty command that opens it in read/write mode, you should use it. Also it can be open in blocking and non blocking mode. Latter means it returns empty buffer if there is no input available, rather than waiting for one.
You need to specify that in stty, too. Also, you can set a timeout. You can read in character mode and in line mode.
I think man page might not be enough reading. Have tried to use 'cu' program interactively? It might help.
![]() Comments are closed.
|
AuthorWrite something about yourself. No need to be fancy, just an overview. Archives
March 2023
Categories |