cana rich <[EMAIL PROTECTED]> writes:
>  First of all, thaznks for your reply.
> To ansmer yours questions, i would like to make a C or C++ program which communicate 
>via the serial port COM1 to a device. The device is a screen plasma. I would like the 
>program to remote the sreen : switch on, switch off, change channel ...
> The serial communication setting is :
> Baud : 4800 BPS
> Data length : 8 bits
> Parity : none
> Stop bit : 1 bit
> Flow control RTS/CTS
> Communication code : ASCII code
> Reception time out : 4 seconds
> To do it, I need to send ASCII code. For exemple, to switch off the screen i must 
>send the "%A0001" code.
> I need to receive the acknoledgment to know if it has been weel done. (code for good 
>receive : "@S")
> Thanks for your help.
> Canarich

The serial port is mapped as a regular file, /dev/ttyS0 for COM1,
/dev/ttyS1 for COM2 and so on (as are most/all other devices in *ix).

To read/write data just open /dev/ttyS0 and use read()/write() (or
fprintf()/fscanf(), whatever seems more suitable).

For this to work the way you want it to you would first need to set
up the communications parameters as you stated them above. See 
  man termios
for how to do that. Basically, you first open() the serial port,
giving you a file descriptor. Then you use tcgetattr() to get its
current configuration, modify it as you need (cfsetispeed(),
cfsetospeed() among others), and use tcsetattr() to apply the changed
configuration.

After that you're all set and can use read()/write() or whatever.

If you wish to use fprint()/fscanf() you'd first need to get a FILE
stream from the descriptor, which you get with fdopen().

For finding out whether the device has answered within a certain
timeout select() or poll() might come in handy.


(All the system and library calls stated above have their own manual
pages, for example type 'man fdopen' to find out more about fdopen()).


So long,
   Joe

-- 
"I use emacs, which might be thought of as a thermonuclear
 word processor."
-- Neal Stephenson, "In the beginning... was the command line"



-- 
redhat-list mailing list
unsubscribe mailto:[EMAIL PROTECTED]?subject=unsubscribe
https://listman.redhat.com/mailman/listinfo/redhat-list

Reply via email to