Make serial port ON-OFF for finite number of times

T

Thread Starter

Tushar

I want to make serial port ON-Off continuously for finite number of times. Basically I want to get finite number of pulses from the output of serial port. for example ,suppose I want 50 pulses at the output of serial port, then I can get 50 pulses at the output.

For that our first step will be to get the continuous pulses at the output of serial port. I want to implement this using C or C++ or .net.

We can also check whether we are getting pulses or not after simulating code by connecting CRO,or simple LED.

Due to continuous pulses LED will be ON-OFF continuously.
 
If you want to have one of the handshake lines turn on or off under code control this can be done:

In c#.NET I would do the following:

Instantiate, enable and open a SerialPort object using either code or the designer in Visual Studio. Set the handshake mode to "none".

port.DtrEnable = true; //turn "ON" DTR line
port.RtsEnable = true; //turn "ON" the RTS line

To turn them off assign them to false. The names for this are messed up, but this works I've tested it with a serial breakout that had LEDs on it.

KEJR
 
R

Robert Scott

Here is a quick solution that does not require any fiddling with handshaking lines:

Know your format. RS-232 serial starts each character with a positive start pulse. Then there are 8 (if you have configured for 8-bits, no parity) data pulses, starting with the least-significant bit. Then there is a stop bit, which is a negative level that stays low. The data bits are negative for "1" and positive for "0" (reversed logic).

So if you send out a hex(FF) raw binary 8-bit character, you get just one pulse - the start bit. All the other bits are low. So that is how you get 1 pulse. Send the data hex(FF). To get two pulses, send something like hex(FD). It would appear as:

H L H L L L L L L....

where the first H (high) is the start bit and the second H is from bit 1 of the data. So that is how you get 2 pulses.

Similarly, you can get these numbered pulses by sending these data bytes:<pre>
# data
- ----------
1 FF
2 FD
3 F5
4 D5
5 55
6 55 FF
7 55 FD
8 55 F5
9 55 D5
10 55 55
11 55 55 FF
12 55 55 FD
...etc.</pre>
Get the pattern? This does require that you be able to send raw binary data characters and not be restricted to ASCII.

Robert Scott
Real-Time Specialties
 
Top