| |

VerySource

 Forgot password?
 Register
Search
View: 852|Reply: 3

Why is there an error that the port is open?

[Copy link]

2

Threads

2

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

Post time: 2021-3-15 12:00:02
| Show all posts |Read mode
procedure TForm1.FormActivate(Sender: TObject);
begin

     MSComm1.CommPort:=1;
     MSComm1.Settings:='9600,n,8,1';
     MSComm1.InBufferSize:=32;
     MSComm1.OutBufferSize:=2;
     MSComm1.InputMode:=comInputModeBinary;//Set the receiving data mode to binary form
     MSComm1.InputLen := 1; //Set the number of bytes that Input reads from the receive buffer at a time to 1
     MSComm1.InputLen:=1; //Set the number of bytes that Input reads from the receive buffer at a time to 1
     MSComm1.SThreshold:=1; //Set Output to read the number of bytes from the sending buffer at one time to 1
     MSComm1.InBufferCount:=0; //Clear the receive buffer
     MSComm1.OutBufferCount:=0; //Clear the sending buffer
     MSComm1.PortOpen:=true; //Open serial port 1
     
end;

procedure TForm1.ComboBox1Change(Sender: TObject);
begin

     MSComm1.CommPort:=2;
     MSComm1.Settings:='9600,n,8,1';
     MSComm1.InBufferSize:=32;
     MSComm1.OutBufferSize:=2;
     MSComm1.InputMode:=comInputModeBinary;//Set the receiving data mode to binary form
     MSComm1.InputLen := 1; //Set the number of bytes that Input reads from the receive buffer at a time to 1
     MSComm1.InputLen:=1; //Set the number of bytes that Input reads from the receive buffer at a time to 1
     MSComm1.SThreshold:=1; //Set Output to read the number of bytes from the sending buffer at one time to 1
     MSComm1.InBufferCount:=0; //Clear the receive buffer
     MSComm1.OutBufferCount:=0; //Clear the sending buffer
     MSComm1.PortOpen:=true; //Open serial port 1
end;


When I change the drop-down box (ComboBox1Change),
The error that appears is:
Port is open
But I only opened serial port 1 when I initialized.
ComboBox1Change
Is to open the serial port 2

Why not?
Thank you!
Reply

Use magic Report

1

Threads

13

Posts

11.00

Credits

Newbie

Rank: 1

Credits
11.00

 China

Post time: 2021-3-15 15:15:02
| Show all posts
Is ComboBox1Change already called when it is created?
Reply

Use magic Report

0

Threads

8

Posts

9.00

Credits

Newbie

Rank: 1

Credits
9.00

 China

Post time: 2021-3-15 15:30:01
| Show all posts
procedure TForm1.ComboBox1Change(Sender: TObject);
begin
     MSComm1.PortOpen := False; //<<First turn it off and have a look
     MSComm1.CommPort:=2;
//...
     MSComm1.PortOpen:=true; //Open serial port 1
end;
Reply

Use magic Report

1

Threads

3

Posts

4.00

Credits

Newbie

Rank: 1

Credits
4.00

 China

Post time: 2021-3-29 16:44:32
| Show all posts
Thank you! Thank you!
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list