|
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! |
|