add serial function from irtoy  code