Note that there are some explanatory texts on larger screens.

plurals
  1. POHow can I send null characters to the serial port using the Windows API?
    primarykey
    data
    text
    <p>I am working on a Windows utility program which communicates with some custom hardware using a standard COM port. The communication protocol (which is out of my control) requires me to transmit and receive raw 8-bit data bytes.</p> <p>I am currently using the following Windows API function to send data to the COM port:</p> <pre><code>WriteFile(hFile, lpBuffer, numberOfBytesToWrite, ...)</code></pre> <p>where <code>hFile</code> is a reference to the properly opened COM port, and <code>lpBuffer</code> is an array of bytes that I have stored in memory. The code works perfectly until a null character (ASCII zero) needs to be sent to the device. <code>WriteFile</code> stops sending as soon as it detects the null character because it assumes that it has reached the end of the string. This happens even though I set <code>numberOfBytesToWrite</code> properly.</p> <p>How can I send raw data to the COM port using the Windows API? I would prefer to use a standard API call similar to <code>WriteFile</code>, but I am open to suggestions.</p> <p>I am currently using <a href="http://rapidqwiki.altervista.org/" rel="nofollow noreferrer">RapidQ</a> to build the utility, but all it does is call the Windows API function directly.</p> <p><b>Edit:</b> My setup consists of a Windows PC connected via serial port to the custom hardware module. The module has a small screen on which I am able to view the transmitted characters. I have tested this setup with another third-party utility program. I am able to communicate with the module using this third party program, and null characters show up properly. In my own program, when I use <code>WriteFile</code>, a null character anywhere in the transmit stream stops the rests of the stream from being sent.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload