Master-slave card system and method for operating the same

A master-slave card system includes a master card and a plurality of slave cards connected in serial. The master card sends a command with a station-number information to the slave cards. A selected slave card designated by the station-number information sends back a response message, where the response message includes an initial packet, a plurality of data packets and a CRC check packet. The master card sends a next command to a next slave cards after the master cards identifies a correct initial packet. When the initial packet is not correct, the master card halts sending the next command until the received signal is already stopped for a predetermined silence time. The master card drops all the data packets if the CRC check packet associated with the data packet is not correct.

BACKGROUND OF THE INVENTION

1. Field of the Invention

The present invention relates to a master-slave card system and method for operating the same, especially to a master-slave card system using polling scheme to convey command to the slave cards and method for operating the same.

2. Description of Prior Art

The conventional master-slave card system utilizes interconnected digital input and output points (DI/O) for communicating signals among master card and slave card. A related-art master-slave card system integrates all of the digital input and output points (DI/O) on a single circuit board. However, it could induce a mess if lots of digital input and output points (DI/O) are provided on the same circuit board. Moreover, the layout of the digital input and output points (DI/O) is predetermined in the beginning of manufacture of the circuit board. Therefore, the number of the digital input and output points (DI/O) may be excessive and cost is increased. Alternatively, the number of the digital input and output points (DI/O) may be insufficient and it is inconvenient for user. Another related-art master-slave card system utilizes serial communication for the I/O control of the digital input and output points (DI/O) and a half-duplex scheme is used for the communication therebetween. In the half-duplex scheme, the master card and slave card cannot send their signal to each other simultaneously. Therefore, unwanted delay occurs and the signal cannot be transmitted in real time manner.

Therefore, it is desirable to provide a more flexible connection of remote digital input and output points (DI/O) for a local master card.

SUMMARY OF THE INVENTION

It is the object of the present invention to provide a master-slave card system using polling scheme to convey command to the slave cards and method for operating the same.

Accordingly, the present invention provides a master-slave card system and method for operating the same. The master-slave card system includes a master card and a plurality of slave cards connected in serial. The master card sends a command with a station-number information to the slave cards. A selected slave card designated by the station-number information sends back a response message, where the response message includes an initial packet, a plurality of data packets and a CRC check packet. The master card sends a next command to a next slave cards after the master cards identifies a correct initial packet. When the initial packet is not correct, the master card halts sending the next command until the received signal is already stopped for a predetermined silence time. The master card drops all the data packets if the CRC check packet associated with the data packet is not correct. The master card can access optional slave cards through this operating method by polling the slave cards and designating station number. Therefore, digital input/output connections can be flexibly accessed by the master card.

DETAILED DESCRIPTION OF THE INVENTION

FIG. 1shows the schematic diagram of the master-slave card system according to a preferred embodiment of the present invention. The master-slave card system comprises a master card10and a plurality of slave cards20A,20B and20C, wherein the master card10and the slave cards are connected in serial through two connection lines40and42. More, particularly, in this preferred embodiment of the present invention, there are a first slave card20A, a second slave card20B and a third slave card20C. It should be noted that the master-slave card system according to the present invention can be applied to slave cards with various number without departing from the scope of the present invention.

The connection lines40and42comprises a TX connection line40for conveying the command of the master card10, and an RX connection line42for conveying the response message from the first slave card20A, the second slave card20B and the third slave card20C to the master card10. The master card10mainly comprises a master processor12and master digital input and output points (master DI/O)14connected to the master processor12. The slave card, for example, the first slave card20A comprises a first slave processor22A, a first slave digital input and output points (first slave DI/O)24A electrically connected to the first slave processor22A, and a first station number switch26A electrically connected to the first slave processor22A. Similarly, the second slave card20B comprises a second slave processor22B, a second slave digital input and output points (second slave DI/O)24B electrically connected to the second slave processor22B, and a second station number switch26B electrically connected to the second slave processor22B. The third slave card20C comprises a third slave processor22C, a third slave digital input and output points (third slave DI/O)24C electrically connected to the third slave processor22C, and a third station number switch26C electrically connected to the third slave processor22C. In above-described master-slave card system, the station number switch26A-26C, for example, can be dip switch to set up the station number for each slave card. The slave processor22A-22C, for example, can be programmable logic device (PLD) to provide fast hardware process and easy software maintenance. The first slave DI/O24A, the second slave DI/O24B and the third slave DI/O24C are remote DI/O for the master card10and can expand I/O number for the master card10.

In above-mentioned master-slave card system, the master card10sends commands thereof to the first slave card20A, the second slave card20B and the third slave card20C in polling manner trough the TX connection line40. The master card10receives response messages from the first slave card20A, the second slave card20B and the third slave card20C trough the RX connection line42. In this way, the master card10can access remote DI/O. Moreover, each of the first slave card20A, the second slave card20B and the third slave card20C can set up its own station number by the station number switch26A-26C, respectively. The command sent by the master card10also contains information about the station number to designate one of the slave cards20A-20C. Therefore, the slave cards20A-20C can identify whether the command sent from the master card10is for themselves.

