Hello,
Below is a snippet of my code, as is it won't run. I am trying to support
an instrument that may be
configured for RS-232 or RS-485 (using a dongle for the latter).
The dongle runs half-duplex and uses the serial port signal RTS to switch
from transmit to receive.
On my computer, the whole serial data takes <4 ms at 9600 baud.
My control of the RTS signal seems to be poor when starting to send the
data, but good when finishing up.
The RTS signal is repeatably released just after the last serial character
exits the serial port.
However, the time between asserting the RTS signal and the 1st character
being sent is inconsistant.
It varies between 0 ms and 25 ms approx, perhaps more.
I have yet to actually try interfacing to the actual instrument, perhaps
this may not be an actual problem.
I welcome suggestions to correct this error, or placate my fears because of
similar experience.
Thanks,
--------8<--------8<--------8<--------8<--------8<--------8<--------8<------
--8<--------
RS232Error = OpenComConfig (comport, "", baudrate,
parity, databits, stopbits, inputq, outputq);
if (RS232Error == 0)
port_open = 1;
SetComTime (comport, 0);
FlushInQ (comport);
FlushOutQ (comport);
Delay(1);
ComSetEscape (comport, CLRRTS); // just to see the line toggle once
Delay(0.1);
ComSetEscape (comport, SETRTS);
}
strcpy(send_data,"S80");
for (q=00;q<30;q++)
{
printf("\n%d...",q);
FlushOutQ (comport);
m=0;
Delay(2);
SendAscii();
printf("%d bs:",bytes_sent);
for (n = 0; n {
printf("%d ",array1[n]);
}
}
void SendAscii (void)
{
char stat;
int stringsize = StringLength (send_data);
int bytes_sent;
ComSetEscape (comport, CLRRTS); // set the line negative voltage
// used a scope and saw a variable delay appear at this location,
// delay varies between 0 ms and 25 ms approx
bytes_sent = ComWrt (comport, send_data, stringsize);
while (GetOutQLen (comport)); // wait for internal buffer to empty
do
{
stat = inp(portbase + LSR);
stat = stat & 0x40;
}
while (stat == 0); // wait for hardware buffer to empty
ComSetEscape (comport, SETRTS); // set the line positive voltage
}