First of all, I'm running the program as root so /dev/ttyS0 permissions isn't the issue.
My program first opens the port at 9600 baud in order to send a command to the external device connected
So I open the port and send the command:
Code: Select all
Open Com Command(1) + ":9600,n,8,1,CS0,DS0,CD0,RS" For Binary As #2
If Err > 0 Then
Print "Can't Open Serial Port 1st time. Press Any Key To Exit"
Sleep
Stop
End If
'send reset command
sleep 10
Print #2, "1*219999" ; Chr(13);
Sleep 1000
'close port and reopen at 57600 baud
Close #2
Open Com Command(1) + ":57600,n,8,1,CS0,DS0,CD0,RS," For Binary As #2
If Err > 0 Then
Print "Can't Open Serial Port 2nd time. Press Any Key To Exit"
Sleep
Stop
End If
Sleep 2000
'Wait for device to send "%"
Bretries = 20 'we try 20 times
TESTFORSTART:
Get #2, , InByte
sleep 50 'need delay for some reason
Print "First InByte " ; InByte
If InByte = 37 Then 'did we receive a % or 37 ?
print "We received a start from device"
Print #2 , "{"; 'send byte 123 to bootloader
Sleep 10
Goto PortLoader
Else 'If InpByte = 0 Then
Bretries = Bretries - 1
If Bretries <> 0 Then
Goto TestforStart 'we test again
End If
End If 'we received a %
Print "Timeout waiting for start character. Press Any Key To Exit"
Sleep
Stop
It appears that the problem is that when compiled under Linux, #2 doesn't close and reopen under the new baud rate but rather stays open at 9600 no matter what. Is this a bug or am I doing something wrong?