Operating System - HP-UX
1823415 Members
2615 Online
109655 Solutions
New Discussion юеВ

How to output a character to serial port (/dev/tty0p0)

 
diudiu_1
Advisor

How to output a character to serial port (/dev/tty0p0)


I have a scanner , and I made the scanner's auto trigger is a character "T".
I use my PC(windos xp)'s serial port to output a character "T" or in hex mode"54" to the scanner, The scanner then auto start to read.

By now, I want to use this scanner on Unix controller(B2000)10.* Hp-unix.
I tried several ways to output "T" to the scanner, But I am failed.
Could you give me some suggestions on how to output a character to the serial port and the read back something from the serial port(scanner)?

Thank you very much

3 REPLIES 3
RAC_1
Honored Contributor

Re: How to output a character to serial port (/dev/tty0p0)

You can write a c code to write/read from serial port. But before that, when you connected scanner to system, is it in claimed state on unix??

Just echoing a char to device should be very easy. You can do as follows.

echo "T" > /dev/device_file_of_device

Reading from it would require some code and in case of scanner, it would be more difficult. Does manufacturer provide some software for unix for thic functionality??
There is no substitute to HARDWORK
diudiu_1
Advisor

Re: How to output a character to serial port (/dev/tty0p0)


Thank for your quick reply.
but It seems it doesn't work also.
Bill Hassell
Honored Contributor

Re: How to output a character to serial port (/dev/tty0p0)

Do you have the right cable? With the B2000, you should have the same connector as the PC (9pin) and it should work. However, your T is being sent at 300 baud. All HP-UX systems set the serial port(s) to 300 baud so you'll have to change the baud rate to the desired rate. The stty command will help but even though you set the port speed, it must remain open for the baud rate to stay at a new setting.

The usual technique is to start a sleep program that runs for several hours and redirect stdin for sleep to use the serial device file. Put the sleep in the background and run the stty program to set the baud rate. Now send the T to the scanner.

Some more details: if you use: echo "T" to send the character, you will get 3 characters by default: T CR LF which may confuse the scanner. Use echo "T\c" to suppress the end of line characters.


Bill Hassell, sysadmin