Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Comm Port

4 views
Skip to first unread message

McKool

unread,
Sep 13, 2004, 10:02:06 AM9/13/04
to
Hello, I'm sending bytes through the port to a device. I need to know the
times when the information come to the device, i mean, calculate the needed
time for a byte to travel from the port to the target. I configure the port
to 360 baud and i send 0x0, then a want to change the baud to 10400 just
when i the 0x0 was received and send other byte. I have to send this two
bytes with that configuration in a time between 49 and 51 millis.... So the
question is how can calculate the time needed in each configuration to
complete a send of a byte in order to calculate my sending times.... shall
be a formula for that, but i don't know it....

Thanks for your help.


Bob Gonder

unread,
Sep 13, 2004, 11:42:25 AM9/13/04
to
McKool wrote:

Depends on your other settings.
These are the things that get sent, and the "bits" they take:
Start 1 always unless running in sync mode, then 0
data 8 setable between 6, 7 and 8 I think
parity 1 setable 0 or 1
stop 1 setable to 1, 1.5 or 2 (0 for sync mode)

"Normal" settings are (8,N,1) for a total of 10 bits.

Each bit at 360 baud takes 1/360 second.
Simple arithmetic from there.

Now, that assumes a DOS box.
If you are using a DOS system, then you can also keep checking the
USART for completion status, then reprogram it for the new baud.

If you are using Windows, then there isn't much telling "when" the
data starts going out, as Win can buffer and send when it pleases.
I think your best bet for Windows app would be to use blocking calls
(functions that don't return until the data has been sent), then just
set baud, send, set baud, send.


McKool

unread,
Sep 14, 2004, 3:23:25 AM9/14/04
to
I use the normal Configuration, but when you configure the Port in a normal
way (8,N,1) are not in total 9 bits instead of 10? i need to have a low
signal in the port for 25 ml, so 9bits / 360 bauds = 0,025 => 25 ml is it
not?
I'm using Widnows but which blocking calls do you refer? I'm use
"TransmitCommChar"... it is a boolean function and I supposed that it
returns only when the byte is sent (so when everything is Ok).

My problem is that ai have to be precise in the time when i write the two
bytes because the divice read the low and hight signals in the port in order
to get active and i have to pulse 25 ml low and then hight oder 25 ml with a
error margin of 1 ml.

25 ml low| 25 ml Hight | hier start my real communication.
--------- --------------
| | |
| | |
|---------- | |50 ml

Because of that I try to send a 0x0 using 360 baud, but after the 25 ml low
i have to change to the communication baud which is 10472 and send the start
byte... this start byte shall arrive to the device between the ml 49 and ml
51. The 25 ml are OK, but when i change the configuration and sent the
start byte i lose time, and i can not calculate it....

Can i maybe at 10472 in someway make the same low-hight behavior?

"Bob Gonder" <no...@notmindspring.invalid> schrieb im Newsbeitrag
news:88fbk0d602p65ajvc...@4ax.com...

Eelke Klein

unread,
Sep 14, 2004, 4:52:37 AM9/14/04
to
McKool wrote:
> I use the normal Configuration, but when you configure the Port in a normal
> way (8,N,1) are not in total 9 bits instead of 10? i need to have a low
> signal in the port for 25 ml, so 9bits / 360 bauds = 0,025 => 25 ml is it
> not?
You forgot the start bit for a total of ten bits.

> I'm using Widnows but which blocking calls do you refer? I'm use
> "TransmitCommChar"... it is a boolean function and I supposed that it
> returns only when the byte is sent (so when everything is Ok).
No it returns immediatly:

BEGIN Win32 documentation:

Remarks
The TransmitCommChar function is useful for sending an interrupt
character (such as a CTRL+C) to a host system.

If the device is not transmitting, TransmitCommChar cannot be called
repeatedly. Once TransmitCommChar places a character in the output
buffer, the character must be transmitted before the function can be
called again. If the previous character has not yet been sent,
TransmitCommChar returns an error.

END Win32 documentation


>
> My problem is that ai have to be precise in the time when i write the two
> bytes because the divice read the low and hight signals in the port in order
> to get active and i have to pulse 25 ml low and then hight oder 25 ml with a
> error margin of 1 ml.
>
> 25 ml low| 25 ml Hight | hier start my real communication.
> --------- --------------
> | | |
> | | |
> |---------- | |50 ml
>
> Because of that I try to send a 0x0 using 360 baud, but after the 25 ml low
> i have to change to the communication baud which is 10472 and send the start
> byte... this start byte shall arrive to the device between the ml 49 and ml
> 51. The 25 ml are OK, but when i change the configuration and sent the
> start byte i lose time, and i can not calculate it....

Notice that these signals will never be completely low or completely
high they will allways be a series of pulses zero bits are short pulses
and 1 bits are long pulses. The start and stop bits have fixed lengths.


>
> Can i maybe at 10472 in someway make the same low-hight behavior?

Probably if you send enough 0 and 0xFF values however the problem of the
signal never being really low or really high will persist. You should
the WriteFile function for this as it will allow you to send a block at
once making the timing more accurate.

Eelke

Bob Gonder

unread,
Sep 14, 2004, 1:50:35 PM9/14/04
to
Eelke Klein wrote:

>Notice that these signals will never be completely low or completely
>high they will allways be a series of pulses zero bits are short pulses
>and 1 bits are long pulses. The start and stop bits have fixed lengths.

No pulses.
You're probably thinking modem signals where the frequency shifts
according to bit state.
The RS232 voltage goes high or low for the duration of the bit time.
The reader is supposed to wait for the middle of the bit time to read
the value. This gives the signal the maximum anount of time to
overcome line capacitance, and achieve a non-ambigous signal state.

>> Can i maybe at 10472 in someway make the same low-hight behavior?

No, then it really would look like pulses.
The start and stop bits are both high. So a 0 looks like goal posts.

Doesn't the OEM have windows drivers for this?

I get the feeling this is ancient hardware and MS isn't going to allow
very nice support for it.

You could also try sending a "break" signal.
It's been too many decades, and I never used them, but perhaps this is
the signal the OEM contemplated being sent.
I no longer have my hardware manual for the UART, but a communications
library says that a Break is spacing (0) for more than a character's
time. It doesn't say how much more, or if it spaces for wall-clock
time, or just a bit more than a char time. In any case, I don't think
it would have any start/stop (high) bits.


McKool

unread,
Sep 15, 2004, 8:55:32 AM9/15/04
to
Thanks for the answers.

I could see with an osciloscope that the Low-Hight state which i want, i can
make ik sending a 0x0 using as baudrate of 360. That is something ;-) .
When i send the 0x0 i get a Low signal for exact 25 ml. The problem is to
calculate the time after that happens.