FIG. 2is a schematic view to explain the way in which the master card10polls each of the first slave card20A, the second slave card20B and the third slave card20C. The master card10sends command composed of multiple packets to the first slave card20A, the second slave card20B and the third slave card20C, respectively, through the TX connection line40. Each of the first slave card20A, the second slave card20B and the third slave card20C decides to response the command or not to response the command according to the station number contained in the command. The master card10sends command to a next slave board if the master card10can identify station number for a currently-accessed slave board in response packets from the currently-accessed slave board. For example, the master card10first sends command with associated station number to the first slave card20A (the currently-accessed slave board), and the master card10will not send command to the second slave card20B (the next slave board) until the master card10identifies the right station number for the first slave card20A from the response packets of the first slave card20A. Therefore, the master card10sends command to the second slave card20B while the master card10keeps receiving packets from the first slave card20A. In this way, the transmission efficiency for the master-slave card system can be enhanced.

FIG. 3Ashows the packet format for the command of the master card10.FIG. 3Bshows the packet format for the response message of the slave cards. With reference toFIG. 3A, the command of the master card10comprises an initial packet50, four data packets52A-52D, and a CRC check packet54. With reference toFIG. 3B, the response message of the slave card comprises an initial packet60, four data packets62A-62D, and a CRC check packet64.

FIGS. 4A,4B and4C show the data structure for the initial packet50, data packet, and the CRC check packet54, respectively. As shown inFIG. 4A, the initial packet50has format compatible to UART format and comprises a start bit500, a stop bit508, and eight data bits which comprises ID code502(3 bits), reserved code504(2 bits) and station number information506(3 bits). As shown inFIG. 4B, the data packet comprises a start bit520, a stop bit524, and eight message data bits522. As shown inFIG. 4C, the CRC check packet54comprises a start bit540, a stop bit544, and eight CRC check bits542. Moreover, the response message from the slave card has the similar data structure as those shown inFIGS. 4A to 4C. Therefore, the detailed description for the data structure of the response message from the slave card is omitted here for clarity. Moreover, the packets in the command and the response message have the same length (bit number) to reduce processing complexity and enhance processing efficiency.

FIG. 5is a schematic view for illustrating how the master card10processes initial packet in the response message from slave card. The master card10halts sending the next command when the initial packet in the response message from slave card is not correct, for example, the station number information in the initial packet in the response message form the currently-accessed slave card is wrong. The master card10halts sending the next command until the master card10judges that it receives a correct initial packet in the response message. Alternatively, the master card10halts sending the next command until the received signal from the currently-accessed slave card is already stopped for a predetermined silence time.

FIG. 6is a schematic view for illustrating how the master card10processes CRC check packet in the response message from the slave card. The master card10drops the data packets62A-62D corresponding to a CRC check packet64when the CRC check is judged to be incorrect. As shown in this figure, the data packets62A-62D are, for example, the data sent from the first slave card20A. Afterward, the master card10further sends command to another slave card.

FIG. 7shows the flowchart for the operation of the master-slave card system of the present invention. The master card10first sends a command to a slave card (such as the first slave card20A) and waits response from the slave card in step S100. When the master card10receives a response message from the first slave card20A (step102), the master card10judges whether the response message from the first slave card20A contains a correct initial packet (step110). When the response message from the first slave card20A contains a correct initial packet, the master card10sends another command to a next slave card (such as the second slave card20B) in step S112. When the initial packet in the response message from the first slave card20A is not correct, the master card10keeps receiving packet from the first slave card20A in step S114and then checks whether it receives the correct initial packet in step S116. When the initial packet is judged to be correct in step S116, the procedure proceeds to step112wherein the master card10sends another command to a next slave card. Alternatively, the master card10halts sending the next command and judges whether the received signal from the first slave card20A is already stopped for a predetermined silence time in step S118. If false, the procedure proceeds to step S114, else the procedure proceeds to step S112. After step S112, the master card10judges whether the CRC check packet of the first slave card20A is correct in step S120. If the CRC check packet is not correct, the master card10drops the response message of the first slave card20A in step S122and then continues polling other slave cards in step S130.

The advantages of the present invention can be summarized as follows:

1. The number of digital input/output points can be flexibly expanded by setting station number information for the slave card and serially connecting the master care and the slave cards.

2. The master card polls the slave card sequentially. The master card sends command to a next slave card when the initial packet in the response message of a currently-accessed slave card is correct. Therefore, the polling time for overall system can be reduced and the transmission efficiency is enhanced.