Home > Back-end >  Can't wait, DELPHI serial port to send data
Can't wait, DELPHI serial port to send data

Time:09-30

Using Delphi program SPCOMM controls, used to send and receive data is normal, then somehow there will be a serial port receives the data is not complete, receive part of the code is primarily a
The begin
SetLength (STR, Bufferlength);
Viewstring:=';
Move (buffer ^ rbuf, bufferlength);
//check checksum
If checksum (rbuf bufferlength)=false then
exit;
Below is the check processing part, and sometimes a serial port to send out the data, step through it will prompt the access violation at address 0044 d97e module in such mistakes, I don't know what's going on? Everybody to see, thank you! Here are sending code
Procedure senddata publishes the event (length: integer);
Var
I: integer;
Commflg: Boolean;
The begin
Viewstring:=';
Commflg:=true;
For I:=1 to length do
The begin
If not welcome.com m1. Writecommdata (@ sbuf [I], 1) then
The begin
Commflg:=false;
break;
end;
sleep(2);

Viewstring:=viewstring + inttohex (sbuf [I], 2) + ";
end;
end;

CodePudding user response:

The easiest way to use the serial port tool, to send and receive test, to ensure that no problem of hardware and software

CodePudding user response:

Use serial debugging assistant to send and receive is normal, is to use the software will appear this problem, if you step through an error, the wrong step over and run to create the form again, then may be good, this will be the programming problem?

CodePudding user response:

You send your data, use a serial port debug tool to receive, you see if you actually send data right

CodePudding user response:

A receiving is not all it's ok, may be associated with lower machine to send, such as: the machine is continuously transmitted the data, the PC and sent an instruction to a machine, a machine under general by polling the processing instructions, if processes is not good, may be in continuous transfer when data is inserted into the return instruction, this doesn't matter, as long as the upper machine completes the length check, check check,

Send not go out, a single bad judgment from the code, still need to carefully analyze!

CodePudding user response:

Serial processing speed slow, delay to set up good, I was sleep before (100) or more, you try, and see if it is for this reason

CodePudding user response:

reference 4 floor u012476316 response:
a receiving is not all it's ok, could send related with the machine, such as: the machine is continuously transmitted the data, the PC and sent an instruction to a machine, a machine under general by polling the processing instructions, if processes is not good, may be in continuous transfer when data is inserted into the return instruction, this doesn't matter, as long as the upper machine completes the length check, check check,

Send not go out, a single bad judgment from the code, still need to carefully analyze!

I see in the map on the Internet address to check the location of the program crashes, find out the results of the code is commreceive function below the begin this way, I don't know what's going on?

CodePudding user response:

reference 5 floor luxuewei5214 reply:
serial processing speed slow, delay to set up good, I was sleep before (100) or more, you try to see if this reason

I'll try

CodePudding user response:

CodePudding user response:

refer to 6th floor u010250765 response:
Quote: refer to 4th floor u012476316 response:

A receiving is not all it's ok, may be associated with lower machine to send, such as: the machine is continuously transmitted the data, the PC and sent an instruction to a machine, a machine under general by polling the processing instructions, if processes is not good, may be in continuous transfer when data is inserted into the return instruction, this doesn't matter, as long as the upper machine completes the length check, check check,

Send not go out, a single bad judgment from the code, still need to carefully analyze!

I see in the map on the Internet address to check the location of the program crashes, find out the results of the code is commreceive function below the begin this way, I don't know what's going on?


I generally use TCComp components, SpComm common, online version, stability does not understand,
Serial communication with what components are actually it doesn't matter, but to understand the principle of serial port communication, components are encapsulated Windows serial port communication of several functions,

CodePudding user response:

You can add my QQ chat, I often do serial program!

CodePudding user response:

Try the serial debugging assistant serial port can use!

CodePudding user response:

The
references to the tenth floor u012476316 response:
you can add my QQ chat, I often do serial program!

Too good, I went to the field test all day today, didn't see that behind the Q_ is your number?

CodePudding user response:

Yes!

The
refer to 12 floor u010250765 reply:
Quote: reference to the tenth floor u012476316 response:

You can add my QQ chat, I often do serial program!

Too good, I went to the field test all day today, didn't see that behind the Q_ is your number?

Q_188136923

CodePudding user response:

Me a serial communication program, component TCCom, there is a problem, I use a serial port component opens a serial port equipment, normal communication is no problem,
Users unplug a serial port equipment at this moment, at this moment I can't operate a serial port, serial port component cannot turn off, the operation will be submitted to the "system error"
The program is then died!

My current solution is to check whether the serial port equipment before operation on the computer, because our serial device in the registry have
To register, can solve this problem temporarily,

New problems come, if the user unplug the device, and plug in the device, so my program can detect equipment again, but because comport a serial port interrupt, so
Operation is still an error, the program may hang up,

My solution is now, if a serial port to abnormal, program to automatically after the user some hints, if I were detected with a serial port equipment, is to run an instance,

How can program, in the case of a serial port equipment does not exist, to have previously opened the serial port, normally closed, the program does not hang up?

CodePudding user response:

reference 1st floor wangwei244157887 response:
the most simple way to use a serial port tool first, send and receive test, to ensure that no problem of hardware and software

Now the problem is that when I use serial debugging assistant for data reception, if written in QT serial debugging assistants can receive correctly, but if written in DELPHI serial debugging assistant would be less a byte, 18 bytes of data, can only be received 17, every time is less 14 bytes, don't know what's going on?

CodePudding user response:

Check your BufferLength Settings, whether the buffer is too small ~ ~ ~ ~ ~

CodePudding user response:

On the 14th floor u012476316
reference response:
...
How can program, in the case of a serial port equipment does not exist, to have previously opened the serial port, normally closed, the program does not hang up?

I think this is unlikely,
One way is to you and the good agreement of singlechip processor system, such as the state of detection circuit, a state of high means that a machine connection, but it didn't

CodePudding user response:

reference 15 floor u010250765 response:
Quote: refer to 1st floor wangwei244157887 response:

.
Every time is less 14 bytes, don't know what's going on?

14 bytes should be what word is any bytes are lost or is that a lost

CodePudding user response:

Make a mark! nullnullnullnullnullnull
  • Related