The rest of the time the GUI can execute any other code it has to run. keep this function in a corner, it will only be called and executed when a message arrives on the serial line.define a separate function which tells your program what to do when a message is received.Fortunately, the asynchronous communication mode will let you: Unless you have a fancy way of controlling your GUI from the instrument, this is something to avoid. Essentially, it became the Slave and the instrument is the Master. If the main program is a GUI, it is highly frustrating to have a GUI seemingly "frozen" because it won't accept any input from the user. but it cannot do anything else in the meantime. If your main program (or GUI) is constantly "waiting" for message arriving on the serial line, it can do that well. As long as the inclination is above the threshold, it continues to send an inclination reading every 5s. If the device is tilted by more than 15 degrees and get close to horizontal, it sends an alarm message to the serial line, immediately followed by a reading of the inclination. It constantly monitor it's own inclination and as long as it is vertical (within a tolerance, let's say +/-15 degrees), it stays silent. Now suppose I started my instrument, but it is more than just a dumb sensor. (opens new window) # Mode 2: Asynchronous Summary: in this mode, the instrument (the Slave) only send data to the serial line immediately after having been asked by the PC (the Master) This is commonly called an ACK/NACK reply (for "Acknowledge(d)" / "NOT Acknowledged"). The instrument receive the command, execute it, then send a confirmation message back to the serial line: " Command executed" (or " Command NOT executed").The PC sends a command: "Change from mode X to mode Y". The instrument receive the command, take the measurement then send back the measurement value to the serial line: "The inclinometer value is XXX".The PC sends a command: "Give me a measurement now".The instrument does not send anything to the serial port on it's own, it only replies an answer after being asked a question/command by the Master (the PC, your program). It correspond to the case where the PC is the Master and the instrument is the slave. For the 3 examples, the instrument I am connecting to is a circuit board with an inclinometer, which can work in the 3 modes I will be describing below. I'll define 3 different cases to illustrate, from the simplest to the most demanding.
0 Comments
Leave a Reply. |