Sending 1 bit to serial port

This is a discussion on Sending 1 bit to serial port within the C Programming forums, part of the General Programming Boards category; Hello, Anybody know if there is a very simple way of sending 1 bit to like a serial port? I ...

  1. #1
    Registered User
    Join Date
    Jan 2008
    Posts
    19

    Sending 1 bit to serial port

    Hello,
    Anybody know if there is a very simple way of sending 1 bit to like a serial port? I have been reading a few things that seem like they do it but I am not for sure.

  2. #2
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    That obviously depends on the serial port. The "standard" Asynchronous device, e.g. the 8250/16550 type devices in a PC [or any other UART device that I personally know of] are only able to send "lumps" of bits, e.g. 5, 6, 7, 8 bits [plus a start/stop bit at either end of the "lump"].

    What are you ACTUALLY trying to achieve, bigger picture like?

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  3. #3
    Registered User
    Join Date
    Mar 2008
    Posts
    14

    reply

    What are you using Unix/Linux or Windows?

    In linux just open the serial port /dev/ttyS? or something like that and write() to it

    sth like

    Code:
      
    int serial_handle;
    
    serial_handle = open("/dev/ttyS0", O_RDWR);
    Note /dev/ttyS0 in linux is where your serial port is located
    O_RDWR is the flags that opens it for read and write.
    and then write() to it

    but like matsp said

    are only able to send "lumps" of bits, e.g. 5, 6, 7, 8 bits [plus a start/stop bit at either end of the "lump"].
    Hope it helps

  4. #4
    Registered User
    Join Date
    Jan 2008
    Posts
    19
    Sorry, lumps of bits will work. What I want to do is replace an ancient buzzer system. I think I will be using windows server 2003 by the way. Basically I want to set schedules and on the schedules execute my code to send traffic down a serial port which will trigger something on the other end when traffic is detected. Oh, and another thing is I didn't know if it could be that easy. I am no expert when it comes to devices like serial but I think there is an onboard rom chip that does some processing and channeling when receiving data down the serial pipe? Or am I wrong.

    Thanks again guys ( and girls? )

  5. #5
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,699
    For serial port I/O under windows - there are plenty of examples out in the wild. All of them will be using the API's and concepts described in this article: Serial Communications in Win32.

    What's the name of the device you're connecting to? What are the connection settings (baud, parity, stop bit, flow control)? Is the serial protocal for the device published online?

    gg

  6. #6
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    If you just want to trigger something, wouldn't the parallel port of the PC be a better choice. It's got 8 pins that you can set to 0 or 1 individually.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  7. #7
    Registered User
    Join Date
    Jan 2008
    Posts
    19
    Using serial instead of parallel because of distance capabilities. Also, on the receiving end it seems to be irrelevant. The guy taking care of that says that all he needs to do is have anything flow down the pipe.

  8. #8
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,822
    So send a single byte of 0xFF.
    Or any character for that matter, since all that seems to be required is a sense of "now!", which can be just the arrival of the character.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. sending streams over serial port in win32
    By deian in forum C Programming
    Replies: 2
    Last Post: 07-13-2009, 01:01 PM
  2. FTP program
    By jakemott in forum Linux Programming
    Replies: 14
    Last Post: 10-06-2008, 02:58 PM
  3. Serial port programming in Linux
    By g4j31a5 in forum C++ Programming
    Replies: 1
    Last Post: 09-28-2006, 09:24 PM
  4. Problem with string and serial port
    By collinm in forum C Programming
    Replies: 2
    Last Post: 03-23-2005, 10:19 AM
  5. Receiving characters on serial port
    By Roaring_Tiger in forum Networking/Device Communication
    Replies: 3
    Last Post: 07-01-2004, 02:52 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21