I've written several little apps, and they all work great under XP or 2000. But I spent all of last week trying to get a new program to work under DOS. I installed Win95 to see what would happen, and it works better, but still not well.
I've got a program that continually talks to the serial port. Every 100ms. It's controlling a card (Ontrack ADR112) to operate a stepper motor, monitor buttons pressed, and read a loadcell (analog input). Like I mentioned, the program works perfectly under 2000 and XP. In pure Dos (MS 6.22) the program runs deathly slow. When I insert a routine to count loops and measure time between events, everything comes out funky.. like 3,000 loops when under windows it was 400 loops, 1.23E+08 instead of .102 when calculating Timer - oldTimer [=Timer stored before routine]. It's like time functions work differently under Dos? or are not Double type in Dos?
After trying the program in a Windows 95 dos box, things are improved, but not good enough yet. What I get here is a seeming Pause every time I read or write to the serial port. I send a string, and sometimes I get the correct response, other times no response, and sometimes I get back part of what I sent. I've played with buffer settings and how I'm sending/receiving and speeds and times and ... ??
I got nothing. And now I'm here.
I've ripped all of the graphical / mathematical stuff out of the program so all I have left is talking to the serial port. It works on and off. Seemingly at random. I hope someone can offer advice on getting this to work! Here's the routine that _seems_ to be the problem (with setup snipets):
Code: Select all
Serial.Ok = 0 'set 1 when when return Ok, 0 if error
Serial.Handle = FREEFILE
Open COM "COM1:9600,N,8,1,CS0,DS0,CD0,OP0,TB8,RB16,BIN,IR4" AS #Serial.Handle
Sub TxRx(Transmit As String, WaitResponse As Byte)
Dim AS DOUBLE TimeEnd, TimeOut
Dim AS STRING Character, Sample, Receive
TimeOut = SerialPort.Timeout / 1000 'milliSeconds allowed for Transmit or Recieve
Sample=""
If (Serial.IsOpen = 1) Then
Serial.Ok = 1
' Empty the buffer.
While (LOC(Serial.Handle) > 0)
Sample = INPUT(1, Serial.Handle) 'read one character at a time
Wend
'Send the data.
If Transmit <> "" THEN
TimeEnd = Timer + TimeOut
Print #Serial.Handle, Transmit
If Timer > TimeEnd THEN
Serial.Ok = 0
Transmit = ""
EndIf
Transmit = ""
End If
' Read the response if requested
Receive = ""
Response = ""
If (WaitResponse = 1) And (Serial.Ok = 1) Then
Serial.Ok = 0
TimeEnd = Timer + TimeOut
Do
While (LOC(Serial.Handle) > 0)
Sample = INPUT(1, Serial.Handle) 'read one character at a time
If (ASC(Sample) <= 31) Then 'found control code
If Receive <> "" Then
Response = Receive
Exit Do
EndIf
Else
Serial.Ok = 1
Receive = Receive & Sample
End If
Wend
If Timer > TimeEnd THEN
Serial.Ok = 0
Receive = ""
Exit Do
EndIf
sleep 1
Loop While (Timer < timeEnd)
EndIf
Else
Serial.Ok = 0
EndIf
END SUB