Detecting a RS-232 com port in Linux - c

I have an ECR(Electronic Cash Register) device,it has a RS-232 com port cable for the connection to PC but I have not been given any drivers for it. I am trying to connect the device to PC but PC is not able to detect the cable. How to detect this device attached on this RS-232? I am working under Linux. Any help on how to find the device is appreciated?
Following is the code snippet I found in C to connect to device based on Baudrate and Com Port number.
int OpenComport(int comport_number, int baudrate)
int SendByte(int comport_number, unsigned char byte)
int SendBuf(int comport_number, unsigned char *buf, int size)

Please see my answer to a related question which shows how to open and configure the serial port.
On Linux, serial ports are almost always /dev/ttyS[0123] (that is /dev/ttyS0, /dev/ttyS1, etc.) for the hardwired ports, and /dev/ttyUSB* for USB ports. The hardwired "devices" may appear only when the hardware is present on some distributions. On others, they always appear whether there is hardware or not. (Try cat /dev/ttyS2 and see if you get the error "no such device".) This is a kernel configuration option which is frequently set to create the device entries whether the hardware is there or not.
The USB ports are present only when there is hardware plugged in, but if there are multiple USB serial ports, it can be difficult identifying which is which.
There is a mechanism within /etc/udev/rules.d/* which can be configured if some aspects of the devices are consistent. See man 7 udev for details.
For applications I have written, I determine which device is which by writing to the device and identifying its response. For devices which don't respond, this is either a worthy programming challenge or a mundane configuration solution.

I think you need to do a little reading about RS-232, and well, C programming also. There are no drivers for RS-232. It is a very "dumb" protocol - you basically just shove data out the port.
The PC cannot detect the cable? That's because it's not USB. Believe it or not, Plug-and-play didn't always exist; you tell the software what port the device is supposedly connected to, and it tries to talk to it.
Furthermore, those aren't "code snippets", those are just function prototypes. There isn't any actual code there.

1>since there's no operating system on your ECR so I guess u don't need any drivers ,instead a firmware will be there in the ECR , which tries to communicate with your Linux UART driver
2> Rs-232 is basically a serial protocol , I mean it has 9 wires , and hence a connecter with 9 pins are used DB-9 connectors ,all the communications inside a processor is in parallel format so a chip called UART is used to convert all the parallel data into serial data , and since yu want to pass the data in Rs-232 format , it needs to be packaged in that format .
3> Linux kernel already has a uart driver , which is implemented for RS-232 . so need to worry about drivers from Linux side.
4> Open a terminal type " dmesg | grep tty " ( connect only the ECR to the PC for rs-232 ports ). it will return something like ttyS or ttyUSB etc , however u just concentrate on ttyS if u have connected only through rs-232 cable .
5> Once u are sure of the ttyS device from the dmesg use minicom (its easy to use ) to communicate with the device.
regards,
Zubraj

Related

Difference between a serial driver and a tty driver

I have a task to write a serial driver for uart and tty_uart driver too on Zephyr (It's my first time in developing drivers).
1.So what is the difference between a serial driver and a tty driver?
Is there any interdependence relation between them? I mean to write a tty driver should I write by first a serial driver, that will be a base to the tty driver or what?
So what is the difference between a serial driver and a tty driver?
A serial driver makes no assumption about the kind of device attached, it merely sends and receives raw "bytes" (see note), and probably offers some way to configure the communication (which baud rate, how many data bits, what kind of parity scheme, what kind of flow control, etc). The device attached to the serial port could be a serial mouse, or a bar code scanner, or a printer, or ... - the serial driver doesn't care.
Note: "byte" might not be a synonym for "octet" - e.g. it could be a group of 7 bits.
A TTY driver is tied to the assumption that the device is an type writer with a keyboard. Note: For the history; before computers existed we went from "people waving flags at each other" (semaphores) to "morse code with a single key" (telegraph) to teleprinters/teletypewriter (see https://en.wikipedia.org/wiki/Teleprinter ); and when computers got invented the (mechanical/electric) teleprinters were simply replaced with (computerized) dumb terminals.
Mostly; TTY is all about what bytes mean (and doesn't care much how the bytes are sent/received); and a serial driver is all about how bytes are sent/received (and doesn't care what the bytes mean).
Is there any interdependence relation between them? I mean to write a tty driver should I write by first a serial driver, that will be a base to the tty driver or what?
Crudely; a TTY driver has IO in 4 directions - getting key press info from local keyboard, sending bytes to remote whatever, receiving bytes from remote whatever, and putting characters on the local screen. For sending/receiving bytes with "remote whatever" you can use a serial driver; but (especially during development/testing) you could use anything else (TCP/IP stream, pipes, file IO, ...) instead - you don't necessarily need to implement the serial driver first.
Regarding your questions:
So what is the difference between a serial driver and a tty
driver? Is there any interdependence relation between them? I
mean to write a tty driver should I write by first a serial driver,
that will be a base to the tty driver or what?
It all depends on your operating system.
Previous answers relate mostly to Linux/Windows. You don't provide more points about it, but I'm assuming your question relates to Zephyr RTOS Project. I also assume you're developing a BSP for a custom board not yet fully supported by the RTOS.
The device driver model in Zephyr is different from Linux's or Window's driver models. You can take a look at the board porting guide and architecture porting guide.
The documentation contains a lot of samples, including quite a few of driver samples.
You'll also find more information here covering how to have access to support from the community.

Reading from and writing to registers of an IMU via UART

I have an IMU that has a UART interface. The manufacturer has provided a Windows based program that get all the data from the IMU and displays it in real time. (The device is connected to the PC via the USB). I need to write my own software that does this in order to integrate it into my project.
The datasheet/manual for the IMU gives all details about which registers have to be written to and read from (issue commands and read responses) in order to get the IMU data. My question is, how do I implement this in C under Linux?
The closest information I found out was this one but when compiling it it seems I need Linux kernel headers since that program uses #include <linux/module.h> so I'm not sure if I am on the right track.
You need not any kernel headers to talk over a serial port with any device connected to that serial port.
You would get a 'connection' to your device by simply opening a file /dev/ttyUSB0 with open() call (the actual name could be found by looking into dmesg for relevant device messages or by looking what device node appears under /dev when you plug your device into usb port).
Then you would need to set the baud rate and the word format (number of bits, parity and number of stop bits). To achieve that from the user-space process you would use a set of ioctls. For details read man ioctl and man ioctl_list

BLE Bridge Mode in Linux example

I want to use Bluetooth(4.0) on my board to transmit it's Name so any Mobile Application can see it's name and Mobile application initiates the pairing and connection with my Bluetooth.
I have seen some examples of Bluetooth(4.0) scanning nearby devices; For example:- It does scan for Bluetooth Mouser/Keyboard, but in this case Bluetooth(4.0) is in mode where it chooses the device it want to connect while I want it reverse so Any mobile application can see my Bluetooth and gets connect with it and does communication.
How can I put my Bluetooth(4.0) in such mode in Linux? Is there any C library using which I can put Bluetooth(4.0) is the mode where it goes in Bridge mode instead of scanning nearby devices?
You can set the name of your device like this:
hciconfig name "foo"
and check your name with:
hciconfig name
You also have to enable Low Energy advertising for your device to be found by others:
hciconfig leadv
You can configure your device to accept incoming connections like this (lm for link mode):
hciconfig lm MASTER,ACCEPT
This way the kernel will accept a connection, even if there are no listening sockets.
Considering you want to do actual communication, you would need to write a program, accepting the connection and sending/receiving data. Just putting your device in a mode where other devices can connect to it isn't really worth anything (because you can't communicate).
The basic principle is to open up an L2CAP socket, with the Channel ID of 4 (for Low Energy), then do standard bind/listen/accept. I suggest you look at the source code of Bluez and the examples.

How to dump/burn program into LPC2148

I have LPC2148 daughter board but I am not able to dump/burn code into it, and it doesn't have any usb connector to dump code.
I read on internet by using FT232RL I can able dump code into LPC2148 but I am not able to do so.
please give me solution
thank you..!
The chip supports In-System Programming (ISP) via an on-chip boot loader ROM.
From the User Manual UM10139:
Programming of the Flash memory may be accomplished in several ways:
over the serial built-in JTAG interface, using In System Programming
(ISP) and UART0, or by means of In Application Programming (IAP)
capabilities.
The function of the FT232RL you mentioned is to act as a USB/UART bridge and is necessary primarily because modern PCs lack legacy RS-232 serial ports. You can in fact purchase a USB-Serial cable or adapter which will contain a bridge chip such as the FT232RL. Most of these use RS-232 line level signals, so you would still need an RS-232 line driver/receiver to connect then to your board (if your board has a serial port, it probably already has a line transceiver and you can connect directly to that). It is possible from specialist suppliers including FTDI themselves to get a USB cable with integrated FT232 and bare TTL level connections to connect directly to LPC2148 UART0 Rx/Tx lines.
If your board does not already expose a UART0 serial port and the necessart control to start the boot loader, a Serial Port Bootloader Interface board is available. For that you may then also need a USB/Serial adapter or a PC with a legacy serial ports.
Once you have a suitable serial connection, you will need the LPC2000 Flash Utility software to run on the PC.
The JTAG option is however faster, and more powerful since the JTAG is both a programming and debugging port. With a suitable toolchain and JTAG adapter it is possible to program and execute code with source-level PC hosted debugging including break pointing, data watching and single stepping of the code.

How to find the base address of usb to parallel port device in Linux?

I am doing IO programming in C in Ubuntu. And I need the base address of the port to write data.
My laptop dont have a parallel port. So I bought a USB to Parallel port connector. I plugged in the device and its getting detected in /dev/usb/lp0
I ran "lsusb" to see the list of devices and I can see the ID also. But how can I get the base address ? For the usual hardware parallel devices, the base address is 0x0378. this address is not getting detected while using USB to Parallel device.
Please help.
A USB parallel port doesn't have a base address - it's not a meaningful concept for USB. I'm afraid the days of doing I/O on PC hardware via in and out instructions ended a few years ago, though lots of old tutorials still survive on the web.
You can write bytes to the parallel port as a character device, and these will appear on the printer port pins. The USB adapter will expect the other end to handshake data exactly like a printer. If you want to do general I/O prototyping, you're probably better off with a simple USB microcontroller like an Arduino.
Further discussion here.
If you are still interested to use this USB-to-parallel-printer device for your own bit-banging, it's important to know that their built-in firmware always allows controlling of D0..D7, INIT (as outputs), /ERR, ONL, PE (as inputs), but never for /ACK, BUSY (inputs), /STB, /AF, /SEL (outputs) pins.
And you need an 8-bit latch (e.g. 74HCT574) for catching data while strobing.
See here (https://www-user.tu-chemnitz.de/~ygu/bastelecke/PC/USB2LPT/faq#DIY)
especially for possible data rates.
Accessing from software side is a bit complicated but possible, and you may have to re-structure your software and hardware for making such adapters useable. I don't know for Linux case how to access, but IMHO you don't need to write a kernel-mode driver.

Resources