The following test code depicts the communication between a device and a driver using asynchronous and ASCII based serial communication protocols. The application simulates a driver and device. The user can input commands to the driver which would call for actions from the device.
The two text files Rx and Tx acts as the Rx and Tx of the device. The following picture depicts the wiring diagram of the set up.
The device is a scale which sends stable wight to the driver when requested. The driver sends command S\n to get the stable weight monitored from the scale. The scale once the stable weight is calculated sends the data to the driver.
- Clone the project cd/ to project file.
- Run command npm install to install all node modules.
- Open two powershells.
- Run command npm run start-device on one powershell.
- Run command npm run start-driver on the other powershell.
- You will be able to see that both devices are listening to each other.
- To initiate a the command to the device type S in the terminal of the driver and press enter
- The driver will now send the command S\n to the device.
- Once the device registers the command it will respond back with a weight.
- You can send the command again in driver as before to check the latest weight.
- I did not have time to include the simulation of the parity bit as an extra checker for broken data.
- I would like to add the ability for the device or driver to recognize that there is no connection to either.
- When the scale is sending the data to driver if the driver requests for another weight the device doesnt respond with a busy statement. I would like to invest more time to look at how this can be itegrated.
- If I had time I would look at standardizing the listening and transmitting function so a common function can be used by both device and driver.
- Only the command S/n is available in the driver even though the commands send to the device is coded such that a variable command can be easily integrated. I didnt have time to add more functionality and commands.
- It would be great if I had time to convert speed to baudRate and simulate the baudRate concept.
- When I change the variable "speed" to values less than 300 the data begins to break as the speed of communication increase. I would like to further analyze the issue and see what improvements can be done.
- If I had the time I would have created a set of commands and a documentation for users to refer.
- fs library used for file handling
- readline library used for getting input from user to driver