Skip to content

How Can I Create Serial Device Emulator with Serial Port Mock in v10.x? #2499

Answered by jerrens
jerrens asked this question in Q&A
Discussion options

You must be logged in to vote

I've been able to create an emulator. I'm not sure it is the most elegant solution, but it works. The approach I've used might not be future-compatible as SerialPort moves on to newer versions (specifically changes made to MockBinding and MockPortBinding, so for reference, the below is using v10.4.0.

My demo project is in JavaScript and not TypeScript, so I grabbed the transpiled js file from @serialport/binding-mock as my base code, and trimmed down and modified from there.

In the MockBinding definition, the only change I made was to add a section at the end of the open method that looked for an emulator field to be defined in the openOptions:

// If an emulator command handler (method) w…

Replies: 2 comments 2 replies

Comment options

You must be logged in to vote
2 replies
@reconbot
Comment options

@jerrens
Comment options

Comment options

You must be logged in to vote
0 replies
Answer selected by jerrens
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants