Serial MSR
From Bashlinux
Specifications
- Interface port: Serial (usually /dev/ttyS3)
- Baud rate: 9600
- Byte size: 7 bits
- Stop bits: 1
- Parity: even
Description
The DT515 has attached an MSR that send data through serial port, under Linux CentOS the port is recognized as /dev/ttyS3 known as COM4 on MS Windows.
The data must be converted to ascii with the function toascii()</tt> included in ctype.h library.
How to interface a serial MSR from C
The following is a piece of code that polls data from serial port to <code>stdout
#include <assert.h> #include <ctype.h> #include <fcntl.h> #include <stdio.h> #include <termios.h> #include <sys/ioctl.h> char data[108]; main() { int fd, rc, count; // Open Serial Port fd = open ("/dev/ttyS3", O_RDONLY); assert (fd >= 0); // Read Serial Port while (1) { // Grab the buffer rc = read (fd, data, sizeof (data)); // Terminate String data[rc] = 0; // Loop over the buffer and ignore the high-order bit // converting each char to a 7-bit ascii if(rc > 0) { for (count = 0; count < rc; count++) { printf("%c", toascii(data[count])); } } else if (rc == 0) { printf ("End of file read\\n"); break; } else { perror ("Read error"); break; } } close (fd); }
How to allow regular users read from the serial MSR
In order to let the user have access to the device:
- Add the user to the proper group
# usermod -G $(stat -c '%G' /dev/ttyS3) <my_user>
- Re-login into that user account