The duration of send a 0x0 is (if i understud well) (1/360)*1000 =
2,7777 ml . so, in order to send something in the next 25 ml shall the
program wait theoretic

This hardware is a standard device to communicate to a Car. The name is
K-Line and in order to start a comunication must be sent a 25 ml low, 25 ml
hight and some start bytes after that. But it must be just 25ml, if it is
not exact (+/- 1 ml) don't work. I find a sample program mad in Delphi
(only the Exe file) and i see in the osciloscope that it make just that what
i want, so must to be a simple way.

"Bob Gonder" <no...@notmindspring.invalid> schrieb im Newsbeitrag

news:jf9ek095ohfqfgl30...@4ax.com...

McKool

unread,
Sep 15, 2004, 9:37:24 AM9/15/04
to
How can i make the port work sinchronous? which api function exist für send
a byte and get a return when the byte was received?
I made my class Port and i have to use TransmitCommChar in Windows XP, NT
and 2000 but for ME, 98 and 95 don't work with tha function but with
WriteFile. I know only those two functions and i don't use both at time (at
least i don't know how).

What if i wait until this event

EV_TXEMPTY = The last character in the output buffer was sent

Can i take the time before send a byte, wait for that signal EV_TCEMPTY,
calculate how many millis are gone between send and receive the signal, wait
for the rest of millis what i need (minus 1/360 which is the time to send
other byte) and send the new byte???

Sorry if what i say sounds crazy but i have no more ideas....

thanks for all your help

"McKool" <ken...@peak-system.com> schrieb im Newsbeitrag
news:4148...@newsgroups.borland.com...

Bob Gonder

unread,
Sep 15, 2004, 4:03:21 PM9/15/04
to
McKool wrote:

