Serial Port For Lazarus
Contents • • • • Introduction Communication ports are the way used by the protocol drivers to send and receive data. One communication port can be used by one or more protocol drivers, simultaneously. Communication ports aren’t implemented together with protocol drivers to allow more flexibility to the system. An real application that can be done using this architecture, is the association of a TTCP_UDPPort with a COMServer (devices that acts as a gateway of RS-232/485/422 to TCP/IP), to by example, communicate with a Modbus RTU device that is far, over the Internet.


Another advantage of this design is to put two or more different protocols using the same communication port simultaneously, both on the same application. This is possible because all PascalSCADA ports comes with mechanism that only allows one protocol to use communication port. That is, an application can communicate with multiple devices, these devices with different communication protocols and all connected to the same RS-485 network. It is possible, though not recommended. All port classes that exists on PascalSCADA descend from TCommPort class, that implements the methods to open and close the port, read and write data, and clean the buffers when a communication error occurs. But if a new port is being written, these methods should be specialized to handle the new port being implemented.
TSerialPort The TSerialPort class, descendant of TCommPort class, has been created to allow the protocol drivers to exchange data over serial ports, regardless of the physical layer used by serial port. On Windows, this class need of a serial port with name between COM1 and COM255. Herobrine Skin there.
There are several Serial Communication (COM port) options available for Lazarus, but I would first suggest giving Synaser another try. I'm currently using Lazarus 1.2. Aug 26, 2013 It would be possible to talk to it via the Pi's serial port, but that means bringing a cable out of the PI's enclosure. Installing libusb - Lazarus/freePascal.
Headwind Sms Communicator Serial Season. Running over Linux, any device where the name starts with tty, ttyUSB or ttyACM is valid. On FreeBSD, any device where the name starts with cuad is accepted by the class. Both Linux and FreeBSD (or another Unix) should be added the user that will run the application on the group owner of the serial port and the group must have permission of read/write on the desired serial port. The name of this group can vary depending of the operating system.
Independent of operating system, the TSerialPort class has the following properties that configure the operation of the serial port: • COMPort: defines the name of serial port to be used. If the application has been configured with one serial port and it is disconnected of the system (by example, a USB serial converter) and the application is started, a exception will be raised. If this exception occurs on the application load (initialization), your application will be not loaded, even if Active=false. • Baudrate: communication speed in bits per second that will be used on the configured serial port while it’s in use. Baud rates between 110 bps and 115200 bps are accepted. • DataBits: Defines the word length in bits that will be used when communicating with the serial port.
Only the size of 7 or 8 bits are accepted, the default is 8 bits. Some protocols requires the value of this property set to 7 bits, like Modbus ASCII. Others requires the word size of 8 bits, like Mobus RTU. • StopBits: Configure how many bits will be used to mark start and the end of each word transmitted or received in the serial communication. Valid values are 1 or 2 stop bits. The default is 1 stop bit.
• Paridade: configures if each word received word will have a parity error check, and if error check exists, this defines if it will be even or odd. • Timeout: defines the maximum time that the serial port will wait for reading a certain amount of data. This time is set in milliseconds. In cases of timeout overflow, a clean up of the read and write buffers is performed. • AcceptAnyPortName: if this property is enabled on a Unix system (Linux, FreeBSD, etc), makes the TSerialPort accept any device name on the COMPort property. Very useful when some some drivers create devices with names that don’t matches the patterns described above.
• WriteReadDelay: Delay in milliseconds between write and read commands. • Active: This property controls when the port will be opened or closed.
The serial port should not be open by another process when this property goes to true, otherwise the value of this property come back to false. In the development time, Active = true only checks if everything is OK to open the serial port, but don’t open it. TTCP_UDPPort The class TTCP_UDPPort, descendant of TCommport, has been created to allow the protocol drivers exchange data over TCP (tested) or UPD (not tested) over IPv4, independent of physical and link layer being used by the port. This class has no operating system dependent properties, and the following properties configures its operation: • Host: The IPv4 address of the host to connect.
Host names are not accepted, only IPv4 address. • Port: Port number on the destination host to connect. Only port numbers between 1 and 65535 are accepted. • PortType: Sets the socket type that will created when connected with the host.
It can be a TCP or UDP. • ExclusiveDevice: If true, don’t opens the socket when in the development time.
Useful when the destination host has a few numbers of available connections. • EnableAutoReconnect: If true and if the socket is disconnected (problem on the physical layer or on the host) enables the timer that tries to reconnect the socket. In this case the invalid socket is closed while Active property remains true.
• ReconnectRetryInterval: This property defines the interval in milliseconds to attempt to reconnect lost connections. This property is only valid if both EnableAutoReconnect and Active are true. • Timeout: Sets the maximum time to wait to complete a reading or writing of a certain amount of data. This time is set in milliseconds.
If any operation exceeds this time limit, the buffers are cleaned up, the socket is verified and if some trouble is detected, the current socket will be closed and if EnableAutoReconnect is true, a attempt to connect a new socket will be made. Examples Bellow is listed a example of how exchange data using the PascalSCADA communication ports directly on the source code, in other words, without use a protocol driver. As all the communication ports are descendants of TCommPort class, the example below also applies if you want to implement something using TTCP_UDPPort. • Genius game, ranking interface.
Pascal is another development option for the Pi 2. You can use Free Pascal compiler with the command line or you can use the Lazarus IDE. To get the latest versions of FPC and Lazarus, Free Pascal is installed first then the latest packages for FPC & Lazarus are downloaded to the Pi and compiled from there. Lazarus on Raspberry Pi There is a Lazarus version for the Pi B+ but it's quite slow to compile and I didn't find it usable for me. The instructions in the URL below are only for the Raspberry Pi 2 and not for the Model's A+ B+ etc.The CPU's are different for the Pi 2(quad-core ARM Cortex-A7 CPU running at up to 900MHz) You can follow the install instructions from here: From the comments on that web site you can see that some people installed it without any problems while others struggled.
Free Pascal installed with no problems for me. Lazarus had some challenges during the make stages.
One of the changes recommended on the website (that helped me) was to increase the Pi swap size from 100MB to 500MB on a temporary basis, to complete the install and then set it back once everything is completed. However, I always got stuck at the last make stage for Lazarus. I then realized that I was running out for hard drive space (I was using a 8GB micro SD card) Then I deleted everything I could such as Games, until I got enough free space to continue the process. Eventually I was able to complete the process and get it all installed and working. I decided that 8GB is not big enough and today I picked up a 16 GB, class 10 micro SD card and re-did the OS and Pascal/Lazarus install.
I still had to increase the swap size but everything else went smoothly I then made a test program(screen shots attached). It doesn't do much LOL but it does display the versatility Lazarus and free Pascal. The compile time was a little slow but quite reasonable. The next step is to get the GPIO working and then see how many ways I can communicate with the Propeller Chip Everyone has their favorite language and I'm sure happy to be able to use Pascal on the Pi:) Lazarus Info. I found a com program on: Run minicom with the following parameters: minicom -b 115200 -o -D Port_Name Then I did a scan of USB devices: =============================================================== pi@raspberrypi ~ $ lsusb Bus 001 Device 002: ID 0424:9514 Standard Microsystems Corp. Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub Bus 001 Device 003: ID 0424:ec00 Standard Microsystems Corp.
Bus 001 Device 004: ID 0461:4d8a Primax Electronics, Ltd Bus 001 Device 005: ID 046d:c52b Logitech, Inc. Unifying Receiver Bus 001 Device 006: ID 148f:5370 Ralink Technology, Corp. RT5370 Wireless Adapter ls/dev/tty pi@raspberrypi ~ $ pi@raspberrypi ~ $ lsusb bash: pi@raspberrypi: command not found pi@raspberrypi ~ $ Bus 001 Device 002: ID 0424:9514 Standard Microsystems Corp.
Bash: Bus: command not found pi@raspberrypi ~ $ Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub bash: Bus: command not found pi@raspberrypi ~ $ Bus 001 Device 003: ID 0424:ec00 Standard Microsystems Corp. Bash: Bus: command not found pi@raspberrypi ~ $ Bus 001 Device 004: ID 0461:4d8a Primax Electronics, Ltd bash: Bus: command not found pi@raspberrypi ~ $ Bus 001 Device 005: ID 046d:c52b Logitech, Inc. Unifying Receiver bash: Bus: command not found pi@raspberrypi ~ $ Bus 001 Device 006: ID 148f:5370 Ralink Technology, Corp. RT5370 Wireless Adapter bash: Bus: command not found pi@raspberrypi ~ $ Then I plugged in the Propeller Development Board: pi@raspberrypi ~ $ lsusb Bus 001 Device 002: ID 0424:9514 Standard Microsystems Corp. Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub Bus 001 Device 003: ID 0424:ec00 Standard Microsystems Corp. Bus 001 Device 004: ID 0461:4d8a Primax Electronics, Ltd Bus 001 Device 005: ID 046d:c52b Logitech, Inc.
Unifying Receiver *** (here we have the FTDI device) Bus 001 Device 007: ID 0403:6001 Future Technology Devices International, Ltd FT232 USB-Serial (UART) IC Bus 001 Device 006: ID 148f:5370 Ralink Technology, Corp. This Library can do Serial on the RBP2 side Ararat Synapse FPC/Lazarus Port. Ser:=TBlockSerial.Create; try ser.Connect('COM3'); ser.config(460800,8,'N',0,false,true).
Finally ser.free; end; Looks deceptively simple - just like a PC:) - does that work on a Pi2, and what baud values can it run to, on a Pi2? (I found earlier web mentions of an OS patch for 4MBd, but paybe Pi2 includes that as shipped ) For testing serial ports at higher Bauds, I create large files of 0x55 ('U') and send a couple of seconds worth, while measuring the TX line with a Frequency Counter.
That reveals any 'bonus' stop bits and gives the supported streaming speed, for that requested BAUD rate. It also shows Baud rounding effects. Most USB-Uarts can accept any baud value, and they round (in various ways) to the 'close' practical value. I think Pi2 is more restrictive on baud-values. Baud rates selectable in the Progam: Rates: array[0.MaxRates, 0.1] of cardinal = ( (0, B0), (50, B50), (75, B75), (110, B110), (134, B134), (150, B150), (200, B200), (300, B300), (600, B600), (1200, B1200), (1800, B1800), (2400, B2400), (4800, B4800), (9600, B9600), (19200, B19200), (38400, B38400), (57600, B57600), (115200, B115200), (230400, B230400) BCM2835 Doc: Auxiliaries: UART1 P8 UART - P175 USB 15 - P 200 The baud rate is dependent on the clock rate thus you need to make adjustments if you use the over RBP2 over clocking feature. ====================================================================== From My Book ( Raspberry Pi Hardware Reference) - Raspberry Pi console Baud Rate: 115200 - Tested with no parity and 1 stop bit.
= 11,250 bytes per second unless you use a parity bit which will reduce it to 10,472.7 Bytes/sec (Baud Formula Pict From the Book noted above) ======================================================================= @ jmg re: how high can the BAUD be set, and what sustained flow (one and two way) can you achieve? PropBASIC Serout I think can go up to ~ 4MBd Does that answer your question or is there some other test you require?
Rates: array[0.MaxRates, 0.1] of cardinal = ( (0, B0), (50, B50), (75, B75), (110, B110), (134, B134), (150, B150), (200, B200), (300, B300), (600, B600), (1200, B1200), (1800, B1800), (2400, B2400), (4800, B4800), (9600, B9600), (19200, B19200), (38400, B38400), (57600, B57600), (115200, B115200), (230400, B230400) Does that answer your question or is there some other test you require? Thanks, more tests depends on how deep you want to dig.:) ( Linux is somewhat behind USB-UARTS in the baud handling.) I found other links, where 4MBd is mentioned, and this mentions version upgrades. Not sure if Pi2 comes with mentioned support for init_uart_clock built in, one would hope it has latest changes. The highest confirmed speed I have seen is 4MBd (Pi, not Pi2) but there is also chatter from some who want to go faster - so someone may have cracked it.
The FIFOs are not large in Pi, so high speed needs care on large payloads, but the HW itself some claim is set-able to ~ 25MBd. (maybe more on Pi2?) I also find this says this ['Wed Aug 13, 2014 3:38 pm Above 115200 kbps, these values are supported by stty: 230400, 460800, 500000, 576000, 921600, 1000000, 1152000, 1500000, 2000000, 2500000, 3000000, 3500000 and 4000000. Reference: coreutils.info section 19.2.7 Special settings. Use 'info stty' to read the built-in info file.' ] & this thread has mentions of 4MBd tests ['After reading around, I did some testing to see what the maximum achievable baud rate is. Using the latest stable raspbian build (3.6.11+) and [B]editing init_uart_clock [/B]in /boot/config.txt, I was able to get up to [B]4Mbaud read speeds[/B].
However, past that point it seems that the linux OS stops support, as bits/termios.h has __MAX_BAUD at 4Mbaud'].