Add and delete bulk channels

Python

Code to add or remove channel data displayed in the line profile. [dependency] - SmartRemote

main 1 file
Add and delete …..py
control_bulk_channel.py 1.9 KB
Add and delete …..py 1955 bytes
from json import dumps
from SmartRemote import SmartRemote

class ControlBulkChannel:

    def __init__(self):
        self.__sr = SmartRemote()
        
    def clear_channels(self):
        """ Clearing all channels"""
        mesg=( 
            "chs = spm.scan.channels.names() \n\
            for (var i=0; i < chs.length; i++){ \n\
            print('Remove: '+chs[i]) \n\
            spm.scan.channels.remove(chs[i]) \n\
            }"
            )
        reply = self.__sr.run(mesg)
        return reply['result']

    def add_channel_unit(self, ch:str='ChannelZHeight',unit:str='um'):
        """Add channles with unit
        
        Args:
            ch (str, optional): channel name. Defaults to 'ChannelZHeight.
            unit (str, optional): channel unit. Defaults to 'um'
        """
        channel = {'name': ch, 'unit':unit}
        json_channel = dumps(channel,indent=2)      
        reply = self.__sr.run(f"spm.scan.channels.add({json_channel})")
        return reply['result']

    def add_channel(self, ch:str='ChannelZHeight'):
        """Add channles
        
        Args:
            ch (str, optional): channel name. Defaults to 'ChannelZHeight.
        """
        reply = self.__sr.run(f"spm.scan.channels.add(\'{ch}\')")
        return reply['result']

    def remove_channel(self,ch:str='ChannelZHeight'):
        """Delete channles
        
        Args:
            ch (str, optional): channel name. Defaults to 'ChannelZHeight.
        
        """
        reply = self.__sr.run(f'spm.scan.channels.remove(\'{ch}\')')
        return reply['result']
    
if __name__ == "__main__":
    ch_handler = ControlBulkChannel()
    ch_handler.clear_channels()
    ch_handler.add_channel_unit('ChannelZHeight','nm')
    ch_handler.add_channel('ChannelErrorSignal')
    ch_handler.add_channel('ChannelNcmAmplitude')
    ch_handler.remove_channel('ChannelNcmAmplitude')
Comments (0)

No comments yet. Be the first to comment!

Snippet Information
Author: jungyu.lee
Language: Python
Created: Oct 23, 2025
Updated: 0 minutes ago
Views: 39
Stars: 1

Links & Files

Additional Files (1):