A kind of exclusive formula collecting method based on CAN
Technical field
The present invention relates to a kind of collecting method, particularly a kind of exclusive formula collecting method based on CAN.
Background technology
In numerous fieldbus, CAN is more next due to having the advantages that prominent reliability, real-time and flexibility
More favored by people, correspondingly, the product demand market based on CAN expands day by day, using also more and more wider
It is general.
Data acquisition is from its exterior gathered data and to be input to a kind of interface skill of internal system using a kind of device
Art, at interval of certain hour(Claim the sampling period)Same point Data duplication is gathered, every field is widely used in.With interconnection
The fast development of net industry, data acquisition has been widely used in internet and field of distributed type, and data acquisition is brought into
One brand-new epoch.
Periodic data acquisition uses the work framework of client/server, and data summarization end is used as client computer, collection
Terminal, when data summarization end needs gathered data, command request, acquisition terminal response is sent to acquisition terminal as server
Command request, returns to the data to be gathered.According to this communication process, within a sampling period, complete remaining to adopt other
Collect the data acquisition of terminal.Its defect is:Within a sampling period, data center sends repeatedly same command request,
In CAN, same acquisition terminal can receive repeatedly same command request, add command processing time, greatly waste
Communication bandwidth.In addition, when acquisition terminal needs to send emergency data, the real-time response time of data center does not know.It is best
Response condition be inquiry specify acquisition terminal when, the terminal just need send emergency data;Worst response condition is
When first acquisition terminal is inquired about, last acquisition terminal needs to send emergency data.
The content of the invention
The technical problems to be solved by the invention are directed to the deficiencies in the prior art, there is provided a kind of in real time, to be efficiently based on
The exclusive formula collecting method of CAN.
The technical problems to be solved by the invention are realized by following technical scheme.The present invention is that one kind is based on
The exclusive formula collecting method of CAN, is characterized in:
The method is the exclusive formula collecting method based on CAN multiple terminals, realizes a set of " data summarization end " and N sets
Data communication between " acquisition terminal ", N is positive integer;Described " data summarization end " and " acquisition terminal " are hard with CAN
The smart machine of part interface and energy configuration processor code characteristic;By a CAN cable between N sets " acquisition terminal ", adopt
With in hand-in-hand mode parallel connection CAN, it is ultimately attached at " data summarization end ";
The collecting method includes:Exclusive " one-to-one " communication of formula;In CAN, " data summarization end " is to specified
" acquisition terminal " of identifier value initiates command request, is only somebody's turn to do the request of " acquisition terminal " response command, and return to response data;
Exclusive formula " one-to-many " polling communication;By configuring " father's terminal ", " data summarization end " need to only send a subcommand please
Seek the data acquisition that can just complete a cycle;
Urgency communication;The mutual cooperation method of " urgent position " and " command code " two kinds of flag bits is devised, by different situations
The priority of lower adjustment message, it is ensured that the real-time transmission and response of emergency data.
A kind of exclusive formula collecting method based on CAN of the present invention, its further preferred technical side
Case is:Described smart machine is PC computers.
A kind of exclusive formula collecting method based on CAN of the present invention, its further preferred technical side
Case is:The method supports the CAN hardware of CAN 2.0A or CAN2.0B agreements;M bit identifiers, Y >=M >=3, for CAN are used
2.0A hardware, Y is equal to 11, and for CAN 2.0B hardware, Y is equal to 29;Identifier is stored in the identifier domain of CAN message.
A kind of exclusive formula collecting method based on CAN of the present invention, its further preferred technical side
Case is:The identifier of " data summarization end " and " acquisition terminal " use different numerical value, and " data summarization end " identifier number
Value is minimum;Define identifier minimum one is urgent position, is defaulted as " 1 " and represents normal condition communication, and " 0 " represents urgent number
According to communication;Using the bit (M-2) of identifier | bit (M-1) two is used as command code;Bit0 represents the lowest order of identifier, bit
(M-1)Represent the highest order of identifier.
A kind of exclusive formula collecting method based on CAN of the present invention, its further preferred technical side
Case is:Using following methods definition command code in " data summarization end ":
(1)" 11b " represents that data summarization end sends data polling order, and since request returned successively specifying x-th acquisition terminal
Each data acquisition of terminal is returned, x is the identifier of the acquisition terminal, and x is stored in the data field of CAN message;
(2)" 10b " represents that data summarization end sends particular command and asks to x-th acquisition terminal, and x is the mark of the acquisition terminal
Symbol, x is stored in the data field of CAN message with particular command request;
Using following methods definition command code in " acquisition terminal ":
" 11b " data polling command request that A, " 11b " and " 10b " expression " acquisition terminal " response " data summarization end " send;
The data is activation that wherein " 10b " represents current is not over;The data is activation that " 11b " represents current is over;
B, urgent position be " 1 " when, " 10b " that " 00b " and " 01b " expression " acquisition terminal " response " data summarization end " sends
Particular command is asked;The data is activation that wherein " 00b " represents current is not over;" 01b " represents current data is activation
Through terminating;
(3)When urgent position is " 0 ", " 00b " and " 01b " expression " acquisition terminal " sends provisional orders to " data summarization end " please
Ask;The data is activation that wherein " 00b " represents current is not over;The data is activation that " 01b " represents current is over.
A kind of exclusive formula collecting method based on CAN of the present invention, its further preferred technical side
Case is:The method is initiated using exclusive formula One-to-one communication, i.e. data summarization end to the acquisition terminal with designated identification identifier value
Command request, only the acquisition terminal response command are asked, and return to response data;Configuration father's terminal procedures belong to one-to-one logical
Letter, data summarization end sends " 10b " command request bag, identifier is contained in the data field of command request bag to specified acquisition terminal
There is value, command request the acquisition terminal of the identifier value to be configured to father's terminal of the terminal, and the terminal receives order please
After asking, response configuration is carried out, configuration result is reported and gives data summarization end;Configuration father's terminal is realized and allows the acquisition terminal can be with
The CAN message from father's terminal is received, for the one-to-many polling communication of the formula of monopolizing.
A kind of exclusive formula collecting method based on CAN of the present invention, its further preferred technical side
Case is:The method is using exclusive formula " one-to-many " polling communication:" data summarization end " initiates inquiry to multiple " acquisition terminals " please
Ask, it is desirable to which they return to respective gathered data " data summarization end ", " one-to-many " communication is periodic data communication
Process;In " one-to-many " communication cycle, " data summarization end " need to only send a command request, multiple " acquisition terminals "
Respond successively, return to the gathered data of this terminal;
(1)" data summarization end " includes " acquisition terminal to " 11b " command request is sent in CAN in the data field of message
The identifier value of 1# ", it is desirable to which " acquisition terminal 1# " returns to its gathered data;
(2)All " acquisition terminals " in CAN can receive " 11b " the command request message at " data summarization end ",
By judging the identifier value in message data domain, " acquisition terminal 1# " meets requirement, its response command request, to " data summarization
End " returns to gathered data, and other " acquisition terminals " ignores the command message;
(3)" acquisition terminal 1# " is " father's terminal " of " acquisition terminal 2# ", and " acquisition terminal 2# " can simultaneously receive " collection
The response message of terminal 1# ", " acquisition terminal 1# " judge identifier in message urgent position whether " 0 ", if " 0 ", then neglect
The slightly message;In this way " 1 ", then it is handled as follows by recognizing " command code " of identifier in response message again:
(i)When " command code " is non-" 11b ", " acquisition terminal 2# " ignores the message, does not process;
(ii)When " command code " is " 11b ", " acquisition terminal 2# " returns to itself gathered data to " data summarization end ";
And other " acquisition terminals " then directly ignores the response message of " acquisition terminal 1# ", do not process;
(4)" acquisition terminal 2# " is " father's terminal " of " acquisition terminal 3# ", and " acquisition terminal 3# " can simultaneously be received and " gathered eventually
End 2# " response message, " acquisition terminal 2# " judge identifier in message urgent position whether " 0 " ", if " 0 ", then ignore
The message;In this way " 1 ", then it is handled as follows by recognizing " command code " of identifier in response message again:
(i)When " command code " is non-" 11b ", " acquisition terminal 2# " ignores the message, does not process;
(ii)When " command code " is " 11b ", " acquisition terminal 2# " returns to itself gathered data to " data summarization end ";
And other " acquisition terminals " then directly ignores the response message of " acquisition terminal 2# ", do not process;
(5)By that analogy, last " acquisition terminal N# " returns to gathered data to " data summarization end ", completes a week
The data acquisition of phase.
A kind of exclusive formula collecting method based on CAN of the present invention, its further preferred technical side
Case is:" urgency communication " of the method is that " acquisition terminal " actively sends data to " data summarization end ";" acquisition terminal a " needs
During urgency communication, " the urgent position " of identifier is set to " 0 ", the priority of the polling communication that compares, " acquisition terminal a " has more
High priority, therefore periodic polling communication process will be interrupted, it is ensured that emergency data is preferentially passed at " data summarization end ";
" the urgent position " that self identification is accorded with is set to " 0 ", now " data summarization end " by " data summarization end " after urgent messages are received
Message will be with limit priority, when the emergency data for also having other " acquisition terminals " in CAN will send, it will quilt
Transmission process is interrupted, after waiting a response message to be sent to " acquisition terminal a " at first, " acquisition terminal " being interrupted could continue hair
Send data;
By that analogy, the urgency communication process of other-end is completed.
When in extreme circumstances, having multiple " acquisition terminals " while there is exception, urgent report is sent to " data summarization end "
Text, now CAN can enter arbitration mechanism, send data successively according to the height of priority;" data summarization end " is receiving
To after urgent messages, " the urgent position " that self identification is accorded with is set to " 0 ", now the message at " data summarization end " will be excellent with highest
Response message, corresponding " acquisition terminal " is sent to according to the order for receiving urgent messages by first level successively, finally completes whole
The urgency communication of " acquisition terminal ".
Compared with prior art, the present invention and the present invention for further designing have following remarkable advantage:
1st, " data summarization end " and " acquisition terminal " preferably PC but is not limited to PC, with described CAN hardware interfaces and
The smart machine of energy configuration processor code characteristic all meets technical requirements, has a wide range of application.
2nd, can support greater number of " acquisition terminal ", performance boost decades of times, and " acquisition terminal " quantity is more, adopts
It is more obvious with technique effect of the invention.
3rd, the real-time response ability to emergency data is strong, and using the technology of the present invention, " acquisition terminal " is withouted waiting for can
Directly to send emergency data requirement treatment.Even if in extreme circumstances, having m " acquisition terminal " while requiring to send urgent number
According to " acquisition terminal " of lowest priority is most long to be needed to wait(m-1)The time of × 0.4ms(With the rate calculations of 250kb/s).
Brief description of the drawings
Fig. 1 is a kind of data acquisition modes classification of exclusive formula collecting method based on CAN of the present invention;
Fig. 2 is a kind of hardware structure diagram of the invention;
Fig. 3 is the identifier definition figure of CAN message;
Fig. 4 is the communication process figure of exclusive formula " one-to-many " polling communication;
Fig. 5 initiates the communication process figure of urgency communication when being many " acquisition terminals " difference corresponding to urgency communication;
Fig. 6 is many " acquisition terminals " corresponding to urgency communication while initiating the communication process figure of urgency communication.
Specific embodiment
Referring to the drawings, concrete technical scheme of the invention is further described, is entered in order to those skilled in the art
One step ground understands the present invention, without constituting the limitation to its right.
Reference picture 1, a kind of exclusive formula collecting method based on CAN, the method is based on CAN multiple terminals
Exclusive formula collecting method, realize the data communication between a set of " data summarization end " and N sets " acquisition terminal ", N is for just
Integer;Described " data summarization end " and " acquisition terminal " are the intelligence with CAN hardware interfaces and energy configuration processor code characteristic
Can equipment;By a CAN cable between N sets " acquisition terminal ", using in hand-in-hand mode parallel connection CAN, most
It is connected to eventually at " data summarization end ".
The method includes:
Exclusive " one-to-one " communication of formula, in CAN, " data summarization end " is to " acquisition terminal " with designated identification identifier value
Command request is initiated, the request of " acquisition terminal " response command is only somebody's turn to do, and return to response data;
Exclusive formula " one-to-many " polling communication, by configuring " father's terminal ", " data summarization end " need to only send a subcommand please
Seek the data acquisition that can just complete a cycle;
Urgency communication, devises the mutual cooperation method of " urgent position " and " command code " two kinds of flag bits, by different situations
The priority of lower adjustment message, it is ensured that the real-time transmission and response of emergency data.
Reference picture 2, a kind of exclusive formula collecting method based on CAN:Support CAN 2.0A or CAN 2.0B associations
The CAN hardware of view.Overall hardware configuration includes:CAN, N number of " acquisition terminal " and a data summarization end, and should all support
CAN 2.0A or CAN 2.0B agreements.
Reference picture 3, uses M bit identifiers(Y≥M≥3), for CAN 2.0A hardware, Y is equal to 11, for CAN 2.0B
Hardware, Y is equal to 29.Identifier is stored in the identifier domain of CAN message.
A minimum bit0 of identifier is urgent position, and default value is " 1 ", represents normal condition communication, and value " 0 " represents tight
Anxious data communication;The highest one of identifier is bit(M-1), use minimum two bit of identifier(M-2)| bit(M-1)
As command code.
The identifier of " data summarization end " and " acquisition terminal " uses different numerical value, and " data summarization end " identifier
Numerical value is minimum.The priority of message is determined that identifier value is smaller by identifier value, and priority is higher, with preferential total using CAN
The right of line.
The mutual cooperation method of " urgent position " and " command code " flag bit according to this principle design.The following is to command code
Using definition:
(1)The definition of command code is used in " data summarization end ":
" 11b " expression " data summarization end " sends data polling order, asks since x-th " acquisition terminal " is specified, successively
Each data acquisition of terminal is returned to, x is the identifier for being somebody's turn to do " acquisition terminal ", and x is stored in the data field of CAN message.
" 10b " expression " data summarization end " sends particular command and asks to x-th " acquisition terminal ", and " collection is eventually to be somebody's turn to do for x
The identifier at end ", x is stored in the data field of CAN message with particular command request.
(2)The definition of command code is used in " acquisition terminal ":
" 11b " data polling command request that " 11b " and " 10b " expression " acquisition terminal " response " data summarization end " sends.Its
In " 10b " represent that current data is activation is not over;The data is activation that " 11b " represents current is over.
When urgent position is " 1 ", " 10b " that " 00b " and " 01b " expression " acquisition terminal " response " data summarization end " sends
Particular command is asked.The data is activation that wherein " 00b " represents current is not over;" 01b " represents current data is activation
Through terminating.
When urgent position is " 0 ", " 00b " and " 01b " expression " acquisition terminal " sends provisional orders to " data summarization end "
Request.The data is activation that wherein " 00b " represents current is not over;The data is activation that " 01b " represents current is over.
Reference picture 3-4, monopolizes formula " one-to-many " polling communication, and its step is as follows:
Step one:" data summarization end " includes in the data field of message and " gathers eventually to " 11b " command request is sent in CAN
The identifier value of end 1# ", it is desirable to which " acquisition terminal 1# " returns to its gathered data;
Step 2:All " acquisition terminals " in CAN can all receive " data summarization end " " 11b " command request report
Text, by judging the identifier value in message data domain, " acquisition terminal 1# " meets requirement, its response command request, to " data are converged
Total end " returns to gathered data, and other " acquisition terminals " ignores the command message;
Step 3:" acquisition terminal " 1# " is " father's terminal " of " acquisition terminal 2# ", and " acquisition terminal 2# " can be received simultaneously
The response message of " acquisition terminal 1# ", " acquisition terminal 1# " judge identifier in message urgent position whether " 0 ", if " 0 ",
Then ignore the message;In this way " 1 ", then it is handled as follows by recognizing " command code " of identifier in response message again:
(1)When " command code " is non-" 11b ", " acquisition terminal 2# " ignores the message, does not process;
(2)When " command code " is " 11b ", " acquisition terminal 2# " returns to itself gathered data to " data summarization end ";Other " collections
Terminal " then ignores the response message of " acquisition terminal 1# ", does not deal with;
Step 4:The process as described in step 3, last " acquisition terminal N " is returned to " data summarization end " and gathered
Data, that is, complete the data acquisition of a cycle.
Wherein, the configuration process of described " father's terminal " belongs to " one-to-one " communication." data summarization end " " adopts to specified
Collection terminal " sends " 10b " command request bag, and identifier value is contained in the data field of command request bag, and command request is with the mark
" acquisition terminal " of identifier value is configured to " father's terminal " of the terminal, after the terminal receives command request, carries out response and matches somebody with somebody
Put, configuration result is reported to " data summarization end ".Configuration " father's terminal " is come to allow " acquisition terminal " can receive
The CAN message of " father's terminal ", so as to be applied to exclusive formula " one-to-many " polling communication.
Reference picture 5-6, described urgency communication, its step is as follows:
(1)The identifier " urgent position " of transmitted message is set to " 0 " by " acquisition terminal ", to obtain current highest priority;
(2)After " data summarization end " receives message, the transmitted identifier " urgent position " for obtaining response message is set to " 0 ", to take
Obtain limit priority, it is ensured that the real-time transmission and response of emergency data.
Reference picture 5, urgency communication is that " acquisition terminal " actively sends data to " data summarization end ", and " acquisition terminal a " is needed
When wanting urgency communication, " the urgent position " of identifier is set to " 0 ", the priority of the polling communication that compares, " acquisition terminal a " has
Higher priority, therefore periodic polling communication process will be interrupted, it is ensured that emergency data preferentially passes to " data summarization
End "." the urgent position " that self identification is accorded with is set to " 0 " by " data summarization end " after urgent messages are received, and now " data are converged
The message at total end " will will send with limit priority, the emergency data for also having other " acquisition terminals " such as in CAN,
Transmission process will be interrupted, after waiting a response message to be sent to " acquisition terminal a " at first, " acquisition terminal " ability being interrupted
Continue to send data.By that analogy, the urgency communication process of other-end is completed.
Reference picture 6, in extreme circumstances, has multiple " acquisition terminals " while there is exception, is sent out to " data summarization end "
Urgent messages are sent, now CAN can enter arbitration mechanism, and data are sent successively according to the height of priority." data summarization
" the urgent position " that self identification is accorded with is set to " 0 " by end " after urgent messages are received, and now the message at " data summarization end " will
With limit priority, response message is sent to corresponding " acquisition terminal " successively according to the order for receiving urgent messages, most
The urgency communication of all " acquisition terminal " is completed afterwards.In this way, can make the acquisition terminal of different priorities can be
Emergency data is reported to " data summarization end " and priority treatment is obtained in shortest time.