Serial Port Perl Linux
I need to get data from the serial port of a Linux system and convert it to. Converting serial port data to TCP/IP in. You might find Perl or Python useful to. Hi, I was wondering if it is possible to use Perl to read and write to Serial port directly (in Linux)? I'd appreciate any help.
I'm using a serial device for a project, and what I'm trying to accomplish PC side, is listening for a command sent by the serial device, interpreting the query, running some code depending on the query, and transmitting back the result. To be honest I tried out using PHP as the listener, and it works, unfortunately the infinite loop required to make the script act as a receiver, loads the CPU to 25%.
So it's not really the best option. Police road king for sale. I'm using cygwin right now, I'd like to create a bash script using linux native commands.
I can receive data by using: cat /dev/ttyS2 And send a response with: echo 'command to send' /dev/ttyS2 My question is, how do I make an automated listener to be able to receive and send data? The main issue I have, is actually how do I stop the cat /dev/ttyS2 command once information was received, put it into a variable which then I could compare with a switch, or a series of if else then blocks. Afterwards send back a response and start the cycle all over again?
In a way I am limiting myself, but on the other hand bash is native in Linux as well as in Mac and available on Windows via Cygwin. Also I'm not using any additional software/packages/libraries that would not be available cross platform in the native state. By using simple commands such as while read -r line /dev/ttyS2 I'm removing the dependance of required libraries or software that may not be ported cross platform or that interact differently with the OS in question.
Your method is also more logical I guess, but I'm not familiar with Python:) – Oct 21 '12 at 10:14. It works perfectly. I didn't have to install or tweak anything.
Download Perl Linux
I just opened Cygwin, ran echo 'led on' /dev/ttyS2 and my serial device turned on the led instantly. For receiving data I had to initiate it with the stty command. I agree I am adding libraries TO Windows, but in a way, having a solution with Python would require almost all OSes to install Python as it isn't native, rather than just with Windows having to install Cygwin.
It is a workaround I agree, but it's much more easier for myself personally. – Oct 21 '12 at 10:22. Using Cygwin, the listener process, created with the loop given by rici, (as shown in the Task Manager) uses 0% CPU and only 100k of memory. However once a request is received from the serial device, the CPU spikes up depending on the complexity of the required output (such as regexp matching, curl to get info from webpages etc), it ranges from 0% to 25%.
Perl Serial Port Communication
I guess using a higher level language this would be smaller, but I'm happy with the results, as it's much better than having PHP loop infinitely with 25% CPU usage:) – Oct 21 '12 at 10:08.
#!E: xampp perl bin perl.exe # The above line is perl execution path in xampp # The below line tells the browser, that this script will send html content. # If you miss this line then it will show 'malformed header from script' error.