Datta Dhonde
Datta Dhonde

Reputation: 193

Detecting a RS-232 com port in Linux

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)

Upvotes: 1

Views: 4996

Answers (3)

wallyk
wallyk

Reputation: 57784

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.

Upvotes: 3

Zubraj Singha
Zubraj Singha

Reputation: 35

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

Upvotes: 0

Jonathon Reinhart
Jonathon Reinhart

Reputation: 137497

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.

Upvotes: 0

Related Questions