Skip to content

Provide mock serial interfaces suitable for testing

Notifications You must be signed in to change notification settings

joranbeasley/SerialMock

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

49 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

SerialMock

Build Status

A library to mock serial ports... designed with developers in mind.

In order to create a mock serial port you must know enough about its protocol to replicate it to some extent

import sys
from serial_mock import Serial,serial_query

class MyRS232Device(Serial):
     #this will provide interfaces "get offset","set offset <value>"
     data = {"offset":0.5}
     current_reading = 3.1
     @serial_query
     def get_reading(self,output="mV"):
        """
        this provices a serial interface for "get reading\r" or "get reading pH\r"
        it will return the current_reading+offset
        :param str output: one of "mV" or "pH" or None
        """
        return self.current_reading + float(self.offset)
if __name__ == "__main__":
    # pass in "COM99" or something on the command line
    MyRS232Device(sys.argv[1]).MainLoop()
     

About

Provide mock serial interfaces suitable for testing

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages