Environment:This article is meant to give you a jump start on doing serial communication in Windows (NT family). The article will provide a class called CSerialCommHelper that you can use directly to do serial communication in your application. The class that is provided here with this article does uses overlapped IO. You do not need to know much about serial communication or overlapped IO for this article. However, you need to know some about the synchronization objects such as Events and some Windows APIs like WaitForSingleObject and WaitForMultipleObject, and so forth.
Also, some basic understanding of Windows threads is required—such as thread creation and termination.
PHP Serial: Communicate with a serial port - PHP Classes This class can be used to communicate with a serial port under Linux or Windows. It takes the path (like '/dev/ttyS0' for linux or 'COM1' for windows) of serial device and checks whether it is valid before opening a connection to it.
I have a piece of simple code that works on a Windows - WAMP environment, e.g. It connects via a USB cable (using USB-Serial drivers) to a circuit-board to light some LEDs, and it works fine - so similarly windows software like 232Analyser, can connect to COM3 and send code in DEC like 1,255,255,255,255,5, and light the LEDs. The number 255, is a DEC number from: 1,2,4,8,16,32,64,128,255 which will light a certain LED depending on which number is called.Anyway, the code above works fine on Windows, and lights LEDs by calling this PHP file. So can call a URL like: which works ok.Now I need it to work via Linux, on a Raspberry Pi, so I have just installed standard Raspberry Linux, and Apache with PHP.Then attached the USB cable, and it appears as /dev/ttyUSB0 I have then CHMOD 777 /dev/ttyUSB0And changed the PHP code to: However calling this file on Linux in a browser is not Lighting the LEDs, as it does on Windows.Now when I call this file it goes through with no errors, without chmod 777, it gave a permission denied error. So it seems like it goes through ok, but something else is wrong.So question is anyone know how to make it work on Linux, it might be I am calling the USB wrong, or Raspberry Linux needs some kind of drivers, or ' `mode ' needs to be defined differently.or maybe the decimal/binary code sent is not right like 'chr(2)' etc. Needs to be different and wont be sent in same way on a LAMP setup.Any ideas on what I can try?
Comments are closed.
|
AuthorWrite something about yourself. No need to be fancy, just an overview. Archives
February 2023
Categories |