>How can i make the port work sinchronous? which api function exist für send
>a byte and get a return when the byte was received?

Don't open the port with FILE_FLAG_OVERLAPPED.
Use WriteFile() with lpOverlapped = NULL.

>> I could see with an osciloscope that the Low-Hight state which i want, i
>> can make ik sending a 0x0 using as baudrate of 360. That is something ;-)
>> . When i send the 0x0 i get a Low signal for exact 25 ml. The problem is
>> to calculate the time after that happens.

Is this what you need to happen?
25 ms low,
25ms high,
then commands at 10400 baud?

>> The duration of send a 0x0 is (if i understud well) (1/360)*1000 =
>> 2,7777 ml . so, in order to send something in the next 25 ml shall the
>> program wait theoretic

Huh?
There is no 360 setting. Docs say 300 or 600.
The duration of a character at 360 baud would be 1/36 second. The
duration of the 8 zero bits would be 1/45 second.
But, you are looking for a zero duration of 1/40 second (25 ms)
OTOH, if you set Parity to Even instead of None, then you would get a
Zero-Time of 1/40 second.
But, that makes it hard to get 25 ms of high.

>> This hardware is a standard device to communicate to a Car. The name is
>> K-Line and in order to start a comunication must be sent a 25 ml low, 25
>> ml hight and some start bytes after that. But it must be just 25ml, if it
>> is not exact (+/- 1 ml) don't work. I find a sample program mad in Delphi
>> (only the Exe file) and i see in the osciloscope that it make just that
>> what i want, so must to be a simple way.

Try this sequence:

CreateFile();
SetBaud(10400);
SetThreadPriority(Higher)
starttime=GetTime();
SetCommBreak();
while( (GetTime()-starttime) < 25ms );
ClearCommBreak();
SetThreadPriority(Normal)
/*Now for 25ms high.*/
WriteFile( 26 times 0xff ) /* (10400/10)/40 == 26 */
WriteFile(Commands)

McKool

unread,
Sep 16, 2004, 8:20:10 AM9/16/04
to
Bob Gonder wrote:
> Is this what you need to happen?
> 25 ms low,
> 25ms high,
> then commands at 10400 baud?

Yes, exact that timing and it must to be so:
Baud: 360 -> 25 ml low, 25 ml hight (total of 50 ml)
Baud: 10472 -> init byte (maximal at milli 51).

> Huh?
> There is no 360 setting. Docs say 300 or 600.

360 is not an standard setting but you can use whichever baudrate, when the
baud is between the aalowed range.

> The duration of a character at 360 baud would be 1/36 second. The
> duration of the 8 zero bits would be 1/45 second.
> But, you are looking for a zero duration of 1/40 second (25 ms)
> OTOH, if you set Parity to Even instead of None, then you would get a
> Zero-Time of 1/40 second.
> But, that makes it hard to get 25 ms of high.

So far as I know (just what i tried this week ;-) ) the speed to sent a byte
is the number of bytes over the speed of the port, so 1 byte / 360 baud
which is 0,025 seg (25ml). The osciloscope tell me that the calculation is
ok. with 360 b i sent a 0x0 and i get 25 ml of pulse.

> Don't open the port with FILE_FLAG_OVERLAPPED.
> Use WriteFile() with lpOverlapped = NULL.

The behavior is bettter... now i can see that a time to write a byte is 2.8
ml. Now i have to play a little with multitreathing or multimedia timer.
Thanks it was very helpfully.

> Try this sequence:
>
> CreateFile();
> SetBaud(10400);
> SetThreadPriority(Higher)
> starttime=GetTime();
> SetCommBreak();
> while( (GetTime()-starttime) < 25ms );
> ClearCommBreak();
> SetThreadPriority(Normal)
> /*Now for 25ms high.*/
> WriteFile( 26 times 0xff ) /* (10400/10)/40 == 26 */
> WriteFile(Commands)

So comes many fast picks ... not only one.

I try to make now someting like :

- configure port Synchronic at 360 bauds
- Save Start Time.
- Write 0x0
- Save Stop time
- calculate the difference between times
- wait 25 ml - the calculate Time differences
- Send byte for Start communication

It shall work..

Thanks again
Keneth


0 new messages